Class HierarchicalConfigurationConverter
java.lang.Object
org.apache.commons.configuration2.HierarchicalConfigurationConverter
- Direct Known Subclasses:
BaseConfigurationXMLReader.SAXConverter
A base class for converters that transform a normal configuration object into a hierarchical configuration.
This class provides a default mechanism for iterating over the keys in a configuration and to throw corresponding element start and end events. By handling these events a hierarchy can be constructed that is equivalent to the keys in the original configuration.
Concrete sub classes will implement event handlers that generate SAX events for XML processing or construct a
HierarchicalConfiguration
root node. All in all with this class it is possible to treat a default
configuration as if it was a hierarchical configuration, which can be sometimes useful.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
closeElements
(DefaultConfigurationKey keyLast, DefaultConfigurationKey keyAct) Fires all necessary element end events for the specified keys.protected abstract void
elementEnd
(String name) An event handler method that is called when an element ends.protected abstract void
elementStart
(String name, Object value) An event handler method that is called when an element starts.protected void
Fires all necessary element start events with the actual element values.protected String
openElements
(DefaultConfigurationKey keyLast, DefaultConfigurationKey keyAct, Configuration config, Set<String> keySet) Fires all necessary element start events for the specified key.void
process
(Configuration config) Processes the specified configuration object.Helper method for determining a reverse iterator for the specified key.
-
Constructor Details
-
HierarchicalConfigurationConverter
HierarchicalConfigurationConverter()
-
-
Method Details
-
closeElements
Fires all necessary element end events for the specified keys. This method is called for each key obtained from the configuration to be converted. It calculates the common part of the actual and the last processed key and thus determines how many elements must be closed.- Parameters:
keyLast
- the last processed keykeyAct
- the actual key
-
elementEnd
An event handler method that is called when an element ends. For each call ofelementStart()
there will be a corresponding call of this method. Concrete sub classes must implement it to perform a proper event handling.- Parameters:
name
- the name of the ending element
-
elementStart
An event handler method that is called when an element starts. Concrete sub classes must implement it to perform a proper event handling.- Parameters:
name
- the name of the new elementvalue
- the element's value; can be null if the element does not have any value
-
fireValue
Fires all necessary element start events with the actual element values. This method is called for each key obtained from the configuration to be processed with the last part of the key as argument. The value can be either a single value or a collection.- Parameters:
name
- the name of the actual elementvalue
- the element's value
-
openElements
protected String openElements(DefaultConfigurationKey keyLast, DefaultConfigurationKey keyAct, Configuration config, Set<String> keySet) Fires all necessary element start events for the specified key. This method is called for each key obtained from the configuration to be converted. It ensures that all elements "between" the last key and the actual key are opened and their values are set.- Parameters:
keyLast
- the last processed keykeyAct
- the actual keyconfig
- the configuration to processkeySet
- the set with the processed keys- Returns:
- the name of the last element on the path
-
process
Processes the specified configuration object. This method implements the iteration over the configuration's keys. All defined keys are translated into a set of element start and end events represented by calls to theelementStart()
andelementEnd()
methods.- Parameters:
config
- the configuration to be processed
-
reverseIterator
Helper method for determining a reverse iterator for the specified key. This implementation returns an iterator that returns the parts of the given key in reverse order, ignoring indices.- Parameters:
key
- the key- Returns:
- a reverse iterator for the parts of this key
-