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/04/23 09:44:46 UTC

svn commit: r164355 - in /directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/grammar: AbstractGrammar.java GrammarTransition.java IAction.java IGrammar.java

Author: elecharny
Date: Sat Apr 23 00:44:46 2005
New Revision: 164355

URL: http://svn.apache.org/viewcvs?rev=164355&view=rev
Log:
Changed the import of DecodedException

Modified:
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/grammar/AbstractGrammar.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/grammar/GrammarTransition.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/grammar/IAction.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/grammar/IGrammar.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=164355&r1=164354&r2=164355&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 Sat Apr 23 00:44:46 2005
@@ -16,12 +16,12 @@
  */
 package org.apache.asn1.ber.grammar;
 
+import org.apache.asn1.AbstractPOJO;
+import org.apache.asn1.Asn1POJO;
+import org.apache.asn1.DecoderException;
 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.DecoderException;
-import org.apache.asn1.ldap.pojo.AbstractPOJO;
-import org.apache.asn1.ldap.pojo.LdapPOJO;
 import org.apache.asn1.util.StringUtils;
 
 import org.apache.log4j.Logger;
@@ -48,28 +48,33 @@
     /** Table of transitions. It's a two dimension array, the first dimension
      * indice the states, the second dimension indices the Tag value, so it is 256 wide. */
     protected GrammarTransition[][] transitions;
-    
+
     /** The grammar name */
     protected String name;
-    
+
+    /** The grammar's states */
+    protected IStates statesEnum;
+
     //~ Methods ------------------------------------------------------------------------------------
 
     /**
      * Return the grammar's name
-     */
+     * @return DOCUMENT ME!
+    */
     public String getName()
     {
         return name;
     }
-    
+
     /**
      * Set the grammar's name
-     */
-    public void setName(String name)
+     * @param name DOCUMENT ME!
+    */
+    public void setName( String name )
     {
         this.name = name;
     }
-    
+
     /**
      * Checks the Length. If the current TLV length is above the expected length of the 
      * PDU, an exception is thrown.
@@ -82,25 +87,27 @@
      * @throws DecoderException Thrown if the expected length is lower than the sum
      * of all the included elements.
      */
-    protected void checkLength(LdapPOJO ldapPOJO, TLV tlv) throws DecoderException
-	{
-	    // Create a new expected Length
-	    int expectedLength = tlv.getLength().getLength();
-
-	    int tlvLength = tlv.getSize();
-	    
-	    if ( DEBUG )
-	    {
-	        log.debug("Expected Length = " + ((AbstractPOJO)ldapPOJO).getExpectedLength() + 
-	                	", current length = " + ((AbstractPOJO)ldapPOJO).getCurrentLength() + 
-	                	", added length = " + expectedLength + 
-	                	", tlv length = " + tlvLength);
-	    }
-
-	    // We already are at the top level.
-	    // An exception will be thrown if the current length exceed the expected length
-		((AbstractPOJO)ldapPOJO).addLength(expectedLength + tlvLength);
-	}
+    protected void checkLength( Asn1POJO ldapPOJO, TLV tlv ) throws DecoderException
+    {
+
+        // Create a new expected Length
+        int expectedLength = tlv.getLength().getLength();
+
+        int tlvLength      = tlv.getSize();
+
+        if ( DEBUG )
+        {
+            log.debug(
+                "Expected Length = " + ( ( AbstractPOJO ) ldapPOJO ).getExpectedLength() +
+                ", current length = " + ( ( AbstractPOJO ) ldapPOJO ).getCurrentLength() +
+                ", added length = " + expectedLength +
+                ", tlv length = " + tlvLength );
+        }
+
+        // We already are at the top level.
+        // An exception will be thrown if the current length exceed the expected length
+        ( ( AbstractPOJO ) ldapPOJO ).addLength( expectedLength + tlvLength );
+    }
 
     /**
      * Get the transition associated with the state and tag
@@ -108,11 +115,11 @@
      * @param tag The current tag
      * @return A valid transition if any, or null.
      */
-    public GrammarTransition getTransition(int state, int tag)
+    public GrammarTransition getTransition( int state, int tag )
     {
         return transitions[state][tag & 0x00FF];
     }
-    
+
     /**
      * The main function. This is where an action is executed. If the 
      * action is null, nothing is done.
@@ -123,7 +130,8 @@
      */
     public void executeAction( IAsn1Container container ) throws DecoderException
     {
-        int currentState = container.getTransition();
+
+        int      currentState   = container.getTransition();
         IGrammar currentGrammar = container.getGrammar();
 
         if ( currentState == -1 )
@@ -131,47 +139,72 @@
             return;
         }
 
-        Tag               tag        = container.getCurrentTLV().getTag();
-        byte              tagByte    = tag.getTagByte();
-        
-        while (true)
+        Tag  tag     = container.getCurrentTLV().getTag();
+        byte tagByte = tag.getTagByte();
+
+        while ( true )
         {
-	        GrammarTransition transition = ((AbstractGrammar)container.getGrammar()).getTransition(currentState, tagByte & 0x00FF);
-	        
-	        if ( transition == null )
-	        {
-	            throw new DecoderException(
-	                "Bad transition from state " + StatesEnum.getState( container.getCurrentGrammarType() , currentState ) + ", tag " +
-	                StringUtils.dumpByte( tag.getTagByte() ) );
-	        }
-	
-	        if ( DEBUG )
-	        {
-	            log.debug( transition.toString(container.getCurrentGrammarType()) );
-	        }
-	
-	        int nextState = transition.getNextState();
-	        
-	        if (((nextState & StatesEnum.GRAMMAR_SWITCH_MASK) != 0) && (nextState != -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 & StatesEnum.GRAMMAR_SWITCH_MASK);
-	            currentState = StatesEnum.INIT_GRAMMAR_STATE;
-	        } 
-	        else
-	        {
-	            // This is not a grammar switch, so we execute the 
-	            // action if we have one, and we quit the loop.
-		        container.setTransition( nextState );
-		    	
-    	        if ( transition.hasAction() )
-    	        {
-    	            transition.getAction().action( container );
-    	        }
-    	        
-    	        break;
-	        }
+
+            GrammarTransition transition = ( ( AbstractGrammar ) container.getGrammar() )
+                .getTransition( currentState, tagByte & 0x00FF );
+
+            if ( transition == null )
+            {
+                throw new DecoderException(
+                    "Bad transition from state " +
+                    currentGrammar.getStatesEnum().getState( container.getCurrentGrammarType(),
+                        currentState ) + ", tag " + StringUtils.dumpByte( tag.getTagByte() ) );
+            }
+
+            if ( DEBUG )
+            {
+                log.debug( transition.toString( container.getCurrentGrammarType(), currentGrammar.getStatesEnum() ) );
+            }
+
+            int nextState = transition.getNextState();
+
+            if ( ( ( nextState & IStates.GRAMMAR_SWITCH_MASK ) != 0 ) && ( nextState != -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 );
+                currentState = IStates.INIT_GRAMMAR_STATE;
+            }
+            else
+            {
+
+                // This is not a grammar switch, so we execute the
+                // action if we have one, and we quit the loop.
+                container.setTransition( nextState );
+
+                if ( transition.hasAction() )
+                {
+                    transition.getAction().action( container );
+                }
+
+                break;
+            }
         }
+    }
+
+    /**
+     * Get the states of the current grammar
+     *
+     * @return Returns the statesEnum.
+     */
+    public IStates getStatesEnum()
+    {
+        return statesEnum;
+    }
+
+    /**
+     * Set the states for this grammar
+     *
+     * @param statesEnum The statesEnum to set.
+     */
+    public void setStatesEnum( IStates statesEnum )
+    {
+        this.statesEnum = statesEnum;
     }
 }

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/grammar/GrammarTransition.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/grammar/GrammarTransition.java?rev=164355&r1=164354&r2=164355&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/grammar/GrammarTransition.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/grammar/GrammarTransition.java Sat Apr 23 00:44:46 2005
@@ -63,16 +63,6 @@
     }
 
     /**
-     * DOCUMENT ME!
-     *
-     * @param nextState DOCUMENT ME!
-     */
-    //public void setNextState( int nextState )
-    //{
-    //    this.nextState = nextState;
-    //}
-
-    /**
      * Tells if the transition has an associated action.
      *
      * @return <code>true</code> if an action has been asociated to the transition
@@ -94,13 +84,13 @@
      * @param grammar The grammar which state we want a String from
      * @return A representation of the transition as a string.
      */
-    public String toString(int grammar)
+    public String toString(int grammar, IStates statesEnum)
     {
 
         StringBuffer sb = new StringBuffer();
 
-        sb.append( "Transition from <" ).append( StatesEnum.getState( grammar, currentState ) ).append( "> to <" )
-          .append( StatesEnum.getState( grammar, nextState ) ).append( ">, action : " )
+        sb.append( "Transition from <" ).append( statesEnum.getState( grammar, currentState ) ).append( "> to <" )
+          .append( statesEnum.getState( grammar, nextState ) ).append( ">, action : " )
           .append( ( ( action == null ) ? "no action" : action.toString() ) ).append( ">" );
 
         return sb.toString();

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/grammar/IAction.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/grammar/IAction.java?rev=164355&r1=164354&r2=164355&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/grammar/IAction.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/grammar/IAction.java Sat Apr 23 00:44:46 2005
@@ -16,8 +16,8 @@
  */
 package org.apache.asn1.ber.grammar;
 
+import org.apache.asn1.DecoderException;
 import org.apache.asn1.ber.containers.IAsn1Container;
-import org.apache.asn1.ldap.codec.DecoderException;
 
 
 /**

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/grammar/IGrammar.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/grammar/IGrammar.java?rev=164355&r1=164354&r2=164355&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/grammar/IGrammar.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/grammar/IGrammar.java Sat Apr 23 00:44:46 2005
@@ -16,8 +16,8 @@
  */
 package org.apache.asn1.ber.grammar;
 
+import org.apache.asn1.DecoderException;
 import org.apache.asn1.ber.containers.IAsn1Container;
-import org.apache.asn1.ldap.codec.DecoderException;
 
 
 /**
@@ -38,14 +38,23 @@
      * @throws DecoderException Thrown when an unrecoverable error occurs.
      */
     void executeAction( IAsn1Container asn1Container ) throws DecoderException;
-    
+
     /**
-     * Return the grammar's name
+     * Get the grammar name
+     *
+     * @return Return the grammar's name
      */
     String getName();
 
     /**
-     * Set the grammar's name
+     * Get the statesEnum for the current grammar 
+     * @return The specific States Enum for the current grammar
      */
-    void setName(String name);
+    IStates getStatesEnum();
+
+    /**
+     * Set the grammar's name
+     * @param name The grammar name
+    */
+    void setName( String name );
 }