directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 9826 - in incubator/directory/snickers/trunk/ber/src: java/org/apache/snickers/ber/digester test/org/apache/snickers/ber/digester
Date Tue, 30 Mar 2004 08:10:20 GMT
Author: akarasulu
Date: Tue Mar 30 00:10:20 2004
New Revision: 9826

Added:
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/RulesBase.java
  (contents, props changed)
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/Rules.java
   incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/digester/TagTreeTest.java
  (props changed)
Log:
added rules base management interfaces

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
Tue Mar 30 00:10:20 2004
@@ -37,8 +37,23 @@
  */
 public class BERDigester implements BERDecoderCallback
 {
+    /** the underlying decoder used by this digester */
     private BERDecoder decoder ;
+    /** the object stack where rules push and pop ASN.1 POJO stubs */
     private Stack objectStack ;
+    /** the rules base used by this digester */
+    private Rules rules ;
+
+
+    /**
+     * Creates a BER TLV event digester.
+     */
+    public BERDigester()
+    {
+        this.rules = new RulesBase() ;
+        this.objectStack = new Stack() ;
+        this.decoder = new BERDecoder() ;
+    }
     
     
     // ------------------------------------------------------------------------
@@ -99,7 +114,7 @@
      */
     public void addRule( int[] pattern, Rule rule )
     {
-        throw new NotImplementedException( "STUB" ) ;
+        rules.add( pattern, rule ) ;
     }
                
     
@@ -111,7 +126,7 @@
      */
     public Rules getRules()
     {
-        throw new NotImplementedException( "STUB" ) ;
+        return rules ;
     }
              
 
@@ -124,17 +139,82 @@
     }
     
     
+    /**
+     * Return the current depth of the element stack.
+     * 
+     * @return the size of the element stack
+     */
+    public int getCount()
+    {
+        return objectStack.size() ;
+    }
+    
+    
+    /**
+     * Return the top object on the stack without removing it.
+     * 
+     * @return the object on the top of the stack
+     */
+    public Object peek()
+    {
+        return objectStack.peek() ;
+    }
+    
+    
+    /**
+     * Return the n'th object down the stack, where 0 is the top element and 
+     * [getCount()-1] is the bottom element.
+     * 
+     * @param n the element index
+     * @return the element at the index
+     */
+    public Object peek( int n )
+    {
+        return objectStack.get( n ) ;
+    }
+              
+    
+    /**
+     * Pop the top object off of the stack, and return it.
+     * 
+     * @return the top object off of the stack
+     */
+    public Object pop()
+    {
+        return objectStack.pop() ;
+    }
+              
+    
+    /**
+     * Push a new object onto the top of the object stack.
+     * 
+     * @param object the object to push onto the stack
+     */
+    public void push( Object object )
+    {
+        objectStack.push( object ) ;
+    }
+              
+
+    /**
+     * Set the Rules implementation object containing our rules collection 
+     * and associated matching policy.
+     * 
+     * @param rules the rules to add to this digester
+     */
+    public void setRules( Rules rules )
+    {
+        this.rules = rules ;
+    }
+    
+    
     
     /*
 
      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() 
@@ -142,26 +222,16 @@
  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/Rules.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/Rules.java
(original)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/Rules.java
Tue Mar 30 00:10:20 2004
@@ -15,13 +15,11 @@
  */ 
 
 
-package org.apache.snickers.ber.digester;
+package org.apache.snickers.ber.digester ;
 
 
 import java.util.List ;
 
-import org.apache.snickers.ber.BERDecoder;
-
 
 /**
  * Public interface defining a collection of Rule instances (and corresponding
@@ -36,20 +34,21 @@
 public interface Rules 
 {
     /**
-     * Get the <code>BERDecoder</code> instance with which this <code>Rules
+     * Get the <code>BERDigester</code> instance with which this <code>Rules
      * </code> instance is associated.
      * 
-     * @return the BERDecoder associated with this Rules instance
+     * @return the BERDigester associated with this Rules instance
      */
-    public BERDecoder getDecoder() ;
+    public BERDigester getDigester() ;
 
     /**
-     * Get the <code>BERDecoder</code> instance with which this <code>Rules
+     * Get the <code>BERDigester</code> instance with which this <code>Rules
      * </code> instance is associated.
      * 
-     * @param the new BERDecoder to be associated with this Rules instance
+     * @param digester the new BERDigester to be associated with this Rules 
+     * instance
      */
-    public void setDecoder( BERDecoder decoder ) ;
+    public void setDigester( BERDigester digester ) ;
 
     /**
      * Register a new Rule instance matching the specified pattern.
@@ -72,8 +71,6 @@
      * method.
      *
      * @param pattern Nesting pattern to be matched
-     *
-     * @deprecated Call match(namespaceURI,pattern) instead.
      */
     public List match( int[] pattern ) ;
 

Added: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/RulesBase.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/RulesBase.java
Tue Mar 30 00:10:20 2004
@@ -0,0 +1,102 @@
+/*
+ *   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.ArrayList ;
+import java.util.Collections ;
+
+
+/**
+ * A base Rules implementation using a fast pattern match.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">
+ * Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class RulesBase implements Rules
+{
+    private TagTree tagTree ;
+    private ArrayList rules ;
+    private BERDigester digester ;
+    
+    
+    public RulesBase()
+    {
+        tagTree = new TagTree() ;
+        rules = new ArrayList() ;
+    }
+    
+    
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.digester.Rules#setDigester(
+     * org.apache.snickers.ber.digester.BERDigester)
+     */
+    public void setDigester( BERDigester digester )
+    {
+        this.digester = digester ;
+    }
+    
+    
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.digester.Rules#getDigester()
+     */
+    public BERDigester getDigester()
+    {
+        return digester ;
+    }
+    
+    
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.digester.Rules#add(int[], 
+     * org.apache.snickers.ber.digester.Rule)
+     */
+    public void add( int[] pattern, Rule rule )
+    {
+        tagTree.addRule( pattern, rule ) ;
+        rules.add( rule ) ;
+    }
+
+    
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.digester.Rules#clear()
+     */
+    public void clear()
+    {
+        tagTree = new TagTree() ;
+        rules.clear() ;
+    }
+    
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.digester.Rules#match(int[])
+     */
+    public List match( int[] pattern )
+    {
+        return tagTree.match( pattern ) ;
+    }
+    
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.digester.Rules#rules()
+     */
+    public List rules()
+    {
+        return Collections.unmodifiableList( rules ) ;
+    }
+}

Mime
View raw message