Author: oheger
Date: Sun Aug 23 18:10:53 2009
New Revision: 806994
URL: http://svn.apache.org/viewvc?rev=806994&view=rev
Log:
Copied FlatNode classes from flat to base package and made them compatible with
the ConfigurationSource interface.
Added:
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/FlatLeafNode.java
- copied, changed from r800525,
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/FlatLeafNode.java
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/FlatNode.java
- copied, changed from r800525,
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/FlatNode.java
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/FlatRootNode.java
- copied, changed from r805568,
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/FlatRootNode.java
Copied:
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/FlatLeafNode.java
(from r800525,
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/FlatLeafNode.java)
URL:
http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/FlatLeafNode.java?p2=commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/FlatLeafNode.java&p1=commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/FlatLeafNode.java&r1=800525&r2=806994&rev=806994&view=diff
==============================================================================
---
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/FlatLeafNode.java
(original)
+++
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/FlatLeafNode.java
Sun Aug 23 18:10:53 2009
@@ -14,13 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.configuration2.flat;
+package org.apache.commons.configuration2.base;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
-import org.apache.commons.configuration2.Configuration;
import org.apache.commons.configuration2.ConfigurationRuntimeException;
/**
@@ -28,31 +27,31 @@
* A leaf node in the hierarchy of flat nodes.
* </p>
* <p>
- * A flat configuration has two kinds of nodes: a single root node and an
- * arbitrary number of child nodes. This class represents the child nodes. A
- * child node has a name, a value and a parent. Child nodes, however, are not
- * supported.
+ * The node structure of a flat {...@code ConfigurationSource} has two kinds of
+ * nodes: a single root node and an arbitrary number of child nodes. This class
+ * represents the child nodes. A child node has a name, a value and a parent.
+ * Child nodes, however, are not supported.
* </p>
*
- * @author <a
href="http://commons.apache.org/configuration/team-list.html">Commons
+ * @author <a
+ *
href="http://commons.apache.org/configuration/team-list.html">Commons
* Configuration team</a>
* @version $Id$
*/
class FlatLeafNode extends FlatNode
{
/** Stores the parent node. */
- private FlatRootNode parent;
+ private final FlatRootNode parent;
/** Stores the name of this node. */
- private String name;
+ private final String name;
/** Stores a flag whether this node is associated with an existing value.
*/
private boolean hasValue;
/**
- * Creates a new instance of <code>FlatLeafNode</code> and initializes it.
- * (This constructor is intended to be called by <code>FlatRootNode</code>
- * only.)
+ * Creates a new instance of {...@code FlatLeafNode} and initializes it.
(This
+ * constructor is intended to be called by {...@code FlatRootNode} only.)
*
* @param parent the parent node
* @param name the name of this node
@@ -82,8 +81,8 @@
/**
* Returns the child node with the given index. Because leaf nodes do not
- * support children, this implementation always throws an
- * <code>IndexOutOfBoundsException</code> exception.
+ * support children, this implementation always throws an {...@code
+ * IndexOutOfBoundsException} exception.
*
* @param index the index
* @return the child node at this index
@@ -159,14 +158,14 @@
/**
* Returns the value of this node. This implementation obtains the value
- * from the passed in configuration. It also takes its value index into
- * account if the represented property has multiple values.
+ * from the passed in {...@code ConfigurationSource}. It also takes its
value
+ * index into account if the represented property has multiple values.
*
- * @param config the associated configuration
+ * @param config the associated {...@code ConfigurationSource}
* @return the value of the represented property
*/
@Override
- public Object getValue(Configuration config)
+ public Object getValue(ConfigurationSource config)
{
Object value = config.getProperty(getName());
if (value instanceof Collection<?>)
@@ -209,28 +208,29 @@
* Removes a child from this node. Leaf nodes do not support children, so
* this implementation always throws a runtime exception.
*
- * @param config the associated configuration
+ * @param config the associated {...@code ConfigurationSource}
* @param child the node to be removed
* @throws ConfigurationRuntimeException if the child cannot be removed
*/
@Override
- public void removeChild(Configuration config, FlatNode child)
+ public void removeChild(ConfigurationSource config, FlatNode child)
{
throw new ConfigurationRuntimeException(
"Cannot remove a child from a leaf node!");
}
/**
- * Sets the value of this node. The value is set at the passed in
- * configuration. If this node is not associated with a value (i.e. the
node
- * was newly created), this method adds a new value to the represented
- * property. Otherwise the corresponding property value is overridden.
+ * Sets the value of this node. The value is set at the passed in {...@code
+ * ConfigurationSource}. If this node is not associated with a value (i.e.
+ * the node was newly created), this method adds a new value to the
+ * represented property. Otherwise the corresponding property value is
+ * overridden.
*
- * @param config the associated configuration
+ * @param config the associated {...@code ConfigurationSource}
* @param value the new value
*/
@Override
- public void setValue(Configuration config, Object value)
+ public void setValue(ConfigurationSource config, Object value)
{
if (hasValue)
{
Copied:
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/FlatNode.java
(from r800525,
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/FlatNode.java)
URL:
http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/FlatNode.java?p2=commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/FlatNode.java&p1=commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/FlatNode.java&r1=800525&r2=806994&rev=806994&view=diff
==============================================================================
---
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/FlatNode.java
(original)
+++
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/FlatNode.java
Sun Aug 23 18:10:53 2009
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.configuration2.flat;
+package org.apache.commons.configuration2.base;
import java.util.List;
@@ -24,19 +24,19 @@
/**
* <p>
* A base class for representing a configuration node for a "flat"
- * configuration.
+ * configuration source.
* </p>
* <p>
- * There are concrete configuration implementations whose data is not organized
- * in a hierarchical manner, but rather in a flat, map-like structure.
- * Nevertheless, the <code>Configuration</code> interface defines some
+ * The {...@link ConfigurationSource} interface provides a map-oriented access
to
+ * configuration settings rather than organizing data in a hierarchical
+ * structure. Nevertheless, the {...@link Configuration} interface defines some
* operations that are hierarchical in nature. This is required for instance to
* support enhanced query facilities (expression engines) for all kind of
* configurations or to allow them to be added to combined configurations.
* </p>
* <p>
* Because of that a way is needed to make the hierarchical operations required
- * available for non-hierarchical configurations. The idea is to create a
+ * available for non-hierarchical configuration sources. The idea is to create
a
* pseudo-hierarchical node structure (consisting of one root node and its
* children) when necessary. This class is the base class of the nodes that are
* part of this structure. It defines the general properties of such nodes.
@@ -49,7 +49,8 @@
* of children.
* </p>
*
- * @author <a
href="http://commons.apache.org/configuration/team-list.html">Commons
+ * @author <a
+ *
href="http://commons.apache.org/configuration/team-list.html">Commons
* Configuration team</a>
* @version $Id$
* @since 2.0
@@ -58,9 +59,9 @@
{
/**
* Constant for an undefined index. This constant is returned by
- * <code>getValueIndex()</code> to indicate that this node does not
- * correspond to a single value of a property with multiple values, but
- * represents the whole property.
+ * {...@link #getValueIndex()} to indicate that this node does not
correspond
+ * to a single value of a property with multiple values, but represents the
+ * whole property.
*/
public static final int INDEX_UNDEFINED = -1;
@@ -73,31 +74,30 @@
/**
* Returns the value of this node. An implementation can access the passed
- * in configuration to obtain the value.
+ * in {...@code ConfigurationSource} to obtain the value.
*
- * @param config the owning configuration
+ * @param config the owning {...@code ConfigurationSource}
* @return the value of this node
*/
- public abstract Object getValue(Configuration config);
+ public abstract Object getValue(ConfigurationSource config);
/**
* Sets the value of this node. An implementation can access the passed in
- * configuration to set the value.
+ * {...@code ConfigurationSource} to set the value.
*
- * @param config the owning configuration
+ * @param config the owning {...@code ConfigurationSource}
* @param value the new value
* @throws ConfigurationRuntimeException if the value cannot be set
*/
- public abstract void setValue(Configuration config, Object value);
+ public abstract void setValue(ConfigurationSource config, Object value);
/**
* Returns the index of the value represented by this node. This is needed
* for properties with multiple values: In this case, for each value a
* separate node instance is created. Manipulating a node instance will
only
- * affect the selected value. A return value of
- * <code>{...@link #INDEX_UNDEFINED}</code> means that there is only a
single
- * value of the represented property (in this case the property is affected
- * as a whole).
+ * affect the selected value. A return value of {...@link #INDEX_UNDEFINED}
+ * means that there is only a single value of the represented property (in
+ * this case the property is affected as a whole).
*
* @return the index of the property value
*/
@@ -155,11 +155,12 @@
/**
* Removes the specified child node from this node. This may also affect
the
- * owning configuration, so this object is also passed to this method.
+ * owning {...@code ConfigurationSource}, so this object is also passed to
this
+ * method.
*
- * @param config the owning configuration
+ * @param config the owning {...@code ConfigurationSource}
* @param child the child to be removed
* @throws ConfigurationRuntimeException if the child cannot be removed
*/
- public abstract void removeChild(Configuration config, FlatNode child);
+ public abstract void removeChild(ConfigurationSource config, FlatNode
child);
}
Copied:
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/FlatRootNode.java
(from r805568,
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/FlatRootNode.java)
URL:
http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/FlatRootNode.java?p2=commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/FlatRootNode.java&p1=commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/FlatRootNode.java&r1=805568&r2=806994&rev=806994&view=diff
==============================================================================
---
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/FlatRootNode.java
(original)
+++
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/FlatRootNode.java
Sun Aug 23 18:10:53 2009
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.configuration2.flat;
+package org.apache.commons.configuration2.base;
import java.util.ArrayList;
import java.util.Collection;
@@ -25,7 +25,6 @@
import java.util.List;
import java.util.Map;
-import org.apache.commons.configuration2.Configuration;
import org.apache.commons.configuration2.ConfigurationRuntimeException;
/**
@@ -33,17 +32,18 @@
* The root node in the hierarchy of flat nodes.
* </p>
* <p>
- * A flat configuration has two kinds of nodes: a single root node and an
- * arbitrary number of child nodes. This class represents the root node. The
- * root node is somewhat special. It does not have a name nor a value. It is
the
- * only node in the whole structure that has children.
+ * The node structure of a flat {...@code ConfigurationSource} has two kinds of
+ * nodes: a single root node and an arbitrary number of child nodes. This class
+ * represents the root node. The root node is somewhat special. It does not
have
+ * a name nor a value. It is the only node in the whole structure that has
+ * children.
* </p>
* <p>
* The children are stored internally in two different structures: a list for
* accessing all children (optionally with indices), and a map for accessing
* children by name. Because standard lists and maps from the Java collection
* framework are used, this data cannot be updated concurrently. Read-only
- * access from multiple threads is possible however.
+ * access from multiple threads is possible though.
* </p>
*
* @author <a
href="http://commons.apache.org/configuration/team-list.html">Commons
@@ -62,7 +62,7 @@
private final Map<String, ChildNodeManager> childrenByName;
/**
- * Creates a new instance of <code>FlatRootNode</code>.
+ * Creates a new instance of {...@code FlatRootNode}.
*/
public FlatRootNode()
{
@@ -72,7 +72,7 @@
/**
* Creates a new child node and adds it to the list of children. This is a
- * short cut of <code>addChild(name, <b>false</b>)</code>.
+ * short cut of {...@code addChild(name, false)}.
*
* @param name the name of the child node
* @return the newly created child node
@@ -85,15 +85,15 @@
/**
* Creates a new child node, adds it to the list of children, and sets its
- * <code>hasValue</code> flag. This implementation will create a new
- * <code>FlatLeafNode</code> instance.
+ * {...@code hasValue} flag. This implementation will create a new
{...@code
+ * FlatLeafNode} instance.
*
* @param name the name of the child node
* @param hasValue a flag whether the node already has a value; this flag
- * impacts the behavior of the <code>setValue()</code> method: if it
- * is <b>false</code>, the next <code>setValue()</code> call will
add
- * a new property to the configuration; otherwise an existing
- * property value is overridden
+ * impacts the behavior of the {...@code setValue()} method: if it
is
+ * <b>false</b>, the next {...@code setValue()} call will add a new
+ * property to the configuration; otherwise an existing property
+ * value is overridden
* @return the newly created child node
*/
public FlatNode addChild(String name, boolean hasValue)
@@ -186,11 +186,11 @@
* Returns the value of this node. The root node does not have a value, so
* result is always <b>null</b>.
*
- * @param config the associated configuration
+ * @param config the associated {...@code ConfigurationSource}
* @return the value of this node
*/
@Override
- public Object getValue(Configuration config)
+ public Object getValue(ConfigurationSource config)
{
return null;
}
@@ -209,15 +209,15 @@
/**
* Removes the specified child node. The corresponding value in the
- * associated configuration will also be removed.
+ * associated {...@code ConfigurationSource} will also be removed.
*
- * @param config the associated configuration
+ * @param config the associated {...@code ConfigurationSource}
* @param child the node to be removed
* @throws ConfigurationRuntimeException if this node is not a child of
this
* node
*/
@Override
- public void removeChild(Configuration config, FlatNode child)
+ public void removeChild(ConfigurationSource config, FlatNode child)
{
if (child != null)
{
@@ -247,12 +247,12 @@
* Sets the value of this node. A root node cannot have a value. This
* implementation will throw an exception.
*
- * @param config the associated configuration
+ * @param config the associated {...@code ConfigurationSource}
* @param value the new value
* @throws ConfigurationRuntimeException if the value cannot be set
*/
@Override
- public void setValue(Configuration config, Object value)
+ public void setValue(ConfigurationSource config, Object value)
{
throw new ConfigurationRuntimeException(
"Cannot set the value of the root node of a flat
configuration!");
@@ -279,13 +279,13 @@
* times. It obtains the list with all values for this property, changes
the
* value with the given index, and sets the new value.
*
- * @param config the current configuration
+ * @param config the current {...@code ConfigurationSource}
* @param child the child node that was changed
* @param index the value index of this child node
* @param value the new value
*/
- void setMultiProperty(Configuration config, FlatNode child, int index,
- Object value)
+ void setMultiProperty(ConfigurationSource config, FlatNode child,
+ int index, Object value)
{
changeMultiProperty(config, child, index, value, false);
}
@@ -327,13 +327,13 @@
* at a given index can either be changed or removed. If the index is
* invalid, no change is performed.
*
- * @param config the current configuration
+ * @param config the current {...@code ConfigurationSource}
* @param child the child node that was changed
* @param index the value index of this child node
* @param value the new value
* @param remove a flag whether the value at the index is to be removed
*/
- private static void changeMultiProperty(Configuration config,
+ private static void changeMultiProperty(ConfigurationSource config,
FlatNode child, int index, Object value, boolean remove)
{
Object val = config.getProperty(child.getName());
@@ -351,7 +351,10 @@
{
newValues.set(index, value);
}
- config.setProperty(child.getName(), newValues);
+
+ Object newValue = (newValues.size() > 1) ? newValues
+ : newValues.get(0);
+ config.setProperty(child.getName(), newValue);
}
}
}