directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 9821 - incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester
Date Tue, 30 Mar 2004 07:34:57 GMT
Author: akarasulu
Date: Mon Mar 29 23:34:56 2004
New Revision: 9821

Added:
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/TagNode.java
  (contents, props changed)
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/TagTree.java
  (contents, props changed)
Modified:
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/AbstractRule.java
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/BERDigester.java
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/Rule.java
Log:
starting to build the digester out working first on pattern matching

Modified: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/AbstractRule.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/AbstractRule.java
(original)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/AbstractRule.java
Mon Mar 29 23:34:56 2004
@@ -14,13 +14,12 @@
  *   limitations under the License.
  *
  */
-package org.apache.snickers.ber.digester;
+package org.apache.snickers.ber.digester ;
 
 
 import java.nio.ByteBuffer ;
 
-import org.apache.snickers.ber.BERDecoder;
-import org.apache.snickers.ber.TypeClass;
+import org.apache.snickers.ber.TypeClass ;
 
 
 /**
@@ -32,25 +31,25 @@
  */
 public abstract class AbstractRule implements Rule
 {
-    private BERDecoder decoder = null ;
-    
+    private BERDigester digester = null ;
 
+    
     /* (non-Javadoc)
-     * @see org.apache.snickers.ber.Rule#getDecoder()
+     * @see org.apache.snickers.ber.digester.Rule#getDecoder()
      */
-    public BERDecoder getDecoder()
+    public BERDigester getDecoder()
     {
-        return decoder ;
+        return digester ;
     }
     
-
+    
     /* (non-Javadoc)
-     * @see org.apache.snickers.ber.Rule#setDecoder(
-     * org.apache.snickers.ber.BERDecoder)
+     * @see org.apache.snickers.ber.digester.Rule#setDigester(
+     * org.apache.snickers.ber.digester.BERDigester)
      */
-    public void setDecoder( BERDecoder decoder )
+    public void setDigester( BERDigester digester )
     {
-        this.decoder = decoder ;
+        this.digester = digester ;
     }
 
     

Modified: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/BERDigester.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/BERDigester.java
(original)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/BERDigester.java
Mon Mar 29 23:34:56 2004
@@ -17,10 +17,14 @@
 package org.apache.snickers.ber.digester ;
 
 
+import java.util.Stack ;
+
 import org.apache.snickers.ber.Tuple ;
+import org.apache.snickers.ber.BERDecoder ;
 import org.apache.snickers.ber.BERDecoderCallback ;
 
 import org.apache.commons.codec.stateful.StatefulDecoder ;
+import org.apache.commons.lang.NotImplementedException ;
 
 
 /**
@@ -33,6 +37,10 @@
  */
 public class BERDigester implements BERDecoderCallback
 {
+    private BERDecoder decoder ;
+    private Stack objectStack ;
+    
+    
     // ------------------------------------------------------------------------
     // BERDecoderCallback methods 
     // ------------------------------------------------------------------------
@@ -44,6 +52,7 @@
      */
     public void tagDecoded( Tuple tlv )
     {
+        throw new NotImplementedException( "STUB" ) ;
     }
 
     
@@ -53,6 +62,7 @@
      */
     public void lengthDecoded( Tuple tlv )
     {
+        throw new NotImplementedException( "STUB" ) ;
     }
 
     
@@ -62,6 +72,7 @@
      */
     public void partialValueDecoded( Tuple tlv )
     {
+        throw new NotImplementedException( "STUB" ) ;
     }
 
 
@@ -71,12 +82,89 @@
      */
     public void decodeOccurred( StatefulDecoder decoder, Object decoded )
     {
+        throw new NotImplementedException( "STUB" ) ;
     }
 
 
     // ------------------------------------------------------------------------
-    // BERDecoderCallback methods 
+    // Digester like methods 
     // ------------------------------------------------------------------------
 
+
+    /**
+     * Register a new <code>Rule</code> matching the specified pattern.
+     * 
+     * @param pattern tag nesting pattern
+     * @param rule the Rule to add to this BERDigester 
+     */
+    public void addRule( int[] pattern, Rule rule )
+    {
+        throw new NotImplementedException( "STUB" ) ;
+    }
+               
     
+    /**
+     * Return the Rules implementation object containing our rules collection 
+     * and associated matching policy.
+     * 
+     * @return the entire set of rules
+     */
+    public Rules getRules()
+    {
+        throw new NotImplementedException( "STUB" ) ;
+    }
+             
+
+    /**
+     * Clear the current contents of the object stack.
+     */
+    public void clear()
+    {
+        objectStack.clear() ;
+    }
+    
+    
+    
+    /*
+
+     Methods of interest from the original digester class:     
+
+void addRuleSet(RuleSet ruleSet) 
+          Register a set of Rule instances defined in a RuleSet. 
+ java.lang.ClassLoader getClassLoader() 
+          Return the class loader to be used for instantiating application objects when required.

+ int getCount() 
+          Return the current depth of the element stack. 
+ java.lang.String getCurrentElementName() 
+          Return the name of the XML element that is currently being processed. 
+ java.lang.String getMatch() 
+          Return the current rule match path 
+ boolean getUseContextClassLoader() 
+          Return the boolean as to whether the context classloader should be used. 
+
+ java.lang.Object peek() 
+          Return the top object on the stack without removing it. 
+ java.lang.Object peek(int n) 
+          Return the n'th object down the stack, where 0 is the top element and [getCount()-1]
is the bottom element. 
+ java.lang.Object peekParams() 
+          Return the top object on the parameters stack without removing it. 
+ java.lang.Object peekParams(int n) 
+          Return the n'th object down the parameters stack, where 0 is the top element and
[getCount()-1] is the bottom element. 
+ java.lang.Object pop() 
+          Pop the top object off of the stack, and return it. 
+ java.lang.Object popParams() 
+          Pop the top object off of the parameters stack, and return it. 
+ void push(java.lang.Object object) 
+          Push a new object onto the top of the object stack. 
+ void pushParams(java.lang.Object object) 
+          Push a new object onto the top of the parameters stack. 
+ void setClassLoader(java.lang.ClassLoader classLoader) 
+          Set the class loader to be used for instantiating application objects when required.

+ void setRules(Rules rules) 
+          Set the Rules implementation object containing our rules collection and associated
matching policy. 
+ void setUseContextClassLoader(boolean use) 
+          Determine whether to use the Context ClassLoader (the one found by calling Thread.currentThread().getContextClassLoader())
to resolve/load classes that are defined in various rules. 
+                                        
+
+    */
 }

Modified: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/Rule.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/Rule.java
(original)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/Rule.java
Mon Mar 29 23:34:56 2004
@@ -14,13 +14,12 @@
  *   limitations under the License.
  *
  */
-package org.apache.snickers.ber.digester;
+package org.apache.snickers.ber.digester ;
 
 
 import java.nio.ByteBuffer ;
 
-import org.apache.snickers.ber.BERDecoder;
-import org.apache.snickers.ber.TypeClass;
+import org.apache.snickers.ber.TypeClass ;
 
 
 /**
@@ -33,20 +32,20 @@
 public interface Rule
 {
     /**
-     * Get the <code>BERDecoder</code> with which this <code>Rule</code>
has
+     * Get the <code>BERDigester</code> with which this <code>Rule</code>
has
      * been associated.
      * 
-     * @return the associated decoder
+     * @return the associated digester
      */
-    BERDecoder getDecoder() ;
+    BERDigester getDecoder() ;
     
     /**
-     * Set the <code>BERDecoder</code> with which this <code>Rule</code>
will
+     * Set the <code>BERDigester</code> with which this <code>Rule</code>
will
      * be associated.
      * 
-     * @param decoder the decoder to associate this rule with
+     * @param digester the digester to associate this rule with
      */
-    void setDecoder( BERDecoder decoder ) ;
+    void setDigester( BERDigester digester ) ;
     
     /**
      * Called when the tag of the matched TLV is encountered.

Added: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/TagNode.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/TagNode.java
Mon Mar 29 23:34:56 2004
@@ -0,0 +1,99 @@
+/*
+ *   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.digester ;
+
+
+import java.util.HashMap ;
+import java.util.ArrayList ;
+import java.util.List;
+
+
+/**
+ * A speed (verses size) optimized data structure to match tag patterns.  
+ * As tuples are pushed and popped off of the decoder's stack and the tag 
+ * nesting path changes this tree is traversed.  A position member of type
+ * TagNode is used to track the current position in this tree.  If the nesting
+ * does not correspond to a valid node then it is null and thus underfined so
+ * no rules are correlated with the position.  When a node is located and set
+ * the rules contained in that node are triggered.
+ *   
+ * @author <a href="mailto:directory-dev@incubator.apache.org">
+ * Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class TagNode
+{
+    private Integer tag ;
+    private int depth ;
+    private HashMap children = new HashMap( 3 ) ;
+    private ArrayList rules = new ArrayList( 3 ) ;
+    
+    
+    TagNode( Integer tag )
+    {
+        this.tag = tag ;
+    }
+    
+    
+    void addNode( TagNode node )
+    {
+        children.put( node.getTag(), node ) ;
+        node.setDepth( depth + 1 ) ;
+    }
+    
+    
+    void addRule( Rule rule )
+    {
+        rules.add( rule ) ;
+    }
+    
+    
+    void setDepth( int depth )
+    {
+        this.depth = depth ;
+    }
+    
+    
+    public Integer getTag() 
+    {
+        return tag ;
+    }
+    
+    
+    public int getDepth()
+    {
+        return depth ;
+    }
+    
+    
+    public List getRules()
+    {
+        return rules ;
+    }
+    
+    
+    public boolean hasChild( Integer tag )
+    {
+        return children.containsKey( tag ) ;
+    }
+    
+    
+    public TagNode getChild( Integer tag )
+    {
+        return ( TagNode ) children.get( tag ) ;
+    }
+}

Added: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/TagTree.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/TagTree.java
Mon Mar 29 23:34:56 2004
@@ -0,0 +1,143 @@
+/*
+ *   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.digester ;
+
+
+import java.util.List ;
+import java.util.HashMap ;
+import java.util.Collections ;
+
+import org.apache.commons.lang.Validate ;
+
+
+/**
+ * A tree of tags.
+ *
+ * @todo find and start using a hash table keyed by primitive int instead of
+ * an Integer
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">
+ * Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class TagTree
+{
+    /** a set of tag nodes */
+    private HashMap nodes = new HashMap( 3 ) ;
+
+    
+    /**
+     * Adds a Rule to this TagTree.
+     * 
+     * @param pattern the pattern of nested tags
+     * @param rule the rule to add for the pattern
+     */
+    public void addRule( int[] pattern, Rule rule )
+    {
+        Integer tag = null ;
+        TagNode node = null ;
+
+        Validate.notNull( rule, "cannot add null rule" ) ;
+        Validate.notNull( pattern, "cannot add rule with null pattern" ) ;
+        Validate.isTrue( pattern.length > 0, 
+                "cannot add rule with empty pattern" ) ;
+
+        tag = new Integer( pattern[0] ) ;
+        if ( nodes.containsKey( tag ) )
+        {
+            node = ( TagNode ) nodes.get( tag ) ;
+        }
+        else
+        {
+            node = new TagNode( tag ) ;
+            nodes.put( tag, node ) ;
+        }
+        
+        for ( int ii = 1; ii < pattern.length; ii++ )
+        {    
+            Integer childTag = new Integer( pattern[ii] ) ;
+            TagNode childNode = node.getChild( childTag ) ;
+            
+            if ( childNode == null )
+            {
+                childNode = new TagNode( childTag ) ;
+                node.addNode( childNode ) ;
+            }
+            
+            node = childNode ;
+            tag = childTag ;
+        }
+        
+        node.addRule( rule ) ;
+    }
+    
+    
+    public List match( int[] pattern )
+    {
+        TagNode node = getNode( pattern ) ;
+        
+        if ( node == null )
+        {
+            return Collections.EMPTY_LIST ;
+        }
+        
+        return node.getRules() ;
+    }
+    
+    
+    public TagNode getNode( int[] pattern ) 
+    {
+        Integer tag = null ;
+        TagNode node = null ;
+
+        Validate.notNull( pattern, "cannot match using null pattern" ) ;
+        Validate.isTrue( pattern.length > 0, 
+                "cannot match with empty pattern" ) ;
+
+        tag = new Integer( pattern[0] ) ;
+        if ( nodes.containsKey( tag ) )
+        {
+            node = ( TagNode ) nodes.get( tag ) ;
+        }
+        else
+        {
+            return null ;
+        }
+        
+        for ( int ii = 1; ii < pattern.length; ii++ )
+        {    
+            Integer childTag = new Integer( pattern[ii] ) ;
+            TagNode childNode = node.getChild( childTag ) ;
+            
+            if ( childNode == null )
+            {
+                return null ;
+            }
+            
+            node = childNode ;
+            tag = childTag ;
+        }
+        
+        return node ;
+    }
+
+
+    public TagNode getNode( int tag ) 
+    {
+        return ( TagNode ) nodes.get( new Integer( tag ) ) ;
+    }
+}

Mime
View raw message