org.jconfig
Class NestedConfiguration

java.lang.Object
  extended byorg.jconfig.DefaultConfiguration
      extended byorg.jconfig.NestedConfiguration
All Implemented Interfaces:
Configuration, java.io.Serializable

public class NestedConfiguration
extends DefaultConfiguration
implements java.io.Serializable, Configuration

This class is the configuration itself. The Configuration is useful if one wants to manage multiple configurations. A single instance of the Configuration may contain, for example, information for one application or user.

Author:
Andreas Mecky andreas.mecky@xcom.de, Terry Dye terry.dye@xcom.de
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class org.jconfig.DefaultConfiguration
DefaultConfiguration.MyCategoryListener
 
Field Summary
 
Fields inherited from class org.jconfig.DefaultConfiguration
baseConfigName, categories, configName, mainCategory
 
Constructor Summary
NestedConfiguration(java.lang.String configName)
          The constructor that creates a new configuration with one empty category called "general".
 
Method Summary
 boolean containsCategory(java.lang.String categoryName)
          Use this method to determine if a category exists.
 Category getCategory(java.lang.String name)
          Returns a category based on the name provided.
 java.lang.String[] getCategoryNames()
          This method returns a string array with all category names.
protected  java.lang.String[] getCategoryNames(boolean includeParent)
          A convenience method that returns the key set in the form or a String Array.
 java.lang.String getProperty(java.lang.String key, java.lang.String defaultValue, java.lang.String categoryName)
          This is the real implementation.
 java.lang.String getXMLAsString()
          This method converts the Configuration into a String which looks like XML.
 void setCategory(Category category)
           
 void setCategory(java.lang.String name, boolean main)
          Besides setting the category, it will also set this category as default category if main is true.
 java.lang.String toString()
          This method creates a string representation of the configuration.
 
Methods inherited from class org.jconfig.DefaultConfiguration
addCategoryListener, addCategoryListener, addConfigurationListener, addInclude, addIncludeBlock, addPropertyListener, addPropertyListener, addVariableBlock, escapeForXML, fireConfigurationChangedEvent, getArray, getArray, getArray, getArray, getBaseConfiguration, getBooleanProperty, getBooleanProperty, getCategory, getCharProperty, getCharProperty, getConfigName, getDoubleProperty, getDoubleProperty, getEncoding, getIncludes, getIntProperty, getIntProperty, getLongProperty, getLongProperty, getMainCategoryName, getNumberOfCategories, getProperties, getProperties, getProperties, getProperty, getProperty, getPropertyNames, getSortedProperties, getVariable, getVariables, hasChanged, isNew, markDirty, removeCategory, removeConfigurationListener, removeProperty, removeProperty, renameCategory, resetCreated, setBaseConfiguration, setBooleanProperty, setBooleanProperty, setCategory, setCharProperty, setCharProperty, setConfigName, setDoubleProperty, setDoubleProperty, setEncoding, setIntProperty, setIntProperty, setLongProperty, setLongProperty, setProperty, setProperty, setVariable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jconfig.Configuration
addCategoryListener, addCategoryListener, addConfigurationListener, addInclude, addPropertyListener, addPropertyListener, fireConfigurationChangedEvent, getArray, getArray, getArray, getBaseConfiguration, getBooleanProperty, getBooleanProperty, getCategory, getCharProperty, getCharProperty, getConfigName, getDoubleProperty, getDoubleProperty, getEncoding, getIncludes, getIntProperty, getIntProperty, getLongProperty, getLongProperty, getMainCategoryName, getNumberOfCategories, getProperties, getProperties, getProperty, getProperty, getPropertyNames, getVariable, getVariables, hasChanged, isNew, removeCategory, removeConfigurationListener, removeProperty, removeProperty, renameCategory, resetCreated, setBaseConfiguration, setBooleanProperty, setBooleanProperty, setCategory, setCharProperty, setCharProperty, setConfigName, setDoubleProperty, setDoubleProperty, setEncoding, setIntProperty, setIntProperty, setLongProperty, setLongProperty, setProperty, setProperty, setVariable
 

Constructor Detail

NestedConfiguration

public NestedConfiguration(java.lang.String configName)
The constructor that creates a new configuration with one empty category called "general". This category is also the default category.

Parameters:
configName - the name of the configuration
Method Detail

getCategoryNames

public java.lang.String[] getCategoryNames()
Description copied from interface: Configuration
This method returns a string array with all category names.

Specified by:
getCategoryNames in interface Configuration
Overrides:
getCategoryNames in class DefaultConfiguration
Returns:
a string array with all category names

getCategoryNames

protected java.lang.String[] getCategoryNames(boolean includeParent)
Description copied from class: DefaultConfiguration
A convenience method that returns the key set in the form or a String Array.

Overrides:
getCategoryNames in class DefaultConfiguration
Parameters:
includeParent - true will check for a base configuration and include those category names as well.
Returns:
the String Array as described

setCategory

public void setCategory(java.lang.String name,
                        boolean main)
Besides setting the category, it will also set this category as default category if main is true. It will only set (ie create) the category if it does not exist. If you want delete a category then use @see #removeCategory(String)

Specified by:
setCategory in interface Configuration
Overrides:
setCategory in class DefaultConfiguration
Parameters:
name - the name of the category
main - if true then this category is the default category

setCategory

public void setCategory(Category category)
Specified by:
setCategory in interface Configuration
Overrides:
setCategory in class DefaultConfiguration

getProperty

public java.lang.String getProperty(java.lang.String key,
                                    java.lang.String defaultValue,
                                    java.lang.String categoryName)
This is the real implementation. It will return the value of the property with the specific name. First of all, it checks if the name of the category exists. If not, then it will use the name of the default category. The next step is that it will look for the property. If it is not found in the category, it will look inside the default category (inheritance). If it still cannot find the property, it will return the defaultValue

Specified by:
getProperty in interface Configuration
Overrides:
getProperty in class DefaultConfiguration
Parameters:
key - the name of the property
defaultValue - the default value
categoryName - the name of the category
Returns:
the value as String

toString

public java.lang.String toString()
This method creates a string representation of the configuration.

Specified by:
toString in interface Configuration
Overrides:
toString in class DefaultConfiguration
Returns:
a string with the configuration

getXMLAsString

public java.lang.String getXMLAsString()
This method converts the Configuration into a String which looks like XML.

Specified by:
getXMLAsString in interface Configuration
Overrides:
getXMLAsString in class DefaultConfiguration
Returns:
the Configuration as String in XML format

getCategory

public Category getCategory(java.lang.String name)
Returns a category based on the name provided.

Specified by:
getCategory in interface Configuration
Overrides:
getCategory in class DefaultConfiguration
Parameters:
name - The name of the category (if null, main category will be used)
Returns:
The category object (new instance if necessary)

containsCategory

public boolean containsCategory(java.lang.String categoryName)
Description copied from interface: Configuration
Use this method to determine if a category exists. The getCategory method will return the default category if the requested category was not found. So if you need to know if a category already exists then call this method.

Specified by:
containsCategory in interface Configuration
Overrides:
containsCategory in class DefaultConfiguration


Copyright © 2001-2005 Andreas Mecky, Terry Dye. All Rights Reserved.