net.sourceforge.geeboss.util
Class ConfigurationUtil

java.lang.Object
  extended by net.sourceforge.geeboss.util.ConfigurationUtil

public class ConfigurationUtil
extends java.lang.Object

Utility methods for Configurations

Author:
Frederic BORRY

Field Summary
static java.lang.String CONFIG_DIR_ATTRIBUTE
          config dir attribute
static java.lang.String CONFIG_DIR_PATH_ATTRIBUTE
          config dir path attribute
static java.lang.String CONFIG_FILE_ATTRIBUTE
          config path attribute
static java.lang.String CONFIG_FILE_PATH_ATTRIBUTE
          config file path attribute
 
Constructor Summary
ConfigurationUtil()
           
 
Method Summary
static org.apache.avalon.framework.configuration.Configuration buildFromFile(java.io.File file)
          Build a configuration from a file
static org.apache.avalon.framework.configuration.Configuration buildFromStream(java.io.InputStream stream)
          Build a configuration from a stream
static org.apache.avalon.framework.configuration.Configuration buildFromString(java.lang.String configurationString)
          Build a configuration from a string
static java.lang.String checkAndGetAttribute(org.apache.avalon.framework.configuration.Configuration config, java.lang.String attributeName)
          Check and Get a configuration's attribute value
static java.lang.Double checkAndGetAttributeAsDouble(org.apache.avalon.framework.configuration.Configuration config, java.lang.String attributeName)
          Check and Get a configuration's attribute value as a Double
static org.apache.avalon.framework.configuration.Configuration checkAndGetElement(org.apache.avalon.framework.configuration.Configuration config, java.lang.String elementName)
          Check and Get a configuration's child element
static java.lang.String checkAndGetElementValue(org.apache.avalon.framework.configuration.Configuration config, java.lang.String elementName)
          Check and Get a configuration's element value
static java.lang.String checkAndGetElementValue(org.apache.avalon.framework.configuration.Configuration config, java.lang.String elementName, java.lang.String defaultValue)
          Check and Get a configuration's element value
static long checkAndGetHexElementValue(org.apache.avalon.framework.configuration.Configuration config, java.lang.String elementName)
          Check and Get a configuration's element hex value
static int checkAndGetIntElementValue(org.apache.avalon.framework.configuration.Configuration config, java.lang.String elementName)
          Check and Get a configuration's element int value
static void checkElementName(org.apache.avalon.framework.configuration.Configuration config, java.lang.String name)
          Check configuration's name
static org.apache.avalon.framework.configuration.Configuration createDateElement(java.lang.String elementName, java.lang.String valueAttributeName, java.util.Date date)
          Create a configuration element hodling a date value attribute according to the sepcified Date
static org.apache.avalon.framework.configuration.Configuration createIdElement(java.lang.String elementName, java.lang.String idAttributeName, java.lang.String id)
          Create a configuration element hodling an id attribute
static org.apache.avalon.framework.configuration.Configuration createValueElement(java.lang.String elementName, java.lang.String valueAttributeName, java.lang.Number value)
          Create a configuration element hodling a value attribute according to the sepcified number
static java.lang.Double getAttributeAsDouble(org.apache.avalon.framework.configuration.Configuration configuration, java.lang.String attributeName, double defaultValue)
          Get the Double value of an attribute.
static java.lang.Double getAttributeAsDouble(org.apache.avalon.framework.configuration.Configuration configuration, java.lang.String attributeName, java.lang.Double defaultValue)
          Get the Double value of an attribute
static java.lang.String getChildValue(org.apache.avalon.framework.configuration.Configuration configuration, java.lang.String elementName, java.lang.String defaultValue)
          Get the value (text content) of an child element within a configuration
static int[] getRange(org.apache.avalon.framework.configuration.Configuration configuration)
          Get the range from a configuration
static java.util.Date readDateElement(org.apache.avalon.framework.configuration.Configuration configuration, java.lang.String dateAttributeName)
          Read a date element
static void serializeToStream(org.apache.avalon.framework.configuration.Configuration configuration, java.io.OutputStream stream)
          Serialize a given condiguration to a Stream
static java.lang.String serializeToString(org.apache.avalon.framework.configuration.Configuration configuration)
          Serialize a given condiguration to a String
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONFIG_DIR_PATH_ATTRIBUTE

public static final java.lang.String CONFIG_DIR_PATH_ATTRIBUTE
config dir path attribute

See Also:
Constant Field Values

CONFIG_DIR_ATTRIBUTE

public static final java.lang.String CONFIG_DIR_ATTRIBUTE
config dir attribute

See Also:
Constant Field Values

CONFIG_FILE_PATH_ATTRIBUTE

public static final java.lang.String CONFIG_FILE_PATH_ATTRIBUTE
config file path attribute

See Also:
Constant Field Values

CONFIG_FILE_ATTRIBUTE

public static final java.lang.String CONFIG_FILE_ATTRIBUTE
config path attribute

See Also:
Constant Field Values
Constructor Detail

ConfigurationUtil

public ConfigurationUtil()
Method Detail

buildFromFile

public static org.apache.avalon.framework.configuration.Configuration buildFromFile(java.io.File file)
                                                                             throws org.apache.avalon.framework.configuration.ConfigurationException
Build a configuration from a file

Parameters:
file - the file to load
Returns:
the loaded configuration
Throws:
org.apache.avalon.framework.configuration.ConfigurationException - if an error occured while reading file

buildFromStream

public static org.apache.avalon.framework.configuration.Configuration buildFromStream(java.io.InputStream stream)
                                                                               throws org.apache.avalon.framework.configuration.ConfigurationException
Build a configuration from a stream

Parameters:
stream - to load
Returns:
the loaded configuration
Throws:
org.apache.avalon.framework.configuration.ConfigurationException - if an error occured while reading the stream

buildFromString

public static org.apache.avalon.framework.configuration.Configuration buildFromString(java.lang.String configurationString)
                                                                               throws org.apache.avalon.framework.configuration.ConfigurationException
Build a configuration from a string

Parameters:
configurationString - the String to read
Returns:
the loaded configuration
Throws:
org.apache.avalon.framework.configuration.ConfigurationException - if an error occured while reading file

serializeToString

public static java.lang.String serializeToString(org.apache.avalon.framework.configuration.Configuration configuration)
                                          throws org.apache.avalon.framework.configuration.ConfigurationException
Serialize a given condiguration to a String

Parameters:
configuration - the Configuration to serialize
Returns:
the serialized configuration
Throws:
org.apache.avalon.framework.configuration.ConfigurationException - if an error occured while seriliazing configuration

serializeToStream

public static void serializeToStream(org.apache.avalon.framework.configuration.Configuration configuration,
                                     java.io.OutputStream stream)
                              throws org.apache.avalon.framework.configuration.ConfigurationException,
                                     java.io.IOException
Serialize a given condiguration to a Stream

Parameters:
configuration - the Configuration to serialize
stream - the stream to serialize the configuration to
Throws:
org.apache.avalon.framework.configuration.ConfigurationException - if an error occured while seriliazing configuration
java.io.IOException

checkElementName

public static void checkElementName(org.apache.avalon.framework.configuration.Configuration config,
                                    java.lang.String name)
                             throws org.apache.avalon.framework.configuration.ConfigurationException
Check configuration's name

Parameters:
config - the configuration
name - the name
Throws:
org.apache.avalon.framework.configuration.ConfigurationException - the name is not the one expceted

checkAndGetAttribute

public static java.lang.String checkAndGetAttribute(org.apache.avalon.framework.configuration.Configuration config,
                                                    java.lang.String attributeName)
                                             throws org.apache.avalon.framework.configuration.ConfigurationException
Check and Get a configuration's attribute value

Parameters:
config - the configuration
attributeName - the name of the attribute to check
Returns:
the attribute value
Throws:
org.apache.avalon.framework.configuration.ConfigurationException - if attribute is not present

checkAndGetAttributeAsDouble

public static java.lang.Double checkAndGetAttributeAsDouble(org.apache.avalon.framework.configuration.Configuration config,
                                                            java.lang.String attributeName)
                                                     throws org.apache.avalon.framework.configuration.ConfigurationException
Check and Get a configuration's attribute value as a Double

Parameters:
config - the configuration
attributeName - the name of the attribute to check
Returns:
the attribute value
Throws:
org.apache.avalon.framework.configuration.ConfigurationException - if attribute is not present

checkAndGetHexElementValue

public static long checkAndGetHexElementValue(org.apache.avalon.framework.configuration.Configuration config,
                                              java.lang.String elementName)
                                       throws org.apache.avalon.framework.configuration.ConfigurationException
Check and Get a configuration's element hex value

Parameters:
config - the configuration
elementName - the name of the element to check
Returns:
the element value
Throws:
org.apache.avalon.framework.configuration.ConfigurationException - if element is not present

checkAndGetIntElementValue

public static int checkAndGetIntElementValue(org.apache.avalon.framework.configuration.Configuration config,
                                             java.lang.String elementName)
                                      throws org.apache.avalon.framework.configuration.ConfigurationException
Check and Get a configuration's element int value

Parameters:
config - the configuration
elementName - the name of the element to check
Returns:
the element value
Throws:
org.apache.avalon.framework.configuration.ConfigurationException - if element is not present

checkAndGetElementValue

public static java.lang.String checkAndGetElementValue(org.apache.avalon.framework.configuration.Configuration config,
                                                       java.lang.String elementName)
                                                throws org.apache.avalon.framework.configuration.ConfigurationException
Check and Get a configuration's element value

Parameters:
config - the configuration
elementName - the name of the element to check
Returns:
the element value
Throws:
org.apache.avalon.framework.configuration.ConfigurationException - if element is not present

checkAndGetElementValue

public static java.lang.String checkAndGetElementValue(org.apache.avalon.framework.configuration.Configuration config,
                                                       java.lang.String elementName,
                                                       java.lang.String defaultValue)
                                                throws org.apache.avalon.framework.configuration.ConfigurationException
Check and Get a configuration's element value

Parameters:
config - the configuration
elementName - the name of the element to check
defaultValue - the default value
Returns:
the element value
Throws:
org.apache.avalon.framework.configuration.ConfigurationException - if element is not present

checkAndGetElement

public static org.apache.avalon.framework.configuration.Configuration checkAndGetElement(org.apache.avalon.framework.configuration.Configuration config,
                                                                                         java.lang.String elementName)
                                                                                  throws org.apache.avalon.framework.configuration.ConfigurationException
Check and Get a configuration's child element

Parameters:
config - the configuration
elementName - the name of the element to check
Returns:
the element
Throws:
org.apache.avalon.framework.configuration.ConfigurationException - if element is not present

getRange

public static int[] getRange(org.apache.avalon.framework.configuration.Configuration configuration)
                      throws org.apache.avalon.framework.configuration.ConfigurationException
Get the range from a configuration

Parameters:
configuration - the configuration containing the range
Returns:
an array containing the min and max value
Throws:
org.apache.avalon.framework.configuration.ConfigurationException

getChildValue

public static java.lang.String getChildValue(org.apache.avalon.framework.configuration.Configuration configuration,
                                             java.lang.String elementName,
                                             java.lang.String defaultValue)
Get the value (text content) of an child element within a configuration

Parameters:
configuration - the configuration to search the element for
elementName - the name of the element we want the value for
defaultValue - the default value
Returns:
the element's context or the default value

getAttributeAsDouble

public static java.lang.Double getAttributeAsDouble(org.apache.avalon.framework.configuration.Configuration configuration,
                                                    java.lang.String attributeName,
                                                    java.lang.Double defaultValue)
                                             throws org.apache.avalon.framework.configuration.ConfigurationException
Get the Double value of an attribute

Parameters:
configuration - the configuration to search the attribute for
defaultValue - the default value
Returns:
the attribute value or the default value if attribute is not present
Throws:
org.apache.avalon.framework.configuration.ConfigurationException

getAttributeAsDouble

public static java.lang.Double getAttributeAsDouble(org.apache.avalon.framework.configuration.Configuration configuration,
                                                    java.lang.String attributeName,
                                                    double defaultValue)
Get the Double value of an attribute. If a parsing error occurs, silently return the default value.

Parameters:
configuration - the configuration to search the attribute for
defaultValue - the default value
Returns:
the attribute value or the default value if attribute is not present or misspelled

createValueElement

public static org.apache.avalon.framework.configuration.Configuration createValueElement(java.lang.String elementName,
                                                                                         java.lang.String valueAttributeName,
                                                                                         java.lang.Number value)
Create a configuration element hodling a value attribute according to the sepcified number

Parameters:
elementName - the name of the element to create
valueAttributeName - the name of the value attribute
value - the value
Returns:
a configuration element hodling the value attribute

createIdElement

public static org.apache.avalon.framework.configuration.Configuration createIdElement(java.lang.String elementName,
                                                                                      java.lang.String idAttributeName,
                                                                                      java.lang.String id)
Create a configuration element hodling an id attribute

Parameters:
elementName - the name of the element to create
idAttributeName - the name of the value attribute
id - the id
Returns:
a configuration element hodling the value attribute

createDateElement

public static org.apache.avalon.framework.configuration.Configuration createDateElement(java.lang.String elementName,
                                                                                        java.lang.String valueAttributeName,
                                                                                        java.util.Date date)
Create a configuration element hodling a date value attribute according to the sepcified Date

Parameters:
elementName - the name of the element to create
valueAttributeName - the name of the value attribute
date - the date
Returns:
a configuration element hodling the value attribute

readDateElement

public static java.util.Date readDateElement(org.apache.avalon.framework.configuration.Configuration configuration,
                                             java.lang.String dateAttributeName)
                                      throws org.apache.avalon.framework.configuration.ConfigurationException
Read a date element

Parameters:
configuration - the date element
dateAttributeName - the date attribute name
Returns:
the date value
Throws:
org.apache.avalon.framework.configuration.ConfigurationException


Copyright (c) 2005 The Geeboss team (http://geeboss.sourceforge.net). All Rights Reserved.