directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 36427 - incubator/directory/snickers/branches/encoder-redesign/ber-codec/src/java/org/apache/snickers/ber
Date Mon, 16 Aug 2004 02:20:07 GMT
Author: akarasulu
Date: Sun Aug 15 19:20:06 2004
New Revision: 36427

Added:
   incubator/directory/snickers/branches/encoder-redesign/ber-codec/src/java/org/apache/snickers/ber/TupleNodeVisitor.java
Modified:
   incubator/directory/snickers/branches/encoder-redesign/ber-codec/src/java/org/apache/snickers/ber/DefaultMutableTupleNode.java
   incubator/directory/snickers/branches/encoder-redesign/ber-codec/src/java/org/apache/snickers/ber/TupleNode.java
Log:
Commit Changes ...

 All changes were made to start using the extrinsic visitor pattern with
 TupleNode trees.  This is in an effort to generate the tree which can
 then be massaged into or out of the definate/indefinate configuration
 using visitors.

 o Added the node visitor interface for visiting the tree
 o Added the accept() method to the TupleNode interface
 o Implemented the accept() method for the DefaultMutableTupleNode 
   class which implements TupleNode
 


Modified: incubator/directory/snickers/branches/encoder-redesign/ber-codec/src/java/org/apache/snickers/ber/DefaultMutableTupleNode.java
==============================================================================
--- incubator/directory/snickers/branches/encoder-redesign/ber-codec/src/java/org/apache/snickers/ber/DefaultMutableTupleNode.java
(original)
+++ incubator/directory/snickers/branches/encoder-redesign/ber-codec/src/java/org/apache/snickers/ber/DefaultMutableTupleNode.java
Sun Aug 15 19:20:06 2004
@@ -56,13 +56,20 @@
     
 
     /**
-     * Creates a node without a parent.
+     * Creates a node without a parent using a tuple.  If the tuple is primitive
+     * and has a non-null last value chunk, that value chunk is added to the
+     * list of value chunks.
      * 
      * @param tuple the tuple to set for this node
      */
     public DefaultMutableTupleNode( Tuple tuple )
     {
         this.tuple = tuple ;
+
+        if ( tuple.isPrimitive() && tuple.getLastValueChunk() != null )
+        {
+            valueChunks.add( tuple.getLastValueChunk() );
+        }
     }
     
 
@@ -485,5 +492,17 @@
         }
         
         return true ;
+    }
+
+
+    /**
+     * @see TupleNode#accept(TupleNodeVisitor)
+     */
+    public void accept( TupleNodeVisitor visitor )
+    {
+        if ( visitor.canVisit( this ) )
+        {
+            visitor.visit( this ) ;
+        }
     }
 }

Modified: incubator/directory/snickers/branches/encoder-redesign/ber-codec/src/java/org/apache/snickers/ber/TupleNode.java
==============================================================================
--- incubator/directory/snickers/branches/encoder-redesign/ber-codec/src/java/org/apache/snickers/ber/TupleNode.java
(original)
+++ incubator/directory/snickers/branches/encoder-redesign/ber-codec/src/java/org/apache/snickers/ber/TupleNode.java
Sun Aug 15 19:20:06 2004
@@ -117,4 +117,12 @@
      * @return true if the obj and this node are exact replicas of one another
      */
     boolean equals( Object obj ) ;
+
+    /**
+     * Element/node accept method for visitor pattern.
+     *
+     * @param visitor the tuple node tree structure visitor
+     * @see TupleNodeVisitor
+     */
+    void accept( TupleNodeVisitor visitor ) ;
 }

Added: incubator/directory/snickers/branches/encoder-redesign/ber-codec/src/java/org/apache/snickers/ber/TupleNodeVisitor.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/branches/encoder-redesign/ber-codec/src/java/org/apache/snickers/ber/TupleNodeVisitor.java
Sun Aug 15 19:20:06 2004
@@ -0,0 +1,78 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.snickers.ber;
+
+
+import java.util.ArrayList;
+
+
+/**
+ * Tuple tree node visitor interface.  Note that this is a more specific
+ * variant of the extrinsic visitor pattern.  It has the following advantages
+ * over the standard visitor pattern:
+ * <ul>
+ *  <li>Visitor takes responsibility that a visitor can visit a node</li>
+ *  <li>Each visitor knows which types of concrete classes it can visit</li>
+ *  <li>New visitors can be created without changing the node class</li>
+ *  <li>New node classes can be added without having to change old visitors</li>
+ *  <li>Visitation order can be controled in every respect:</li>
+ *  <ul>
+ *      <li>Visitation rejection with canVisit() and/or getOrder()</li>
+ *      <li>Recursive visitation ordering with isPrefix()</li>
+ *      <li>Child visitation ordering with getOrder()</li>
+ *  </ul>
+ * </ul>
+ *
+ * @see TupleNode#accept(TupleNodeVisitor)
+ * @author <a href="mailto:directory-dev@incubator.apache.org"> Apache Directory
+ *         Project</a> $Rev$
+ */
+public interface TupleNodeVisitor
+{
+    /**
+     * Visits a tree of tuple nodes using a specific visitation order.
+     *
+     * @param node the node to visit
+     */
+    void visit( TupleNode node ) ;
+
+    /**
+     * Checks to see if a node can be visited.
+     *
+     * @param node the node to be visited
+     * @return whether or node the node should be visited
+     */
+    boolean canVisit( TupleNode node ) ;
+
+    /**
+     * Determines whether the visitation order is prefix or postfix.
+     *
+     * @return true if the visitation is in prefix order, false otherwise.
+     */
+    boolean isPrefix() ;
+
+    /**
+     * Get the array of children to visit sequentially to determine the order of
+     * child visitations.  Some children may not be returned at all if
+     * canVisit() returns false on them.
+     *
+     * @param node the parent branch node
+     * @param children the child node array
+     * @return the new reordered array of children
+     */
+    ArrayList getOrder( TupleNode node, ArrayList children ) ;
+}

Mime
View raw message