Interface ConfigRegistry

  • All Known Implementing Classes:
    CommonsConfigurationRegistry

    public interface ConfigRegistry
    The configuration registry is a single source of external configuration. Each configuration entry is accessible by a unique key. The keys may be hierarchical so, that you can build subsets of the configuration. A configuration may be combined by multiple sources. How the multiple sources are combined, is part of the implementation classes. You can register listeners that are notified, if the configuration changes. The syntax for filter of notifications is implementation specific.
    • Method Detail

      • dump

        String dump()
        Dump the entire registry to a string, for debugging purposes.
        Returns:
        the registry contents
      • getValue

        Object getValue​(String key)
        Get the original value stored in the registry. If not found, null is returned.
        Parameters:
        key - The key in the registry.
        Returns:
        The value.
      • getString

        String getString​(String key)
        Get a string value from the registry. If not found, null is returned.
        Parameters:
        key - the key in the registry
        Returns:
        the value
      • getString

        String getString​(String key,
                         String defaultValue)
        Get a string value from the registry. If not found, the default value is used.
        Parameters:
        key - the key in the registry
        defaultValue - the default value
        Returns:
        the value
      • setString

        void setString​(String key,
                       String value)
        Set a string value in the registry.
        Parameters:
        key - the key in the registry
        value - the value to set
      • getInt

        int getInt​(String key,
                   int defaultValue)
        Get an integer value from the registry. If not found, the default value is used.
        Parameters:
        key - the key in the registry
        defaultValue - the default value
        Returns:
        the value
      • setInt

        void setInt​(String key,
                    int value)
        Set an integer value in the registry.
        Parameters:
        key - the key in the registry
        value - the value to set
      • getBoolean

        boolean getBoolean​(String key,
                           boolean defaultValue)
        Get a boolean value from the registry. If not found, the default value is used.
        Parameters:
        key - the key in the registry
        defaultValue - the default value
        Returns:
        the value
      • setBoolean

        void setBoolean​(String key,
                        boolean value)
        Set a boolean value in the registry.
        Parameters:
        key - the key in the registry
        value - the value to set
      • addConfigurationFromResource

        void addConfigurationFromResource​(String name,
                                          String resource)
                                   throws RegistryException
        Load configuration from the given classloader resource.
        Parameters:
        name - the unique name that identifies this configuration in the combined one
        resource - the location to load the configuration from
        Throws:
        RegistryException - if a problem occurred reading the resource to add to the registry
      • addConfigurationFromResource

        void addConfigurationFromResource​(String name,
                                          String resource,
                                          String prefix)
                                   throws RegistryException
        Load configuration from the given classloader resource.
        Parameters:
        name - the unique name that identifies this configuration in the combined one
        resource - the location to load the configuration from
        prefix - the location to add the configuration at in the registry
        Throws:
        RegistryException - if a problem occurred reading the resource to add to the registry
      • addConfigurationFromFile

        void addConfigurationFromFile​(String name,
                                      Path file)
                               throws RegistryException
        Load configuration from the given file.
        Parameters:
        name - the unique name that identifies this configuration in the combined one
        file - the location to load the configuration from
        Throws:
        RegistryException - if a problem occurred reading the resource to add to the registry
      • addConfigurationFromFile

        void addConfigurationFromFile​(String name,
                                      Path file,
                                      String prefix)
                               throws RegistryException
        Load configuration from the given file.
        Parameters:
        name - the unique name that identifies this configuration in the combined one
        file - the location to load the configuration from
        prefix - the location to add the configuration at in the registry
        Throws:
        RegistryException - if a problem occurred reading the resource to add to the registry
      • isEmpty

        boolean isEmpty()
        Determine if the registry contains any elements.
        Returns:
        whether the registry contains any elements
      • getList

        List<StringgetList​(String key)
        Get a list of strings at the given key in the registry. If not found a empty list will be returned.
        Parameters:
        key - the key to lookup
        Returns:
        the list of strings
      • getProperties

        Map<String,​StringgetProperties​(String key)
        Get the properties at the given key in the registry.
        Parameters:
        key - the key to lookup
        Returns:
        the properties
      • getPartOfCombined

        ConfigRegistry getPartOfCombined​(String name)
        Get a configuration source part of the registry, identified by the given name. If it doesn't exist, null will be returned. Configurations can be combined from different sources. This returns the configuration of a specific source. The names are the ones given by the addConfiguration* methods or defined during the initialization process.
        Parameters:
        name - The source name of the configuration source.
        Returns:
        the The config registry object that represents this source part.
      • getBaseKeys

        Collection<StringgetBaseKeys()
        Get all keys on the base level in this registry. Keys are only retrieved at a depth of 1.
        Returns:
        the set of keys
      • getKeys

        Collection<StringgetKeys​(String prefix)
        Return the keys that match the given prefix.
        Parameters:
        prefix - The prefix
        Returns:
        A collection of keys
      • remove

        void remove​(String key)
        Remove a keyed element from the registry.
        Parameters:
        key - the key to remove
      • removeSubset

        void removeSubset​(String key)
        Remove a keyed subset of the registry.
        Parameters:
        key - the subset to remove
      • initialize

        void initialize()
                 throws RegistryException
        Initializes the given registry. The definition for the configuration sources is implementation specific. Implementations should provide methods and/or constructors that allows to define the configuration source.
        Throws:
        RegistryException - if the initialization was not successful