org.eclipse.stardust.common.config
Class Parameters

java.lang.Object
  extended by org.eclipse.stardust.common.config.Parameters

public abstract class Parameters
extends Object

The JDK has various mechanisms to obtain environmental parameters such as system properties, resources etc. which are confusing to use. This class provides a homogenous mechanism to access all this information.

It is possible to store additional properties sets, being considered as a "chain of responsibilities" in a "last in-first considered" manner.

Parameters are key/value-pairs. The name may be a list of identifiers separated by ".". The identifiers are considered case-insensitive.

Version:
$Revision$

Nested Class Summary
static interface Parameters.IDisposable
           
 
Constructor Summary
Parameters()
           
 
Method Summary
abstract  void addProperties(String fileName)
          There must be a a file ".properties" in one of the directories provided with the classpath.
abstract  void flush()
          Resets the cached configuration, effectively enforcing a configuration reload when properties are retrieved the next time.
abstract  Object get(String name)
           
 boolean getBoolean(String name, boolean defaultValue)
           
 Calendar getDate(String name)
          We expect the format yyyy-mm-dd.
 Calendar getDate(String name, Calendar defaultValue)
          We expect the format yyyy-mm-dd.
static String getDefaultProperties()
           
 double getDouble(String name, double defaultValue)
          Gets the value of the property.
 int getInteger(String name, int defaultValue)
          Gets the value of the property.
 long getLong(String name, long defaultValue)
           
<T> T
getObject(String name)
           
<T> T
getObject(String name, T defaultValue)
           
 String getString(String name)
          Gets the value of the property.
 String getString(String name, String defaultValue)
          Gets the value of the property.
 List<String> getStrings(String name)
           
 List<String> getStrings(String name, String separators)
          Returns a list of values.
static Parameters instance()
           
abstract  void set(String name, Object value)
           
 void setBoolean(String name, boolean value)
           
static void setDefaultProperties(String baseName)
          There must be a a file ".properties" in one of the directories provided with the classpath.
 void setInteger(String name, int value)
           
 void setString(String name, String value)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Parameters

public Parameters()
Method Detail

setDefaultProperties

public static void setDefaultProperties(String baseName)
There must be a a file ".properties" in one of the directories provided with the classpath. This file will be used as the default properties file when calling instance().

Parameters:
baseName - the name of the file storing your properties (e.g. "carnot" will render "carnot.properties")

getDefaultProperties

public static String getDefaultProperties()

instance

public static Parameters instance()
Returns:
a singleton object of this class

get

public abstract Object get(String name)

getObject

public <T> T getObject(String name)

getObject

public <T> T getObject(String name,
                       T defaultValue)

getString

public final String getString(String name)
Gets the value of the property.

Parameters:
name - the name of the property
Returns:
a string representing of the property value if the property is found or null.
See Also:
getString(String, String)

getString

public final String getString(String name,
                              String defaultValue)
Gets the value of the property.

Parameters:
name - the name of the property
defaultValue - the default value of the property
Returns:
a string representing the property value if the property is found or the default value passed to the method.
See Also:
getString(String)

getInteger

public final int getInteger(String name,
                            int defaultValue)
Gets the value of the property.

Parameters:
name - the name of the property
defaultValue - the default value of the property
Returns:
an int representing the property value if the property is found or the default value passed to the method.

getLong

public final long getLong(String name,
                          long defaultValue)

getDouble

public double getDouble(String name,
                        double defaultValue)
Gets the value of the property.

Parameters:
name - the name of the property
defaultValue - the default value of the property
Returns:
an int representing the property value if the property is found or the default value passed to the method.

getBoolean

public final boolean getBoolean(String name,
                                boolean defaultValue)

getDate

public final Calendar getDate(String name,
                              Calendar defaultValue)
We expect the format yyyy-mm-dd.


getDate

public final Calendar getDate(String name)
We expect the format yyyy-mm-dd.


getStrings

public final List<String> getStrings(String name)

getStrings

public final List<String> getStrings(String name,
                                     String separators)
Returns a list of values. The values have to be comma separated in the property file.

Returns:
a LinkedList of the values. If no value is found, an empty list is returned.

set

public abstract void set(String name,
                         Object value)
Parameters:
name -
value -

setString

public final void setString(String name,
                            String value)

setInteger

public final void setInteger(String name,
                             int value)

setBoolean

public final void setBoolean(String name,
                             boolean value)

flush

public abstract void flush()
Resets the cached configuration, effectively enforcing a configuration reload when properties are retrieved the next time.


addProperties

public abstract void addProperties(String fileName)
There must be a a file ".properties" in one of the directories provided with the classpath. This file will be used as the properties file.

Parameters:
fileName - the name of the file storing your properties (e.g. "carnot" will render "carnot.properties")


Copyright © 2017 Eclipse Stardust. All Rights Reserved.