directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r179156 - /directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/AbstractContainer.java
Date Mon, 30 May 2005 22:05:20 GMT
Author: elecharny
Date: Mon May 30 15:05:20 2005
New Revision: 179156

URL: http://svn.apache.org/viewcvs?rev=179156&view=rev
Log:
- added a states stack, to be able to continue the parsing when coming back from a grammar
switch
- modified the grammarSwitch method, which take one more parameter : the current state
- fixed javadoco

Modified:
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/AbstractContainer.java

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/AbstractContainer.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/AbstractContainer.java?rev=179156&r1=179155&r2=179156&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/AbstractContainer.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/AbstractContainer.java
Mon May 30 15:05:20 2005
@@ -20,20 +20,30 @@
 import org.apache.asn1.ber.grammar.IGrammar;
 import org.apache.asn1.ber.tlv.TLV;
 
+
 /**
+ * DOCUMENT ME!
+ * 
+ *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class AbstractContainer implements IAsn1Container {
+public class AbstractContainer implements IAsn1Container
+{
+    //~ Instance fields ----------------------------------------------------------------------------
+
     /** The grammars that are used.
      * It's a stack as we can switch grammars */
     protected IGrammar[] grammarStack;
-    
+
     /** All the possible grammars */
     protected IGrammar[] grammars;
-    
-    /** The number of stored grammars */ 
+
+    /** Store a stack of the current states used when switching grammars */
+    protected int[] stateStack;
+
+    /** The number of stored grammars */
     protected int nbGrammars;
-    
+
     /** The current grammar */
     protected int currentGrammar;
 
@@ -46,7 +56,11 @@
     /** The current TLV */
     protected TLV tlv;
 
+    //~ Methods ------------------------------------------------------------------------------------
+
     /**
+     * DOCUMENT ME!
+     *
      * @return Returns the grammar used to decode a LdapMessage.
      */
     public IGrammar getGrammar()
@@ -67,26 +81,40 @@
     /**
      * Switch to another grammar
      *
+     * @param currentState DOCUMENT ME!
      * @param grammar The grammar to add.
      */
-    public void switchGrammar( int grammar )
+    public void switchGrammar( int currentState, int grammar )
     {
-        currentGrammar ++;
-        grammarStack[currentGrammar] = grammars[(grammar >> 8) - 1];
+        stateStack[currentGrammar] = currentState;
+        currentGrammar++;
+        grammarStack[currentGrammar] = grammars[( grammar >> 8 ) - 1];
     }
 
     /**
      * restore the previous grammar (the one before a switch has occured)
      *
-     * @param grammar The grammar to add.
+     * @return The previous current state, if any.
      */
-    public void restoreGrammar()
+    public int restoreGrammar()
     {
         grammarStack[currentGrammar] = null;
-        currentGrammar --;
+        currentGrammar--;
+
+        if ( currentGrammar >= 0 )
+        {
+            return stateStack[currentGrammar];
+        }
+        else
+        {
+            return -1;
+        }
+
     }
 
     /**
+     * DOCUMENT ME!
+     *
      * @return Returns the current grammar state
      */
     public int getState()
@@ -105,6 +133,8 @@
     }
 
     /**
+     * DOCUMENT ME!
+     *
      * @return Returns the transition from the previous state to the new 
      * state
      */
@@ -122,35 +152,47 @@
     {
         this.transition = transition;
     }
-    
+
     /**
+     * Gert the current grammar number
+     *
      * @return Returns the currentGrammar.
      */
-    public int getCurrentGrammar() {
+    public int getCurrentGrammar()
+    {
         return currentGrammar;
     }
 
     /**
+     * Get the current grammar type.
+     *
      * @return Returns the current Grammar type, or -1 if not found.
      */
-    public int getCurrentGrammarType() {
-        for ( int i = 0; i < grammars.length; i++)
+    public int getCurrentGrammarType()
+    {
+
+        for ( int i = 0; i < grammars.length; i++ )
         {
-            if (grammars[i] == grammarStack[currentGrammar])
-                {
+
+            if ( grammars[i] == grammarStack[currentGrammar] )
+            {
                 return i;
-                }
+            }
         }
-        
+
         return -1;
     }
 
     /**
-     * @return Set the grammar that will be used to start a decoding.
-     */
-    public void setInitGrammar(int grammar) {
-        currentGrammar ++;
+     * Initialize the grammar stack
+     *
+     * @param grammar Set the initial grammar
+    */
+    public void setInitGrammar( int grammar )
+    {
+        currentGrammar++;
         grammarStack[currentGrammar] = grammars[grammar];
+        stateStack[currentGrammar]   = 0;
     }
 
     /**
@@ -164,11 +206,12 @@
     }
 
     /**
+     * Get the current TLV
+     *
      * @return Returns the current TLV being decoded
      */
     public TLV getCurrentTLV()
     {
-
         return this.tlv;
     }
 }



Mime
View raw message