org.castor.core.util
Class AbstractProperties

java.lang.Object
  extended by org.castor.core.util.AbstractProperties
Direct Known Subclasses:
CastorProperties, CoreProperties

public abstract class AbstractProperties
extends Object

Abstract base class to hold Castor configuration properties.

Since:
1.1.3
Version:
$Id: Configuration.java,v 1.8 2006/03/08 17:25:52 jens Exp $
Author:
Ralf Joachim

Constructor Summary
protected AbstractProperties()
          Default constructor.
protected AbstractProperties(AbstractProperties parent)
          Construct properties with given parent.
protected AbstractProperties(ClassLoader app, ClassLoader domain)
          Construct properties that uses the specified class loaders.
 
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 module properties from default locations.
protected  void loadUserProperties(String filename)
          Load common user properties 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 properties.
 Object remove(String key)
          Remove any value previously associated with the given key from this properties.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractProperties

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


AbstractProperties

protected AbstractProperties(ClassLoader app,
                             ClassLoader domain)
Construct properties that uses the specified class loaders. No parent properties 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.

AbstractProperties

protected AbstractProperties(AbstractProperties parent)
Construct properties with given parent. Application and domain class loaders will be initialized to the ones of the parent.

Parameters:
parent - Parent properties.
Method Detail

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.

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.

loadDefaultProperties

protected void loadDefaultProperties(String path,
                                     String filename)
Load module properties from default locations.
First it loads default properties contained in Castor JAR. This gets overwritten by a properties found on Java library directory. If no properties could be found until that point a PropertiesException will be thrown.

Parameters:
path - Path to the default properties to load.
filename - Name of the properties file.

loadUserProperties

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

Parameters:
filename - Name of the properties file.

put

public final Object put(String key,
                        Object value)
Put given value associated with given key into the properties map of this properties. If the properties previously associated the key to another value the previous value will be returned. If a mapping for the key previously exist in the parent properties only, the method returns null and not the value of the parent. This allows to distingush if the mapping existed in this properties or one of its parents.
Putting a value in this properties does not change the value of its parent but the parents value isn't visible any more as it gets overwritten by this properties one. While this allows to redefine 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 properties.
value - Value to put into properties associated with the given key..
Returns:
Object in this properties 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 properties. The value previously associated with the key in this properties will be returned. If a mapping for the key existed in the parent properties only, the method returns null and not the value of the parent. This allows to distingush if the mapping existed in this properties or one of its parents.
Removing the value from this properties 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 properties.

Parameters:
key - Key of the property to remove from properties.
Returns:
Object in this properties that previously has been associated with the given key.

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 properties.
Returns:
Object in this property map with the specified key value.

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 PropertiesException 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.

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 PropertiesException 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.

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 PropertiesException 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 PropertiesException will be thrown.

Parameters:
key - Property key.
Returns:
String array 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 PropertiesException 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 PropertiesException 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.

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 PropertiesException 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.


Copyright © 2012. All Rights Reserved.