org.castor.core.util

Class Configuration

Known Direct Subclasses:
CastorConfiguration, CoreConfiguration, CPAConfiguration, XMLConfiguration

public abstract class Configuration
extends java.lang.Object

Abstract base class to hold Castor configuration properties.
Version:
$Id: Configuration.java,v 1.8 2006/03/08 17:25:52 jens Exp $
Author:
Ralf Joachim
Since:
1.1.3

Constructor Summary

Configuration()
Default constructor.
Configuration(ClassLoader app, ClassLoader domain)
Construct a configuration that uses the specified class loaders.
Configuration(Configuration parent)
Construct a configuration with given parent.

Method Summary

protected Object
get(String key)
Searches for the property with the specified key in this property map.
ClassLoader
getApplicationClassLoader()
Get classloader to be used for all classes of Castor and its required libraries.
Boolean
getBoolean(String key)
Searches for the property with the specified key in this property map.
boolean
getBoolean(String key, boolean defaultValue)
Searches for the property with the specified key in this property map.
Class
getClass(String key, ClassLoader loader)
Searches for the property with the specified key in this property map.
Class[]
getClassArray(String key, ClassLoader loader)
Searches for the property with the specified key in this property map.
ClassLoader
getDomainClassLoader()
Get classloader to be used for all domain objects that are marshalled/unmarshalled or loaded from the database.
Integer
getInteger(String key)
Searches for the property with the specified key in this property map.
int
getInteger(String key, int defaultValue)
Searches for the property with the specified key in this property map.
Object
getObject(String key)
Searches for the property with the specified key in this property map.
Object[]
getObjectArray(String key, ClassLoader loader)
Searches for the property with the specified key in this property map.
String
getString(String key)
Searches for the property with the specified key in this property map.
String
getString(String key, String defaultValue)
Searches for the property with the specified key in this property map.
String[]
getStringArray(String key)
Searches for the property with the specified key in this property map.
protected void
loadDefaultProperties(String path, String filename)
Load modul configuration from default locations.
protected void
loadUserProperties(String filename)
Load common user configuration from classpath root and current working directory.
Object
put(String key, Object value)
Put given value associated with given key into the properties map of this configuration.
Object
remove(String key)
Remove any value previously associated with the given key from this configuration.

Constructor Details

Configuration

protected Configuration()
Default constructor. Application and domain class loaders will be initialized to the one used to load the Configuration class. No parent configuration will be set.

Configuration

protected Configuration(ClassLoader app,
                        ClassLoader domain)
Construct a configuration that uses the specified class loaders. No parent configuration will be set.
Parameters:
app - Classloader to be used for all classes of Castor and its required libraries.
domain - Classloader to be used for all domain objects.

Configuration

protected Configuration(Configuration parent)
Construct a configuration with given parent. Application and domain class loaders will be initialized to the ones of the parent.
Parameters:
parent - Parent configuration.

Method Details

get

protected Object get(String key)
Searches for the property with the specified key in this property map. If the key is not found in this property map, the parent property map, and its parents, recursively, are then checked.
If the key maps to any object value, it will be returned as is. If the property is not found, null will be returned.
Parameters:
key - Key of the property to get from configuration.
Returns:
Object in this property map with the specified key value.

getApplicationClassLoader

public final ClassLoader getApplicationClassLoader()
Get classloader to be used for all classes of Castor and its required libraries.
Returns:
Classloader to be used for all classes of Castor and its required libraries.

getBoolean

public final Boolean getBoolean(String key)
Searches for the property with the specified key in this property map. If the key is not found in this property map, the parent property map, and its parents, recursively, are then checked.
If the key maps to a boolean value, it will be returned as is. For string values that are equal, ignore case, to 'true' or 'false', the respective boolean value will be returned. If the property is not found, null will be returned. For all other types and string values a ConfigurationException will be thrown. This behaviour is intended for those usecases that need distinguish between values that are missconfigured or not specified at all.
Parameters:
key - Property key.
Returns:
Boolean value in this property map with the specified key value.

getBoolean

public final boolean getBoolean(String key,
                                boolean defaultValue)
Searches for the property with the specified key in this property map. If the key is not found in this property map, the parent property map, and its parents, recursively, are then checked.
If the key maps to a boolean value, it will be returned as is. For string values that are equal, ignore case, to 'true' or 'false', the respective boolean value will be returned. In all other cases the given default value will be returned.
Parameters:
key - Property key.
defaultValue - Default value.
Returns:
Boolean value in this property map with the specified key value.

getClass

public final Class getClass(String key,
                            ClassLoader loader)
Searches for the property with the specified key in this property map. If the key is not found in this property map, the parent property map, and its parents, recursively, are then checked.
If the key maps to a class, it will be returned as is. A simple string will be interpreted as class name of which the class will be loaded with the given class loader. If the property is not found, null will be returned. For all other types and if loading of the class fails a ConfigurationException will be thrown.
Parameters:
key - Property key.
loader - Class loader to load classes with.
Returns:
Class in this property map with the specified key value.

getClassArray

public final Class[] getClassArray(String key,
                                   ClassLoader loader)
Searches for the property with the specified key in this property map. If the key is not found in this property map, the parent property map, and its parents, recursively, are then checked.
If the key maps to a class array, it will be returned as is. A simple string will be splitted it into substrings at every occurence of ',' character. Each of these substrings will interpreted as class name of which the class will be loaded with the given class loader. If the property is not found, null will be returned. For all other types and if loading of one of the classes fails a ConfigurationException will be thrown.
Parameters:
key - Property key.
loader - Class loader to load classes with.
Returns:
Class array in this property map with the specified key value.

getDomainClassLoader

public final ClassLoader getDomainClassLoader()
Get classloader to be used for all domain objects that are marshalled/unmarshalled or loaded from the database.
Returns:
Classloader to be used for all domain objects.

getInteger

public final Integer getInteger(String key)
Searches for the property with the specified key in this property map. If the key is not found in this property map, the parent property map, and its parents, recursively, are then checked.
If the key maps to a integer value, it will be returned as is. For string values that can be interpreted as signed decimal integer, the respective integer value will be returned. If the property is not found, null will be returned. For all other types and string values a ConfigurationException will be thrown. This behaviour is intended for those usecases that need distinguish between values that are missconfigured or not specified at all.
Parameters:
key - Property key.
Returns:
Integer value in this property map with the specified key value.

getInteger

public final int getInteger(String key,
                            int defaultValue)
Searches for the property with the specified key in this property map. If the key is not found in this property map, the parent property map, and its parents, recursively, are then checked.
If the key maps to a integer value, it will be returned as is. For string values that can be interpreted as signed decimal integer, the respective integer value will be returned. In all other cases the given default value will be returned.
Parameters:
key - Property key.
defaultValue - Default value.
Returns:
Integer value in this property map with the specified key value.

getObject

public final Object getObject(String key)
Searches for the property with the specified key in this property map. If the key is not found in this property map, the parent property map, and its parents, recursively, are then checked.
If the key maps to any object value, it will be returned as is. If the property is not found, null will be returned.
Parameters:
key - Property key.
Returns:
Object in this property map with the specified key value.

getObjectArray

public final Object[] getObjectArray(String key,
                                     ClassLoader loader)
Searches for the property with the specified key in this property map. If the key is not found in this property map, the parent property map, and its parents, recursively, are then checked.
If the key maps to a object array, it will be returned as is. A simple string will be splitted it into substrings at every occurence of ',' character. Each of these substrings will interpreted as class name of which the class will be loaded with the given class loader and instantiated using its default constructor. If the property is not found, null will be returned. For all other types and if loading or instantiation of one of the classes fails a ConfigurationException will be thrown.
Parameters:
key - Property key.
loader - Class loader to load classes with.
Returns:
Class array in this property map with the specified key value.

getString

public final String getString(String key)
Searches for the property with the specified key in this property map. If the key is not found in this property map, the parent property map, and its parents, recursively, are then checked.
If the key maps to a string value, it will be returned as is. If the property is not found, null will be returned. For all other types a ConfigurationException will be thrown.
Parameters:
key - Property key.
Returns:
String value in this property map with the specified key value.

getString

public final String getString(String key,
                              String defaultValue)
Searches for the property with the specified key in this property map. If the key is not found in this property map, the parent property map, and its parents, recursively, are then checked.
If the key maps to a string value that is not empty, it will be returned as is. In all other cases the given default value will be returned.
Parameters:
key - Property key.
defaultValue - Default value.
Returns:
String value in this property map with the specified key value.

getStringArray

public final String[] getStringArray(String key)
Searches for the property with the specified key in this property map. If the key is not found in this property map, the parent property map, and its parents, recursively, are then checked.
If the key maps to a string array, it will be returned as is. A simple string will be converted into a string array by splitting it into substrings at every occurence of ',' character. If the property is not found, null will be returned. For all other types a ConfigurationException will be thrown.
Parameters:
key - Property key.
Returns:
String array in this property map with the specified key value.

loadDefaultProperties

protected void loadDefaultProperties(String path,
                                     String filename)
Load modul configuration from default locations.
First it loads default configuration contained in Castor JAR. This gets overwritten by a configuration found on Java library directory. If no configuration could be found until that point a ConfigurationException will be thrown.
Parameters:
path - Path to the default configuration to load.
filename - Name of the configuration file.

loadUserProperties

protected void loadUserProperties(String filename)
Load common user configuration from classpath root and current working directory.
First it loads default configuration contained in Castor JAR. This gets overwritten by a configuration found on Java library directory. If no configuration could be found until that point a ConfigurationException will be thrown. At last an overriding configuration is loaded from root of classpath or, if that could not be found, from local working directory.
Parameters:
filename - Name of the configuration file.

put

public final Object put(String key,
                        Object value)
Put given value associated with given key into the properties map of this configuration. If the configuration previously associated the key to another value the previous value will be returned. If a mapping for the key previously exist in the parent configuration only, the method returns null and not the value of the parent. This allows to distingush if the mapping existed in this configuration or one of its parents.
Putting a value in this configuration does not change the value of its parent but the parents value isn't visible any more as it gets overwritten by this configurations one. While this allows to redifine the value of a property it isn't allowed to undefine it. Therefore a NullPointerException will be thrown if the given value is null.
Parameters:
key - Key of the property to put into configuration.
value - Value to put into configuration associated with the given key..
Returns:
Object in this configuration that previously has been associated with the given key.

remove

public final Object remove(String key)
Remove any value previously associated with the given key from this configuration. The value previously associated with the key int this configuration will be returned. If a mapping for the key existed in the parent configuration only, the method returns null and not the value of the parent. This allows to distingush if the mapping existed in this configuration or one of its parents.
Removing the value from this configuration does not mean that consecutive gets return null as one of the parents may still contain a mapping for the key that was hidden by the mapping in this configuration.
Parameters:
key - Key of the property to remove from configuration.
Returns:
Object in this configuration that previously has been associated with the given key.

Intalio Inc. (C) 1999-2008. All rights reserved http://www.intalio.com