org.codehaus.spice.salt.config
Class DefaultParameters

java.lang.Object
  extended byorg.codehaus.spice.salt.config.DefaultParameters
All Implemented Interfaces:
Parameters

public class DefaultParameters
extends Object
implements Parameters

Parameters implementation backed by a Properties object. The developer should create the DefaultParameters, associate parameters and then invoke makeReadOnly() before passing the Parameters to the client component.

Version:
$Revision: 1.1 $ $Date: 2003/12/02 02:15:04 $
Author:
Peter Donald

Constructor Summary
DefaultParameters()
          Create a parameters object with empty prefix.
DefaultParameters(String prefix)
          Create a parameters object with specified prefix.
 
Method Summary
protected  void checkWriteable()
          Check if the resource has been "frozen" and thus is read only.
 Parameters getChildParameters(String prefix)
          Return a Parameters object that represents a subset of parameters with specified prefix.
protected  Set getChildren()
          Return the set of child parameter objects.
 String getParameter(String name)
          Return value of parameter with specified name.
 String getParameter(String name, String defaultValue)
          Return value of parameter with specified name.
 boolean getParameterAsBoolean(String name)
          Return value of parameter with specified name as a boolean.
 boolean getParameterAsBoolean(String name, boolean defaultValue)
          Return value of parameter with specified name as a boolean.
 float getParameterAsFloat(String name)
          Return value of parameter with specified name as a float.
 float getParameterAsFloat(String name, float defaultValue)
          Return value of parameter with specified name as a float.
 int getParameterAsInteger(String name)
          Return value of parameter with specified name as an integer.
 int getParameterAsInteger(String name, int defaultValue)
          Return value of parameter with specified name as an integer.
 long getParameterAsLong(String name)
          Return value of parameter with specified name as a long.
 long getParameterAsLong(String name, long defaultValue)
          Return value of parameter with specified name as a long.
 String[] getParameterNames()
          Return the names of all the parameters.
protected  Properties getParameters()
          Return the backing properties object associated with parameters.
protected  String getPrefix()
          Return the prefix associated with Parameters object.
 boolean isParameter(String name)
          Return true of parameter with specified name exists.
protected  boolean isReadOnly()
          Return true if resource has been made read-only or frozen.
 void makeReadOnly()
          Mark the resource and all child parameter objects as read only.
 void setParameter(String name, String value)
          Set parameter with specified name to specified value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultParameters

public DefaultParameters()
Create a parameters object with empty prefix.


DefaultParameters

public DefaultParameters(String prefix)
Create a parameters object with specified prefix.

Parameters:
prefix - the prefix
Method Detail

getParameterNames

public String[] getParameterNames()
Return the names of all the parameters.

Specified by:
getParameterNames in interface Parameters
Returns:
the names of all the parameters.

isParameter

public boolean isParameter(String name)
Return true of parameter with specified name exists.

Specified by:
isParameter in interface Parameters
Parameters:
name - the name
Returns:
true of parameter with specified name exists.

getParameter

public String getParameter(String name)
                    throws ParameterException
Return value of parameter with specified name.

Specified by:
getParameter in interface Parameters
Parameters:
name - the name
Returns:
the value
Throws:
ParameterException - if unable to locate parameter

getParameter

public String getParameter(String name,
                           String defaultValue)
Return value of parameter with specified name.

Specified by:
getParameter in interface Parameters
Parameters:
name - the name
defaultValue - the defaultValue if specified parameter does not exist
Returns:
the value

getParameterAsBoolean

public boolean getParameterAsBoolean(String name)
                              throws ParameterException
Return value of parameter with specified name as a boolean.

Specified by:
getParameterAsBoolean in interface Parameters
Parameters:
name - the name
Returns:
the value
Throws:
ParameterException - if unable to locate parameter or parameter can not be converted to correct type

getParameterAsBoolean

public boolean getParameterAsBoolean(String name,
                                     boolean defaultValue)
Return value of parameter with specified name as a boolean.

Specified by:
getParameterAsBoolean in interface Parameters
Parameters:
name - the name
defaultValue - the defaultValue if specified parameter does not exist or parameter can not be converted to the correct type
Returns:
the value

getParameterAsInteger

public int getParameterAsInteger(String name)
                          throws ParameterException
Return value of parameter with specified name as an integer.

Specified by:
getParameterAsInteger in interface Parameters
Parameters:
name - the name
Returns:
the value
Throws:
ParameterException - if unable to locate parameter or parameter can not be converted to correct type

getParameterAsInteger

public int getParameterAsInteger(String name,
                                 int defaultValue)
Return value of parameter with specified name as an integer.

Specified by:
getParameterAsInteger in interface Parameters
Parameters:
name - the name
defaultValue - the defaultValue if specified parameter does not exist or parameter can not be converted to the correct type
Returns:
the value

getParameterAsLong

public long getParameterAsLong(String name)
                        throws ParameterException
Return value of parameter with specified name as a long.

Specified by:
getParameterAsLong in interface Parameters
Parameters:
name - the name
Returns:
the value
Throws:
ParameterException - if unable to locate parameter or parameter can not be converted to correct type

getParameterAsLong

public long getParameterAsLong(String name,
                               long defaultValue)
Return value of parameter with specified name as a long.

Specified by:
getParameterAsLong in interface Parameters
Parameters:
name - the name
defaultValue - the defaultValue if specified parameter does not exist or parameter can not be converted to the correct type
Returns:
the value

getParameterAsFloat

public float getParameterAsFloat(String name)
                          throws ParameterException
Return value of parameter with specified name as a float.

Specified by:
getParameterAsFloat in interface Parameters
Parameters:
name - the name
Returns:
the value
Throws:
ParameterException - if unable to locate parameter or parameter can not be converted to correct type

getParameterAsFloat

public float getParameterAsFloat(String name,
                                 float defaultValue)
Return value of parameter with specified name as a float.

Specified by:
getParameterAsFloat in interface Parameters
Parameters:
name - the name
defaultValue - the defaultValue if specified parameter does not exist or parameter can not be converted to the correct type
Returns:
the value

getChildParameters

public Parameters getChildParameters(String prefix)
Return a Parameters object that represents a subset of parameters with specified prefix. The child parameters has a prefix with the separator ('.') appended. ie. if the prefix was "foo" then the parameter "foo.baz" would be included in child Parameters object using the key "baz".

Specified by:
getChildParameters in interface Parameters
Parameters:
prefix - the prefix
Returns:
the parameters object

makeReadOnly

public void makeReadOnly()
Mark the resource and all child parameter objects as read only.


setParameter

public void setParameter(String name,
                         String value)
Set parameter with specified name to specified value.

Parameters:
name - the parameter name
value - the parameter value

getParameters

protected final Properties getParameters()
Return the backing properties object associated with parameters.

Returns:
the backing properties object associated with parameters.

getPrefix

protected final String getPrefix()
Return the prefix associated with Parameters object.

Returns:
the prefix associated with Parameters object.

getChildren

protected final Set getChildren()
Return the set of child parameter objects.

Returns:
the set of child parameter objects

checkWriteable

protected final void checkWriteable()
Check if the resource has been "frozen" and thus is read only. If read-only then throw an IllegalStateException.

Throws:
IllegalStateException - if resource is read-only

isReadOnly

protected final boolean isReadOnly()
Return true if resource has been made read-only or frozen.

Returns:
true if resource has been made read-only or frozen, false otherwise.


Copyright © 1999-2005 Codehaus. All Rights Reserved.