001/*
002 * (C) Copyright 2011 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Thomas Roger <troger@nuxeo.com>
016 */
017
018package org.nuxeo.ecm.localconf;
019
020import java.util.Map;
021
022import org.nuxeo.ecm.core.api.localconfiguration.LocalConfiguration;
023
024/**
025 * An object that maps keys to values.
026 * <p>
027 * The mappings can be stored on documents with the facet {@code SimpleConfiguration}.
028 *
029 * @author <a href="mailto:troger@nuxeo.com">Thomas Roger</a>
030 * @since 5.5
031 */
032public interface SimpleConfiguration extends LocalConfiguration<SimpleConfiguration> {
033
034    String SIMPLE_CONFIGURATION_FACET = "SimpleConfiguration";
035
036    String SIMPLE_CONFIGURATION_SCHEMA = "simpleconfiguration";
037
038    String SIMPLE_CONFIGURATION_PARAMETERS_PROPERTY = "sconf:simpleconfigurationparameters";
039
040    String SIMPLE_CONFIGURATION_PARAMETER_KEY = "key";
041
042    String SIMPLE_CONFIGURATION_PARAMETER_VALUE = "value";
043
044    /**
045     * Returns the value to which the specified {@code key} is mapped, or {@code null} if there is no mapping for the
046     * {@code key}.
047     *
048     * @param key the key whose associated value is to be returned
049     */
050    String get(String key);
051
052    /**
053     * Returns the value to which the specified key is mapped, or the given default value if there is no mapping for the
054     * key.
055     *
056     * @param key the key whose associated value is to be returned
057     * @param defaultValue the value returned if there is no mapping for the key
058     */
059    String get(String key, String defaultValue);
060
061    /**
062     * Associates the specified value with the specified key.
063     * <p>
064     * If the map previously contained a mapping for the key, the old value is replaced by the specified value.
065     *
066     * @param key key with which the specified value is to be associated
067     * @param value value to be associated with the specified key
068     * @return the previous value associated with {@code key}, or {@code null} if there was no mapping for {@code key}.
069     */
070    String put(String key, String value);
071
072    /**
073     * Copies all of the parameters from the specified map to this Simple configuration
074     *
075     * @param parameters parameters to be stored in this Simple configuration
076     */
077    void putAll(Map<String, String> parameters);
078
079}