Package org.castor.core.util
Class AbstractProperties
- java.lang.Object
-
- org.castor.core.util.AbstractProperties
-
- Direct Known Subclasses:
CastorProperties
,CoreProperties
,CPAProperties
,XMLProperties
public abstract class AbstractProperties extends java.lang.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
Constructors Modifier Constructor Description protected
AbstractProperties()
Default constructor.protected
AbstractProperties(java.lang.ClassLoader app, java.lang.ClassLoader domain)
Construct properties that uses the specified class loaders.protected
AbstractProperties(AbstractProperties parent)
Construct properties with given parent.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.Object
get(java.lang.String key)
Searches for the property with the specified key in this property map.java.lang.ClassLoader
getApplicationClassLoader()
Get classloader to be used for all classes of Castor and its required libraries.java.lang.Boolean
getBoolean(java.lang.String key)
Searches for the property with the specified key in this property map.boolean
getBoolean(java.lang.String key, boolean defaultValue)
Searches for the property with the specified key in this property map.java.lang.Class
getClass(java.lang.String key, java.lang.ClassLoader loader)
Searches for the property with the specified key in this property map.java.lang.Class[]
getClassArray(java.lang.String key, java.lang.ClassLoader loader)
Searches for the property with the specified key in this property map.java.lang.ClassLoader
getDomainClassLoader()
Get classloader to be used for all domain objects that are marshalled/unmarshalled or loaded from the database.java.lang.Integer
getInteger(java.lang.String key)
Searches for the property with the specified key in this property map.int
getInteger(java.lang.String key, int defaultValue)
Searches for the property with the specified key in this property map.java.lang.Object
getObject(java.lang.String key)
Searches for the property with the specified key in this property map.java.lang.Object[]
getObjectArray(java.lang.String key, java.lang.ClassLoader loader)
Searches for the property with the specified key in this property map.java.lang.String
getString(java.lang.String key)
Searches for the property with the specified key in this property map.java.lang.String
getString(java.lang.String key, java.lang.String defaultValue)
Searches for the property with the specified key in this property map.java.lang.String[]
getStringArray(java.lang.String key)
Searches for the property with the specified key in this property map.protected void
loadDefaultProperties(java.lang.String path, java.lang.String filename)
Load module properties from default locations.protected void
loadUserProperties(java.lang.String filename)
Load common user properties from classpath root and current working directory.java.lang.Object
put(java.lang.String key, java.lang.Object value)
Put given value associated with given key into the properties map of this properties.java.lang.Object
remove(java.lang.String key)
Remove any value previously associated with the given key from this properties.
-
-
-
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(java.lang.ClassLoader app, java.lang.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 java.lang.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 java.lang.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(java.lang.String path, java.lang.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(java.lang.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 java.lang.Object put(java.lang.String key, java.lang.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 returnsnull
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 aNullPointerException
will be thrown if the given value isnull
.- 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 java.lang.Object remove(java.lang.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 returnsnull
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 returnnull
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 java.lang.Object get(java.lang.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 java.lang.Boolean getBoolean(java.lang.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(java.lang.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 java.lang.Integer getInteger(java.lang.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(java.lang.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 java.lang.String getString(java.lang.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 java.lang.String getString(java.lang.String key, java.lang.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 java.lang.String[] getStringArray(java.lang.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 java.lang.Class getClass(java.lang.String key, java.lang.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 java.lang.Class[] getClassArray(java.lang.String key, java.lang.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 java.lang.Object getObject(java.lang.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 java.lang.Object[] getObjectArray(java.lang.String key, java.lang.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.
-
-