Class CombinedBuilderParametersImpl

    • Field Detail

      • PARAM_KEY

        private static final java.lang.String PARAM_KEY
        Constant for the key in the parameters map used by this class.
      • definitionBuilderParameters

        private BuilderParameters definitionBuilderParameters
        A parameters object for the definition configuration builder.
      • providers

        private final java.util.Map<java.lang.String,​ConfigurationBuilderProvider> providers
        A map with registered configuration builder providers.
      • childParameters

        private final java.util.Collection<BuilderParameters> childParameters
        A list with default parameters for child configuration sources.
      • childDefaultParametersManager

        private DefaultParametersManager childDefaultParametersManager
        The manager for default handlers.
      • basePath

        private java.lang.String basePath
        The base path for configuration sources to be loaded.
      • inheritSettings

        private boolean inheritSettings
        A flag whether settings should be inherited by child builders.
    • Constructor Detail

      • CombinedBuilderParametersImpl

        public CombinedBuilderParametersImpl()
        Creates a new instance of CombinedBuilderParametersImpl.
    • Method Detail

      • fromParameters

        public static CombinedBuilderParametersImpl fromParameters​(java.util.Map<java.lang.String,​?> params)
        Looks up an instance of this class in the specified parameters map. This is equivalent to fromParameters(params, false);
        Parameters:
        params - the map with parameters (must not be null
        Returns:
        the instance obtained from the map or null
        Throws:
        java.lang.NullPointerException - if the map is null
      • fromParameters

        public static CombinedBuilderParametersImpl fromParameters​(java.util.Map<java.lang.String,​?> params,
                                                                   boolean createIfMissing)
        Looks up an instance of this class in the specified parameters map and optionally creates a new one if none is found. This method can be used to obtain an instance of this class which has been stored in a parameters map. It is compatible with the getParameters() method.
        Parameters:
        params - the map with parameters (must not be null
        createIfMissing - determines the behavior if no instance is found in the map; if true, a new instance with default settings is created; if false, null is returned
        Returns:
        the instance obtained from the map or null
        Throws:
        java.lang.NullPointerException - if the map is null
      • clone

        public CombinedBuilderParametersImpl clone()
        Clones this object. This is useful because multiple builder instances may use a similar set of parameters. However, single instances of parameter objects must not assigned to multiple builders. Therefore, cloning a parameters object provides a solution for this use case. This method creates a new parameters object with the same content as this one. The internal map storing the parameter values is cloned, too, also collection structures contained in this map. However, no a full deep clone operation is performed. Objects like a ConfigurationInterpolator or Lookups are shared between this and the newly created instance. This implementation also clones the parameters object for the definition builder if possible.
        Overrides:
        clone in class BasicBuilderParameters
        Returns:
        a clone of this object
      • getBasePath

        public java.lang.String getBasePath()
        Gets the base path for relative names of configuration sources. Result may be null if no base path has been set.
        Returns:
        the base path for resolving relative file names
      • getChildDefaultParametersManager

        public DefaultParametersManager getChildDefaultParametersManager()
        Gets the DefaultParametersManager object for initializing parameter objects for child configuration sources. This method never returns null. If no manager was set, a new instance is created right now.
        Returns:
        the DefaultParametersManager for child configuration sources
      • getDefaultChildParameters

        public java.util.Collection<? extends BuilderParameters> getDefaultChildParameters()
        Gets a collection with default parameter objects for child configuration sources. This collection contains the same objects (in the same order) that were passed to addChildParameters(). The returned collection is a defensive copy; it can be modified, but this has no effect on the parameters stored in this object.
        Returns:
        a map with default parameters for child sources
      • getDefinitionBuilder

        public ConfigurationBuilder<? extends HierarchicalConfiguration<?>> getDefinitionBuilder()
        Gets the ConfigurationBuilder object for obtaining the definition configuration.
        Returns:
        the definition ConfigurationBuilder
      • getDefinitionBuilderParameters

        public BuilderParameters getDefinitionBuilderParameters()
        Gets the parameters object for the definition configuration builder if present.
        Returns:
        the parameters object for the definition configuration builder or null
      • getParameters

        public java.util.Map<java.lang.String,​java.lang.Object> getParameters()
        Gets a map with all parameters defined by this objects. The keys of the map correspond to concrete properties supported by the Configuration implementation class the builder produces. The values are the corresponding property values. The return value must not be null. This implementation returns a copy of the internal parameters map with the values set so far. Collection structures (e.g. for lookup objects) are stored as defensive copies, so the original data cannot be modified. This implementation returns a map which contains this object itself under a specific key. The static fromParameters() method can be used to extract an instance from a parameters map.
        Specified by:
        getParameters in interface BuilderParameters
        Overrides:
        getParameters in class BasicBuilderParameters
        Returns:
        a map with builder parameters
      • getProviders

        public java.util.Map<java.lang.String,​ConfigurationBuilderProvider> getProviders()
        Gets an (unmodifiable) map with the currently registered ConfigurationBuilderProvider objects.
        Returns:
        the map with ConfigurationBuilderProvider objects (the keys are the tag names)
      • inheritFrom

        public void inheritFrom​(java.util.Map<java.lang.String,​?> source)
        Inherits properties from the specified map. This can be used for instance to reuse parameters from one builder in another builder - also in parent-child relations in which a parent builder creates child builders. The purpose of this method is to let a concrete implementation decide which properties can be inherited. Because parameters are basically organized as a map it would be possible to simply copy over all properties from the source object. However, this is not appropriate in all cases. For instance, some properties - like a ConfigurationInterpolator - are tightly connected to a configuration and cannot be reused in a different context. For other properties, e.g. a file name, it does not make sense to copy it. Therefore, an implementation has to be explicit in the properties it wants to take over. This implementation additionally copies some properties defined by this class.
        Overrides:
        inheritFrom in class BasicBuilderParameters
        Parameters:
        source - the source properties to inherit from
      • isInheritSettings

        public boolean isInheritSettings()
        Returns the current value of the flag that controls whether the settings of the parent combined configuration builder should be inherited by its child configurations.
        Returns:
        the flag whether settings should be inherited by child configurations
      • providerForTag

        public ConfigurationBuilderProvider providerForTag​(java.lang.String tagName)
        Returns the ConfigurationBuilderProvider which is registered for the specified tag name or null if there is no registration for this tag.
        Parameters:
        tagName - the tag name
        Returns:
        the provider registered for this tag or null
      • registerChildDefaultsHandler

        public <D> CombinedBuilderParametersImpl registerChildDefaultsHandler​(java.lang.Class<D> paramClass,
                                                                              DefaultParametersHandler<? super D> handler)
        Registers a DefaultParametersHandler for child configuration sources. With this method an arbitrary number of handler objects can be set. When creating builders for child configuration sources their parameters are initialized by invoking all matching DefaultParametersHandlers on them. So, basically the same mechanism is used for the initialization of parameters for child configuration sources as for normal parameter objects. This implementation registers the passed in handler at an internal DefaultParametersManager instance. If none was set, a new instance is created now.
        Specified by:
        registerChildDefaultsHandler in interface CombinedBuilderProperties<CombinedBuilderParametersImpl>
        Type Parameters:
        D - the type of the handler to be registered
        Parameters:
        paramClass - the parameter class supported by the handler
        handler - the DefaultParametersHandler to be registered
        Returns:
        a reference to this object for method chaining
        See Also:
        DefaultParametersManager.registerDefaultsHandler(Class, DefaultParametersHandler)
      • registerMissingProviders

        public CombinedBuilderParametersImpl registerMissingProviders​(CombinedBuilderParametersImpl params)
        Registers all ConfigurationBuilderProviders in the given parameters object which have not yet been registered. This method works like the method with the same name, but the map with providers is obtained from the passed in parameters object.
        Parameters:
        params - the parameters object from which to copy providers(must not be null)
        Returns:
        a reference to this object for method chaining
        Throws:
        java.lang.IllegalArgumentException - if the source parameters object is null
      • registerMissingProviders

        public CombinedBuilderParametersImpl registerMissingProviders​(java.util.Map<java.lang.String,​ConfigurationBuilderProvider> providers)
        Registers all ConfigurationBuilderProviders in the given map to this object which have not yet been registered. This method is mainly used for internal purposes: a CombinedConfigurationBuilder takes the providers contained in a parameters object and adds all standard providers. This way it is possible to override a standard provider by registering a provider object for the same tag name at the parameters object.
        Parameters:
        providers - a map with tag names and corresponding providers (must not be null or contain null entries)
        Returns:
        a reference to this object for method chaining
        Throws:
        java.lang.IllegalArgumentException - if the map with providers is null or contains null entries
      • registerProvider

        public CombinedBuilderParametersImpl registerProvider​(java.lang.String tagName,
                                                              ConfigurationBuilderProvider provider)
        Registers the given ConfigurationBuilderProvider for the specified tag name. This means that whenever this tag is encountered in a configuration definition file, the corresponding builder provider is invoked.
        Specified by:
        registerProvider in interface CombinedBuilderProperties<CombinedBuilderParametersImpl>
        Parameters:
        tagName - the name of the tag (must not be null)
        provider - the ConfigurationBuilderProvider (must not be null)
        Returns:
        a reference to this object for method chaining
        Throws:
        java.lang.IllegalArgumentException - if a required parameter is missing
      • setBasePath

        public CombinedBuilderParametersImpl setBasePath​(java.lang.String path)
        Sets the base path for this combined configuration builder. Normally it it not necessary to set the base path explicitly. Per default, relative file names of configuration sources are resolved based on the location of the definition file. If this is not desired or if the definition configuration is loaded by a different means, the base path for relative file names can be specified using this method.
        Specified by:
        setBasePath in interface CombinedBuilderProperties<CombinedBuilderParametersImpl>
        Parameters:
        path - the base path for resolving relative file names
        Returns:
        a reference to this object for method chaining
      • setChildDefaultParametersManager

        public CombinedBuilderParametersImpl setChildDefaultParametersManager​(DefaultParametersManager manager)
        Sets a DefaultParametersManager object responsible for managing the default parameter handlers to be applied on child configuration sources. When creating builders for child configuration sources their parameters are initialized using this DefaultParametersManager instance. This way, meaningful defaults can be set. Note that calling this method overrides all DefaultParametersHandler objects previously set by one of the registerChildDefaultsHandler() methods! So either use this method if a pre-configured manager object is to be set or call the registerChildDefaultHandler() methods with the handlers to be registered (in the latter case, it is not necessary to set a DefaultParametersManager explicitly; a default one is created behind the scenes). This implementation stores the passed in manager object. An already existing manager object (either explicitly set or created on demand) is overridden. This also removes all default handlers registered before!
        Specified by:
        setChildDefaultParametersManager in interface CombinedBuilderProperties<CombinedBuilderParametersImpl>
        Parameters:
        manager - the DefaultParametersManager
        Returns:
        a reference to this object for method chaining
      • setInheritSettings

        public CombinedBuilderParametersImpl setInheritSettings​(boolean inheritSettings)
        Description copied from interface: CombinedBuilderProperties
        Sets a flag whether the child configurations created by a CombinedConfigurationBuilder should inherit the settings defined for the builder. This is typically useful because for configurations coming from homogeneous sources often similar conventions are used. Therefore, this flag is true per default.
        Specified by:
        setInheritSettings in interface CombinedBuilderProperties<CombinedBuilderParametersImpl>
        Parameters:
        inheritSettings - the flag whether settings should be inherited by child configurations
        Returns:
        a reference to this object for method chaining