Class SubsetConfiguration

    • Field Detail

      • parent

        protected Configuration parent
        The parent configuration.
      • prefix

        protected java.lang.String prefix
        The prefix used to select the properties.
      • delimiter

        protected java.lang.String delimiter
        The prefix delimiter
    • Constructor Detail

      • SubsetConfiguration

        public SubsetConfiguration​(Configuration parent,
                                   java.lang.String prefix)
        Create a subset of the specified configuration
        Parameters:
        parent - The parent configuration (must not be null)
        prefix - The prefix used to select the properties
        Throws:
        java.lang.IllegalArgumentException - if the parent configuration is null
      • SubsetConfiguration

        public SubsetConfiguration​(Configuration parent,
                                   java.lang.String prefix,
                                   java.lang.String delimiter)
        Create a subset of the specified configuration
        Parameters:
        parent - The parent configuration (must not be null)
        prefix - The prefix used to select the properties
        delimiter - The prefix delimiter
        Throws:
        java.lang.IllegalArgumentException - if the parent configuration is null
    • Method Detail

      • getParentKey

        protected java.lang.String getParentKey​(java.lang.String key)
        Return the key in the parent configuration associated to the specified key in this subset.
        Parameters:
        key - The key in the subset.
        Returns:
        the key as to be used by the parent
      • getChildKey

        protected java.lang.String getChildKey​(java.lang.String key)
        Return the key in the subset configuration associated to the specified key in the parent configuration.
        Parameters:
        key - The key in the parent configuration.
        Returns:
        the key in the context of this subset configuration
      • getParent

        public Configuration getParent()
        Return the parent configuration for this subset.
        Returns:
        the parent configuration
      • getPrefix

        public java.lang.String getPrefix()
        Return the prefix used to select the properties in the parent configuration.
        Returns:
        the prefix used by this subset
      • setPrefix

        public void setPrefix​(java.lang.String prefix)
        Set the prefix used to select the properties in the parent configuration.
        Parameters:
        prefix - the prefix
      • subset

        public Configuration subset​(java.lang.String prefix)
        Description copied from interface: Configuration
        Return a decorator Configuration containing every key from the current Configuration that starts with the specified prefix. The prefix is removed from the keys in the subset. For example, if the configuration contains the following properties:
            prefix.number = 1
            prefix.string = Apache
            prefixed.foo = bar
            prefix = Jakarta
         
        the Configuration returned by subset("prefix") will contain the properties:
            number = 1
            string = Apache
            = Jakarta
         
        (The key for the value "Jakarta" is an empty string)

        Since the subset is a decorator and not a modified copy of the initial Configuration, any change made to the subset is available to the Configuration, and reciprocally.

        Specified by:
        subset in interface Configuration
        Overrides:
        subset in class AbstractConfiguration
        Parameters:
        prefix - The prefix used to select the properties.
        Returns:
        a subset configuration
        See Also:
        SubsetConfiguration
      • isEmptyInternal

        protected boolean isEmptyInternal()
        Description copied from class: AbstractConfiguration
        Actually checks whether this configuration contains data. This method is called by isEmpty(). It has to be defined by concrete subclasses.
        Specified by:
        isEmptyInternal in class AbstractConfiguration
        Returns:
        true if this configuration contains no data, false otherwise
      • containsKeyInternal

        protected boolean containsKeyInternal​(java.lang.String key)
        Description copied from class: AbstractConfiguration
        Actually checks whether the specified key is contained in this configuration. This method is called by containsKey(). It has to be defined by concrete subclasses.
        Specified by:
        containsKeyInternal in class AbstractConfiguration
        Parameters:
        key - the key in question
        Returns:
        true if this key is contained in this configuration, false otherwise
      • addPropertyDirect

        public void addPropertyDirect​(java.lang.String key,
                                      java.lang.Object value)
        Description copied from class: AbstractConfiguration
        Adds a key/value pair to the Configuration. Override this method to provide write access to underlying Configuration store.
        Specified by:
        addPropertyDirect in class AbstractConfiguration
        Parameters:
        key - key to use for mapping
        value - object to store
      • clearPropertyDirect

        protected void clearPropertyDirect​(java.lang.String key)
        Description copied from class: AbstractConfiguration
        Removes the specified property from this configuration. This method is called by clearProperty() after it has done some preparations. It must be overridden in sub classes.
        Specified by:
        clearPropertyDirect in class AbstractConfiguration
        Parameters:
        key - the key to be removed
      • getPropertyInternal

        protected java.lang.Object getPropertyInternal​(java.lang.String key)
        Description copied from class: AbstractConfiguration
        Actually obtains the value of the specified property. This method is called by getProperty(). Concrete subclasses must define it to fetch the value of the desired property.
        Specified by:
        getPropertyInternal in class AbstractConfiguration
        Parameters:
        key - the key of the property in question
        Returns:
        the (raw) value of this property
      • getKeysInternal

        protected java.util.Iterator<java.lang.String> getKeysInternal​(java.lang.String prefix)
        Description copied from class: AbstractConfiguration
        Gets an Iterator with all property keys starting with the specified prefix. This method is called by AbstractConfiguration.getKeys(String). It is fully implemented by delegating to getKeysInternal() and returning a special iterator which filters for the passed in prefix. Subclasses can override it if they can provide a more efficient way to iterate over specific keys only.
        Overrides:
        getKeysInternal in class AbstractConfiguration
        Parameters:
        prefix - the prefix for the keys to be taken into account
        Returns:
        an Iterator returning the filtered keys
      • getKeysInternal

        protected java.util.Iterator<java.lang.String> getKeysInternal()
        Description copied from class: AbstractConfiguration
        Actually creates an iterator for iterating over the keys in this configuration. This method is called by getKeys(), it has to be defined by concrete subclasses.
        Specified by:
        getKeysInternal in class AbstractConfiguration
        Returns:
        an Iterator with all property keys in this configuration
      • setThrowExceptionOnMissing

        public void setThrowExceptionOnMissing​(boolean throwExceptionOnMissing)
        Allows to set the throwExceptionOnMissing flag. This flag controls the behavior of property getter methods that return objects if the requested property is missing. If the flag is set to false (which is the default value), these methods will return null. If set to true, they will throw a NoSuchElementException exception. Note that getter methods for primitive data types are not affected by this flag. Change the behavior of the parent configuration if it supports this feature.
        Overrides:
        setThrowExceptionOnMissing in class AbstractConfiguration
        Parameters:
        throwExceptionOnMissing - The new value for the property
      • isThrowExceptionOnMissing

        public boolean isThrowExceptionOnMissing()
        Returns true if missing values throw Exceptions. The subset inherits this feature from its parent if it supports this feature.
        Overrides:
        isThrowExceptionOnMissing in class AbstractConfiguration
        Returns:
        true if missing values throw Exceptions
      • setListDelimiterHandler

        public void setListDelimiterHandler​(ListDelimiterHandler listDelimiterHandler)

        Sets the ListDelimiterHandler to be used by this instance. This object is invoked every time when dealing with string properties that may contain a list delimiter and thus have to be split to multiple values. Per default, a ListDelimiterHandler implementation is set which does not support list splitting. This can be changed for instance by setting a DefaultListDelimiterHandler object.

        Warning: Be careful when changing the list delimiter handler when the configuration has already been loaded/populated. List handling is typically applied already when properties are added to the configuration. If later another handler is set which processes lists differently, results may be unexpected; some operations may even cause exceptions.

        If the parent configuration extends AbstractConfiguration, the list delimiter handler is passed to the parent.
        Overrides:
        setListDelimiterHandler in class AbstractConfiguration
        Parameters:
        listDelimiterHandler - the ListDelimiterHandler to be used (must not be null)