org.jconfig
Interface Configuration

All Known Implementing Classes:
DefaultConfiguration, NestedConfiguration

public interface Configuration

A Configuraton provides access to all Category and Properties. The Configuration was converted into an Interface after the need for other Configuration implementations existed.

Since:
2.3
Author:
Andreas Mecky , Terry Dye
See Also:
DefaultConfiguration, ExtensibleConfiguration

Method Summary
 void addCategoryListener(CategoryListener listener)
           
 void addCategoryListener(CategoryListener listener, java.lang.String categoryName)
           
 void addConfigurationListener(ConfigurationListener listener)
          Adds the specified configuration listener to receive configuration changed events from this configuration.
 void addInclude(int type, java.lang.String name)
           
 void addPropertyListener(PropertyListener listener)
          Adds the PropertyListener to the main category.
 void addPropertyListener(PropertyListener listener, java.lang.String categoryName)
          Adds the PropertyListener to the given category.
 boolean containsCategory(java.lang.String categoryName)
          Use this method to determine if a category exists.
 void fireConfigurationChangedEvent(ConfigurationChangedEvent event)
          Deliver configuration changed event to all listeners that are registered with our listener list.
 java.lang.String[] getArray(java.lang.String key)
           
 java.lang.String[] getArray(java.lang.String key, java.lang.String[] defaultValue)
           
 java.lang.String[] getArray(java.lang.String key, java.lang.String[] defaultValue, java.lang.String category)
           
 java.lang.String getBaseConfiguration()
           
 boolean getBooleanProperty(java.lang.String name, boolean defaultValue)
          Wrapper method to keep API simple
 boolean getBooleanProperty(java.lang.String name, boolean defaultValue, java.lang.String categoryName)
          Wrapper method to Category method
 Category getCategory()
          Returns the main category for this configuration
 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.
 char getCharProperty(java.lang.String name, char defaultValue)
          Wrapper method to Category method
 char getCharProperty(java.lang.String name, char defaultValue, java.lang.String category)
          Wrapper method to Category method
 java.lang.String getConfigName()
          Return the name of the current configuration.
 double getDoubleProperty(java.lang.String name, double defaultValue)
          Wrapper method to Category method
 double getDoubleProperty(java.lang.String name, double defaultValue, java.lang.String category)
          Wrapper method to Category method
 java.lang.String getEncoding()
           
 java.util.Vector getIncludes()
           
 int getIntProperty(java.lang.String name, int defaultValue)
           
 int getIntProperty(java.lang.String name, int defaultValue, java.lang.String category)
           
 long getLongProperty(java.lang.String name, long defaultValue)
          Wrapper method to Category method
 long getLongProperty(java.lang.String name, long defaultValue, java.lang.String categoryName)
          Wrapper method to Category method
 java.lang.String getMainCategoryName()
          This method returns the name of the default category
 int getNumberOfCategories()
          The method returns the number of categories inside this configuration.
 java.util.Properties getProperties()
          This method returns all properties for the default category
 java.util.Properties getProperties(java.lang.String name)
          This method returns all properties for the category with the given name
 java.lang.String getProperty(java.lang.String key)
          This method returns the String value based on the given key.
 java.lang.String getProperty(java.lang.String key, java.lang.String defaultValue)
          This method is the same as getProperty(key) but it returns the defaultValue if the property cannot be found.
 java.lang.String getProperty(java.lang.String key, java.lang.String defaultValue, java.lang.String categoryName)
          This is the real implementation.
 java.lang.String[] getPropertyNames(java.lang.String category)
          This method returns all the names of the properties for the specific category
 java.lang.String getVariable(java.lang.String name)
           
 java.util.HashMap getVariables()
          It returns a HashMap with all variables with the variable name as key
 java.lang.String getXMLAsString()
          This method converts the Configuration into a String which looks like XML.
 boolean hasChanged()
          This methods returns a flag which indicates if the configuration has changed since it was loaded.
 boolean isNew()
          This method determines if the configuration was loaded successfully (returns false) or if the configuration was created by the ConfigurationManager.
 void removeCategory(java.lang.String category)
          This method deletes a category with all its properties
 void removeConfigurationListener(ConfigurationListener listener)
          Removes the specified configuration listener from the configuration change events from this configuration.
 void removeProperty(java.lang.String name)
          This method deletes a property from the default category.
 void removeProperty(java.lang.String name, java.lang.String category)
          This method deletes a property with the given name from the specific category.
 void renameCategory(java.lang.String newName, java.lang.String oldName)
           
 void resetCreated()
          This method is used by the handlers to reset the isNew flag to false.
 void setBaseConfiguration(java.lang.String name)
          This method is used to define the base configuration of a configuration.
 void setBooleanProperty(java.lang.String key, boolean value)
          Wrapper method to Category method
 void setBooleanProperty(java.lang.String key, boolean value, java.lang.String category)
          Wrapper method to Category method
 void setCategory(Category category)
           
 void setCategory(java.lang.String name)
          Adds a category to the current configuration.
 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.
 void setCharProperty(java.lang.String key, char value)
          Wrapper method to Category method
 void setCharProperty(java.lang.String key, char value, java.lang.String category)
          Wrapper method to Category method
 void setConfigName(java.lang.String configName)
          Sets the name of the configuration.
 void setDoubleProperty(java.lang.String key, double value)
          Wrapper method to Category method
 void setDoubleProperty(java.lang.String key, double value, java.lang.String category)
          Wrapper method to Category method
 void setEncoding(java.lang.String encoding)
           
 void setIntProperty(java.lang.String key, int value)
          Wrapper method to Category method
 void setIntProperty(java.lang.String key, int value, java.lang.String category)
          Wrapper method to Category method
 void setLongProperty(java.lang.String key, long value)
          Wrapper method to Category method
 void setLongProperty(java.lang.String key, long value, java.lang.String category)
          Wrapper method to Category method
 void setProperty(java.lang.String name, java.lang.String value)
          This method sets a property with the name and the value in the default category.
 void setProperty(java.lang.String name, java.lang.String value, java.lang.String categoryName)
          This method sets the value for a property for the given category.
 void setVariable(java.lang.String name, java.lang.String value)
          This method sets a variable inside the configuration.
 java.lang.String toString()
          This method creates a string representation of the configuration.
 

Method Detail

setCategory

public void setCategory(java.lang.String name)
Adds a category to the current configuration.

Parameters:
name - Name of the category to be added.

setCategory

public void setCategory(Category category)

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)

Parameters:
name - the name of the category
main - if true then this category is the default category

getMainCategoryName

public java.lang.String getMainCategoryName()
This method returns the name of the default category

Returns:
name of the default category

getCategoryNames

public java.lang.String[] getCategoryNames()
This method returns a string array with all category names.

Returns:
a string array with all category names

getProperty

public java.lang.String getProperty(java.lang.String key)
This method returns the String value based on the given key. Implementation details: It calls getProperty(name,null,null). It searches inside the default category for the property.

Parameters:
key - the name of the property
Returns:
the value as String if it is found or null

getProperty

public java.lang.String getProperty(java.lang.String key,
                                    java.lang.String defaultValue)
This method is the same as getProperty(key) but it returns the defaultValue if the property cannot be found. Implementation details: It calls getProperty(key,defaultValue,null).

Parameters:
key - the name of the property
defaultValue - the defaultValue that will be returned if the property cannot be found
Returns:
the value as String

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

Parameters:
key - the name of the property
defaultValue - the default value
categoryName - the name of the category
Returns:
the value as String

setProperty

public void setProperty(java.lang.String name,
                        java.lang.String value)
This method sets a property with the name and the value in the default category. It calls setProperty(name.value,null).

Parameters:
name - the name of the property
value - the value as String

setProperty

public void setProperty(java.lang.String name,
                        java.lang.String value,
                        java.lang.String categoryName)
This method sets the value for a property for the given category. It also raises a PropertyEvent. If the category is null then it uses the default category.

Parameters:
name - the name of the property
value - the value as String
categoryName - the name of the category

removeProperty

public void removeProperty(java.lang.String name)
This method deletes a property from the default category. It calls removeProperty(name,null).

Parameters:
name - the name of the property

removeProperty

public void removeProperty(java.lang.String name,
                           java.lang.String category)
This method deletes a property with the given name from the specific category. If the category is null then it will delete the property from the default category.

Parameters:
name - the name of the property
category - the name of the category

getNumberOfCategories

public int getNumberOfCategories()
The method returns the number of categories inside this configuration.

Returns:
the number of categories

removeCategory

public void removeCategory(java.lang.String category)
This method deletes a category with all its properties

Parameters:
category - the name of the category

getProperties

public java.util.Properties getProperties()
This method returns all properties for the default category

Returns:
all properties for the default category

getProperties

public java.util.Properties getProperties(java.lang.String name)
This method returns all properties for the category with the given name

Parameters:
name - the name of the category
Returns:
all properties for the default category

getPropertyNames

public java.lang.String[] getPropertyNames(java.lang.String category)
This method returns all the names of the properties for the specific category

Parameters:
category - the name of the category
Returns:
the names as string array

setVariable

public void setVariable(java.lang.String name,
                        java.lang.String value)
This method sets a variable inside the configuration.

Parameters:
name - the name of the variable
value - the value of the variable

getVariables

public java.util.HashMap getVariables()
It returns a HashMap with all variables with the variable name as key

Returns:
a HashMap with all variables

getVariable

public java.lang.String getVariable(java.lang.String name)

getIntProperty

public int getIntProperty(java.lang.String name,
                          int defaultValue)
Parameters:
name -
defaultValue -
Returns:

getIntProperty

public int getIntProperty(java.lang.String name,
                          int defaultValue,
                          java.lang.String category)
Parameters:
name -
defaultValue -
category -
Returns:

getBooleanProperty

public boolean getBooleanProperty(java.lang.String name,
                                  boolean defaultValue)
Wrapper method to keep API simple

Parameters:
name -
defaultValue -
Returns:
See Also:
Category.getBooleanProperty(String, boolean)

getBooleanProperty

public boolean getBooleanProperty(java.lang.String name,
                                  boolean defaultValue,
                                  java.lang.String categoryName)
Wrapper method to Category method

Parameters:
defaultValue -
categoryName -
Returns:
See Also:
Category#getBooleanProperty(String, boolean, String)

setBooleanProperty

public void setBooleanProperty(java.lang.String key,
                               boolean value)
Wrapper method to Category method

Parameters:
key -
value -

setBooleanProperty

public void setBooleanProperty(java.lang.String key,
                               boolean value,
                               java.lang.String category)
Wrapper method to Category method

Parameters:
key -
value -
category -

getLongProperty

public long getLongProperty(java.lang.String name,
                            long defaultValue)
Wrapper method to Category method

Parameters:
name -
defaultValue -
Returns:

getLongProperty

public long getLongProperty(java.lang.String name,
                            long defaultValue,
                            java.lang.String categoryName)
Wrapper method to Category method

Parameters:
name -
defaultValue -
Returns:

getDoubleProperty

public double getDoubleProperty(java.lang.String name,
                                double defaultValue)
Wrapper method to Category method

Parameters:
name -
defaultValue -
Returns:

getDoubleProperty

public double getDoubleProperty(java.lang.String name,
                                double defaultValue,
                                java.lang.String category)
Wrapper method to Category method

Parameters:
name -
defaultValue -
category -
Returns:

getCharProperty

public char getCharProperty(java.lang.String name,
                            char defaultValue)
Wrapper method to Category method

Parameters:
name -
defaultValue -
Returns:

getCharProperty

public char getCharProperty(java.lang.String name,
                            char defaultValue,
                            java.lang.String category)
Wrapper method to Category method

Parameters:
name -
defaultValue -
category -
Returns:

toString

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

Returns:
a string with the configuration

getXMLAsString

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

Returns:
the Configuration as String in XML format

addPropertyListener

public void addPropertyListener(PropertyListener listener)
Adds the PropertyListener to the main category. If the main category changes after the listener has already been added, the listener is still registered, but not to the main category any longer. One way to handle this behavior is to remove the listener from the old main category and add it to the new main category.

Parameters:
listener -

addPropertyListener

public void addPropertyListener(PropertyListener listener,
                                java.lang.String categoryName)
Adds the PropertyListener to the given category.


getConfigName

public java.lang.String getConfigName()
Return the name of the current configuration.

Returns:

setConfigName

public void setConfigName(java.lang.String configName)
Sets the name of the configuration.

Parameters:
configName -

addConfigurationListener

public void addConfigurationListener(ConfigurationListener listener)
Adds the specified configuration listener to receive configuration changed events from this configuration.

Parameters:
listener - The ConfigurationListener

removeConfigurationListener

public void removeConfigurationListener(ConfigurationListener listener)
Removes the specified configuration listener from the configuration change events from this configuration.

Parameters:
listener - The ConfigurationListener

fireConfigurationChangedEvent

public void fireConfigurationChangedEvent(ConfigurationChangedEvent event)
Deliver configuration changed event to all listeners that are registered with our listener list.

Parameters:
event - The ConfigurationChangedEvent

getCategory

public Category getCategory()
Returns the main category for this configuration

Returns:
The main category

getCategory

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

Parameters:
name - The name of the category (if null, main category will be used)
Returns:
The category object (new instance if necessary)

setLongProperty

public void setLongProperty(java.lang.String key,
                            long value)
Wrapper method to Category method

Parameters:
key -
value -

setIntProperty

public void setIntProperty(java.lang.String key,
                           int value)
Wrapper method to Category method

Parameters:
key -
value -

setCharProperty

public void setCharProperty(java.lang.String key,
                            char value)
Wrapper method to Category method

Parameters:
key -
value -

setCharProperty

public void setCharProperty(java.lang.String key,
                            char value,
                            java.lang.String category)
Wrapper method to Category method

Parameters:
key -
value -
category -

setDoubleProperty

public void setDoubleProperty(java.lang.String key,
                              double value)
Wrapper method to Category method

Parameters:
key -
value -

setLongProperty

public void setLongProperty(java.lang.String key,
                            long value,
                            java.lang.String category)
Wrapper method to Category method

Parameters:
key -
value -
category -

setIntProperty

public void setIntProperty(java.lang.String key,
                           int value,
                           java.lang.String category)
Wrapper method to Category method

Parameters:
key -
value -
category -

setDoubleProperty

public void setDoubleProperty(java.lang.String key,
                              double value,
                              java.lang.String category)
Wrapper method to Category method

Parameters:
key -
value -
category -

hasChanged

public boolean hasChanged()
This methods returns a flag which indicates if the configuration has changed since it was loaded.

Returns:
true if the configuration has changed

getArray

public java.lang.String[] getArray(java.lang.String key)
Parameters:
key -
Returns:

getArray

public java.lang.String[] getArray(java.lang.String key,
                                   java.lang.String[] defaultValue)
Parameters:
key -
defaultValue -
Returns:

getArray

public java.lang.String[] getArray(java.lang.String key,
                                   java.lang.String[] defaultValue,
                                   java.lang.String category)
Parameters:
key -
defaultValue -
category -
Returns:

isNew

public boolean isNew()
This method determines if the configuration was loaded successfully (returns false) or if the configuration was created by the ConfigurationManager.

Returns:
true if created by the ConfigurationManager

resetCreated

public void resetCreated()
This method is used by the handlers to reset the isNew flag to false. This indicates that the configuration was loaded and not created.


setEncoding

public void setEncoding(java.lang.String encoding)

getEncoding

public java.lang.String getEncoding()

addCategoryListener

public void addCategoryListener(CategoryListener listener)

addCategoryListener

public void addCategoryListener(CategoryListener listener,
                                java.lang.String categoryName)

containsCategory

public boolean containsCategory(java.lang.String categoryName)
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.


addInclude

public void addInclude(int type,
                       java.lang.String name)

getIncludes

public java.util.Vector getIncludes()

setBaseConfiguration

public void setBaseConfiguration(java.lang.String name)
This method is used to define the base configuration of a configuration. This means if config A extends config B then this method will be called in config A with the name of config B.


getBaseConfiguration

public java.lang.String getBaseConfiguration()

renameCategory

public void renameCategory(java.lang.String newName,
                           java.lang.String oldName)


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