Author: oheger
Date: Wed Feb 27 23:03:05 2008
New Revision: 631875

URL: http://svn.apache.org/viewvc?rev=631875&view=rev
Log:
Added experimental NodeHandler interface

Added:
    
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/
    
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/ExpressionEngine.java
      - copied, changed from r630471, 
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/tree/ExpressionEngine.java
    
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/NodeAddData.java
      - copied, changed from r630471, 
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/tree/NodeAddData.java
    
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/NodeHandler.java
   (with props)

Copied: 
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/ExpressionEngine.java
 (from r630471, 
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/tree/ExpressionEngine.java)
URL: 
http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/ExpressionEngine.java?p2=commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/ExpressionEngine.java&p1=commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/tree/ExpressionEngine.java&r1=630471&r2=631875&rev=631875&view=diff
==============================================================================
--- 
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/tree/ExpressionEngine.java
 (original)
+++ 
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/ExpressionEngine.java
 Wed Feb 27 23:03:05 2008
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.commons.configuration2.tree;
+package org.apache.commons.configuration2.expr;
 
 import java.util.List;
 
@@ -34,7 +34,7 @@
  * configuration nodes are addressed by the key.
  * </p>
  * <p>
- * Seperating the task of evaluating property keys from the configuration 
object
+ * Separating the task of evaluating property keys from the configuration 
object
  * has the advantage that many different expression languages (i.e. ways for
  * querying or setting properties) can be supported. Just set a suitable
  * implementation of this interface as the configuration's expression engine,
@@ -52,14 +52,17 @@
      * traverse the given root node and its children to find all nodes that are
      * matched by the given key. If the key is not correct in the syntax
      * provided by that implementation, it is free to throw a (runtime)
-     * exception indicating this error condition.
+     * exception indicating this error condition. The passed in
+     * <code>[EMAIL PROTECTED] NodeHandler}</code> can be used for accessing 
the properties
+     * of the node.
      *
      * @param root the root node of a hierarchy of configuration nodes
      * @param key the key to be evaluated
+     * @param handler the node handler to be used
      * @return a list with the nodes that are matched by the key (should never
      * be <b>null</b>)
      */
-    List<ConfigurationNode> query(ConfigurationNode root, String key);
+    <T> List<T> query(T root, String key, NodeHandler<T> handler);
 
     /**
      * Returns the key for the specified node in the expression language
@@ -71,9 +74,10 @@
      * @param node the node, for which the key must be constructed
      * @param parentKey the key of this node's parent (can be <b>null</b> for
      * the root node)
+     * @param handler the node handler
      * @return this node's key
      */
-    String nodeKey(ConfigurationNode node, String parentKey);
+    <T> String nodeKey(T node, String parentKey, NodeHandler<T> handler);
 
     /**
      * Returns information needed for an add operation. This method gets called
@@ -83,7 +87,8 @@
      *
      * @param root the root node
      * @param key the key for the new property
+     * @param handler the node handler
      * @return an object with all information needed for the add operation
      */
-    NodeAddData prepareAdd(ConfigurationNode root, String key);
+    <T> NodeAddData<T> prepareAdd(T root, String key, NodeHandler<T> handler);
 }

Copied: 
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/NodeAddData.java
 (from r630471, 
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/tree/NodeAddData.java)
URL: 
http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/NodeAddData.java?p2=commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/NodeAddData.java&p1=commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/tree/NodeAddData.java&r1=630471&r2=631875&rev=631875&view=diff
==============================================================================
--- 
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/tree/NodeAddData.java
 (original)
+++ 
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/NodeAddData.java
 Wed Feb 27 23:03:05 2008
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.commons.configuration2.tree;
+package org.apache.commons.configuration2.expr;
 
 import java.util.Collections;
 import java.util.LinkedList;
@@ -48,10 +48,10 @@
  * @since 1.3
  * @author Oliver Heger
  */
-public class NodeAddData
+public class NodeAddData<T>
 {
     /** Stores the parent node of the add operation. */
-    private ConfigurationNode parent;
+    private T parent;
 
     /**
      * Stores a list with nodes that are on the path between the parent node 
and
@@ -80,7 +80,7 @@
      * @param parent the parent node
      * @param nodeName the name of the new node
      */
-    public NodeAddData(ConfigurationNode parent, String nodeName)
+    public NodeAddData(T parent, String nodeName)
     {
         setParent(parent);
         setNewNodeName(nodeName);
@@ -134,7 +134,7 @@
      *
      * @return the parent node
      */
-    public ConfigurationNode getParent()
+    public T getParent()
     {
         return parent;
     }
@@ -144,7 +144,7 @@
      *
      * @param parent the parent node
      */
-    public void setParent(ConfigurationNode parent)
+    public void setParent(T parent)
     {
         this.parent = parent;
     }

Added: 
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/NodeHandler.java
URL: 
http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/NodeHandler.java?rev=631875&view=auto
==============================================================================
--- 
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/NodeHandler.java
 (added)
+++ 
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/NodeHandler.java
 Wed Feb 27 23:03:05 2008
@@ -0,0 +1,133 @@
+/*
+ * 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.expr;
+
+import java.util.List;
+
+/**
+ * <p>
+ * Definition of an interface for dealing with the nodes of a hierarchical
+ * configuration.
+ * </p>
+ * <p>
+ * Different configuration implementations internally use different node
+ * structures. This interface provides a generic way of dealing with these
+ * structures by providing common query and manipulation methods. That way 
large
+ * parts of the functionality required by a hierarchical configuration can be
+ * implemented in a central base class, while tasks specific for a concrete 
node
+ * structure are delegated to an implementation of this interface.
+ * </p>
+ *
+ * @author Oliver Heger
+ * @version $Id$
+ * @param <T> the type of the nodes this handler deals with
+ */
+public interface NodeHandler<T>
+{
+    /**
+     * Returns the name of the specified node
+     *
+     * @param node the node
+     * @return the name of this node
+     */
+    String nodeName(T node);
+
+    /**
+     * Returns the value of the specified node.
+     *
+     * @param node the node
+     * @return the value of this node
+     */
+    Object getValue(T node);
+
+    /**
+     * Sets the value of the specified node.
+     *
+     * @param node the node
+     * @param value the new value
+     */
+    void setValue(T node, Object value);
+
+    /**
+     * Returns the parent of the specified node.
+     *
+     * @param node the node
+     * @return the parent node
+     */
+    T getParent(T node);
+
+    /**
+     * Adds a child with the given node name to the specified node.
+     *
+     * @param node the node
+     * @param name the name of the new child
+     * @return the newly added child
+     */
+    T addChild(T node, String name);
+
+    /**
+     * Returns a list with all children of the specified node.
+     *
+     * @param node the node
+     * @return a list with the child nodes of this node
+     */
+    List<T> getChildren(T node);
+
+    /**
+     * Returns a list of all children of the specified node with the given 
name.
+     *
+     * @param node the node
+     * @param name the name of the desired child nodes
+     * @return a list with all children with the given name
+     */
+    List<T> getChildren(T node, String name);
+
+    /**
+     * Returns the child with the given index of the specified node.
+     *
+     * @param node the node
+     * @param index the index (0-based)
+     * @return the child with the given index
+     */
+    T getChild(T node, int index);
+
+    /**
+     * Returns a list with the names of all attributes of the specified node.
+     *
+     * @param node the node
+     * @return a list with all attributes of this node
+     */
+    List<String> getAttributes(T node);
+
+    /**
+     * Returns the value of the specified attribute from the given node.
+     *
+     * @param node the node
+     * @param name the name of the attribute
+     * @return the value of this attribute
+     */
+    Object getAttributeValue(T node, String name);
+
+    /**
+     * Sets the value of an attribute for the specified node.
+     *
+     * @param node the node
+     * @param name the name of the attribute
+     * @param value the value of the attribute
+     */
+    void setAttributeValue(T node, String name, Object value);
+}

Propchange: 
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/NodeHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/NodeHandler.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: 
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/NodeHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain


Reply via email to