directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r372168 - in /directory/trunks/asn1/src/main/java/org/apache/asn1/ber: AbstractContainer.java IAsn1Container.java grammar/AbstractGrammar.java
Date Wed, 25 Jan 2006 09:19:19 GMT
Author: elecharny
Date: Wed Jan 25 01:19:14 2006
New Revision: 372168

URL: http://svn.apache.org/viewcvs?rev=372168&view=rev
Log:
- Added a stack to allow popIng of sub-grammars. This is necessary
for cases where a sub-grammar met a tag which is not part of the 
state automaton, and we are in a case where the sub-grammmar
could reach a terminaison state.

Modified:
    directory/trunks/asn1/src/main/java/org/apache/asn1/ber/AbstractContainer.java
    directory/trunks/asn1/src/main/java/org/apache/asn1/ber/IAsn1Container.java
    directory/trunks/asn1/src/main/java/org/apache/asn1/ber/grammar/AbstractGrammar.java

Modified: directory/trunks/asn1/src/main/java/org/apache/asn1/ber/AbstractContainer.java
URL: http://svn.apache.org/viewcvs/directory/trunks/asn1/src/main/java/org/apache/asn1/ber/AbstractContainer.java?rev=372168&r1=372167&r2=372168&view=diff
==============================================================================
--- directory/trunks/asn1/src/main/java/org/apache/asn1/ber/AbstractContainer.java (original)
+++ directory/trunks/asn1/src/main/java/org/apache/asn1/ber/AbstractContainer.java Wed Jan
25 01:19:14 2006
@@ -44,6 +44,9 @@
     /** Store a stack of the current states used when switching grammars */
     protected int[] stateStack;
 
+    /** Store a stack of allowed pop */
+    protected boolean[] popAllowedStack;
+
     /** The number of stored grammars */
     protected int nbGrammars;
 
@@ -68,10 +71,13 @@
     /** The grammar end transition flag */
     protected boolean grammarEndAllowed;
 
+    /** The grammar pop transition flag */
+    protected boolean grammarPopAllowed;
+
     //~ Methods ------------------------------------------------------------------------------------
 
     /**
-     * DOCUMENT ME!
+     * Get the current grammar
      *
      * @return Returns the grammar used to decode a LdapMessage.
      */
@@ -93,13 +99,14 @@
     /**
      * Switch to another grammar
      *
-     * @param currentState DOCUMENT ME!
+     * @param currentState The current state in the current grammar
      * @param grammar The grammar to add.
      */
     public void switchGrammar( int currentState, int grammar )
     {
         stateStack[currentGrammar] = currentState;
         currentGrammar++;
+        popAllowedStack[currentGrammar] = false;
         grammarStack[currentGrammar] = grammars[( grammar >> 8 ) - 1];
     }
 
@@ -111,6 +118,7 @@
     public int restoreGrammar()
     {
         grammarStack[currentGrammar] = null;
+        popAllowedStack[currentGrammar] = false;
         currentGrammar--;
 
         if ( currentGrammar >= 0 )
@@ -161,6 +169,25 @@
     public void grammarEndAllowed( boolean grammarEndAllowed )
     {
     	this.grammarEndAllowed = grammarEndAllowed;
+    }
+
+    /**
+     * Check that we can have a pop after this transition
+     * @return true if this can be the last transition before a pop
+     */
+    public boolean isGrammarPopAllowed( )
+    {
+        return popAllowedStack[currentGrammar];
+    }
+    
+    /**
+     * Set the flag to allow a pop transition
+     * @param popAllowed true or false, depending on the next
+     * transition allows a pop or not.
+     */
+    public void grammarPopAllowed( boolean grammarPopAllowed )
+    {
+        popAllowedStack[currentGrammar] = grammarPopAllowed;
     }
 
     /**

Modified: directory/trunks/asn1/src/main/java/org/apache/asn1/ber/IAsn1Container.java
URL: http://svn.apache.org/viewcvs/directory/trunks/asn1/src/main/java/org/apache/asn1/ber/IAsn1Container.java?rev=372168&r1=372167&r2=372168&view=diff
==============================================================================
--- directory/trunks/asn1/src/main/java/org/apache/asn1/ber/IAsn1Container.java (original)
+++ directory/trunks/asn1/src/main/java/org/apache/asn1/ber/IAsn1Container.java Wed Jan 25
01:19:14 2006
@@ -146,4 +146,17 @@
      * transition being an end or not.
      */
     public void grammarEndAllowed( boolean grammarEndAllowed );
+
+    /**
+     * Check that we can have a pop state after this transition
+     * @return true if we can pop the grammar
+     */
+    public boolean isGrammarPopAllowed();
+    
+    /**
+     * Set the flag to allow a pop of the current grammar
+     * @param popAllowed true or false, depending on the next
+     * transition allows a pop or not.
+     */
+    public void grammarPopAllowed( boolean grammarPopAllowed );
 }

Modified: directory/trunks/asn1/src/main/java/org/apache/asn1/ber/grammar/AbstractGrammar.java
URL: http://svn.apache.org/viewcvs/directory/trunks/asn1/src/main/java/org/apache/asn1/ber/grammar/AbstractGrammar.java?rev=372168&r1=372167&r2=372168&view=diff
==============================================================================
--- directory/trunks/asn1/src/main/java/org/apache/asn1/ber/grammar/AbstractGrammar.java (original)
+++ directory/trunks/asn1/src/main/java/org/apache/asn1/ber/grammar/AbstractGrammar.java Wed
Jan 25 01:19:14 2006
@@ -174,9 +174,29 @@
                 {
 
                     // We have finished with the current grammar, so we have to continue
with the
-                    // previous one.
-                    currentState = container.restoreGrammar();
-                    continue;
+                    // previous one, only if allowed
+                    
+                    if ( container.isGrammarPopAllowed() )
+                    {
+                        if ( log.isDebugEnabled() )
+                        {
+                            log.debug( "Pop grammar {}, state = {}", container.getStates().getGrammarName(
currentGrammar ), 
+                                    currentGrammar.getStatesEnum().getState( container.getCurrentGrammarType(),
currentState ) );
+                        }
+                        
+                        currentState = container.restoreGrammar();
+                        continue;
+                    }
+                    else
+                    {
+                        String msg = "Cannot pop the grammar " + 
+                                      container.getStates().getGrammarName( currentGrammar
) +
+                                      " for state " + 
+                                      currentGrammar.getStatesEnum().getState( container.getCurrentGrammarType(),
currentState );
+                        // We can't pop the grammar
+                        log.error( msg );
+                        throw new DecoderException( msg );
+                    }
                 }
             }
 
@@ -191,6 +211,11 @@
             if ( ( ( nextState & IStates.GRAMMAR_SWITCH_MASK ) != 0 ) &&
                     ( nextState != IStates.END_STATE ) )
             {
+
+                if ( transition.hasAction() )
+                {
+                    transition.getAction().action( container );
+                }
 
                 if ( log.isDebugEnabled() )
                 {



Mime
View raw message