|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.avalon.framework.parameters.Parameters
The Parameters
class represents a set of key-value
pairs.
The Parameters
object provides a mechanism to obtain
values based on a String
name. There are convenience
methods that allow you to use defaults if the value does not exist,
as well as obtain the value in any of the same formats that are in
the Configuration
interface.
While there are similarities between the Parameters
object and the java.util.Properties object, there are some
important semantic differences. First, Parameters
are
read-only. Second, Parameters
are easily
derived from Configuration
objects. Lastly, the
Parameters
object is derived from XML fragments that
look like this:
<parameter name="param-name" value="param-value" />
Note: this class is not thread safe by default. If you require thread safety please synchronize write access to this class to prevent potential data corruption.
Field Summary | |
static Parameters |
EMPTY_PARAMETERS
Empty Parameters object |
Constructor Summary | |
Parameters()
|
Method Summary | |
protected void |
checkWriteable()
Checks is this Parameters object is writeable. |
boolean |
equals(java.lang.Object other)
Compare this parameters instance with the supplied object for equality. |
static Parameters |
fromConfiguration(Configuration configuration)
Create a Parameters object from a Configuration
object. |
static Parameters |
fromConfiguration(Configuration configuration,
java.lang.String elementName)
Create a Parameters object from a Configuration
object using the supplied element name. |
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 |
int |
hashCode()
Returns a hashed value of the Parameters instance. |
boolean |
isParameter(java.lang.String name)
Test if the specified parameter can be retrieved. |
void |
makeReadOnly()
Make this Parameters read-only so that it will throw a IllegalStateException if someone tries to
modify it. |
Parameters |
merge(Parameters other)
Merge parameters from another Parameters instance
into this. |
void |
removeParameter(java.lang.String name)
Remove a parameter from the parameters object |
java.lang.String |
setParameter(java.lang.String name,
java.lang.String value)
Set the String value of a specified parameter. |
static java.util.Properties |
toProperties(Parameters params)
Creates a java.util.Properties object from an Avalon
Parameters object. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final Parameters EMPTY_PARAMETERS
Constructor Detail |
public Parameters()
Method Detail |
public java.lang.String setParameter(java.lang.String name, java.lang.String value) throws java.lang.IllegalStateException
String
value of a specified parameter.
If the specified value is null the parameter is removed.
name
- a String
valuevalue
- a String
value
java.lang.IllegalStateException
- if the Parameters object is read-onlypublic void removeParameter(java.lang.String name)
name
- a String
valuepublic java.util.Iterator getParameterNames()
Iterator
view of all parameter names.
public java.lang.String[] getNames()
public boolean isParameter(java.lang.String name)
name
- the parameter name
public java.lang.String getParameter(java.lang.String name) throws ParameterException
String
value of the specified parameter.
If the specified parameter cannot be found, an exception is thrown.
name
- the name of parameter
ParameterException
- if the specified parameter cannot be foundpublic java.lang.String getParameter(java.lang.String name, java.lang.String defaultValue)
String
value of the specified parameter.
If the specified parameter cannot be found, defaultValue
is returned.
name
- the name of parameterdefaultValue
- the default value, returned if parameter does not exist
or parameter's name is null
public int getParameterAsInteger(java.lang.String name) throws ParameterException
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.
name
- the name of parameter
ParameterException
- if the specified parameter cannot be found
or is not an Integer valuepublic int getParameterAsInteger(java.lang.String name, int defaultValue)
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.
name
- the name of parameterdefaultValue
- value returned if parameter does not exist or is of wrong type
public long getParameterAsLong(java.lang.String name) throws ParameterException
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.
name
- the name of parameter
ParameterException
- if the specified parameter cannot be found
or is not a Long value.public long getParameterAsLong(java.lang.String name, long defaultValue)
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.
name
- the name of parameterdefaultValue
- value returned if parameter does not exist or is of wrong type
public float getParameterAsFloat(java.lang.String name) throws ParameterException
float
value of the specified parameter.
If the specified parameter cannot be found, an exception is thrown.
name
- the parameter name
ParameterException
- if the specified parameter cannot be found
or is not a Float valuepublic float getParameterAsFloat(java.lang.String name, float defaultValue)
float
value of the specified parameter.
If the specified parameter cannot be found, defaultValue
is returned.
name
- the parameter namedefaultValue
- the default value if parameter does not exist or is of wrong type
public boolean getParameterAsBoolean(java.lang.String name) throws ParameterException
boolean
value of the specified parameter.
If the specified parameter cannot be found, an exception is thrown.
name
- the parameter name
ParameterException
- if an error occurs
ParameterException
public boolean getParameterAsBoolean(java.lang.String name, boolean defaultValue)
boolean
value of the specified parameter.
If the specified parameter cannot be found, defaultValue
is returned.
name
- the parameter namedefaultValue
- the default value if parameter does not exist or is of wrong type
public Parameters merge(Parameters other)
Parameters
instance
into this.
other
- the other Parameters
Parameters
instance.public void makeReadOnly()
IllegalStateException
if someone tries to
modify it.
public boolean equals(java.lang.Object other)
other
- the object to compare this parameters instance with
public int hashCode()
public java.lang.String toString()
protected final void checkWriteable() throws java.lang.IllegalStateException
Parameters
object is writeable.
java.lang.IllegalStateException
- if this Parameters
object is read-onlypublic static Parameters fromConfiguration(Configuration configuration) throws ConfigurationException
Parameters
object from a Configuration
object. This acts exactly like the following method call:
Parameters.fromConfiguration(configuration, "parameter");
configuration
- the Configuration
Parameters
instance.
ConfigurationException
- if an error occurspublic static Parameters fromConfiguration(Configuration configuration, java.lang.String elementName) throws ConfigurationException
Parameters
object from a Configuration
object using the supplied element name.
configuration
- the ConfigurationelementName
- the element name for the parameters
Parameters
instance.
ConfigurationException
- if an error occurspublic static Parameters fromProperties(java.util.Properties properties)
Parameters
object from a Properties
object.
properties
- the Properties
Parameters
instance.public static java.util.Properties toProperties(Parameters params)
java.util.Properties
object from an Avalon
Parameters object.
params
- a Parameters
instance
Properties
instance
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |