You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oh...@apache.org on 2008/04/04 21:22:54 UTC
svn commit: r644835 -
/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/FlatNode.java
Author: oheger
Date: Fri Apr 4 12:22:48 2008
New Revision: 644835
URL: http://svn.apache.org/viewvc?rev=644835&view=rev
Log:
Base class for the nodes of a flat configuration
Added:
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/FlatNode.java (with props)
Added: 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/flat/FlatNode.java?rev=644835&view=auto
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/FlatNode.java (added)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/FlatNode.java Fri Apr 4 12:22:48 2008
@@ -0,0 +1,165 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.configuration2.flat;
+
+import java.util.List;
+
+import org.apache.commons.configuration2.ConfigurationRuntimeException;
+
+/**
+ * <p>
+ * A base class for representing a configuration node for a "flat"
+ * configuration.
+ * </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
+ * 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
+ * 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.
+ * There will be concrete sub classes for the root node and the leaf nodes.
+ * </p>
+ * <p>
+ * Note that in contrast to truly hierarchical configuration nodes the nodes
+ * used here are pretty simple. For instance, they do not support attributes.
+ * Leaf nodes can have a name and a value. The root node has an arbitrary number
+ * of children.
+ * </p>
+ *
+ * @author <a href="http://commons.apache.org/configuration/team-list.html">Commons
+ * Configuration team</a>
+ * @version $Id$
+ * @since 2.0
+ */
+public abstract class FlatNode
+{
+ /**
+ * 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.
+ */
+ public static final int INDEX_UNDEFINED = -1;
+
+ /**
+ * Returns the name of this node.
+ *
+ * @return the name of this node
+ */
+ public abstract String getName();
+
+ /**
+ * Returns the value of this node. An implementation can access the passed
+ * in configuration to obtain the value.
+ *
+ * @param config the owning configuration
+ * @return the value of this node
+ */
+ public abstract Object getValue(AbstractFlatConfiguration config);
+
+ /**
+ * Sets the value of this node. An implementation can access the passed in
+ * configuration to set the value.
+ *
+ * @param config the owning configuration
+ * @param value the new value
+ * @throws ConfigurationRuntimeException if the value cannot be set
+ */
+ public abstract void setValue(AbstractFlatConfiguration 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).
+ *
+ * @return the index of the property value
+ */
+ public abstract int getValueIndex();
+
+ /**
+ * Returns the parent node.
+ *
+ * @return the parent node
+ */
+ public abstract FlatNode getParent();
+
+ /**
+ * Returns a list with the child nodes of this node. Note that only the root
+ * node has children. All children of the root are leaf nodes.
+ *
+ * @return a list with the child nodes of this node
+ */
+ public abstract List<FlatNode> getChildren();
+
+ /**
+ * Returns a list with the child nodes of this node with the given name.
+ *
+ * @param name the name of the desired child nodes
+ * @return a list with the found children
+ */
+ public abstract List<FlatNode> getChildren(String name);
+
+ /**
+ * Returns the number of children with the given name. If the passed in name
+ * is <b>null</b>, the total number of children is returned.
+ *
+ * @param name the name (can be <b>null</b>)
+ * @return the number of children with this name
+ */
+ public abstract int getChildrenCount(String name);
+
+ /**
+ * Returns the child node of this node with the given index.
+ *
+ * @param index the index (0-based)
+ * @return the child with this index
+ * @throws IndexOutOfBoundsException if the index is invalid
+ */
+ public abstract FlatNode getChild(int index);
+
+ /**
+ * Adds a child node to this node with the given name.
+ *
+ * @param name the name of the new child
+ * @return the newly created child node
+ * @throws ConfigurationRuntimeException if the child node cannot be added
+ */
+ public abstract FlatNode addChild(String name);
+
+ /**
+ * Removes the specified child node from this node. This may also affect the
+ * owning configuration, so this object is also passed to this method.
+ *
+ * @param config the owning configuration
+ * @param child the child to be removed
+ * @throws ConfigurationRuntimeException if the child cannot be removed
+ */
+ public abstract void removeChild(AbstractFlatConfiguration config,
+ FlatNode child);
+}
Propchange: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/FlatNode.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/FlatNode.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/FlatNode.java
------------------------------------------------------------------------------
svn:mime-type = text/plain