org.jconfig
Class NestedConfiguration
java.lang.Object
|
+--org.jconfig.DefaultConfiguration
|
+--org.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
Constructor Summary |
protected |
NestedConfiguration()
|
|
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 |
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, addPropertyListener, addPropertyListener, fireConfigurationChangedEvent, getArray, getArray, getArray, getBooleanProperty, getBooleanProperty, getCategory, getCategoryNames, getCharProperty, getCharProperty, getConfigName, getDoubleProperty, getDoubleProperty, getEncoding, getIncludes, getIntProperty, getIntProperty, getLongProperty, getLongProperty, getMainCategoryName, getNumberOfCategories, getProperties, getProperty, getProperty, getPropertyNames, getVariable, getVariables, hasChanged, isNew, markDirty, removeCategory, removeConfigurationListener, removeProperty, removeProperty, 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, getBooleanProperty, getBooleanProperty, getCategory, getCategoryNames, getCharProperty, getCharProperty, getConfigName, getDoubleProperty, getDoubleProperty, getEncoding, getIncludes, getIntProperty, getIntProperty, getLongProperty, getLongProperty, getMainCategoryName, getNumberOfCategories, getProperty, getProperty, getPropertyNames, getVariable, getVariables, hasChanged, isNew, removeCategory, removeConfigurationListener, removeProperty, removeProperty, resetCreated, setBaseConfiguration, setBooleanProperty, setBooleanProperty, setCategory, setCharProperty, setCharProperty, setConfigName, setDoubleProperty, setDoubleProperty, setEncoding, setIntProperty, setIntProperty, setLongProperty, setLongProperty, setProperty, setProperty, setVariable |
NestedConfiguration
protected NestedConfiguration()
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
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 categorymain
- 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 propertydefaultValue
- the default valuecategoryName
- 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-2003 Andreas Mecky, Terry Dye. All Rights Reserved.