Class DefaultConfigurationKey
A simple class that supports creation of and iteration on configuration keys
supported by a DefaultExpressionEngine
object.
For key creation the class works similar to a StringBuffer: There are several
appendXXXX()
methods with which single parts of a key can be
constructed. All these methods return a reference to the actual object so
they can be written in a chain. When using this methods the exact syntax for
keys need not be known.
This class also defines a specialized iterator for configuration keys. With such an iterator a key can be tokenized into its single parts. For each part it can be checked whether it has an associated index.
Instances of this class are always associated with an instance of
DefaultExpressionEngine
, from which the current
delimiters are obtained. So key creation and parsing is specific to this
associated expression engine.
- Since:
- 1.3
- Version:
- $Id: DefaultConfigurationKey.java 1231724 2012-01-15 18:40:31Z oheger $
- Author:
- Commons Configuration team
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
A specialized iterator class for tokenizing a configuration key. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance ofDefaultConfigurationKey
and sets the associated expression engine.DefaultConfigurationKey
(DefaultExpressionEngine engine, String key) Creates a new instance ofDefaultConfigurationKey
and sets the associated expression engine and an initial key. -
Method Summary
Modifier and TypeMethodDescriptionAppends the name of a property to this key.Appends the name of a property to this key.appendAttribute
(String attr) Appends an attribute to this configuration key.appendIndex
(int index) Appends an index to this configuration key.attributeName
(String key) Extracts the name of the attribute from the given attribute key.Decorates the given key so that it represents an attribute.boolean
Checks if twoConfigurationKey
objects are equal.Returns the associated default expression engine.int
hashCode()
Returns the hash code for this object.boolean
isAttributeKey
(String key) Tests if the specified key represents an attribute according to the current expression engine.iterator()
Returns an iterator for iterating over the single components of this configuration key.int
length()
Returns the actual length of this configuration key.void
setExpressionEngine
(DefaultExpressionEngine expressionEngine) Sets the associated expression engine.void
setLength
(int len) Sets the new length of this configuration key.toString()
Returns a string representation of this object.Removes delimiters at the beginning and the end of the specified key.Removes leading property delimiters from the specified key.Removes trailing property delimiters from the specified key.
-
Constructor Details
-
DefaultConfigurationKey
Creates a new instance ofDefaultConfigurationKey
and sets the associated expression engine.- Parameters:
engine
- the expression engine
-
DefaultConfigurationKey
Creates a new instance ofDefaultConfigurationKey
and sets the associated expression engine and an initial key.- Parameters:
engine
- the expression enginekey
- the key to be wrapped
-
-
Method Details
-
getExpressionEngine
Returns the associated default expression engine.- Returns:
- the associated expression engine
-
setExpressionEngine
Sets the associated expression engine.- Parameters:
expressionEngine
- the expression engine (must not be null)
-
append
Appends the name of a property to this key. If necessary, a property delimiter will be added. If the boolean argument is set to true, property delimiters contained in the property name will be escaped.- Parameters:
property
- the name of the property to be addedescape
- a flag if property delimiters in the passed in property name should be escaped- Returns:
- a reference to this object
-
append
Appends the name of a property to this key. If necessary, a property delimiter will be added. Property delimiters in the given string will not be escaped.- Parameters:
property
- the name of the property to be added- Returns:
- a reference to this object
-
appendIndex
Appends an index to this configuration key.- Parameters:
index
- the index to be appended- Returns:
- a reference to this object
-
appendAttribute
Appends an attribute to this configuration key.- Parameters:
attr
- the name of the attribute to be appended- Returns:
- a reference to this object
-
length
Returns the actual length of this configuration key.- Returns:
- the length of this key
-
setLength
Sets the new length of this configuration key. With this method it is possible to truncate the key, e.g. to return to a state prior calling someappend()
methods. The semantic is the same as thesetLength()
method ofStringBuilder
.- Parameters:
len
- the new length of the key
-
equals
Checks if twoConfigurationKey
objects are equal. The method can be called with strings or other objects, too. -
hashCode
Returns the hash code for this object. -
toString
Returns a string representation of this object. This is the configuration key as a plain string. -
isAttributeKey
Tests if the specified key represents an attribute according to the current expression engine.- Parameters:
key
- the key to be checked- Returns:
- true if this is an attribute key, false otherwise
-
constructAttributeKey
Decorates the given key so that it represents an attribute. Adds special start and end markers. The passed in string will be modified only if does not already represent an attribute.- Parameters:
key
- the key to be decorated- Returns:
- the decorated attribute key
-
attributeName
Extracts the name of the attribute from the given attribute key. This method removes the attribute markers - if any - from the specified key.- Parameters:
key
- the attribute key- Returns:
- the name of the corresponding attribute
-
trimLeft
Removes leading property delimiters from the specified key.- Parameters:
key
- the key- Returns:
- the key with removed leading property delimiters
-
trimRight
Removes trailing property delimiters from the specified key.- Parameters:
key
- the key- Returns:
- the key with removed trailing property delimiters
-
trim
Removes delimiters at the beginning and the end of the specified key.- Parameters:
key
- the key- Returns:
- the key with removed property delimiters
-
iterator
Returns an iterator for iterating over the single components of this configuration key.- Returns:
- an iterator for this key
-