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/09/08 18:54:49 UTC

svn commit: r441570 - /directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/ControlAsn1Ber.java

Author: elecharny
Date: Fri Sep  8 09:54:48 2006
New Revision: 441570

URL: http://svn.apache.org/viewvc?view=rev&rev=441570
Log:
The computeLength method has been completed.

Modified:
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/ControlAsn1Ber.java

Modified: directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/ControlAsn1Ber.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/ControlAsn1Ber.java?view=diff&rev=441570&r1=441569&r2=441570
==============================================================================
--- directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/ControlAsn1Ber.java (original)
+++ directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/ControlAsn1Ber.java Fri Sep  8 09:54:48 2006
@@ -21,30 +21,48 @@
 
 import java.nio.ByteBuffer;
 
+import javax.naming.ldap.Control;
+
+import org.apache.directory.shared.asn1.ber.tlv.Length;
 import org.apache.directory.shared.asn1.ber.tlv.ValueException;
 import org.apache.directory.shared.ldap.codec.Decoder;
 import org.apache.directory.shared.ldap.codec.Encoder;
 import org.apache.directory.shared.ldap.codec.EncoderException;
-import org.apache.directory.shared.ldap.messages.Control;
 import org.apache.directory.shared.ldap.messages.ControlDecorator;
+import org.apache.directory.shared.ldap.utils.StringTools;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
  * 
  * This class is a ASN.1 BER codec decorator. It adds coding and decoding
- * behavior to the Control object. 
+ * behavior to the ConcreteControl object. 
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
 public class ControlAsn1Ber extends ControlDecorator implements Encoder, Decoder
 {
+    /**
+     * Declares the Serial Version Uid.
+     *
+     * @see <a
+     *      href="http://c2.com/cgi/wiki?AlwaysDeclareSerialVersionUid">Always
+     *      Declare Serial Version Uid</a>
+     */
+    static final long serialVersionUID = 2L;
+
     /** The logger */
     private static Logger log = LoggerFactory.getLogger( ControlAsn1Ber.class );
 
     /** A speedup for logger */
     private static final boolean IS_DEBUG = log.isDebugEnabled();
     
+    /** The control length */
+    private transient int controlLength;
+    
+    /** The ID bytes */
+    private transient byte[] idBytes;
+
     /**
      * 
      * Creates a new instance of BindRequestAsn1Ber.
@@ -56,9 +74,41 @@
         super( control );
     }
     
+    /**
+     * Compute the Control length 
+     * 
+     * Control : 
+     * 0x30 L1 
+     *   | 
+     *   +--> 0x04 L2 controlType
+     *  [+--> 0x01 0x01 criticality] 
+     *  [+--> 0x04 L3 controlValue] 
+     *  
+     * Control length = Length(0x30) + length(L1) + Length(0x04) 
+     *   + Length(L2) + L2 
+     *  [+ Length(0x01) + 1 + 1] 
+     *  [+ Length(0x04) + Length(L3) + L3]
+     */
     public int computeLength()
     {
-        int length = 0;
+        // The control ID         
+        idBytes = StringTools.getBytesUtf8( getID() );
+
+        controlLength = 1 + Length.getNbBytes( idBytes.length ) + idBytes.length;
+
+        // The criticality, only if true
+        if ( isCritical() )
+        {
+            controlLength += 1 + 1 + 1; // Always 3 for a boolean
+        }
+
+        // The control value, if any
+        if ( getControlValue() != null )
+        {
+            controlLength += 1 + Length.getNbBytes( getControlValue().length ) + getControlValue().length;
+        }
+
+        int length = 1 + Length.getNbBytes( controlLength ) + controlLength;
         
         if ( IS_DEBUG )
         {