You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2005/05/31 00:13:48 UTC

svn commit: r179159 - /directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/grammar/AbstractGrammar.java

Author: elecharny
Date: Mon May 30 15:13:47 2005
New Revision: 179159

URL: http://svn.apache.org/viewcvs?rev=179159&view=rev
Log:
A major fix. When we had a sub-grammar (like LdapResult) into a grammar, and when this sub-grammar is following by 
some other elements to parse, the decoder was simply not working. This has been fixed by adding a state stack to 
store the current state before the switch, and some controls when we are coming back from a swicth to know when we 
have to pursue the decoding on the current grammar or finishing it.

Quite complicated...

Fortunatly, this leads to some simplification in all the grammars, as we don't anymore have to deal with the 
following states when leaving a sub-grammar.


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

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/grammar/AbstractGrammar.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/grammar/AbstractGrammar.java?rev=179159&r1=179158&r2=179159&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/grammar/AbstractGrammar.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/grammar/AbstractGrammar.java Mon May 30 15:13:47 2005
@@ -22,6 +22,7 @@
 import org.apache.asn1.ber.containers.IAsn1Container;
 import org.apache.asn1.ber.tlv.TLV;
 import org.apache.asn1.ber.tlv.Tag;
+import org.apache.asn1.ldap.codec.grammars.LdapStatesEnum;
 import org.apache.asn1.util.StringUtils;
 
 import org.apache.log4j.Logger;
@@ -59,7 +60,7 @@
 
     /**
      * Return the grammar's name
-     * @return DOCUMENT ME!
+     * @return The grammar name
     */
     public String getName()
     {
@@ -134,14 +135,21 @@
         int      currentState   = container.getTransition();
         IGrammar currentGrammar = container.getGrammar();
 
+        // We have to deal with the special case of a GRAMLMAR_END state
         if ( currentState == -1 )
         {
-            return;
+            currentState = container.restoreGrammar();
+
+            if ( currentState == -1 )
+            {
+                return;
+            }
         }
 
         Tag  tag     = container.getCurrentTLV().getTag();
         byte tagByte = tag.getTagByte();
 
+        // We will loop until no more action are to be executed
         while ( true )
         {
 
@@ -150,15 +158,30 @@
 
             if ( transition == null )
             {
-                throw new DecoderException(
-                    "Bad transition from state " +
-                    currentGrammar.getStatesEnum().getState( container.getCurrentGrammarType(),
-                        currentState ) + ", tag " + StringUtils.dumpByte( tag.getTagByte() ) );
+
+                if ( container.getCurrentGrammar() == 0 )
+                {
+
+                    // If we have no more grammar on the stack, then this is an error
+                    throw new DecoderException(
+                        "Bad transition from state " +
+                        currentGrammar.getStatesEnum().getState( container.getCurrentGrammarType(),
+                            currentState ) + ", tag " + StringUtils.dumpByte( tag.getTagByte() ) );
+                }
+                else
+                {
+
+                    // We have finished with the current grammar, so we have to continue with the
+                    // previous one.
+                    currentState = container.restoreGrammar();
+                    continue;
+                }
             }
 
             if ( DEBUG )
             {
-                log.debug( transition.toString( container.getCurrentGrammarType(), currentGrammar.getStatesEnum() ) );
+                log.debug( transition.toString( container.getCurrentGrammarType(),
+                        currentGrammar.getStatesEnum() ) );
             }
 
             int nextState = transition.getNextState();
@@ -166,9 +189,17 @@
             if ( ( ( nextState & IStates.GRAMMAR_SWITCH_MASK ) != 0 ) && ( nextState != -1 ) )
             {
 
+                if ( DEBUG )
+                {
+                    log.debug(
+                        "Switching from grammar " +
+                        LdapStatesEnum.getGrammarName( currentGrammar ) +
+                        " to grammar " + LdapStatesEnum.getGrammarName( ( nextState >> 8 ) - 1 ) );
+                }
+
                 // We have a grammar switch, so we change the current state to the initial
                 // state in the new grammar and loop.
-                container.switchGrammar( nextState & IStates.GRAMMAR_SWITCH_MASK );
+                container.switchGrammar( currentState, nextState & IStates.GRAMMAR_SWITCH_MASK );
                 currentState = IStates.INIT_GRAMMAR_STATE;
             }
             else