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 2006/10/02 01:07:49 UTC

svn commit: r451836 [7/11] - in /directory/branches/shared/0.9.5/ldap/src: main/java/org/apache/directory/shared/ldap/codec/ main/java/org/apache/directory/shared/ldap/codec/abandon/ main/java/org/apache/directory/shared/ldap/codec/actions/ main/java/o...

Modified: directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/bind/SaslCredentials.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/bind/SaslCredentials.java?view=diff&rev=451836&r1=451835&r2=451836
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/bind/SaslCredentials.java (original)
+++ directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/bind/SaslCredentials.java Sun Oct  1 16:07:44 2006
@@ -23,11 +23,11 @@
 import java.nio.BufferOverflowException;
 import java.nio.ByteBuffer;
 
-import org.apache.directory.shared.asn1.ber.tlv.Length;
+import org.apache.directory.shared.asn1.ber.tlv.TLV;
 import org.apache.directory.shared.asn1.ber.tlv.Value;
 import org.apache.directory.shared.asn1.codec.EncoderException;
 import org.apache.directory.shared.ldap.codec.LdapConstants;
-import org.apache.directory.shared.ldap.codec.util.LdapString;
+import org.apache.directory.shared.ldap.util.StringTools;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -51,7 +51,10 @@
     /**
      * Any mechanism defined in RFC 2222 : KERBEROS_V4, GSSAPI, SKEY, EXTERNAL
      */
-    private LdapString mechanism;
+    private String mechanism;
+    
+    /** The mechanism bytes */
+    private transient byte[] mechanismBytes;
 
     /** optional credentials of the user */
     private byte[] credentials;
@@ -80,8 +83,7 @@
     /**
      * Set the credentials
      * 
-     * @param credentials
-     *            The credentials
+     * @param credentials The credentials
      */
     public void setCredentials( byte[] credentials )
     {
@@ -97,40 +99,50 @@
     public String getMechanism()
     {
 
-        return ( ( mechanism == null ) ? null : mechanism.getString() );
+        return ( ( mechanism == null ) ? null : mechanism );
     }
 
 
     /**
      * Set the mechanism
      * 
-     * @param mechanism
-     *            The mechanism
+     * @param mechanism The mechanism
      */
-    public void setMechanism( LdapString mechanism )
+    public void setMechanism( String mechanism )
     {
         this.mechanism = mechanism;
     }
 
 
     /**
-     * Compute the Sasl authentication length Sasl authentication : 0xA3 L1 0x04
-     * L2 mechanism [0x04 L3 credentials] L2 = Length(mechanism) L3 =
-     * Length(credentials) L1 = L2 + L3 Length(Sasl authentication) =
-     * Length(0xA3) + Length(L1) + Length(0x04) + Length(L2) + Length(mechanism) [+
-     * Length(0x04) + Length(L3) + Length(credentials)]
+     * Compute the Sasl authentication length 
+     * 
+     * Sasl authentication :
+     * 
+     * 0xA3 L1 
+     *   0x04 L2 mechanism
+     *   [0x04 L3 credentials]
+     * 
+     * L2 = Length(mechanism)
+     * L3 = Length(credentials)
+     * L1 = L2 + L3
+     * 
+     * Length(Sasl authentication) = Length(0xA3) + Length(L1) + 
+     *                               Length(0x04) + Length(L2) + Length(mechanism)
+     *                               [+ Length(0x04) + Length(L3) + Length(credentials)]
      */
     public int computeLength()
     {
-        mechanismLength = 1 + Length.getNbBytes( mechanism.getNbBytes() ) + mechanism.getNbBytes();
+        mechanismBytes = StringTools.getBytesUtf8( mechanism );
+        mechanismLength = 1 + TLV.getNbBytes( mechanismBytes.length ) + mechanismBytes.length;
         credentialsLength = 0;
 
         if ( credentials != null )
         {
-            credentialsLength = 1 + Length.getNbBytes( credentials.length ) + credentials.length;
+            credentialsLength = 1 + TLV.getNbBytes( credentials.length ) + credentials.length;
         }
 
-        int saslLength = 1 + Length.getNbBytes( mechanismLength + credentialsLength ) + mechanismLength
+        int saslLength = 1 + TLV.getNbBytes( mechanismLength + credentialsLength ) + mechanismLength
             + credentialsLength;
 
         if ( IS_DEBUG )
@@ -143,11 +155,14 @@
 
 
     /**
-     * Encode the sasl authentication to a PDU. SimpleAuthentication : 0xA3 L1
-     * 0x04 L2 mechanism [0x04 L3 credentials]
+     * Encode the sasl authentication to a PDU. 
+     * 
+     * SimpleAuthentication : 
+     * 0xA3 L1 
+     *   0x04 L2 mechanism
+     *   [0x04 L3 credentials]
      * 
-     * @param buffer
-     *            The buffer where to put the PDU
+     * @param buffer The buffer where to put the PDU
      * @return The PDU.
      */
     public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
@@ -163,9 +178,9 @@
             // The saslAuthentication Tag
             buffer.put( ( byte ) LdapConstants.BIND_REQUEST_SASL_TAG );
 
-            buffer.put( Length.getBytes( mechanismLength + credentialsLength ) );
+            buffer.put( TLV.getBytes( mechanismLength + credentialsLength ) );
 
-            Value.encode( buffer, mechanism.toString() );
+            Value.encode( buffer, mechanism );
 
             if ( credentials != null )
             {

Modified: directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/bind/SimpleAuthentication.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/bind/SimpleAuthentication.java?view=diff&rev=451836&r1=451835&r2=451836
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/bind/SimpleAuthentication.java (original)
+++ directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/bind/SimpleAuthentication.java Sun Oct  1 16:07:44 2006
@@ -23,7 +23,7 @@
 import java.nio.BufferOverflowException;
 import java.nio.ByteBuffer;
 
-import org.apache.directory.shared.asn1.ber.tlv.Length;
+import org.apache.directory.shared.asn1.ber.tlv.TLV;
 import org.apache.directory.shared.asn1.codec.EncoderException;
 import org.apache.directory.shared.ldap.codec.LdapConstants;
 import org.slf4j.Logger;
@@ -67,8 +67,7 @@
     /**
      * Set the simple password
      * 
-     * @param simple
-     *            The simple password
+     * @param simple The simple password
      */
     public void setSimple( byte[] simple )
     {
@@ -77,15 +76,18 @@
 
 
     /**
-     * Compute the Simple authentication length Simple authentication : 0x80 L1
-     * simple L1 = Length(simple) Length(Simple authentication) = Length(0x80) +
-     * Length(L1) + Length(simple)
+     * Compute the Simple authentication length 
+     * 
+     * Simple authentication : 0x80 L1 simple 
+     * 
+     * L1 = Length(simple) 
+     * Length(Simple authentication) = Length(0x80) + Length(L1) + Length(simple)
      */
     public int computeLength()
     {
         int length = 1;
 
-        length += Length.getNbBytes( simple.length ) + simple.length;
+        length += TLV.getNbBytes( simple.length ) + simple.length;
 
         if ( IS_DEBUG )
         {
@@ -97,11 +99,11 @@
 
 
     /**
-     * Encode the simple authentication to a PDU. SimpleAuthentication : 0x80 LL
-     * simple
+     * Encode the simple authentication to a PDU. 
+     * 
+     * SimpleAuthentication : 0x80 LL simple
      * 
-     * @param buffer
-     *            The buffer where to put the PDU
+     * @param buffer The buffer where to put the PDU
      * @return The PDU.
      */
     public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
@@ -116,7 +118,7 @@
         {
             // The simpleAuthentication Tag
             buffer.put( ( byte ) LdapConstants.BIND_REQUEST_SIMPLE_TAG );
-            buffer.put( Length.getBytes( simple.length ) );
+            buffer.put( TLV.getBytes( simple.length ) );
 
             if ( simple.length != 0 )
             {

Modified: directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/compare/CompareRequest.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/compare/CompareRequest.java?view=diff&rev=451836&r1=451835&r2=451836
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/compare/CompareRequest.java (original)
+++ directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/compare/CompareRequest.java Sun Oct  1 16:07:44 2006
@@ -23,22 +23,28 @@
 import java.nio.BufferOverflowException;
 import java.nio.ByteBuffer;
 
-import org.apache.directory.shared.asn1.ber.tlv.Length;
+import org.apache.directory.shared.asn1.ber.tlv.TLV;
 import org.apache.directory.shared.asn1.ber.tlv.UniversalTag;
 import org.apache.directory.shared.asn1.ber.tlv.Value;
 import org.apache.directory.shared.asn1.codec.EncoderException;
 import org.apache.directory.shared.ldap.codec.LdapConstants;
 import org.apache.directory.shared.ldap.codec.LdapMessage;
-import org.apache.directory.shared.ldap.codec.util.LdapString;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.util.StringTools;
 
 
 /**
- * A CompareRequest Message. Its syntax is : CompareRequest ::= [APPLICATION 14]
- * SEQUENCE { entry LDAPDN, ava AttributeValueAssertion }
- * AttributeValueAssertion ::= SEQUENCE { attributeDesc AttributeDescription,
- * assertionValue AssertionValue } AttributeDescription ::= LDAPString
+ * A CompareRequest Message. Its syntax is :
+ * CompareRequest ::= [APPLICATION 14] SEQUENCE {
+ *              entry           LDAPDN,
+ *              ava             AttributeValueAssertion }
+ * 
+ * AttributeValueAssertion ::= SEQUENCE {
+ *              attributeDesc   AttributeDescription,
+ *              assertionValue  AssertionValue }
+ * 
+ * AttributeDescription ::= LDAPString
+ * 
  * AssertionValue ::= OCTET STRING
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
@@ -52,7 +58,7 @@
     private LdapDN entry;
 
     /** The attribute to be compared */
-    private LdapString attributeDesc;
+    private String attributeDesc;
 
     /** The value to be compared */
     private Object assertionValue;
@@ -104,8 +110,7 @@
     /**
      * Set the entry to be compared
      * 
-     * @param entry
-     *            The entry to set.
+     * @param entry The entry to set.
      */
     public void setEntry( LdapDN entry )
     {
@@ -127,8 +132,7 @@
     /**
      * Set the assertion value
      * 
-     * @param assertionValue
-     *            The assertionValue to set.
+     * @param assertionValue The assertionValue to set.
      */
     public void setAssertionValue( Object assertionValue )
     {
@@ -143,64 +147,78 @@
      */
     public String getAttributeDesc()
     {
-        return ( ( attributeDesc == null ) ? "" : attributeDesc.getString() );
+        return ( ( attributeDesc == null ) ? "" : attributeDesc );
     }
 
 
     /**
      * Set the attribute description
      * 
-     * @param attributeDesc
-     *            The attributeDesc to set.
+     * @param attributeDesc The attributeDesc to set.
      */
-    public void setAttributeDesc( LdapString attributeDesc )
+    public void setAttributeDesc( String attributeDesc )
     {
         this.attributeDesc = attributeDesc;
     }
 
 
     /**
-     * Compute the CompareRequest length CompareRequest : 0x6E L1 | +--> 0x04 L2
-     * entry +--> 0x30 L3 (ava) | +--> 0x04 L4 attributeDesc +--> 0x04 L5
-     * assertionValue L3 = Length(0x04) + Length(L4) + L4 + Length(0x04) +
-     * Length(L5) + L5 Length(CompareRequest) = Length(0x6E) + Length(L1) + L1 +
-     * Length(0x04) + Length(L2) + L2 + Length(0x30) + Length(L3) + L3
+     * Compute the CompareRequest length 
      * 
-     * @return DOCUMENT ME!
+     * CompareRequest : 
+     * 0x6E L1 
+     *   | 
+     *   +--> 0x04 L2 entry 
+     *   +--> 0x30 L3 (ava) 
+     *         | 
+     *         +--> 0x04 L4 attributeDesc 
+     *         +--> 0x04 L5 assertionValue 
+     *         
+     * L3 = Length(0x04) + Length(L4) + L4 + Length(0x04) +
+     *      Length(L5) + L5 
+     * Length(CompareRequest) = Length(0x6E) + Length(L1) + L1 +
+     *      Length(0x04) + Length(L2) + L2 + Length(0x30) + Length(L3) + L3
+     * 
+     * @return The CompareRequest PDU's length
      */
     public int computeLength()
     {
 
         // The entry
-        compareRequestLength = 1 + Length.getNbBytes( LdapDN.getNbBytes( entry ) ) + LdapDN.getNbBytes( entry );
+        compareRequestLength = 1 + TLV.getNbBytes( LdapDN.getNbBytes( entry ) ) + LdapDN.getNbBytes( entry );
 
         // The attribute value assertion
-        avaLength = 1 + Length.getNbBytes( attributeDesc.getNbBytes() ) + attributeDesc.getNbBytes();
+        int attributeDescLength = StringTools.getBytesUtf8( attributeDesc ).length;
+        avaLength = 1 + TLV.getNbBytes( attributeDescLength ) + attributeDescLength;
 
         if ( assertionValue instanceof String )
         {
             int assertionValueLength = StringTools.getBytesUtf8( ( String ) assertionValue ).length;
-            avaLength += 1 + Length.getNbBytes( assertionValueLength ) + assertionValueLength;
+            avaLength += 1 + TLV.getNbBytes( assertionValueLength ) + assertionValueLength;
         }
         else
         {
-            avaLength += 1 + Length.getNbBytes( ( ( byte[] ) assertionValue ).length )
+            avaLength += 1 + TLV.getNbBytes( ( ( byte[] ) assertionValue ).length )
                 + ( ( byte[] ) assertionValue ).length;
         }
 
-        compareRequestLength += 1 + Length.getNbBytes( avaLength ) + avaLength;
+        compareRequestLength += 1 + TLV.getNbBytes( avaLength ) + avaLength;
 
-        return 1 + Length.getNbBytes( compareRequestLength ) + compareRequestLength;
+        return 1 + TLV.getNbBytes( compareRequestLength ) + compareRequestLength;
     }
 
 
     /**
-     * Encode the CompareRequest message to a PDU. CompareRequest : 0x6E LL 0x04
-     * LL entry 0x30 LL attributeValueAssertion 0x04 LL attributeDesc 0x04 LL
-     * assertionValue
+     * Encode the CompareRequest message to a PDU. 
+     * 
+     * CompareRequest : 
+     *   0x6E LL 
+     *     0x04 LL entry 
+     *     0x30 LL attributeValueAssertion 
+     *       0x04 LL attributeDesc 
+     *       0x04 LL assertionValue
      * 
-     * @param buffer
-     *            The buffer where to put the PDU
+     * @param buffer The buffer where to put the PDU
      * @return The PDU.
      */
     public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
@@ -214,14 +232,14 @@
         {
             // The CompareRequest Tag
             buffer.put( LdapConstants.COMPARE_REQUEST_TAG );
-            buffer.put( Length.getBytes( compareRequestLength ) );
+            buffer.put( TLV.getBytes( compareRequestLength ) );
 
             // The entry
             Value.encode( buffer, LdapDN.getBytes( entry ) );
 
             // The attributeValueAssertion sequence Tag
             buffer.put( UniversalTag.SEQUENCE_TAG );
-            buffer.put( Length.getBytes( avaLength ) );
+            buffer.put( TLV.getBytes( avaLength ) );
         }
         catch ( BufferOverflowException boe )
         {
@@ -229,7 +247,7 @@
         }
 
         // The attributeDesc
-        Value.encode( buffer, attributeDesc.getString() );
+        Value.encode( buffer, attributeDesc );
 
         // The assertionValue
         if ( assertionValue instanceof String )

Modified: directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/compare/CompareResponse.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/compare/CompareResponse.java?view=diff&rev=451836&r1=451835&r2=451836
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/compare/CompareResponse.java (original)
+++ directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/compare/CompareResponse.java Sun Oct  1 16:07:44 2006
@@ -23,15 +23,16 @@
 import java.nio.BufferOverflowException;
 import java.nio.ByteBuffer;
 
-import org.apache.directory.shared.asn1.ber.tlv.Length;
+import org.apache.directory.shared.asn1.ber.tlv.TLV;
 import org.apache.directory.shared.asn1.codec.EncoderException;
 import org.apache.directory.shared.ldap.codec.LdapConstants;
 import org.apache.directory.shared.ldap.codec.LdapResponse;
 
 
 /**
- * An CompareResponse Message. Its syntax is : CompareResponse ::= [APPLICATION
- * 15] LDAPResult
+ * An CompareResponse Message. Its syntax is : 
+ * 
+ * CompareResponse ::= [APPLICATION 15] LDAPResult
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
@@ -64,23 +65,30 @@
 
 
     /**
-     * Compute the CompareResponse length CompareResponse : 0x6F L1 | +-->
-     * LdapResult L1 = Length(LdapResult) Length(CompareResponse) = Length(0x6F) +
-     * Length(L1) + L1
+     * Compute the CompareResponse length 
+     * 
+     * CompareResponse :
+     * 
+     * 0x6F L1
+     *  |
+     *  +--> LdapResult
+     * 
+     * L1 = Length(LdapResult)
+     * 
+     * Length(CompareResponse) = Length(0x6F) + Length(L1) + L1
      */
     public int computeLength()
     {
         int ldapResponseLength = super.computeLength();
 
-        return 1 + Length.getNbBytes( ldapResponseLength ) + ldapResponseLength;
+        return 1 + TLV.getNbBytes( ldapResponseLength ) + ldapResponseLength;
     }
 
 
     /**
      * Encode the CompareResponse message to a PDU.
      * 
-     * @param buffer
-     *            The buffer where to put the PDU
+     * @param buffer The buffer where to put the PDU
      * @return The PDU.
      */
     public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
@@ -94,7 +102,7 @@
         {
             // The tag
             buffer.put( LdapConstants.COMPARE_RESPONSE_TAG );
-            buffer.put( Length.getBytes( getLdapResponseLength() ) );
+            buffer.put( TLV.getBytes( getLdapResponseLength() ) );
         }
         catch ( BufferOverflowException boe )
         {

Modified: directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/del/DelRequest.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/del/DelRequest.java?view=diff&rev=451836&r1=451835&r2=451836
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/del/DelRequest.java (original)
+++ directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/del/DelRequest.java Sun Oct  1 16:07:44 2006
@@ -23,7 +23,7 @@
 import java.nio.BufferOverflowException;
 import java.nio.ByteBuffer;
 
-import org.apache.directory.shared.asn1.ber.tlv.Length;
+import org.apache.directory.shared.asn1.ber.tlv.TLV;
 import org.apache.directory.shared.asn1.codec.EncoderException;
 import org.apache.directory.shared.ldap.codec.LdapConstants;
 import org.apache.directory.shared.ldap.codec.LdapMessage;
@@ -31,7 +31,11 @@
 
 
 /**
- * A DelRequest Message. Its syntax is : DelRequest ::= [APPLICATION 10] LDAPDN
+ * A DelRequest Message. 
+ * 
+ * Its syntax is : 
+ * 
+ * DelRequest ::= [APPLICATION 10] LDAPDN
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
@@ -84,8 +88,7 @@
     /**
      * Set the entry to be deleted
      * 
-     * @param entry
-     *            The entry to set.
+     * @param entry The entry to set.
      */
     public void setEntry( LdapDN entry )
     {
@@ -94,21 +97,28 @@
 
 
     /**
-     * Compute the DelRequest length DelRequest : 0x4A L1 entry L1 =
-     * Length(entry) Length(DelRequest) = Length(0x4A) + Length(L1) + L1
+     * Compute the DelRequest length 
+     * 
+     * DelRequest : 
+     * 0x4A L1 entry 
+     * 
+     * L1 = Length(entry) 
+     * Length(DelRequest) = Length(0x4A) + Length(L1) + L1
      */
     public int computeLength()
     {
         // The entry
-        return 1 + Length.getNbBytes( LdapDN.getNbBytes( entry ) ) + LdapDN.getNbBytes( entry );
+        return 1 + TLV.getNbBytes( LdapDN.getNbBytes( entry ) ) + LdapDN.getNbBytes( entry );
     }
 
 
     /**
-     * Encode the DelRequest message to a PDU. DelRequest : 0x4A LL entry
+     * Encode the DelRequest message to a PDU. 
+     * 
+     * DelRequest : 
+     * 0x4A LL entry
      * 
-     * @param buffer
-     *            The buffer where to put the PDU
+     * @param buffer The buffer where to put the PDU
      * @return The PDU.
      */
     public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
@@ -124,7 +134,7 @@
             buffer.put( LdapConstants.DEL_REQUEST_TAG );
 
             // The entry
-            buffer.put( Length.getBytes( LdapDN.getNbBytes( entry ) ) );
+            buffer.put( TLV.getBytes( LdapDN.getNbBytes( entry ) ) );
             buffer.put( LdapDN.getBytes( entry ) );
         }
         catch ( BufferOverflowException boe )

Modified: directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/del/DelResponse.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/del/DelResponse.java?view=diff&rev=451836&r1=451835&r2=451836
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/del/DelResponse.java (original)
+++ directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/del/DelResponse.java Sun Oct  1 16:07:44 2006
@@ -23,15 +23,16 @@
 import java.nio.BufferOverflowException;
 import java.nio.ByteBuffer;
 
-import org.apache.directory.shared.asn1.ber.tlv.Length;
+import org.apache.directory.shared.asn1.ber.tlv.TLV;
 import org.apache.directory.shared.asn1.codec.EncoderException;
 import org.apache.directory.shared.ldap.codec.LdapConstants;
 import org.apache.directory.shared.ldap.codec.LdapResponse;
 
 
 /**
- * An DelResponse Message. Its syntax is : DelResponse ::= [APPLICATION 11]
- * LDAPResult
+ * An DelResponse Message. Its syntax is : 
+ * 
+ * DelResponse ::= [APPLICATION 11] LDAPResult
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
@@ -61,22 +62,30 @@
 
 
     /**
-     * Compute the DelResponse length DelResponse : 0x6B L1 | +--> LdapResult L1 =
-     * Length(LdapResult) Length(DelResponse) = Length(0x6B) + Length(L1) + L1
+     * Compute the DelResponse length 
+     * 
+     * DelResponse :
+     * 
+     * 0x6B L1
+     *  |
+     *  +--> LdapResult
+     * 
+     * L1 = Length(LdapResult)
+     * 
+     * Length(DelResponse) = Length(0x6B) + Length(L1) + L1
      */
     public int computeLength()
     {
         int ldapResponseLength = super.computeLength();
 
-        return 1 + Length.getNbBytes( ldapResponseLength ) + ldapResponseLength;
+        return 1 + TLV.getNbBytes( ldapResponseLength ) + ldapResponseLength;
     }
 
 
     /**
      * Encode the DelResponse message to a PDU.
      * 
-     * @param buffer
-     *            The buffer where to put the PDU
+     * @param buffer The buffer where to put the PDU
      * @return The PDU.
      */
     public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
@@ -90,7 +99,7 @@
         {
             // The tag
             buffer.put( LdapConstants.DEL_RESPONSE_TAG );
-            buffer.put( Length.getBytes( getLdapResponseLength() ) );
+            buffer.put( TLV.getBytes( getLdapResponseLength() ) );
         }
         catch ( BufferOverflowException boe )
         {

Modified: directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/ExtendedRequest.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/ExtendedRequest.java?view=diff&rev=451836&r1=451835&r2=451836
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/ExtendedRequest.java (original)
+++ directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/ExtendedRequest.java Sun Oct  1 16:07:44 2006
@@ -23,7 +23,7 @@
 import java.nio.BufferOverflowException;
 import java.nio.ByteBuffer;
 
-import org.apache.directory.shared.asn1.ber.tlv.Length;
+import org.apache.directory.shared.asn1.ber.tlv.TLV;
 import org.apache.directory.shared.asn1.codec.EncoderException;
 import org.apache.directory.shared.asn1.primitives.OID;
 import org.apache.directory.shared.ldap.codec.LdapConstants;
@@ -32,9 +32,10 @@
 
 
 /**
- * A ExtendedRequest Message. Its syntax is : ExtendedRequest ::= [APPLICATION
- * 23] SEQUENCE { requestName [0] LDAPOID, requestValue [1] OCTET STRING
- * OPTIONAL }
+ * A ExtendedRequest Message. Its syntax is :
+ *   ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
+ *              requestName      [0] LDAPOID,
+ *              requestValue     [1] OCTET STRING OPTIONAL }
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
@@ -96,8 +97,7 @@
     /**
      * Set the extended request name
      * 
-     * @param requestName
-     *            The request name to set.
+     * @param requestName The request name to set.
      */
     public void setRequestName( OID requestName )
     {
@@ -119,8 +119,7 @@
     /**
      * Set the extended request value
      * 
-     * @param requestValue
-     *            The request value to set.
+     * @param requestValue The request value to set.
      */
     public void setRequestValue( byte[] requestValue )
     {
@@ -129,32 +128,44 @@
 
 
     /**
-     * Compute the ExtendedRequest length ExtendedRequest : 0x77 L1 | +--> 0x80
-     * L2 name [+--> 0x81 L3 value] L1 = Length(0x80) + Length(L2) + L2 [+
-     * Length(0x81) + Length(L3) + L3] Length(ExtendedRequest) = Length(0x77) +
-     * Length(L1) + L1
+     * Compute the ExtendedRequest length
+     * 
+     * ExtendedRequest :
+     * 
+     * 0x77 L1
+     *  |
+     *  +--> 0x80 L2 name
+     *  [+--> 0x81 L3 value]
+     * 
+     * L1 = Length(0x80) + Length(L2) + L2
+     *      [+ Length(0x81) + Length(L3) + L3]
+     * 
+     * Length(ExtendedRequest) = Length(0x77) + Length(L1) + L1
      */
     public int computeLength()
     {
         oidLength = requestName.toString().length();
-        extendedRequestLength = 1 + Length.getNbBytes( oidLength ) + oidLength;
+        extendedRequestLength = 1 + TLV.getNbBytes( oidLength ) + oidLength;
 
         if ( requestValue != null )
         {
-            extendedRequestLength += 1 + Length.getNbBytes( ( ( byte[] ) requestValue ).length )
+            extendedRequestLength += 1 + TLV.getNbBytes( ( ( byte[] ) requestValue ).length )
                 + ( ( byte[] ) requestValue ).length;
         }
 
-        return 1 + Length.getNbBytes( extendedRequestLength ) + extendedRequestLength;
+        return 1 + TLV.getNbBytes( extendedRequestLength ) + extendedRequestLength;
     }
 
 
     /**
-     * Encode the ExtendedRequest message to a PDU. ExtendedRequest : 0x80 LL
-     * resquest name [0x81 LL request value]
+     * Encode the ExtendedRequest message to a PDU. 
+     * 
+     * ExtendedRequest :
+     * 
+     * 0x80 LL resquest name
+     * [0x81 LL request value]
      * 
-     * @param buffer
-     *            The buffer where to put the PDU
+     * @param buffer The buffer where to put the PDU
      * @return The PDU.
      */
     public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
@@ -168,7 +179,7 @@
         {
             // The BindResponse Tag
             buffer.put( LdapConstants.EXTENDED_REQUEST_TAG );
-            buffer.put( Length.getBytes( extendedRequestLength ) );
+            buffer.put( TLV.getBytes( extendedRequestLength ) );
 
             // The requestName, if any
             if ( requestName == null )
@@ -177,7 +188,7 @@
             }
 
             buffer.put( ( byte ) LdapConstants.EXTENDED_REQUEST_NAME_TAG );
-            buffer.put( Length.getBytes( oidLength ) );
+            buffer.put( TLV.getBytes( oidLength ) );
 
             if ( requestName.getOIDLength() != 0 )
             {
@@ -189,7 +200,7 @@
             {
                 buffer.put( ( byte ) LdapConstants.EXTENDED_REQUEST_VALUE_TAG );
 
-                buffer.put( Length.getBytes( requestValue.length ) );
+                buffer.put( TLV.getBytes( requestValue.length ) );
 
                 if ( requestValue.length != 0 )
                 {

Modified: directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/ExtendedResponse.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/ExtendedResponse.java?view=diff&rev=451836&r1=451835&r2=451836
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/ExtendedResponse.java (original)
+++ directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/ExtendedResponse.java Sun Oct  1 16:07:44 2006
@@ -23,7 +23,7 @@
 import java.nio.BufferOverflowException;
 import java.nio.ByteBuffer;
 
-import org.apache.directory.shared.asn1.ber.tlv.Length;
+import org.apache.directory.shared.asn1.ber.tlv.TLV;
 import org.apache.directory.shared.asn1.codec.EncoderException;
 import org.apache.directory.shared.asn1.primitives.OID;
 import org.apache.directory.shared.ldap.codec.LdapConstants;
@@ -32,9 +32,11 @@
 
 
 /**
- * A ExtendedResponse Message. Its syntax is : ExtendedResponse ::= [APPLICATION
- * 24] SEQUENCE { COMPONENTS OF LDAPResult, responseName [10] LDAPOID OPTIONAL,
- * response [11] OCTET STRING OPTIONAL }
+ * A ExtendedResponse Message. Its syntax is :
+ *   ExtendedResponse ::= [APPLICATION 24] SEQUENCE {
+ *              COMPONENTS OF LDAPResult,
+ *              responseName     [10] LDAPOID OPTIONAL,
+ *              response         [11] OCTET STRING OPTIONAL }
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
@@ -96,8 +98,7 @@
     /**
      * Set the extended response name
      * 
-     * @param responseName
-     *            The name to set.
+     * @param responseName The name to set.
      */
     public void setResponseName( OID responseName )
     {
@@ -119,8 +120,7 @@
     /**
      * Set the extended response
      * 
-     * @param response
-     *            The response to set.
+     * @param response The response to set.
      */
     public void setResponse( Object response )
     {
@@ -129,11 +129,21 @@
 
 
     /**
-     * Compute the ExtendedResponse length ExtendedResponse : 0x78 L1 | +-->
-     * LdapResult [+--> 0x8A L2 name [+--> 0x8B L3 response]] L1 =
-     * Length(LdapResult) [ + Length(0x8A) + Length(L2) + L2 [ + Length(0x8B) +
-     * Length(L3) + L3]] Length(ExtendedResponse) = Length(0x78) + Length(L1) +
-     * L1
+     * Compute the ExtendedResponse length
+     * 
+     * ExtendedResponse :
+     * 
+     * 0x78 L1
+     *  |
+     *  +--> LdapResult
+     * [+--> 0x8A L2 name
+     * [+--> 0x8B L3 response]]
+     * 
+     * L1 = Length(LdapResult)
+     *      [ + Length(0x8A) + Length(L2) + L2
+     *       [ + Length(0x8B) + Length(L3) + L3]]
+     * 
+     * Length(ExtendedResponse) = Length(0x78) + Length(L1) + L1
      * 
      * @return The ExtendedResponse length
      */
@@ -144,30 +154,33 @@
         if ( responseName != null )
         {
             responseNameLength = responseName.toString().length();
-            extendedResponseLength += 1 + Length.getNbBytes( responseNameLength ) + responseNameLength;
+            extendedResponseLength += 1 + TLV.getNbBytes( responseNameLength ) + responseNameLength;
 
             if ( response != null )
             {
                 if ( response instanceof String )
                 {
                     int responseLength = StringTools.getBytesUtf8( ( String ) response ).length;
-                    extendedResponseLength += 1 + Length.getNbBytes( responseLength ) + responseLength;
+                    extendedResponseLength += 1 + TLV.getNbBytes( responseLength ) + responseLength;
                 }
                 else
                 {
-                    extendedResponseLength += 1 + Length.getNbBytes( ( ( byte[] ) response ).length )
+                    extendedResponseLength += 1 + TLV.getNbBytes( ( ( byte[] ) response ).length )
                         + ( ( byte[] ) response ).length;
                 }
             }
         }
 
-        return 1 + Length.getNbBytes( extendedResponseLength ) + extendedResponseLength;
+        return 1 + TLV.getNbBytes( extendedResponseLength ) + extendedResponseLength;
     }
 
 
     /**
-     * Encode the ExtendedResponse message to a PDU. ExtendedResponse :
-     * LdapResult.encode() [0x8A LL response name] [0x8B LL response]
+     * Encode the ExtendedResponse message to a PDU. 
+     * ExtendedResponse :
+     * LdapResult.encode()
+     * [0x8A LL response name]
+     * [0x8B LL response]
      * 
      * @param buffer
      *            The buffer where to put the PDU
@@ -184,7 +197,7 @@
         {
             // The BindResponse Tag
             buffer.put( LdapConstants.EXTENDED_RESPONSE_TAG );
-            buffer.put( Length.getBytes( extendedResponseLength ) );
+            buffer.put( TLV.getBytes( extendedResponseLength ) );
 
             // The LdapResult
             super.encode( buffer );
@@ -193,7 +206,7 @@
             if ( responseName != null )
             {
                 buffer.put( ( byte ) LdapConstants.EXTENDED_RESPONSE_RESPONSE_NAME_TAG );
-                buffer.put( Length.getBytes( responseNameLength ) );
+                buffer.put( TLV.getBytes( responseNameLength ) );
 
                 if ( responseName.getOIDLength() != 0 )
                 {
@@ -209,7 +222,7 @@
                 if ( response instanceof String )
                 {
                     byte[] responseBytes = StringTools.getBytesUtf8( ( String ) response );
-                    buffer.put( Length.getBytes( responseBytes.length ) );
+                    buffer.put( TLV.getBytes( responseBytes.length ) );
 
                     if ( responseBytes.length != 0 )
                     {
@@ -218,7 +231,7 @@
                 }
                 else
                 {
-                    buffer.put( Length.getBytes( ( ( byte[] ) response ).length ) );
+                    buffer.put( TLV.getBytes( ( ( byte[] ) response ).length ) );
 
                     if ( ( ( byte[] ) response ).length != 0 )
                     {

Modified: directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/GracefulAction.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/GracefulAction.java?view=diff&rev=451836&r1=451835&r2=451836
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/GracefulAction.java (original)
+++ directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/GracefulAction.java Sun Oct  1 16:07:44 2006
@@ -58,10 +58,8 @@
     /**
      * Create a GracefulAction object, with a timeOffline and a delay
      * 
-     * @param timeOffline
-     *            The time the server will be offline
-     * @param delay
-     *            The delay before the disconnection
+     * @param timeOffline The time the server will be offline
+     * @param delay The delay before the disconnection
      */
     public GracefulAction(int timeOffline, int delay)
     {

Modified: directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/GracefulDisconnect.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/GracefulDisconnect.java?view=diff&rev=451836&r1=451835&r2=451836
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/GracefulDisconnect.java (original)
+++ directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/GracefulDisconnect.java Sun Oct  1 16:07:44 2006
@@ -25,7 +25,7 @@
 import java.util.Iterator;
 import java.util.List;
 
-import org.apache.directory.shared.asn1.ber.tlv.Length;
+import org.apache.directory.shared.asn1.ber.tlv.TLV;
 import org.apache.directory.shared.asn1.ber.tlv.UniversalTag;
 import org.apache.directory.shared.asn1.ber.tlv.Value;
 import org.apache.directory.shared.asn1.codec.EncoderException;
@@ -62,10 +62,8 @@
     /**
      * Create a GracefulDisconnect object, with a timeOffline and a delay
      * 
-     * @param timeOffline
-     *            The time the server will be offline
-     * @param delay
-     *            The delay before the disconnection
+     * @param timeOffline The time the server will be offline
+     * @param delay The delay before the disconnection
      */
     public GracefulDisconnect(int timeOffline, int delay)
     {
@@ -102,8 +100,7 @@
     /**
      * Add a new URL of a replicated server
      * 
-     * @param replicatedContext
-     *            The replictaed server to add.
+     * @param replicatedContext The replictaed server to add.
      */
     public void addReplicatedContexts( LdapURL replicatedContext )
     {
@@ -112,9 +109,15 @@
 
 
     /**
-     * Compute the GracefulDisconnect length 0x30 L1 | +--> [ 0x02 0x0(1-4)
-     * [0..720] ] +--> [ 0x80 0x0(1-3) [0..86400] ] +--> [ 0x30 L2 | +--> (0x04
-     * L3 value) +
+     * Compute the GracefulDisconnect length 
+     * 
+     * 0x30 L1 
+     *   | 
+     *   +--> [ 0x02 0x0(1-4) [0..720] ] 
+     *   +--> [ 0x80 0x0(1-3) [0..86400] ] 
+     *   +--> [ 0x30 L2 
+     *           | 
+     *           +--> (0x04 L3 value) + ]
      */
     public int computeLength()
     {
@@ -140,25 +143,23 @@
             while ( replicatedContextIterator.hasNext() )
             {
                 int ldapUrlLength = ( ( LdapURL ) replicatedContextIterator.next() ).getNbBytes();
-                replicatedContextsLength += 1 + Length.getNbBytes( ldapUrlLength ) + ldapUrlLength;
+                replicatedContextsLength += 1 + TLV.getNbBytes( ldapUrlLength ) + ldapUrlLength;
             }
 
-            gracefulDisconnectSequenceLength += 1 + Length.getNbBytes( replicatedContextsLength )
+            gracefulDisconnectSequenceLength += 1 + TLV.getNbBytes( replicatedContextsLength )
                 + replicatedContextsLength;
         }
 
-        return 1 + Length.getNbBytes( gracefulDisconnectSequenceLength ) + gracefulDisconnectSequenceLength;
+        return 1 + TLV.getNbBytes( gracefulDisconnectSequenceLength ) + gracefulDisconnectSequenceLength;
     }
 
 
     /**
      * Encodes the gracefulDisconnect extended operation.
      * 
-     * @param buffer
-     *            The encoded sink
+     * @param buffer The encoded sink
      * @return A ByteBuffer that contains the encoded PDU
-     * @throws EncoderException
-     *             If anything goes wrong.
+     * @throws EncoderException If anything goes wrong.
      */
     public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
     {
@@ -166,7 +167,7 @@
         ByteBuffer bb = ByteBuffer.allocate( computeLength() );
 
         bb.put( UniversalTag.SEQUENCE_TAG );
-        bb.put( Length.getBytes( gracefulDisconnectSequenceLength ) );
+        bb.put( TLV.getBytes( gracefulDisconnectSequenceLength ) );
 
         if ( timeOffline != 0 )
         {
@@ -176,14 +177,14 @@
         if ( delay != 0 )
         {
             bb.put( ( byte ) GracefulActionConstants.GRACEFUL_ACTION_DELAY_TAG );
-            bb.put( ( byte ) Length.getNbBytes( delay ) );
+            bb.put( ( byte ) TLV.getNbBytes( delay ) );
             bb.put( Value.getBytes( delay ) );
         }
 
         if ( replicatedContexts.size() != 0 )
         {
             bb.put( UniversalTag.SEQUENCE_TAG );
-            bb.put( Length.getBytes( replicatedContextsLength ) );
+            bb.put( TLV.getBytes( replicatedContextsLength ) );
 
             Iterator replicatedContextIterator = replicatedContexts.iterator();
 

Modified: directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/GracefulDisconnectContainer.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/GracefulDisconnectContainer.java?view=diff&rev=451836&r1=451835&r2=451836
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/GracefulDisconnectContainer.java (original)
+++ directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/GracefulDisconnectContainer.java Sun Oct  1 16:07:44 2006
@@ -22,7 +22,6 @@
 
 import org.apache.directory.shared.asn1.ber.AbstractContainer;
 import org.apache.directory.shared.asn1.ber.IAsn1Container;
-import org.apache.directory.shared.asn1.ber.grammar.IGrammar;
 
 
 /**
@@ -43,14 +42,8 @@
     public GracefulDisconnectContainer()
     {
         super();
-        currentGrammar = 0;
-        grammars = new IGrammar[GracefulDisconnectStatesEnum.NB_GRAMMARS];
-        grammarStack = new IGrammar[1];
         stateStack = new int[1];
-        nbGrammars = 0;
-
-        grammars[GracefulDisconnectStatesEnum.GRACEFUL_DISCONNECT_GRAMMAR] = GracefulDisconnectGrammar.getInstance();
-        grammarStack[currentGrammar] = grammars[GracefulDisconnectStatesEnum.GRACEFUL_DISCONNECT_GRAMMAR];
+        grammar = GracefulDisconnectGrammar.getInstance();
         states = GracefulDisconnectStatesEnum.getInstance();
     }
 
@@ -68,8 +61,7 @@
      * Set a GracefulDisconnect Object into the container. It will be completed
      * by the ldapDecoder.
      * 
-     * @param control
-     *            the GracefulShutdown to set.
+     * @param control the GracefulShutdown to set.
      */
     public void setGracefulDisconnect( GracefulDisconnect gracefulDisconnect )
     {

Modified: directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/GracefulDisconnectDecoder.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/GracefulDisconnectDecoder.java?view=diff&rev=451836&r1=451835&r2=451836
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/GracefulDisconnectDecoder.java (original)
+++ directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/GracefulDisconnectDecoder.java Sun Oct  1 16:07:44 2006
@@ -44,11 +44,9 @@
      * Decode a PDU which must contain a GracefulDisconnect extended operation.
      * Note that the stream of bytes much contain a full PDU, not a partial one.
      * 
-     * @param stream
-     *            The bytes to be decoded
+     * @param stream The bytes to be decoded
      * @return An GracefulDisconnect object
-     * @throws DecoderException
-     *             If the decoding failed
+     * @throws DecoderException If the decoding failed
      */
     public Asn1Object decode( byte[] stream ) throws DecoderException, NamingException
     {

Modified: directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/GracefulDisconnectGrammar.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/GracefulDisconnectGrammar.java?view=diff&rev=451836&r1=451835&r2=451836
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/GracefulDisconnectGrammar.java (original)
+++ directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/GracefulDisconnectGrammar.java Sun Oct  1 16:07:44 2006
@@ -44,10 +44,10 @@
  * 
  * <pre>
  *  GracefulDisconnect ::= SEQUENCE {
- *                         timeOffline INTEGER (0..720) DEFAULT 0,
- *                         delay [0] INTEGER (0..86400) DEFAULT 0,
- *                         replicatedContexts Referral OPTIONAL
- *              }
+ *      timeOffline INTEGER (0..720) DEFAULT 0,
+ *      delay [0] INTEGER (0..86400) DEFAULT 0,
+ *      replicatedContexts Referral OPTIONAL
+ * }
  *  
  *  Referral ::= SEQUENCE OF LDAPURL
  *  
@@ -71,6 +71,100 @@
 
 
     /**
+     * The action used to store a Time Offline.
+     */
+    GrammarAction storeDelay = new GrammarAction( "Set Graceful Disconnect Delay" )
+    {
+        public void action( IAsn1Container container ) throws DecoderException
+        {
+            GracefulDisconnectContainer gracefulDisconnectContainer = ( GracefulDisconnectContainer ) container;
+            Value value = gracefulDisconnectContainer.getCurrentTLV().getValue();
+    
+            try
+            {
+                int delay = IntegerDecoder.parse( value, 0, 86400 );
+    
+                if ( IS_DEBUG )
+                {
+                    log.debug( "Delay = " + delay );
+                }
+    
+                gracefulDisconnectContainer.getGracefulDisconnect().setDelay( delay );
+                gracefulDisconnectContainer.grammarEndAllowed( true );
+            }
+            catch ( IntegerDecoderException e )
+            {
+                String msg = "failed to decode the delay, the value should be between 0 and 86400 seconds, it is '"
+                    + StringTools.dumpBytes( value.getData() ) + "'";
+                log.error( msg );
+                throw new DecoderException( msg );
+            }
+        }
+    };
+    
+    /**
+     * The action used to store a referral.
+     */
+    GrammarAction storeReferral = new GrammarAction( "Stores a referral" )
+    {
+        public void action( IAsn1Container container ) throws DecoderException
+        {
+            GracefulDisconnectContainer gracefulDisconnectContainer = ( GracefulDisconnectContainer ) container;
+            Value value = gracefulDisconnectContainer.getCurrentTLV().getValue();
+
+            try
+            {
+                LdapURL url = new LdapURL( value.getData() );
+                gracefulDisconnectContainer.getGracefulDisconnect().addReplicatedContexts( url );
+                gracefulDisconnectContainer.grammarEndAllowed( true );
+                
+                if ( IS_DEBUG )
+                {
+                    log.debug( "Stores a referral : {}", url );
+                }
+            }
+            catch ( LdapURLEncodingException e )
+            {
+                String msg = "failed to decode the URL '" + StringTools.dumpBytes( value.getData() ) + "'";
+                log.error( msg );
+                throw new DecoderException( msg );
+            }
+        }
+    };
+    
+    /**
+     * The action used to store a Time Offline.
+     */
+    GrammarAction storeTimeOffline = new GrammarAction( "Set Graceful Disconnect time offline" )
+    {
+        public void action( IAsn1Container container ) throws DecoderException
+        {
+            GracefulDisconnectContainer gracefulDisconnectContainer = ( GracefulDisconnectContainer ) container;
+            Value value = gracefulDisconnectContainer.getCurrentTLV().getValue();
+
+            try
+            {
+                int timeOffline = IntegerDecoder.parse( value, 0, 720 );
+
+                if ( IS_DEBUG )
+                {
+                    log.debug( "Time Offline = " + timeOffline );
+                }
+
+                gracefulDisconnectContainer.getGracefulDisconnect().setTimeOffline( timeOffline );
+                gracefulDisconnectContainer.grammarEndAllowed( true );
+            }
+            catch ( IntegerDecoderException e )
+            {
+                String msg = "failed to decode the timeOffline, the value should be between 0 and 720 minutes, it is '"
+                    + StringTools.dumpBytes( value.getData() ) + "'";
+                log.error( msg );
+                throw new DecoderException( msg );
+            }
+        }
+    };
+
+    /**
      * Creates a new GracefulDisconnectGrammar object.
      */
     private GracefulDisconnectGrammar()
@@ -82,19 +176,17 @@
         super.transitions = new GrammarTransition[GracefulDisconnectStatesEnum.LAST_GRACEFUL_DISCONNECT_STATE][256];
 
         /**
-         * GracefulDisconnect ::= SEQUENCE { (Tag) ... Nothing to do...
-         */
-        super.transitions[GracefulDisconnectStatesEnum.GRACEFUL_DISCONNECT_SEQUENCE_TAG][UniversalTag.SEQUENCE_TAG] = new GrammarTransition(
-            GracefulDisconnectStatesEnum.GRACEFUL_DISCONNECT_SEQUENCE_TAG,
-            GracefulDisconnectStatesEnum.GRACEFUL_DISCONNECT_SEQUENCE_VALUE, null );
-
-        /**
-         * GracefulDisconnect ::= SEQUENCE { (Value) ... Creates the
-         * GracefulDisconnect object
-         */
-        super.transitions[GracefulDisconnectStatesEnum.GRACEFUL_DISCONNECT_SEQUENCE_VALUE][UniversalTag.SEQUENCE_TAG] = new GrammarTransition(
-            GracefulDisconnectStatesEnum.GRACEFUL_DISCONNECT_SEQUENCE_VALUE,
-            GracefulDisconnectStatesEnum.TIME_OFFLINE_OR_DELAY_OR_REPLICATED_OR_END_TAG, new GrammarAction(
+         * Transition from init state to graceful disconnect
+         * GracefulDisconnect ::= SEQUENCE { 
+         *     ... 
+         * 
+         * Creates the GracefulDisconnect object
+         */
+        super.transitions[GracefulDisconnectStatesEnum.INIT_GRAMMAR_STATE][UniversalTag.SEQUENCE_TAG] = 
+            new GrammarTransition( GracefulDisconnectStatesEnum.INIT_GRAMMAR_STATE,
+                                    GracefulDisconnectStatesEnum.GRACEFUL_DISCONNECT_SEQUENCE_STATE, 
+                                    UniversalTag.SEQUENCE_TAG,
+                new GrammarAction(
                 "Init Graceful Disconnect" )
             {
                 public void action( IAsn1Container container )
@@ -107,167 +199,134 @@
             } );
 
         /**
-         * GracefulDisconnect ::= SEQUENCE { timeOffline INTEGER (0..720)
-         * DEFAULT 0, (Tag) ... Nothing to do
-         */
-        super.transitions[GracefulDisconnectStatesEnum.TIME_OFFLINE_OR_DELAY_OR_REPLICATED_OR_END_TAG][UniversalTag.INTEGER_TAG] = new GrammarTransition(
-            GracefulDisconnectStatesEnum.TIME_OFFLINE_OR_DELAY_OR_REPLICATED_OR_END_TAG,
-            GracefulDisconnectStatesEnum.TIME_OFFLINE_VALUE, null );
-
-        /**
-         * GracefulDisconnect ::= SEQUENCE { ... delay [0] INTEGER (0..86400)
-         * DEFAULT 0, (Tag) ... We have no TimeOffline. Nothing to do.
-         */
-        super.transitions[GracefulDisconnectStatesEnum.TIME_OFFLINE_OR_DELAY_OR_REPLICATED_OR_END_TAG][GracefulActionConstants.GRACEFUL_ACTION_DELAY_TAG] = new GrammarTransition(
-            GracefulDisconnectStatesEnum.TIME_OFFLINE_OR_DELAY_OR_REPLICATED_OR_END_TAG,
-            GracefulDisconnectStatesEnum.DELAY_VALUE, null );
+         * Transition from graceful disconnect to time offline
+         * 
+         * GracefulDisconnect ::= SEQUENCE { 
+         *     timeOffline INTEGER (0..720) DEFAULT 0, 
+         *     ... 
+         *     
+         * Set the time offline value into the GracefulDisconnect object.    
+         */
+        super.transitions[GracefulDisconnectStatesEnum.GRACEFUL_DISCONNECT_SEQUENCE_STATE][UniversalTag.INTEGER_TAG] = 
+            new GrammarTransition( GracefulDisconnectStatesEnum.GRACEFUL_DISCONNECT_SEQUENCE_STATE,
+                                    GracefulDisconnectStatesEnum.TIME_OFFLINE_STATE, 
+                                    UniversalTag.INTEGER_TAG, 
+                storeTimeOffline );
+        
+        /**
+         * Transition from graceful disconnect to delay
+         * 
+         * GracefulDisconnect ::= SEQUENCE { 
+         *     ... 
+         *     delay [0] INTEGER (0..86400) DEFAULT 0,
+         *     ... 
+         *     
+         * Set the delay value into the GracefulDisconnect object.    
+         */
+        super.transitions[GracefulDisconnectStatesEnum.GRACEFUL_DISCONNECT_SEQUENCE_STATE][GracefulActionConstants.GRACEFUL_ACTION_DELAY_TAG] = 
+            new GrammarTransition( GracefulDisconnectStatesEnum.GRACEFUL_DISCONNECT_SEQUENCE_STATE,
+                                    GracefulDisconnectStatesEnum.DELAY_STATE, 
+                                    GracefulActionConstants.GRACEFUL_ACTION_DELAY_TAG, 
+                storeDelay );
+        
+        /**
+         * Transition from graceful disconnect to replicated Contexts
+         * 
+         * GracefulDisconnect ::= SEQUENCE { 
+         *     ... 
+         *     replicatedContexts Referral OPTIONAL } 
+         *     
+         * Referral ::= SEQUENCE OF LDAPURL
+         *     
+         * Get some replicated contexts. Nothing to do    
+         */
+        super.transitions[GracefulDisconnectStatesEnum.GRACEFUL_DISCONNECT_SEQUENCE_STATE][UniversalTag.SEQUENCE_TAG] = 
+            new GrammarTransition( GracefulDisconnectStatesEnum.GRACEFUL_DISCONNECT_SEQUENCE_STATE,
+                                    GracefulDisconnectStatesEnum.REPLICATED_CONTEXTS_STATE,
+                                    UniversalTag.SEQUENCE_TAG, null );
+        
+        /**
+         * Transition from time offline to delay
+         * 
+         * GracefulDisconnect ::= SEQUENCE { 
+         *     ... 
+         *     delay [0] INTEGER (0..86400) DEFAULT 0,
+         *     ... 
+         *     
+         * Set the delay value into the GracefulDisconnect object.    
+         */
+        super.transitions[GracefulDisconnectStatesEnum.TIME_OFFLINE_STATE][GracefulActionConstants.GRACEFUL_ACTION_DELAY_TAG] = 
+            new GrammarTransition( GracefulDisconnectStatesEnum.TIME_OFFLINE_STATE,
+                                    GracefulDisconnectStatesEnum.DELAY_STATE, 
+                                    GracefulActionConstants.GRACEFUL_ACTION_DELAY_TAG,
+                storeDelay );
+
+        /**
+         * Transition from time offline to replicated Contexts
+         * 
+         * GracefulDisconnect ::= SEQUENCE { 
+         *     ... 
+         *     replicatedContexts Referral OPTIONAL } 
+         *     
+         * Referral ::= SEQUENCE OF LDAPURL
+         *     
+         * Get some replicated contexts. Nothing to do    
+         */
+        super.transitions[GracefulDisconnectStatesEnum.TIME_OFFLINE_STATE][UniversalTag.SEQUENCE_TAG] = 
+            new GrammarTransition( GracefulDisconnectStatesEnum.TIME_OFFLINE_STATE,
+                                    GracefulDisconnectStatesEnum.REPLICATED_CONTEXTS_STATE,
+                                    UniversalTag.SEQUENCE_TAG, null );
+        
+        /**
+         * Transition from delay to replicated contexts
+         * 
+         * GracefulDisconnect ::= SEQUENCE { 
+         *     ... 
+         *     replicatedContexts Referral OPTIONAL } 
+         *     
+         * Referral ::= SEQUENCE OF LDAPURL
+         *     
+         * Get some replicated contexts. Nothing to do    
+         */
+        super.transitions[GracefulDisconnectStatesEnum.DELAY_STATE][UniversalTag.SEQUENCE_TAG] = 
+            new GrammarTransition( GracefulDisconnectStatesEnum.DELAY_STATE,
+                                    GracefulDisconnectStatesEnum.REPLICATED_CONTEXTS_STATE, 
+                                    UniversalTag.SEQUENCE_TAG, null );
+        
+        /**
+         * Transition from replicated contexts to referral
+         * 
+         * GracefulDisconnect ::= SEQUENCE { 
+         *     ... 
+         *     replicatedContexts Referral OPTIONAL } 
+         *     
+         * Referral ::= SEQUENCE OF LDAPURL
+         *     
+         * Stores the referral
+         */
+        super.transitions[GracefulDisconnectStatesEnum.REPLICATED_CONTEXTS_STATE][UniversalTag.OCTET_STRING_TAG] = 
+            new GrammarTransition( GracefulDisconnectStatesEnum.REPLICATED_CONTEXTS_STATE,
+                                    GracefulDisconnectStatesEnum.REFERRAL_STATE, 
+                                    UniversalTag.OCTET_STRING_TAG,
+                storeReferral );
+
+        /**
+         * Transition from referral to referral
+         * 
+         * GracefulDisconnect ::= SEQUENCE { 
+         *     ... 
+         *     replicatedContexts Referral OPTIONAL } 
+         *     
+         * Referral ::= SEQUENCE OF LDAPURL
+         *     
+         * Stores the referral
+         */
+        super.transitions[GracefulDisconnectStatesEnum.REFERRAL_STATE][UniversalTag.OCTET_STRING_TAG] = 
+            new GrammarTransition( GracefulDisconnectStatesEnum.REFERRAL_STATE,
+                                    GracefulDisconnectStatesEnum.REFERRAL_STATE, 
+                                    UniversalTag.OCTET_STRING_TAG,
+                storeReferral );
 
-        /**
-         * GracefulDisconnect ::= SEQUENCE { ... replicatedContexts Referral
-         * OPTIONAL } Referral ::= SEQUENCE OF LDAPURL (Tag) We have no
-         * TimeOffline nor delay, just a replicatedContexts. Nothing to do.
-         */
-        super.transitions[GracefulDisconnectStatesEnum.TIME_OFFLINE_OR_DELAY_OR_REPLICATED_OR_END_TAG][UniversalTag.SEQUENCE_TAG] = new GrammarTransition(
-            GracefulDisconnectStatesEnum.TIME_OFFLINE_OR_DELAY_OR_REPLICATED_OR_END_TAG,
-            GracefulDisconnectStatesEnum.REPLICATED_CONTEXTS_VALUE, null );
-
-        /**
-         * GracefulDisconnect ::= SEQUENCE { timeOffline INTEGER (0..720)
-         * DEFAULT 0, (Value) ... Set the time offline value into the
-         * GracefulDisconnect object.
-         */
-        super.transitions[GracefulDisconnectStatesEnum.TIME_OFFLINE_VALUE][UniversalTag.INTEGER_TAG] = new GrammarTransition(
-            GracefulDisconnectStatesEnum.TIME_OFFLINE_VALUE,
-            GracefulDisconnectStatesEnum.DELAY_OR_REPLICATED_OR_END_TAG, new GrammarAction(
-                "Set Graceful Disconnect time offline" )
-            {
-                public void action( IAsn1Container container ) throws DecoderException
-                {
-                    GracefulDisconnectContainer gracefulDisconnectContainer = ( GracefulDisconnectContainer ) container;
-                    Value value = gracefulDisconnectContainer.getCurrentTLV().getValue();
-
-                    try
-                    {
-                        int timeOffline = IntegerDecoder.parse( value, 0, 720 );
-
-                        if ( IS_DEBUG )
-                        {
-                            log.debug( "Time Offline = " + timeOffline );
-                        }
-
-                        gracefulDisconnectContainer.getGracefulDisconnect().setTimeOffline( timeOffline );
-                        gracefulDisconnectContainer.grammarEndAllowed( true );
-                    }
-                    catch ( IntegerDecoderException e )
-                    {
-                        String msg = "failed to decode the timeOffline, the value should be between 0 and 720 minutes, it is '"
-                            + StringTools.dumpBytes( value.getData() ) + "'";
-                        log.error( msg );
-                        throw new DecoderException( msg );
-                    }
-                }
-            } );
-
-        /**
-         * GracefulDisconnect ::= SEQUENCE { ... delay [0] INTEGER (0..86400)
-         * DEFAULT 0, (Tag) ... We have had a TimeOffline, and now we are
-         * reading the delay. Nothing to do.
-         */
-        super.transitions[GracefulDisconnectStatesEnum.DELAY_OR_REPLICATED_OR_END_TAG][GracefulActionConstants.GRACEFUL_ACTION_DELAY_TAG] = new GrammarTransition(
-            GracefulDisconnectStatesEnum.DELAY_OR_REPLICATED_OR_END_TAG, GracefulDisconnectStatesEnum.DELAY_VALUE, null );
-
-        /**
-         * GracefulDisconnect ::= SEQUENCE { ... delay [0] INTEGER (0..86400)
-         * DEFAULT 0, (Value) ... Set the delay value into the
-         * GracefulDisconnect object.
-         */
-        super.transitions[GracefulDisconnectStatesEnum.DELAY_VALUE][GracefulActionConstants.GRACEFUL_ACTION_DELAY_TAG] = new GrammarTransition(
-            GracefulDisconnectStatesEnum.DELAY_VALUE, GracefulDisconnectStatesEnum.REPLICATED_CONTEXTS_OR_END_TAG,
-            new GrammarAction( "Set Graceful Disconnect Delay" )
-            {
-                public void action( IAsn1Container container ) throws DecoderException
-                {
-                    GracefulDisconnectContainer gracefulDisconnectContainer = ( GracefulDisconnectContainer ) container;
-                    Value value = gracefulDisconnectContainer.getCurrentTLV().getValue();
-
-                    try
-                    {
-                        int delay = IntegerDecoder.parse( value, 0, 86400 );
-
-                        if ( IS_DEBUG )
-                        {
-                            log.debug( "Delay = " + delay );
-                        }
-
-                        gracefulDisconnectContainer.getGracefulDisconnect().setDelay( delay );
-                        gracefulDisconnectContainer.grammarEndAllowed( true );
-                    }
-                    catch ( IntegerDecoderException e )
-                    {
-                        String msg = "failed to decode the delay, the value should be between 0 and 86400 seconds, it is '"
-                            + StringTools.dumpBytes( value.getData() ) + "'";
-                        log.error( msg );
-                        throw new DecoderException( msg );
-                    }
-                }
-            } );
-
-        /**
-         * GracefulDisconnect ::= SEQUENCE { ... replicatedContexts Referral
-         * OPTIONAL } Referral ::= SEQUENCE OF LDAPURL (Tag) We have a referral
-         * sequence. Nothing to do.
-         */
-        super.transitions[GracefulDisconnectStatesEnum.REPLICATED_CONTEXTS_OR_END_TAG][UniversalTag.SEQUENCE_TAG] = new GrammarTransition(
-            GracefulDisconnectStatesEnum.REPLICATED_CONTEXTS_OR_END_TAG,
-            GracefulDisconnectStatesEnum.REPLICATED_CONTEXTS_VALUE, null );
-
-        /**
-         * GracefulDisconnect ::= SEQUENCE { ... replicatedContexts Referral
-         * OPTIONAL } Referral ::= SEQUENCE OF LDAPURL (Value) We have a
-         * sequence, so we will have Octet String following. Nothing to do.
-         */
-        super.transitions[GracefulDisconnectStatesEnum.REPLICATED_CONTEXTS_VALUE][UniversalTag.SEQUENCE_TAG] = new GrammarTransition(
-            GracefulDisconnectStatesEnum.REPLICATED_CONTEXTS_VALUE,
-            GracefulDisconnectStatesEnum.REPLICATED_CONTEXT_OR_END_TAG, null );
-
-        /**
-         * GracefulDisconnect ::= SEQUENCE { ... replicatedContexts Referral
-         * OPTIONAL } Referral ::= SEQUENCE OF LDAPURL LDAPURL ::= LDAPString
-         * (Tag) We have a referral. It can be the first one, or one of the
-         * following. Nothing to do
-         */
-        super.transitions[GracefulDisconnectStatesEnum.REPLICATED_CONTEXT_OR_END_TAG][UniversalTag.OCTET_STRING] = new GrammarTransition(
-            GracefulDisconnectStatesEnum.REPLICATED_CONTEXT_OR_END_TAG,
-            GracefulDisconnectStatesEnum.REPLICATED_CONTEXT_VALUE, null );
-
-        /**
-         * GracefulDisconnect ::= SEQUENCE { ... replicatedContexts Referral
-         * OPTIONAL } Referral ::= SEQUENCE OF LDAPURL (Tag) LDAPURL ::=
-         * LDAPString (Tag) Read and store a referral url.
-         */
-        super.transitions[GracefulDisconnectStatesEnum.REPLICATED_CONTEXT_VALUE][UniversalTag.OCTET_STRING] = new GrammarTransition(
-            GracefulDisconnectStatesEnum.REPLICATED_CONTEXT_VALUE,
-            GracefulDisconnectStatesEnum.REPLICATED_CONTEXT_OR_END_TAG, new GrammarAction( "Replicated context URL" )
-            {
-                public void action( IAsn1Container container ) throws DecoderException
-                {
-                    GracefulDisconnectContainer gracefulDisconnectContainer = ( GracefulDisconnectContainer ) container;
-                    Value value = gracefulDisconnectContainer.getCurrentTLV().getValue();
-
-                    try
-                    {
-                        LdapURL url = new LdapURL( value.getData() );
-                        gracefulDisconnectContainer.getGracefulDisconnect().addReplicatedContexts( url );
-                        gracefulDisconnectContainer.grammarEndAllowed( true );
-                    }
-                    catch ( LdapURLEncodingException e )
-                    {
-                        String msg = "failed to decode the URL '" + StringTools.dumpBytes( value.getData() ) + "'";
-                        log.error( msg );
-                        throw new DecoderException( msg );
-                    }
-                }
-            } );
     }
 
 

Modified: directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/GracefulDisconnectStatesEnum.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/GracefulDisconnectStatesEnum.java?view=diff&rev=451836&r1=451835&r2=451836
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/GracefulDisconnectStatesEnum.java (original)
+++ directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/GracefulDisconnectStatesEnum.java Sun Oct  1 16:07:44 2006
@@ -38,68 +38,40 @@
     // =========================================================================
     // GracefulDisconnect grammar states
     // =========================================================================
+    /** Initial state */
+    public static final int START_STATE = 0;
 
-    /** Sequence Tag */
-    public static int GRACEFUL_DISCONNECT_SEQUENCE_TAG = 0;
+    /** Sequence */
+    public static int GRACEFUL_DISCONNECT_SEQUENCE_STATE = 1;
 
-    /** Sequence Value */
-    public static int GRACEFUL_DISCONNECT_SEQUENCE_VALUE = 1;
+    /** Time offline */
+    public static int TIME_OFFLINE_STATE = 2;
 
-    /** Time offline Tag */
-    public static int TIME_OFFLINE_OR_DELAY_OR_REPLICATED_OR_END_TAG = 2;
+    /** Delay */
+    public static int DELAY_STATE = 3;
 
-    /** Time offline Value */
-    public static int TIME_OFFLINE_VALUE = 3;
+    /** Replicated contexts */
+    public static int REPLICATED_CONTEXTS_STATE = 4;
 
-    /** Delay Tag */
-    public static int DELAY_OR_REPLICATED_OR_END_TAG = 4;
-
-    /** Delay Value */
-    public static int DELAY_VALUE = 5;
-
-    /** Replicated contexts Tag */
-    public static int REPLICATED_CONTEXTS_OR_END_TAG = 6;
-
-    /** Replicated contexts Value */
-    public static int REPLICATED_CONTEXTS_VALUE = 7;
-
-    /** Replicated contexts Tag */
-    public static int REPLICATED_CONTEXT_OR_END_TAG = 8;
-
-    /** Replicated contexts Value */
-    public static int REPLICATED_CONTEXT_VALUE = 9;
+    /** Referral */
+    public static int REFERRAL_STATE = 5;
 
     /** terminal state */
-    public static int LAST_GRACEFUL_DISCONNECT_STATE = 10;
-
-    // =========================================================================
-    // Grammars declaration.
-    // =========================================================================
-    /** GracefulDisconnect grammar */
-    public static final int GRACEFUL_DISCONNECT_GRAMMAR_SWITCH = 0x0100;
-
-    /** GracefulDisconnect grammar number */
-    public static final int GRACEFUL_DISCONNECT_GRAMMAR = 0;
-
-    /** The total number of grammars used */
-    public static final int NB_GRAMMARS = 1;
-
-    // =========================================================================
-    // Grammar switches debug strings
-    // =========================================================================
-    /** A string representation of grammars */
-    private static String[] GrammarSwitchString = new String[]
-        { "GRACEFUL_DISCONNECT_GRAMMAR_SWITCH" };
+    public static int LAST_GRACEFUL_DISCONNECT_STATE = 6;
 
     // =========================================================================
     // States debug strings
     // =========================================================================
     /** A string representation of all the states */
     private static String[] GracefulDisconnectString = new String[]
-        { "GRACEFUL_DISCONNECT_SEQUENCE_TAG", "GRACEFUL_DISCONNECT_SEQUENCE_VALUE",
-            "TIME_OFFLINE_OR_DELAY_OR_REPLICATED_OR_END_TAG", "TIME_OFFLINE_VALUE", "DELAY_OR_REPLICATED_OR_END_TAG",
-            "DELAY_VALUE", "REPLICATED_CONTEXTS_OR_END_TAG", "REPLICATED_CONTEXTS_VALUE",
-            "REPLICATED_CONTEXT_OR_END_TAG", "REPLICATED_CONTEXT_VALUE" };
+        { 
+        "START_STATE", 
+        "GRACEFUL_DISCONNECT_SEQUENCE_STATE",
+        "TIME_OFFLINE_STATE", 
+        "DELAY_STATE", 
+        "REPLICATED_CONTEXTS_STATE",
+        "REFERRAL_STATE"
+        };
 
     /** The instance */
     private static GracefulDisconnectStatesEnum instance = new GracefulDisconnectStatesEnum();
@@ -133,27 +105,19 @@
     /**
      * Get the grammar name
      * 
-     * @param grammar
-     *            The grammar code
+     * @param grammar The grammar code
      * @return The grammar name
      */
     public String getGrammarName( int grammar )
     {
-        switch ( grammar )
-        {
-            case GRACEFUL_DISCONNECT_GRAMMAR:
-                return "GRACEFUL_DISCONNECT_GRAMMAR";
-            default:
-                return "UNKNOWN";
-        }
+        return "GRACEFUL_DISCONNECT_GRAMMAR";
     }
 
 
     /**
      * Get the grammar name
      * 
-     * @param grammar
-     *            The grammar class
+     * @param grammar The grammar class
      * @return The grammar name
      */
     public String getGrammarName( IGrammar grammar )
@@ -170,33 +134,11 @@
     /**
      * Get the string representing the state
      * 
-     * @param grammar
-     *            The current grammar being used
-     * @param state
-     *            The state number
+     * @param state The state number
      * @return The String representing the state
      */
-    public String getState( int grammar, int state )
+    public String getState( int state )
     {
-
-        if ( ( state & GRAMMAR_SWITCH_MASK ) != 0 )
-        {
-            return ( state == END_STATE ) ? "END_STATE"
-                : GrammarSwitchString[( ( state & GRAMMAR_SWITCH_MASK ) >> 8 ) - 1];
-        }
-        else
-        {
-
-            switch ( grammar )
-            {
-
-                case GRACEFUL_DISCONNECT_GRAMMAR:
-                    return ( ( state == GRAMMAR_END ) ? "GRACEFUL_DISCONNECT_END_STATE"
-                        : GracefulDisconnectString[state] );
-
-                default:
-                    return "UNKNOWN";
-            }
-        }
+        return ( ( state == GRAMMAR_END ) ? "GRACEFUL_DISCONNECT_END_STATE" : GracefulDisconnectString[state] );
     }
 }

Modified: directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/GracefulShutdown.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/GracefulShutdown.java?view=diff&rev=451836&r1=451835&r2=451836
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/GracefulShutdown.java (original)
+++ directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/GracefulShutdown.java Sun Oct  1 16:07:44 2006
@@ -22,7 +22,7 @@
 
 import java.nio.ByteBuffer;
 
-import org.apache.directory.shared.asn1.ber.tlv.Length;
+import org.apache.directory.shared.asn1.ber.tlv.TLV;
 import org.apache.directory.shared.asn1.ber.tlv.UniversalTag;
 import org.apache.directory.shared.asn1.ber.tlv.Value;
 import org.apache.directory.shared.asn1.codec.EncoderException;
@@ -49,8 +49,13 @@
 
 
     /**
-     * Compute the GracefulShutdown length 0x30 L1 | +--> [0x02 0x0(1-4)
-     * [0..720] ] +--> [0x80 0x0(1-3) [0..86400] ] L1 will always be &lt 11.
+     * Compute the GracefulShutdown length 
+     * 0x30 L1 
+     *   | 
+     *   +--> [0x02 0x0(1-4) [0..720] ] 
+     *   +--> [0x80 0x0(1-3) [0..86400] ] 
+     *   
+     * L1 will always be &lt 11.
      */
     public int computeLength()
     {
@@ -74,11 +79,9 @@
     /**
      * Encodes the gracefulShutdown extended operation.
      * 
-     * @param buffer
-     *            The encoded sink
+     * @param buffer The encoded sink
      * @return A ByteBuffer that contains the encoded PDU
-     * @throws EncoderException
-     *             If anything goes wrong.
+     * @throws EncoderException If anything goes wrong.
      */
     public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
     {
@@ -86,7 +89,7 @@
         ByteBuffer bb = ByteBuffer.allocate( computeLength() );
 
         bb.put( UniversalTag.SEQUENCE_TAG );
-        bb.put( Length.getBytes( gracefulSequenceLength ) );
+        bb.put( TLV.getBytes( gracefulSequenceLength ) );
 
         if ( timeOffline != 0 )
         {

Modified: directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/GracefulShutdownContainer.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/GracefulShutdownContainer.java?view=diff&rev=451836&r1=451835&r2=451836
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/GracefulShutdownContainer.java (original)
+++ directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/GracefulShutdownContainer.java Sun Oct  1 16:07:44 2006
@@ -22,7 +22,6 @@
 
 import org.apache.directory.shared.asn1.ber.AbstractContainer;
 import org.apache.directory.shared.asn1.ber.IAsn1Container;
-import org.apache.directory.shared.asn1.ber.grammar.IGrammar;
 
 
 /**
@@ -43,14 +42,8 @@
     public GracefulShutdownContainer()
     {
         super();
-        currentGrammar = 0;
-        grammars = new IGrammar[GracefulShutdownStatesEnum.NB_GRAMMARS];
-        grammarStack = new IGrammar[1];
         stateStack = new int[1];
-        nbGrammars = 0;
-
-        grammars[GracefulShutdownStatesEnum.GRACEFUL_SHUTDOWN_GRAMMAR] = GracefulShutdownGrammar.getInstance();
-        grammarStack[currentGrammar] = grammars[GracefulShutdownStatesEnum.GRACEFUL_SHUTDOWN_GRAMMAR];
+        grammar = GracefulShutdownGrammar.getInstance();
         states = GracefulShutdownStatesEnum.getInstance();
     }
 
@@ -68,8 +61,7 @@
      * Set a GracefulShutdown Object into the container. It will be completed by
      * the ldapDecoder.
      * 
-     * @param control
-     *            the GracefulShutdown to set.
+     * @param control the GracefulShutdown to set.
      */
     public void setGracefulShutdown( GracefulShutdown gracefulShutdown )
     {

Modified: directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/GracefulShutdownDecoder.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/GracefulShutdownDecoder.java?view=diff&rev=451836&r1=451835&r2=451836
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/GracefulShutdownDecoder.java (original)
+++ directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/GracefulShutdownDecoder.java Sun Oct  1 16:07:44 2006
@@ -44,11 +44,9 @@
      * Decode a PDU which must contain a GracefulShutdown extended operation.
      * Note that the stream of bytes much contain a full PDU, not a partial one.
      * 
-     * @param stream
-     *            The bytes to be decoded
+     * @param stream The bytes to be decoded
      * @return An GracefulShutdown object
-     * @throws DecoderException
-     *             If the decoding failed
+     * @throws DecoderException If the decoding failed
      */
     public Asn1Object decode( byte[] stream ) throws DecoderException, NamingException
     {

Modified: directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/GracefulShutdownGrammar.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/GracefulShutdownGrammar.java?view=diff&rev=451836&r1=451835&r2=451836
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/GracefulShutdownGrammar.java (original)
+++ directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/GracefulShutdownGrammar.java Sun Oct  1 16:07:44 2006
@@ -42,9 +42,9 @@
  * 
  * <pre>
  *  GracefulShutdwon ::= SEQUENCE {
- *                         timeOffline INTEGER (0..720) DEFAULT 0,
- *                         delay [0] INTEGER (0..86400) DEFAULT 0
- *              }
+ *      timeOffline INTEGER (0..720) DEFAULT 0,
+ *      delay [0] INTEGER (0..86400) DEFAULT 0
+ *  }
  * </pre>
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
@@ -73,19 +73,16 @@
         super.transitions = new GrammarTransition[GracefulShutdownStatesEnum.LAST_GRACEFUL_SHUTDOWN_STATE][256];
 
         /**
-         * GracefulShutdown ::= SEQUENCE { (Tag) ... Nothing to do...
-         */
-        super.transitions[GracefulShutdownStatesEnum.GRACEFUL_SHUTDOWN_SEQUENCE_TAG][UniversalTag.SEQUENCE_TAG] = new GrammarTransition(
-            GracefulShutdownStatesEnum.GRACEFUL_SHUTDOWN_SEQUENCE_TAG,
-            GracefulShutdownStatesEnum.GRACEFUL_SHUTDOWN_SEQUENCE_VALUE, null );
-
-        /**
-         * GracefulShutdown ::= SEQUENCE { (Tag) ... Creates the
-         * GracefulShutdown object
-         */
-        super.transitions[GracefulShutdownStatesEnum.GRACEFUL_SHUTDOWN_SEQUENCE_VALUE][UniversalTag.SEQUENCE_TAG] = new GrammarTransition(
-            GracefulShutdownStatesEnum.GRACEFUL_SHUTDOWN_SEQUENCE_VALUE,
-            GracefulShutdownStatesEnum.TIME_OFFLINE_OR_DELAY_OR_END_TAG, new GrammarAction( "Init GracefulShutdown" )
+         * Transition from init state to graceful shutdown
+         * 
+         * GracefulShutdown ::= SEQUENCE {
+         *     ...
+         *     
+         * Creates the GracefulShutdown object
+         */
+        super.transitions[GracefulShutdownStatesEnum.INIT_GRAMMAR_STATE][UniversalTag.SEQUENCE_TAG] = 
+            new GrammarTransition( GracefulShutdownStatesEnum.INIT_GRAMMAR_STATE, GracefulShutdownStatesEnum.GRACEFUL_SHUTDOWN_SEQUENCE_STATE, UniversalTag.SEQUENCE_TAG,
+                new GrammarAction( "Init GracefulShutdown" )
             {
                 public void action( IAsn1Container container )
                 {
@@ -97,28 +94,20 @@
             } );
 
         /**
-         * GracefulShutdown ::= SEQUENCE { timeOffline INTEGER (0..720) DEFAULT
-         * 0, (Tag) ... Nothing to do
-         */
-        super.transitions[GracefulShutdownStatesEnum.TIME_OFFLINE_OR_DELAY_OR_END_TAG][UniversalTag.INTEGER_TAG] = new GrammarTransition(
-            GracefulShutdownStatesEnum.TIME_OFFLINE_OR_DELAY_OR_END_TAG, GracefulShutdownStatesEnum.TIME_OFFLINE_VALUE,
-            null );
-
-        /**
-         * GracefulShutdown ::= SEQUENCE { ... delay [0] INTEGER (0..86400)
-         * DEFAULT 0, (Tag) ... We have no TimeOffline. Nothing to do.
-         */
-        super.transitions[GracefulShutdownStatesEnum.TIME_OFFLINE_OR_DELAY_OR_END_TAG][GracefulActionConstants.GRACEFUL_ACTION_DELAY_TAG] = new GrammarTransition(
-            GracefulShutdownStatesEnum.TIME_OFFLINE_OR_DELAY_OR_END_TAG, GracefulShutdownStatesEnum.DELAY_VALUE, null );
-
-        /**
-         * GracefulShutdown ::= SEQUENCE { timeOffline INTEGER (0..720) DEFAULT
-         * 0, (Value) ... Set the time offline value into the GracefulShutdown
+         * Transition from graceful shutdown to time offline
+         *
+         * GracefulShutdown ::= SEQUENCE { 
+         *     timeOffline INTEGER (0..720) DEFAULT 0,
+         *     ...
+         *     
+         * Set the time offline value into the GracefulShutdown
          * object.
          */
-        super.transitions[GracefulShutdownStatesEnum.TIME_OFFLINE_VALUE][UniversalTag.INTEGER_TAG] = new GrammarTransition(
-            GracefulShutdownStatesEnum.TIME_OFFLINE_VALUE, GracefulShutdownStatesEnum.DELAY_OR_END_TAG,
-            new GrammarAction( "Set Graceful Shutdown time offline" )
+        super.transitions[GracefulShutdownStatesEnum.GRACEFUL_SHUTDOWN_SEQUENCE_STATE][UniversalTag.INTEGER_TAG] = 
+            new GrammarTransition( GracefulShutdownStatesEnum.GRACEFUL_SHUTDOWN_SEQUENCE_STATE, 
+                                    GracefulShutdownStatesEnum.TIME_OFFLINE_STATE, 
+                                    UniversalTag.INTEGER_TAG, 
+                new GrammarAction( "Set Graceful Shutdown time offline" )
             {
                 public void action( IAsn1Container container ) throws DecoderException
                 {
@@ -148,21 +137,65 @@
             } );
 
         /**
-         * GracefulShutdown ::= SEQUENCE { ... delay [0] INTEGER (0..86400)
-         * DEFAULT 0, (Tag) ... We have had a TimeOffline, and now we are
-         * reading the delay. Nothing to do.
+         * Transition from time offline to delay
+         * 
+         * GracefulShutdown ::= SEQUENCE { 
+         *     ... 
+         *     delay [0] INTEGER (0..86400) DEFAULT 0 }
+         * 
+         * Set the delay value into the GracefulShutdown
+         * object.
          */
-        super.transitions[GracefulShutdownStatesEnum.DELAY_OR_END_TAG][GracefulActionConstants.GRACEFUL_ACTION_DELAY_TAG] = new GrammarTransition(
-            GracefulShutdownStatesEnum.DELAY_OR_END_TAG, GracefulShutdownStatesEnum.DELAY_VALUE, null );
+        super.transitions[GracefulShutdownStatesEnum.TIME_OFFLINE_STATE][GracefulActionConstants.GRACEFUL_ACTION_DELAY_TAG] = 
+            new GrammarTransition( GracefulShutdownStatesEnum.TIME_OFFLINE_STATE, 
+                                    GracefulShutdownStatesEnum.DELAY_STATE, 
+                                    GracefulActionConstants.GRACEFUL_ACTION_DELAY_TAG, 
 
+                new GrammarAction( "Set Graceful Shutdown Delay" )
+            {
+                public void action( IAsn1Container container ) throws DecoderException
+                {
+                    GracefulShutdownContainer gracefulShutdownContainer = ( GracefulShutdownContainer ) container;
+                    Value value = gracefulShutdownContainer.getCurrentTLV().getValue();
+
+                    try
+                    {
+                        int delay = IntegerDecoder.parse( value, 0, 86400 );
+
+                        if ( IS_DEBUG )
+                        {
+                            log.debug( "Delay = " + delay );
+                        }
+
+                        gracefulShutdownContainer.getGracefulShutdown().setDelay( delay );
+                        gracefulShutdownContainer.grammarEndAllowed( true );
+                    }
+                    catch ( IntegerDecoderException e )
+                    {
+                        String msg = "failed to decode the delay, the value should be between 0 and 86400 seconds, it is '"
+                            + StringTools.dumpBytes( value.getData() ) + "'";
+                        log.error( msg );
+                        throw new DecoderException( msg );
+                    }
+                }
+            } );
+        
         /**
-         * GracefulShutdown ::= SEQUENCE { ... delay [0] INTEGER (0..86400)
-         * DEFAULT 0, (Value) ... Set the delay value into the GracefulShutdown
+         * Transition from graceful shutdown to delay
+         * 
+         * GracefulShutdown ::= SEQUENCE { 
+         *     ... 
+         *     delay [0] INTEGER (0..86400) DEFAULT 0 }
+         * 
+         * Set the delay value into the GracefulShutdown
          * object.
          */
-        super.transitions[GracefulShutdownStatesEnum.DELAY_VALUE][GracefulActionConstants.GRACEFUL_ACTION_DELAY_TAG] = new GrammarTransition(
-            GracefulShutdownStatesEnum.DELAY_VALUE, GracefulShutdownStatesEnum.GRAMMAR_END, new GrammarAction(
-                "Set Graceful Shutdown Delay" )
+        super.transitions[GracefulShutdownStatesEnum.GRACEFUL_SHUTDOWN_SEQUENCE_STATE][GracefulActionConstants.GRACEFUL_ACTION_DELAY_TAG] = 
+            new GrammarTransition( GracefulShutdownStatesEnum.GRACEFUL_SHUTDOWN_SEQUENCE_STATE, 
+                                    GracefulShutdownStatesEnum.DELAY_STATE, 
+                                    GracefulActionConstants.GRACEFUL_ACTION_DELAY_TAG, 
+
+                new GrammarAction( "Set Graceful Shutdown Delay" )
             {
                 public void action( IAsn1Container container ) throws DecoderException
                 {