directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1332635 - in /directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/decorators: AddRequestDecorator.java BindRequestDecorator.java DeleteRequestDecorator.java SearchResultEntryDecorator.java
Date Tue, 01 May 2012 12:53:35 GMT
Author: elecharny
Date: Tue May  1 12:53:34 2012
New Revision: 1332635

URL: http://svn.apache.org/viewvc?rev=1332635&view=rev
Log:
Small improvements in the message codecs

Modified:
    directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/decorators/AddRequestDecorator.java
    directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/decorators/BindRequestDecorator.java
    directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/decorators/DeleteRequestDecorator.java
    directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/decorators/SearchResultEntryDecorator.java

Modified: directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/decorators/AddRequestDecorator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/decorators/AddRequestDecorator.java?rev=1332635&r1=1332634&r2=1332635&view=diff
==============================================================================
--- directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/decorators/AddRequestDecorator.java
(original)
+++ directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/decorators/AddRequestDecorator.java
Tue May  1 12:53:34 2012
@@ -62,6 +62,9 @@ public final class AddRequestDecorator e
     /** The list of all attributes length */
     private List<Integer> attributesLength;
 
+    /** The list of all attributes Id bytes */
+    private List<byte[]> attributeIds;
+
     /** The list of all vals length */
     private List<Integer> valuesLength;
 
@@ -366,8 +369,9 @@ public final class AddRequestDecorator e
 
         if ( entry.size() != 0 )
         {
-            List<Integer> attributesLength = new LinkedList<Integer>();
-            List<Integer> valuesLength = new LinkedList<Integer>();
+            attributesLength = new LinkedList<Integer>();
+            attributeIds = new LinkedList<byte[]>();
+            valuesLength = new LinkedList<Integer>();
 
             // Compute the attributes length
             for ( Attribute attribute : entry )
@@ -376,7 +380,10 @@ public final class AddRequestDecorator e
                 int localValuesLength = 0;
 
                 // Get the type length
-                int idLength = attribute.getUpId().getBytes().length;
+                byte[] attributeIdBytes = Strings.getBytesUtf8( attribute.getUpId() );
+                attributeIds.add( attributeIdBytes );
+
+                int idLength = attributeIdBytes.length;
                 localAttributeLength = 1 + TLV.getNbBytes( idLength ) + idLength;
 
                 // The values
@@ -464,29 +471,22 @@ public final class AddRequestDecorator e
                 {
                     // The attributes list sequence
                     buffer.put( UniversalTag.SEQUENCE.getValue() );
-                    int localAttributeLength = getAttributesLength().get( attributeNumber
);
+                    int localAttributeLength = attributesLength.get( attributeNumber );
                     buffer.put( TLV.getBytes( localAttributeLength ) );
 
                     // The attribute type
-                    BerValue.encode( buffer, attribute.getUpId() );
+                    BerValue.encode( buffer, attributeIds.get( attributeNumber ) );
 
                     // The values
                     buffer.put( UniversalTag.SET.getValue() );
-                    int localValuesLength = getValuesLength().get( attributeNumber );
+                    int localValuesLength = valuesLength.get( attributeNumber );
                     buffer.put( TLV.getBytes( localValuesLength ) );
 
                     if ( attribute.size() != 0 )
                     {
                         for ( Value<?> value : attribute )
                         {
-                            if ( value.isHumanReadable() )
-                            {
-                                BerValue.encode( buffer, value.getString() );
-                            }
-                            else
-                            {
-                                BerValue.encode( buffer, value.getBytes() );
-                            }
+                            BerValue.encode( buffer, value.getBytes() );
                         }
                     }
 

Modified: directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/decorators/BindRequestDecorator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/decorators/BindRequestDecorator.java?rev=1332635&r1=1332634&r2=1332635&view=diff
==============================================================================
--- directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/decorators/BindRequestDecorator.java
(original)
+++ directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/decorators/BindRequestDecorator.java
Tue May  1 12:53:34 2012
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ * 
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ * 
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ * 
  */
 package org.apache.directory.shared.ldap.codec.decorators;
 
@@ -53,6 +53,15 @@ public class BindRequestDecorator extend
 
     /** The SASL credentials length */
     private int saslCredentialsLength;
+    
+    /** The bytes containing the Dn */
+    private byte[] dnBytes;
+    
+    /** The bytes containing the Name */
+    private byte[] nameBytes;
+    
+    /** The bytes containing the SaslMechanism */
+    private byte[] mechanismBytes;
 
 
     /**
@@ -318,19 +327,19 @@ public class BindRequestDecorator extend
     // The Decorator methods
     //-------------------------------------------------------------------------
     /**
-     * Compute the BindRequest length 
+     * Compute the BindRequest length
      * 
-     * BindRequest : 
+     * BindRequest :
      * <pre>
-     * 0x60 L1 
-     *   | 
-     *   +--> 0x02 0x01 (1..127) version 
-     *   +--> 0x04 L2 name 
-     *   +--> authentication 
-     *   
+     * 0x60 L1
+     *   |
+     *   +--> 0x02 0x01 (1..127) version
+     *   +--> 0x04 L2 name
+     *   +--> authentication
+     * 
      * L2 = Length(name)
-     * L3/4 = Length(authentication) 
-     * Length(BindRequest) = Length(0x60) + Length(L1) + L1 + Length(0x02) + 1 + 1 + 
+     * L3/4 = Length(authentication)
+     * Length(BindRequest) = Length(0x60) + Length(L1) + L1 + Length(0x02) + 1 + 1 +
      *      Length(0x04) + Length(L2) + L2 + Length(authentication)
      * </pre>
      */
@@ -343,14 +352,14 @@ public class BindRequestDecorator extend
         if ( !Dn.isNullOrEmpty( dn ) )
         {
             // A DN has been provided
+            dnBytes = Strings.getBytesUtf8( dn.getName() );
+            int dnLength = dnBytes.length;
 
-            bindRequestLength += 1 + TLV.getNbBytes( Dn.getNbBytes( dn ) )
-                + Dn.getNbBytes( dn );
+            bindRequestLength += 1 + TLV.getNbBytes( dnLength ) + dnLength;
         }
         else
         {
             // No DN has been provided, let's use the name as a string instead
-
             String name = getName();
 
             if ( Strings.isEmpty( name ) )
@@ -358,8 +367,10 @@ public class BindRequestDecorator extend
                 name = "";
             }
 
-            bindRequestLength += 1 + TLV.getNbBytes( name.getBytes().length )
-                + name.getBytes().length;
+            nameBytes = Strings.getBytesUtf8( name );
+            int nameLength = nameBytes.length;
+
+            bindRequestLength += 1 + TLV.getNbBytes( nameLength ) + nameLength;
         }
 
         byte[] credentials = getCredentials();
@@ -379,9 +390,8 @@ public class BindRequestDecorator extend
         }
         else
         {
-            byte[] mechanismBytes = Strings.getBytesUtf8( getSaslMechanism() );
-            int saslMechanismLength = 1 + TLV.getNbBytes( mechanismBytes.length ) + mechanismBytes.length;
-            int saslCredentialsLength = 0;
+            mechanismBytes = Strings.getBytesUtf8( getSaslMechanism() );
+            saslMechanismLength = 1 + TLV.getNbBytes( mechanismBytes.length ) + mechanismBytes.length;
 
             if ( credentials != null )
             {
@@ -392,10 +402,6 @@ public class BindRequestDecorator extend
                 + saslCredentialsLength;
 
             bindRequestLength += saslLength;
-
-            // Store the mechanism and credentials lengths
-            setSaslMechanismLength( saslMechanismLength );
-            setSaslCredentialsLength( saslCredentialsLength );
         }
 
         setBindRequestLength( bindRequestLength );
@@ -406,14 +412,14 @@ public class BindRequestDecorator extend
 
 
     /**
-     * Encode the BindRequest message to a PDU. 
+     * Encode the BindRequest message to a PDU.
      * 
-     * BindRequest : 
+     * BindRequest :
      * <pre>
-     * 0x60 LL 
-     *   0x02 LL version         0x80 LL simple 
-     *   0x04 LL name           /   
-     *   authentication.encode() 
+     * 0x60 LL
+     *   0x02 LL version         0x80 LL simple
+     *   0x04 LL name           /
+     *   authentication.encode()
      *                          \ 0x83 LL mechanism [0x04 LL credential]
      * </pre>
      * 
@@ -442,21 +448,12 @@ public class BindRequestDecorator extend
         if ( !Dn.isNullOrEmpty( dn ) )
         {
             // A DN has been provided
-
-            BerValue.encode( buffer, Dn.getBytes( dn ) );
+            BerValue.encode( buffer, dnBytes );
         }
         else
         {
             // No DN has been provided, let's use the name as a string instead
-
-            String name = getName();
-
-            if ( Strings.isEmpty( name ) )
-            {
-                name = "";
-            }
-
-            BerValue.encode( buffer, name.getBytes() );
+            BerValue.encode( buffer, nameBytes );
         }
 
         byte[] credentials = getCredentials();
@@ -498,10 +495,8 @@ public class BindRequestDecorator extend
                 // The saslAuthentication Tag
                 buffer.put( ( byte ) LdapConstants.BIND_REQUEST_SASL_TAG );
 
-                byte[] mechanismBytes = Strings.getBytesUtf8( getSaslMechanism() );
-
                 buffer.put( TLV
-                    .getBytes( getSaslMechanismLength() + getSaslCredentialsLength() ) );
+                    .getBytes( saslMechanismLength + saslCredentialsLength ) );
 
                 BerValue.encode( buffer, mechanismBytes );
 

Modified: directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/decorators/DeleteRequestDecorator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/decorators/DeleteRequestDecorator.java?rev=1332635&r1=1332634&r2=1332635&view=diff
==============================================================================
--- directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/decorators/DeleteRequestDecorator.java
(original)
+++ directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/decorators/DeleteRequestDecorator.java
Tue May  1 12:53:34 2012
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ * 
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ * 
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ * 
  */
 package org.apache.directory.shared.ldap.codec.decorators;
 
@@ -33,6 +33,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.message.DeleteRequest;
 import org.apache.directory.shared.ldap.model.message.DeleteResponse;
 import org.apache.directory.shared.ldap.model.name.Dn;
+import org.apache.directory.shared.util.Strings;
 
 
 /**
@@ -43,6 +44,10 @@ import org.apache.directory.shared.ldap.
 public class DeleteRequestDecorator extends SingleReplyRequestDecorator<DeleteRequest,
DeleteResponse>
     implements DeleteRequest
 {
+    
+    /** The bytes containing the Dn */
+    private byte[] dnBytes;
+
     /**
      * Makes a DeleteRequest a MessageDecorator.
      *
@@ -120,25 +125,28 @@ public class DeleteRequestDecorator exte
     // The Decorator methods
     //-------------------------------------------------------------------------
     /**
-     * Compute the DelRequest length 
+     * Compute the DelRequest length
      * 
-     * DelRequest : 
-     * 0x4A L1 entry 
+     * DelRequest :
+     * 0x4A L1 entry
      * 
-     * L1 = Length(entry) 
+     * L1 = Length(entry)
      * Length(DelRequest) = Length(0x4A) + Length(L1) + L1
      */
     public int computeLength()
     {
+        dnBytes = Strings.getBytesUtf8( getName().getName() );
+        int dnLength = dnBytes.length;
+        
         // The entry
-        return 1 + TLV.getNbBytes( Dn.getNbBytes( getName() ) ) + Dn.getNbBytes( getName()
);
+        return 1 + TLV.getNbBytes( dnLength ) + dnLength;
     }
 
 
     /**
-     * Encode the DelRequest message to a PDU. 
+     * Encode the DelRequest message to a PDU.
      * 
-     * DelRequest : 
+     * DelRequest :
      * 0x4A LL entry
      * 
      * @param buffer The buffer where to put the PDU
@@ -151,8 +159,8 @@ public class DeleteRequestDecorator exte
             buffer.put( LdapConstants.DEL_REQUEST_TAG );
 
             // The entry
-            buffer.put( TLV.getBytes( Dn.getNbBytes( getName() ) ) );
-            buffer.put( Dn.getBytes( getName() ) );
+            buffer.put( TLV.getBytes( dnBytes.length ) );
+            buffer.put( dnBytes );
         }
         catch ( BufferOverflowException boe )
         {

Modified: directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/decorators/SearchResultEntryDecorator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/decorators/SearchResultEntryDecorator.java?rev=1332635&r1=1332634&r2=1332635&view=diff
==============================================================================
--- directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/decorators/SearchResultEntryDecorator.java
(original)
+++ directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/decorators/SearchResultEntryDecorator.java
Tue May  1 12:53:34 2012
@@ -36,6 +36,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.entry.DefaultAttribute;
 import org.apache.directory.shared.ldap.model.entry.Entry;
 import org.apache.directory.shared.ldap.model.entry.Attribute;
+import org.apache.directory.shared.ldap.model.entry.Value;
 import org.apache.directory.shared.ldap.model.exception.LdapException;
 import org.apache.directory.shared.ldap.model.message.SearchResultEntry;
 import org.apache.directory.shared.ldap.model.name.Dn;
@@ -64,8 +65,8 @@ public class SearchResultEntryDecorator 
     /** The list of all attributes Id bytes */
     private List<byte[]> attributeIds;
 
-    /** The list of all vals length */
-    private List<Integer> valsLength;
+    /** The list of all values length */
+    private List<Integer> valuesLength;
 
     /** The current attribute being processed */
     private Attribute currentAttribute;
@@ -165,7 +166,7 @@ public class SearchResultEntryDecorator 
      */
     public List<Integer> getValsLength()
     {
-        return valsLength;
+        return valuesLength;
     }
 
 
@@ -175,7 +176,7 @@ public class SearchResultEntryDecorator 
      */
     public void setValsLength( List<Integer> valsLength )
     {
-        this.valsLength = valsLength;
+        this.valuesLength = valsLength;
     }
 
 
@@ -317,13 +318,13 @@ public class SearchResultEntryDecorator 
 
         if ( ( entry != null ) && ( entry.size() != 0 ) )
         {
-            List<Integer> attributeLength = new LinkedList<Integer>();
+            attributeLength = new LinkedList<Integer>();
             attributeIds = new LinkedList<byte[]>();
-            List<Integer> valsLength = new LinkedList<Integer>();
+            valuesLength = new LinkedList<Integer>();
 
             // Store those lists in the object
             setAttributeLength( attributeLength );
-            setValsLength( valsLength );
+            setValsLength( valuesLength );
 
             // Compute the attributes length
             for ( Attribute attribute : entry )
@@ -332,9 +333,9 @@ public class SearchResultEntryDecorator 
                 int localValuesLength = 0;
 
                 // Get the type length
-                byte[] atrributeIdBytes = attribute.getUpId().getBytes();
-                attributeIds.add( atrributeIdBytes );
-                int idLength = atrributeIdBytes.length;
+                byte[] attributeIdBytes = Strings.getBytesUtf8( attribute.getUpId() );
+                attributeIds.add( attributeIdBytes );
+                int idLength = attributeIdBytes.length;
                 localAttributeLength = 1 + TLV.getNbBytes( idLength ) + idLength;
 
                 if ( attribute.size() != 0 )
@@ -373,7 +374,7 @@ public class SearchResultEntryDecorator 
 
                 // Store the lengths of the encoded attributes and values
                 attributeLength.add( localAttributeLength );
-                valsLength.add( localValuesLength );
+                valuesLength.add( localValuesLength );
             }
 
             // Store the lengths of the entry
@@ -443,7 +444,7 @@ public class SearchResultEntryDecorator 
                 {
                     // The partial attribute list sequence
                     buffer.put( UniversalTag.SEQUENCE.getValue() );
-                    int localAttributeLength = getAttributeLength().get( attributeNumber
);
+                    int localAttributeLength = attributeLength.get( attributeNumber );
                     buffer.put( TLV.getBytes( localAttributeLength ) );
 
                     // The attribute type
@@ -451,12 +452,12 @@ public class SearchResultEntryDecorator 
 
                     // The values
                     buffer.put( UniversalTag.SET.getValue() );
-                    int localValuesLength = getValsLength().get( attributeNumber );
+                    int localValuesLength = valuesLength.get( attributeNumber );
                     buffer.put( TLV.getBytes( localValuesLength ) );
 
                     if ( attribute.size() > 0 )
                     {
-                        for ( org.apache.directory.shared.ldap.model.entry.Value<?>
value : attribute )
+                        for ( Value<?> value : attribute )
                         {
                             BerValue.encode( buffer, value.getBytes() );
                         }



Mime
View raw message