|
my-lib 20041108 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object my.config.Configuration
Configuration
is a Data Object use to store/retrieve hierarchical configuration values.
The data model is a subset of XML's; a single-rooted hierarchical tree where each
node can contain multiple attributes, and leaf nodes can also
contain a value. Reflecting this, Configuration
s are
usually built from an XML file by the XmlConfigurationBuilder
class, but
could be built by program.
Configuration config = new Configuration("foo"); config.setAttribute("attA", "valueA", false); config.setAttribute("attB", "32", false); ...
Checking for the existence of an attribute can be done as follows:
String value = conf.getAttribute( "myAttribute", null ); if ( null == value ) { // Do the processing applicable if the attribute isn't present. }
Field Summary | |
protected static Configuration[] |
EMPTY_ARRAY
|
Constructor Summary | |
Configuration(Configuration other)
|
|
Configuration(java.lang.String name)
|
|
Configuration(java.lang.String name,
Configuration other)
|
Method Summary | |
Configuration |
addChild(Configuration configuration)
Add a child Configuration to this configuration element. |
java.lang.String |
getAttribute(java.lang.String name)
Returns the value of a configuration attribute as a String . |
java.lang.String |
getAttribute(java.lang.String name,
java.lang.String defaultValue)
Returns the value of a configuration attribute as a String . |
boolean |
getAttributeAsBoolean(java.lang.String name)
Returns the value of a configuration attribute as a boolean . |
boolean |
getAttributeAsBoolean(java.lang.String name,
boolean defaultValue)
Returns the value of a configuration attribute as a boolean . |
float |
getAttributeAsFloat(java.lang.String name)
Returns the value of a configuration attribute as a float . |
float |
getAttributeAsFloat(java.lang.String name,
float defaultValue)
Returns the value of a configuration attribute as a float . |
int |
getAttributeAsInteger(java.lang.String name)
Returns the value of a configuration attribute as an int .
|
int |
getAttributeAsInteger(java.lang.String name,
int defaultValue)
Returns the value of a configuration attribute as an int .
|
long |
getAttributeAsLong(java.lang.String name)
Returns the value of a configuration attribute as a long .
|
long |
getAttributeAsLong(java.lang.String name,
long defaultValue)
Returns the value of a configuration attribute as a long .
|
java.lang.String[] |
getAttributes(java.lang.String childrenName,
java.lang.String name)
Returns the values of the children 's configuration attribute as a String . |
Configuration |
getChild(java.lang.String name,
boolean createNew)
Return the first Configuration object child of this
associated with the given name. |
Configuration[] |
getChildren()
Return an array of Configuration
elements containing all node children. |
Configuration[] |
getChildren(java.lang.String name)
Return an array of Configuration objects
children of this associated with the given name.
|
java.lang.String |
getName()
|
java.lang.String |
getValue()
Returns the value of the configuration element as a String . |
java.lang.String |
getValue(java.lang.String defaultValue)
Returns the value of the configuration element as a String . |
boolean |
getValueAsBoolean()
Returns the value of the configuration element as a boolean . |
boolean |
getValueAsBoolean(boolean defaultValue)
Returns the value of the configuration element as a boolean . |
float |
getValueAsFloat()
Returns the value of the configuration element as a float . |
float |
getValueAsFloat(float defaultValue)
Returns the value of the configuration element as a float . |
int |
getValueAsInteger()
Returns the value of the configuration element as an int .
|
int |
getValueAsInteger(int defaultValue)
Returns the value of the configuration element as an int .
|
long |
getValueAsLong()
Returns the value of the configuration element as a long .
|
long |
getValueAsLong(long defaultValue)
Returns the value of the configuration element as a long .
|
java.lang.String[] |
getValues(java.lang.String childrenName)
Returns the values of the children 's configuration element as a String . |
Configuration |
removeChild(Configuration configuration)
|
Configuration |
setAttribute(java.lang.String name,
java.lang.String newValue,
boolean overwrite)
Set the value of the configuration attribute. |
Configuration |
setValue(java.lang.String newValue,
boolean overwrite)
Set the value of the configuration element. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected static final Configuration[] EMPTY_ARRAY
Constructor Detail |
public Configuration(java.lang.String name) throws java.lang.Exception
public Configuration(java.lang.String name, Configuration other) throws java.lang.Exception
public Configuration(Configuration other) throws java.lang.Exception
Method Detail |
public java.lang.String getName() throws java.lang.Exception
java.lang.Exception
public Configuration setValue(java.lang.String newValue, boolean overwrite) throws java.lang.Exception
newValue
- the value to set.overwrite
- if previous value (if not empty) must be overwrote.
java.lang.Exception
public java.lang.String getValue() throws java.lang.Exception
String
.
java.lang.NoSuchFieldException
- if value undefined.
java.lang.Exception
public java.lang.String getValue(java.lang.String defaultValue) throws java.lang.Exception
String
.
defaultValue
- the default value to return if value malformed or empty
String
value
java.lang.Exception
public java.lang.String[] getValues(java.lang.String childrenName) throws java.lang.Exception
String
.
childrenName
- the name of the children from wich extract Values
String[]
of values, empty if no children found.
java.lang.NoSuchFieldException
- if value undefined.
java.lang.Exception
public int getValueAsInteger() throws java.lang.Exception
int
.
Hexadecimal numbers begin with 0x, Octal numbers begin with 0o and binary
numbers begin with 0b, all other values are assumed to be decimal.
ConfigurationException
- if an error occurs
java.lang.NoSuchFieldException
- if value undefined.
java.lang.Exception
public int getValueAsInteger(int defaultValue) throws java.lang.Exception
int
.
Hexadecimal numbers begin with 0x, Octal numbers begin with 0o and binary
numbers begin with 0b, all other values are assumed to be decimal.
defaultValue
- the default value to return if value malformed or empty
java.lang.Exception
public long getValueAsLong() throws java.lang.Exception
long
.
Hexadecimal numbers begin with 0x, Octal numbers begin with 0o and binary
numbers begin with 0b, all other values are assumed to be decimal.
ConfigurationException
- if an error occurs
java.lang.NoSuchFieldException
- if value undefined.
java.lang.Exception
public long getValueAsLong(long defaultValue) throws java.lang.Exception
long
.
Hexadecimal numbers begin with 0x, Octal numbers begin with 0o and binary
numbers begin with 0b, all other values are assumed to be decimal.
defaultValue
- the default value to return if value malformed or empty
java.lang.Exception
public float getValueAsFloat() throws java.lang.Exception
float
.
java.lang.NoSuchFieldException
- if value undefined.
java.lang.Exception
public float getValueAsFloat(float defaultValue) throws java.lang.Exception
float
.
defaultValue
- the default value to return if value malformed or empty
java.lang.Exception
public boolean getValueAsBoolean() throws java.lang.Exception
boolean
.
java.lang.NoSuchFieldException
- if value undefined.
java.lang.Exception
public boolean getValueAsBoolean(boolean defaultValue) throws java.lang.Exception
boolean
.
defaultValue
- the default value to return if value malformed or empty
java.lang.Exception
public Configuration setAttribute(java.lang.String name, java.lang.String newValue, boolean overwrite) throws java.lang.Exception
name
- the attribute name.newValue
- the value to set.overwrite
- if previous value (if not empty) must be overwrote.
java.lang.Exception
public java.lang.String getAttribute(java.lang.String name) throws java.lang.Exception
String
.
name
- the attribute name.
java.lang.NoSuchFieldException
- if attribute undefined.
java.lang.Exception
public java.lang.String getAttribute(java.lang.String name, java.lang.String defaultValue) throws java.lang.Exception
String
.
name
- the attribute namedefaultValue
- the default value to return if empty
java.lang.Exception
public java.lang.String[] getAttributes(java.lang.String childrenName, java.lang.String name) throws java.lang.Exception
String
.
childrenName
- the name of the children from wich extract Valuesname
- the attribute name
String[]
of values, empty if no children found.
java.lang.NoSuchFieldException
- if value undefined.
java.lang.Exception
public int getAttributeAsInteger(java.lang.String name) throws java.lang.Exception
int
.
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 attribute name
java.lang.NoSuchFieldException
- if attribute undefined.
java.lang.Exception
public int getAttributeAsInteger(java.lang.String name, int defaultValue) throws java.lang.Exception
int
.
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 attribute namedefaultValue
- the default value to return if empty
java.lang.Exception
public long getAttributeAsLong(java.lang.String name) throws java.lang.Exception
long
.
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 attribute name
java.lang.NoSuchFieldException
- if attribute undefined.
java.lang.Exception
public long getAttributeAsLong(java.lang.String name, long defaultValue) throws java.lang.Exception
long
.
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 attribute namedefaultValue
- the default value to return if empty
java.lang.Exception
public float getAttributeAsFloat(java.lang.String name) throws java.lang.Exception
float
.
name
- the attribute name
java.lang.NoSuchFieldException
- if attribute undefined.
java.lang.Exception
public float getAttributeAsFloat(java.lang.String name, float defaultValue) throws java.lang.Exception
float
.
name
- the attribute namedefaultValue
- the default value to return if empty
java.lang.Exception
public boolean getAttributeAsBoolean(java.lang.String name) throws java.lang.Exception
boolean
.
name
- the attribute name
java.lang.NoSuchFieldException
- if attribute undefined.
java.lang.Exception
public boolean getAttributeAsBoolean(java.lang.String name, boolean defaultValue) throws java.lang.Exception
boolean
.
name
- the attribute namedefaultValue
- the default value to return if empty
java.lang.Exception
public Configuration getChild(java.lang.String name, boolean createNew) throws java.lang.Exception
Configuration
object child of this
associated with the given name.
name
- the name of the childcreateNew
- true if you want to create a new Configuration object if none exists
java.lang.Exception
public Configuration[] getChildren() throws java.lang.Exception
Configuration
elements containing all node children.
java.lang.Exception
public Configuration[] getChildren(java.lang.String name) throws java.lang.Exception
Configuration
objects
children of this associated with the given name.
null
.
name
- The name of the required children Configuration
.
Configuration[]
value
java.lang.Exception
public Configuration addChild(Configuration configuration) throws java.lang.Exception
Configuration
to this configuration element.
configuration
- a Configuration
value
java.lang.Exception
public java.lang.String toString()
public Configuration removeChild(Configuration configuration)
|
my-lib 20041108 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |