org.apache.avalon.framework.parameters
Class Parameters

java.lang.Object
  |
  +--org.apache.avalon.framework.parameters.Parameters

public class Parameters
extends java.lang.Object

The Parameters represents a set of key-value pairs. Each value stored in Parameters has a key. This class is similar to java.util.Properties with convenience methods to access property values by type.

Author:
Pierpaolo Fumagalli, Peter Donald

Constructor Summary
Parameters()
           
 
Method Summary
protected  void checkWriteable()
           
static Parameters fromConfiguration(Configuration configuration)
          Create a Parameters object from a Configuration object.
static Parameters fromProperties(java.util.Properties properties)
          Create a Parameters object from a Properties object.
 java.lang.String[] getNames()
          Retrieve an array of all parameter names.
 java.lang.String getParameter(java.lang.String name)
          Retrieve the String value of the specified parameter.
 java.lang.String getParameter(java.lang.String name, java.lang.String defaultValue)
          Retrieve the String value of the specified parameter.
 boolean getParameterAsBoolean(java.lang.String name)
          Retrieve the boolean value of the specified parameter.
 boolean getParameterAsBoolean(java.lang.String name, boolean defaultValue)
          Retrieve the boolean value of the specified parameter.
 float getParameterAsFloat(java.lang.String name)
          Retrieve the float value of the specified parameter.
 float getParameterAsFloat(java.lang.String name, float defaultValue)
          Retrieve the float value of the specified parameter.
 int getParameterAsInteger(java.lang.String name)
          Retrieve the int value of the specified parameter.
 int getParameterAsInteger(java.lang.String name, int defaultValue)
          Retrieve the int value of the specified parameter.
 long getParameterAsLong(java.lang.String name)
          Retrieve the long value of the specified parameter.
 long getParameterAsLong(java.lang.String name, long defaultValue)
          Retrieve the long value of the specified parameter.
 java.util.Iterator getParameterNames()
          Deprecated. Use getNames() instead
 boolean isParameter(java.lang.String name)
          Test if the specified parameter can be retrieved.
 void makeReadOnly()
           
 Parameters merge(Parameters other)
          Merge parameters from another Parameters instance into this.
 java.lang.String setParameter(java.lang.String name, java.lang.String value)
          Set the String value of a specified parameter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Parameters

public Parameters()
Method Detail

setParameter

public java.lang.String setParameter(java.lang.String name,
                                     java.lang.String value)
Set the String value of a specified parameter.

If the specified value is null the parameter is removed.

Returns:
The previous value of the parameter or null.

getParameterNames

public java.util.Iterator getParameterNames()
Deprecated. Use getNames() instead

Return an Enumeration view of all parameter names.
Returns:
a iterator of parameter names

getNames

public java.lang.String[] getNames()
Retrieve an array of all parameter names.
Returns:
the parameters names

isParameter

public boolean isParameter(java.lang.String name)
Test if the specified parameter can be retrieved.
Parameters:
name - the parameter name
Returns:
true if parameter is a name

getParameter

public java.lang.String getParameter(java.lang.String name)
                              throws ParameterException
Retrieve the String value of the specified parameter.

If the specified parameter cannot be found, an exception is thrown.

Parameters:
name - the name of parameter
Returns:
the value of parameter
Throws:
ParameterException -  

getParameter

public java.lang.String getParameter(java.lang.String name,
                                     java.lang.String defaultValue)
Retrieve the String value of the specified parameter.

If the specified parameter cannot be found, defaultValue is returned.

Parameters:
name - the name of parameter
defaultValue - the default value, returned if parameter does not exist
Returns:
the value of parameter

getParameterAsInteger

public int getParameterAsInteger(java.lang.String name)
                          throws ParameterException
Retrieve the int value of the specified parameter.

If the specified parameter cannot be found, an exception is thrown. Hexadecimal numbers begin with 0x, Octal numbers begin with 0o and binary numbers begin with 0b, all other values are assumed to be decimal.

Parameters:
name - the name of parameter
Returns:
the integer parameter type
Throws:
ParameterException -  

getParameterAsInteger

public int getParameterAsInteger(java.lang.String name,
                                 int defaultValue)
Retrieve the int value of the specified parameter.

If the specified parameter cannot be found, defaultValue is returned. Hexadecimal numbers begin with 0x, Octal numbers begin with 0o and binary numbers begin with 0b, all other values are assumed to be decimal.

Parameters:
name - the name of parameter
defaultValue - value returned if parameter does not exist or is of wrong type
Returns:
the integer parameter type

getParameterAsLong

public long getParameterAsLong(java.lang.String name)
                        throws ParameterException
Retrieve the long value of the specified parameter.

If the specified parameter cannot be found, an exception is thrown. Hexadecimal numbers begin with 0x, Octal numbers begin with 0o and binary numbers begin with 0b, all other values are assumed to be decimal.

Parameters:
name - the name of parameter
Returns:
the long parameter type
Throws:
ParameterException -  

getParameterAsLong

public long getParameterAsLong(java.lang.String name,
                               long defaultValue)
Retrieve the long value of the specified parameter.

If the specified parameter cannot be found, defaultValue is returned. Hexadecimal numbers begin with 0x, Octal numbers begin with 0o and binary numbers begin with 0b, all other values are assumed to be decimal.

Parameters:
name - the name of parameter
defaultValue - value returned if parameter does not exist or is of wrong type
Returns:
the long parameter type

getParameterAsFloat

public float getParameterAsFloat(java.lang.String name)
                          throws ParameterException
Retrieve the float value of the specified parameter.

If the specified parameter cannot be found, an exception is thrown.

Parameters:
name - the parameter name
Returns:
the value
Throws:
ParameterException -  

getParameterAsFloat

public float getParameterAsFloat(java.lang.String name,
                                 float defaultValue)
Retrieve the float value of the specified parameter.

If the specified parameter cannot be found, defaultValue is returned.

Parameters:
name - the parameter name
defaultValue - the default value if parameter does not exist or is of wrong type
Returns:
the value

getParameterAsBoolean

public boolean getParameterAsBoolean(java.lang.String name)
                              throws ParameterException
Retrieve the boolean value of the specified parameter.

If the specified parameter cannot be found, an exception is thrown.

Parameters:
name - the parameter name
Returns:
the value
Throws:
ParemterException -  

getParameterAsBoolean

public boolean getParameterAsBoolean(java.lang.String name,
                                     boolean defaultValue)
Retrieve the boolean value of the specified parameter.

If the specified parameter cannot be found, defaultValue is returned.

Parameters:
name - the parameter name
defaultValue - the default value if parameter does not exist or is of wrong type
Returns:
the value

merge

public Parameters merge(Parameters other)
Merge parameters from another Parameters instance into this.
Parameters:
other - the other Parameters
Returns:
This Parameters instance.

makeReadOnly

public void makeReadOnly()

checkWriteable

protected final void checkWriteable()
                             throws java.lang.IllegalStateException

fromConfiguration

public static Parameters fromConfiguration(Configuration configuration)
                                    throws ConfigurationException
Create a Parameters object from a Configuration object.
Parameters:
configuration - the Configuration
Returns:
This Parameters instance.

fromProperties

public static Parameters fromProperties(java.util.Properties properties)
Create a Parameters object from a Properties object.
Parameters:
properties - the Properties
Returns:
This Parameters instance.


Copyright © 2001 Apache Jakarta Project. All Rights Reserved.