net.craftforge.commons.configuration
Class PropertiesHolder

java.lang.Object
  extended by net.craftforge.commons.configuration.PropertiesHolder
Direct Known Subclasses:
Configuration

public class PropertiesHolder
extends Object

A properties holder provides a convenient way of accessing a properties resource.

Since:
17.08.11
Author:
Christian Bick

Constructor Summary
PropertiesHolder(String resource)
          Initializes the properties holder from a resource.
 
Method Summary
protected  Class<?> createClass(String propertyName, Class<?> defaultClass)
          Creates a class from a property using a default class if the property is not set.
protected  Map<String,String> createMap(String prefix)
          Creates a map of properties which match the given property name prefix.
 Class<?> getClass(String propertyName, Class<?> defaultClass)
          Gets a class from a property if the property value represents a class path known to class loader.
 Map<String,String> getProperties(String propertyNamePrefix)
          Gets a map of properties which match the given property name prefix.
 String getProperty(String propertyName)
          Gets a property from the holder or manually added properties.
protected  void removeClass(String propertyName)
          Removes the class associated to the given property name from the caching map.
protected  void removeMaps(String propertyName)
          Removes all maps associated to all possible prefixes of the given property name from the caching map.
 void setProperties(String propertyNamePrefix, Map<String,String> properties)
          Sets the properties in the given property map and puts the given property name prefix before to the property name keys.
 void setProperty(String propertyName, String propertyValue)
          Sets a property of the given name to the given value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PropertiesHolder

public PropertiesHolder(String resource)
Initializes the properties holder from a resource.

Parameters:
resource - The resource
Method Detail

getProperty

public String getProperty(String propertyName)
Gets a property from the holder or manually added properties.

Parameters:
propertyName - The property name
Returns:
The property value

setProperty

public void setProperty(String propertyName,
                        String propertyValue)
Sets a property of the given name to the given value.

Parameters:
propertyName - The property name
propertyValue - The property value

setProperties

public void setProperties(String propertyNamePrefix,
                          Map<String,String> properties)
Sets the properties in the given property map and puts the given property name prefix before to the property name keys.

Parameters:
propertyNamePrefix - The property name prefix
properties - The property map

getProperties

public Map<String,String> getProperties(String propertyNamePrefix)

Gets a map of properties which match the given property name prefix.

Example:

my.property.KEY_ONE = value1
my.property.KEY_TWO = value2


my.property -> { KEY_ONE : value1 ; KEY_TWO : value2 }

Parameters:
propertyNamePrefix - The property name prefix
Returns:
The matched map of properties

getClass

public Class<?> getClass(String propertyName,
                         Class<?> defaultClass)
Gets a class from a property if the property value represents a class path known to class loader.

Parameters:
propertyName - The property name
defaultClass - The default class to return if the property is not set
Returns:
The class

createClass

protected Class<?> createClass(String propertyName,
                               Class<?> defaultClass)
Creates a class from a property using a default class if the property is not set.

Parameters:
propertyName - The property name
defaultClass - The default class
Returns:
The created class

createMap

protected Map<String,String> createMap(String prefix)
Creates a map of properties which match the given property name prefix.

Parameters:
prefix - The property name prefix
Returns:
The created matched map of properties

removeClass

protected void removeClass(String propertyName)
Removes the class associated to the given property name from the caching map.

Parameters:
propertyName - The property name

removeMaps

protected void removeMaps(String propertyName)
Removes all maps associated to all possible prefixes of the given property name from the caching map.

Parameters:
propertyName - The property name


Copyright © 2011. All Rights Reserved.