001/*
002 * (C) Copyright 2011 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Thomas Roger <troger@nuxeo.com>
018 */
019
020package org.nuxeo.ecm.localconf;
021
022import java.util.Map;
023
024import org.nuxeo.ecm.core.api.localconfiguration.LocalConfiguration;
025
026/**
027 * An object that maps keys to values.
028 * <p>
029 * The mappings can be stored on documents with the facet {@code SimpleConfiguration}.
030 *
031 * @author <a href="mailto:troger@nuxeo.com">Thomas Roger</a>
032 * @since 5.5
033 */
034public interface SimpleConfiguration extends LocalConfiguration<SimpleConfiguration> {
035
036    String SIMPLE_CONFIGURATION_FACET = "SimpleConfiguration";
037
038    String SIMPLE_CONFIGURATION_SCHEMA = "simpleconfiguration";
039
040    String SIMPLE_CONFIGURATION_PARAMETERS_PROPERTY = "sconf:simpleconfigurationparameters";
041
042    String SIMPLE_CONFIGURATION_PARAMETER_KEY = "key";
043
044    String SIMPLE_CONFIGURATION_PARAMETER_VALUE = "value";
045
046    /**
047     * Returns the value to which the specified {@code key} is mapped, or {@code null} if there is no mapping for the
048     * {@code key}.
049     *
050     * @param key the key whose associated value is to be returned
051     */
052    String get(String key);
053
054    /**
055     * Returns the value to which the specified key is mapped, or the given default value if there is no mapping for the
056     * key.
057     *
058     * @param key the key whose associated value is to be returned
059     * @param defaultValue the value returned if there is no mapping for the key
060     */
061    String get(String key, String defaultValue);
062
063    /**
064     * Associates the specified value with the specified key.
065     * <p>
066     * If the map previously contained a mapping for the key, the old value is replaced by the specified value.
067     *
068     * @param key key with which the specified value is to be associated
069     * @param value value to be associated with the specified key
070     * @return the previous value associated with {@code key}, or {@code null} if there was no mapping for {@code key}.
071     */
072    String put(String key, String value);
073
074    /**
075     * Copies all of the parameters from the specified map to this Simple configuration
076     *
077     * @param parameters parameters to be stored in this Simple configuration
078     */
079    void putAll(Map<String, String> parameters);
080
081}