de.dante.util.framework.configuration.impl
Class MultiConfiguration

java.lang.Object
  extended byde.dante.util.framework.configuration.impl.MultiConfiguration
All Implemented Interfaces:
Configuration

public class MultiConfiguration
extends java.lang.Object
implements Configuration

Container for several Configuration objects. They can be treated as if they where contained in one configuration.

Version:
$Revision: 1.2 $
Author:
Gerd Neugebauer

Constructor Summary
MultiConfiguration(Configuration[] parts)
          Creates a new object.
 
Method Summary
 Configuration findConfiguration(java.lang.String key)
          Extract a sub-configuration with a given name.
 Configuration findConfiguration(java.lang.String key, java.lang.String attribute)
          Extract a sub-configuration with a given name and a given attribute.
 java.lang.String getAttribute(java.lang.String name)
          Getter for an attribute with a given name.
 Configuration getConfiguration(java.lang.String key)
          Extract a sub-configuration with a given name.
 Configuration getConfiguration(java.lang.String key, java.lang.String attribute)
          Extract a sub-configuration with a given name and a given attribute.
 java.lang.String getValue()
          Getter for the textual value of this configuration.
 java.lang.String getValue(java.lang.String key)
          Retrieve a value from the configuration as String.
 int getValueAsInteger(java.lang.String key, int defaultValue)
          Retrieve a value from the configuration as int.
 StringList getValues(java.lang.String key)
          Get the list of all values with the given tag name in the current configuration.
 void getValues(StringList list, java.lang.String key)
          Get the list of all values with the given tag name in the current configuration and append them to a given StringList.
 java.util.Iterator iterator()
          Get an iterator for all sub-configurations.
 java.util.Iterator iterator(java.lang.String key)
          Retrieve an iterator over all items of a sub-configuration.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MultiConfiguration

public MultiConfiguration(Configuration[] parts)
                   throws ConfigurationException
Creates a new object.

Parameters:
parts - the configs to treat jointly
Throws:
ConfigurationException - in case that the configuration is invalid
Method Detail

findConfiguration

public Configuration findConfiguration(java.lang.String key)
                                throws ConfigurationInvalidResourceException,
                                       ConfigurationNotFoundException,
                                       ConfigurationSyntaxException,
                                       ConfigurationIOException
Description copied from interface: Configuration
Extract a sub-configuration with a given name.

Consider the following example with the configuration currently rooted at cfg:

   <cfg>
     . . .
     <abc>
     . . .
     </abc>
     . . .
   </cfg>
 

Then getConfig("abc") returns a new XMLConfig rooted at abc.

If there are more than one tags with the same name then the first one is used.

If there are no tags with the given name then null is returned.

Specified by:
findConfiguration in interface Configuration
Parameters:
key - the tag name of the sub-configuration
Returns:
the sub-configuration or null if none is found
Throws:
ConfigurationSyntaxException - in case that the resource contains syntax errors
ConfigurationNotFoundException - in case that the named path does not lead to a resource
ConfigurationInvalidResourceException - in case that the given resource name is null or empty
ConfigurationIOException - in case of an IO exception while reading the resource
See Also:
Configuration.findConfiguration( java.lang.String)

findConfiguration

public Configuration findConfiguration(java.lang.String key,
                                       java.lang.String attribute)
                                throws ConfigurationException
Description copied from interface: Configuration
Extract a sub-configuration with a given name and a given attribute.

Consider the following example with the configuration currently rooted at cfg:

   <cfg>
     . . .
     <abc name="one">
     . . .
     </abc>
     <abc name="two">
     . . .
     </abc>
     . . .
   </cfg>
 

Then getConfig("abc","two") returns a new XMLConfig rooted at the abc with the name attribute "two".

If there are more than one tags with the same name then the first one is used.

If there are no tags with the given name then null is returned.

Specified by:
findConfiguration in interface Configuration
Parameters:
key - the tag name of the sub-configuration
attribute - the value of the attribute name
Returns:
the sub-configuration
Throws:
ConfigurationException - in case of other errors.
See Also:
Configuration.findConfiguration( java.lang.String, java.lang.String)

getAttribute

public java.lang.String getAttribute(java.lang.String name)
Getter for an attribute with a given name. The first attribute in a sub-configuration is returned.

Specified by:
getAttribute in interface Configuration
Parameters:
name - the tag name of the attribute
Returns:
the value of the attribute or null if such an attribute is not present
See Also:
Configuration.getAttribute( java.lang.String)

getConfiguration

public Configuration getConfiguration(java.lang.String key)
                               throws ConfigurationException
Description copied from interface: Configuration
Extract a sub-configuration with a given name.

Consider the following example with the configuration currently rooted at cfg:

   <cfg>
     . . .
     <abc>
     . . .
     </abc>
     . . .
   </cfg>
 

Then getConfig("abc") returns a new XMLConfig rooted at abc.

If there are more than one tags with the same name then the first one is used.

If there are no tags with the given name then an exception is thrown.

Specified by:
getConfiguration in interface Configuration
Parameters:
key - the tag name of the sub-configuration
Returns:
the sub-configuration
Throws:
ConfigurationException - in case of other errors. Especially
ConfigurationNotFoundException in case that the given name does not correspond to one of the tags in the current configuration
See Also:
Configuration.getConfiguration( java.lang.String)

getConfiguration

public Configuration getConfiguration(java.lang.String key,
                                      java.lang.String attribute)
                               throws ConfigurationException
Description copied from interface: Configuration
Extract a sub-configuration with a given name and a given attribute.

Consider the following example with the configuration currently rooted at cfg:

   <cfg>
     . . .
     <abc name="one">
     . . .
     </abc>
     <abc name="two">
     . . .
     </abc>
     . . .
   </cfg>
 

Then getConfig("abc","two") returns a new XMLConfig rooted at the abc with the name attribute "two".

If there are more than one tags with the same name then the first one is used.

If there are no tags with the given name then an exception is thrown.

Specified by:
getConfiguration in interface Configuration
Parameters:
key - the tag name of the sub-configuration
attribute - the value of the attribute name
Returns:
the sub-configuration
Throws:
ConfigurationException - in case of other errors. Especially
ConfigurationNotFoundException in case that the given name does not correspond to one of the tags in the current configuration
See Also:
Configuration.getConfiguration( java.lang.String, java.lang.String)

getValue

public java.lang.String getValue()
                          throws ConfigurationException
Getter for the textual value of this configuration.

Specified by:
getValue in interface Configuration
Returns:
the text stored directly in this configuration
Throws:
ConfigurationException - in case that something went wrong
See Also:
Configuration.getValue()

getValue

public java.lang.String getValue(java.lang.String key)
                          throws ConfigurationException
Description copied from interface: Configuration
Retrieve a value from the configuration as String. If the value could not be determined then null is returned.

Consider the following example with the configuration currently rooted at cfg:

   <cfg>
     . . .
     <one>the first value</one>
     <two>the second value</two>
     . . .
   </cfg>
 

Then getValue("two") returns the String "the second value".

Specified by:
getValue in interface Configuration
Parameters:
key - the name of the desired value
Returns:
the value of key or null
Throws:
ConfigurationException - in case that something went wrong
See Also:
Configuration.getValue(java.lang.String)

getValueAsInteger

public int getValueAsInteger(java.lang.String key,
                             int defaultValue)
                      throws ConfigurationException
Description copied from interface: Configuration
Retrieve a value from the configuration as int. If the value could not be determined then a given default value is returned.

Specified by:
getValueAsInteger in interface Configuration
Parameters:
key - the name of the desired value
defaultValue - the default value
Returns:
the value of key or the default value
Throws:
ConfigurationException - in case that something went wrong
See Also:
Configuration.getValueAsInteger( java.lang.String, int)

getValues

public StringList getValues(java.lang.String key)
Description copied from interface: Configuration
Get the list of all values with the given tag name in the current configuration.

Specified by:
getValues in interface Configuration
Parameters:
key - the name of the tags
Returns:
the list of values
See Also:
Configuration.getValues(java.lang.String)

getValues

public void getValues(StringList list,
                      java.lang.String key)
Get the list of all values with the given tag name in the current configuration and append them to a given StringList.

Specified by:
getValues in interface Configuration
Parameters:
key - the name of the tags
list - the list tol append the values to
See Also:
Configuration.getValues( de.dante.util.StringList, java.lang.String)

iterator

public java.util.Iterator iterator(java.lang.String key)
                            throws ConfigurationException
Retrieve an iterator over all items of a sub-configuration.

Specified by:
iterator in interface Configuration
Parameters:
key - the name of the sub-configuration
Returns:
the iterator
Throws:
ConfigurationException - in case that something went wrong
See Also:
Configuration.iterator(java.lang.String)

iterator

public java.util.Iterator iterator()
                            throws ConfigurationException
Description copied from interface: Configuration
Get an iterator for all sub-configurations.

Specified by:
iterator in interface Configuration
Returns:
an iterator for all sub-configurations
Throws:
ConfigurationException - in case that something went wrong
See Also:
Configuration.iterator()