directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r986083 [2/2] - in /directory: apacheds/branches/apacheds-codec-merge/core-api/src/main/java/org/apache/directory/server/core/ apacheds/branches/apacheds-codec-merge/core-api/src/main/java/org/apache/directory/server/core/interceptor/contex...
Date Mon, 16 Aug 2010 18:11:23 GMT
Modified: directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/LdapProtocolEncoder.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/LdapProtocolEncoder.java?rev=986083&r1=986082&r2=986083&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/LdapProtocolEncoder.java (original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/LdapProtocolEncoder.java Mon Aug 16 18:11:21 2010
@@ -41,6 +41,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.entry.BinaryValue;
 import org.apache.directory.shared.ldap.entry.Entry;
 import org.apache.directory.shared.ldap.entry.EntryAttribute;
+import org.apache.directory.shared.ldap.entry.Modification;
 import org.apache.directory.shared.ldap.message.control.Control;
 import org.apache.directory.shared.ldap.message.internal.AddResponse;
 import org.apache.directory.shared.ldap.message.internal.BindResponse;
@@ -56,6 +57,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.message.internal.InternalExtendedRequest;
 import org.apache.directory.shared.ldap.message.internal.InternalMessage;
 import org.apache.directory.shared.ldap.message.internal.InternalModifyDnRequest;
+import org.apache.directory.shared.ldap.message.internal.InternalModifyRequest;
 import org.apache.directory.shared.ldap.message.internal.InternalReferral;
 import org.apache.directory.shared.ldap.message.internal.InternalUnbindRequest;
 import org.apache.directory.shared.ldap.message.internal.LdapResult;
@@ -134,7 +136,7 @@ public class LdapProtocolEncoder extends
             || ( message instanceof InternalDeleteRequest ) || ( message instanceof InternalUnbindRequest )
             || ( message instanceof InternalBindRequest ) || ( message instanceof InternalAddRequest )
             || ( message instanceof InternalCompareRequest ) || ( message instanceof InternalExtendedRequest )
-            || ( message instanceof InternalModifyDnRequest ) )
+            || ( message instanceof InternalModifyDnRequest ) || ( message instanceof InternalModifyRequest ) )
         {
             try
             {
@@ -885,6 +887,113 @@ public class LdapProtocolEncoder extends
 
 
     /**
+     * Compute the ModifyRequest length 
+     * 
+     * ModifyRequest :
+     * 
+     * 0x66 L1
+     *  |
+     *  +--> 0x04 L2 object
+     *  +--> 0x30 L3 modifications
+     *        |
+     *        +--> 0x30 L4-1 modification sequence
+     *        |     |
+     *        |     +--> 0x0A 0x01 (0..2) operation
+     *        |     +--> 0x30 L5-1 modification
+     *        |           |
+     *        |           +--> 0x04 L6-1 type
+     *        |           +--> 0x31 L7-1 vals
+     *        |                 |
+     *        |                 +--> 0x04 L8-1-1 attributeValue
+     *        |                 +--> 0x04 L8-1-2 attributeValue
+     *        |                 +--> ...
+     *        |                 +--> 0x04 L8-1-i attributeValue
+     *        |                 +--> ...
+     *        |                 +--> 0x04 L8-1-n attributeValue
+     *        |
+     *        +--> 0x30 L4-2 modification sequence
+     *        .     |
+     *        .     +--> 0x0A 0x01 (0..2) operation
+     *        .     +--> 0x30 L5-2 modification
+     *                    |
+     *                    +--> 0x04 L6-2 type
+     *                    +--> 0x31 L7-2 vals
+     *                          |
+     *                          +--> 0x04 L8-2-1 attributeValue
+     *                          +--> 0x04 L8-2-2 attributeValue
+     *                          +--> ...
+     *                          +--> 0x04 L8-2-i attributeValue
+     *                          +--> ...
+     *                          +--> 0x04 L8-2-n attributeValue
+     */
+    private int computeModifyRequestLength( ModifyRequestImpl modifyRequest )
+    {
+        // Initialized with name
+        int modifyRequestLength = 1 + TLV.getNbBytes( DN.getNbBytes( modifyRequest.getName() ) )
+            + DN.getNbBytes( modifyRequest.getName() );
+
+        // All the changes length
+        int changesLength = 0;
+
+        Collection<Modification> modifications = modifyRequest.getModifications();
+
+        if ( ( modifications != null ) && ( modifications.size() != 0 ) )
+        {
+            List<Integer> changeLength = new LinkedList<Integer>();
+            List<Integer> modificationLength = new LinkedList<Integer>();
+            List<Integer> valuesLength = new LinkedList<Integer>();
+
+            for ( Modification modification : modifications )
+            {
+                // Modification sequence length initialized with the operation
+                int localModificationSequenceLength = 1 + 1 + 1;
+                int localValuesLength = 0;
+
+                // Modification length initialized with the type
+                int typeLength = modification.getAttribute().getId().length();
+                int localModificationLength = 1 + TLV.getNbBytes( typeLength ) + typeLength;
+
+                // Get all the values
+                if ( modification.getAttribute().size() != 0 )
+                {
+                    for ( org.apache.directory.shared.ldap.entry.Value<?> value : modification.getAttribute() )
+                    {
+                        localValuesLength += 1 + TLV.getNbBytes( value.getBytes().length ) + value.getBytes().length;
+                    }
+                }
+
+                localModificationLength += 1 + TLV.getNbBytes( localValuesLength ) + localValuesLength;
+
+                // Compute the modificationSequenceLength
+                localModificationSequenceLength += 1 + TLV.getNbBytes( localModificationLength )
+                    + localModificationLength;
+
+                // Add the tag and the length
+                changesLength += 1 + TLV.getNbBytes( localModificationSequenceLength )
+                    + localModificationSequenceLength;
+
+                // Store the arrays of values
+                valuesLength.add( localValuesLength );
+                modificationLength.add( localModificationLength );
+                changeLength.add( localModificationSequenceLength );
+            }
+
+            // Add the modifications length to the modificationRequestLength
+            modifyRequestLength += 1 + TLV.getNbBytes( changesLength ) + changesLength;
+            modifyRequest.setChangeLength( changeLength );
+            modifyRequest.setModificationLength( modificationLength );
+            modifyRequest.setValuesLength( valuesLength );
+        }
+
+        modifyRequest.setChangesLength( changesLength );
+        modifyRequest.setModifyRequestLength( modifyRequestLength );
+
+        return 1 + TLV.getNbBytes( modifyRequestLength ) + modifyRequestLength;
+
+    }
+
+
+    /**
      * Compute the ModifyResponse length 
      * 
      * ModifyResponse : 
@@ -1259,7 +1368,7 @@ public class LdapProtocolEncoder extends
      * 
      * @param buffer The buffer where to put the PDU
      */
-    protected void encodeAddRequest( ByteBuffer buffer, AddRequestImpl addRequest ) throws EncoderException
+    private void encodeAddRequest( ByteBuffer buffer, AddRequestImpl addRequest ) throws EncoderException
     {
         try
         {
@@ -1764,6 +1873,112 @@ public class LdapProtocolEncoder extends
 
 
     /**
+     * Encode the ModifyRequest message to a PDU. 
+     * 
+     * ModifyRequest : 
+     * <pre>
+     * 0x66 LL
+     *   0x04 LL object
+     *   0x30 LL modifiations
+     *     0x30 LL modification sequence
+     *       0x0A 0x01 operation
+     *       0x30 LL modification
+     *         0x04 LL type
+     *         0x31 LL vals
+     *           0x04 LL attributeValue
+     *           ... 
+     *           0x04 LL attributeValue
+     *     ... 
+     *     0x30 LL modification sequence
+     *       0x0A 0x01 operation
+     *       0x30 LL modification
+     *         0x04 LL type
+     *         0x31 LL vals
+     *           0x04 LL attributeValue
+     *           ... 
+     *           0x04 LL attributeValue
+     * </pre>
+     * 
+     * @param buffer The buffer where to put the PDU
+     * @return The PDU.
+     */
+    private void encodeModifyRequest( ByteBuffer buffer, ModifyRequestImpl modifyRequest ) throws EncoderException
+    {
+        try
+        {
+            // The AddRequest Tag
+            buffer.put( LdapConstants.MODIFY_REQUEST_TAG );
+            buffer.put( TLV.getBytes( modifyRequest.getModifyRequestLength() ) );
+
+            // The entry
+            Value.encode( buffer, DN.getBytes( modifyRequest.getName() ) );
+
+            // The modifications sequence
+            buffer.put( UniversalTag.SEQUENCE_TAG );
+            buffer.put( TLV.getBytes( modifyRequest.getChangesLength() ) );
+
+            // The modifications list
+            Collection<Modification> modifications = modifyRequest.getModifications();
+
+            if ( ( modifications != null ) && ( modifications.size() != 0 ) )
+            {
+                int modificationNumber = 0;
+
+                // Compute the modifications length
+                for ( Modification modification : modifications )
+                {
+                    // The modification sequence
+                    buffer.put( UniversalTag.SEQUENCE_TAG );
+                    int localModificationSequenceLength = modifyRequest.getChangeLength().get( modificationNumber );
+                    buffer.put( TLV.getBytes( localModificationSequenceLength ) );
+
+                    // The operation. The value has to be changed, it's not
+                    // the same value in DirContext and in RFC 2251.
+                    buffer.put( UniversalTag.ENUMERATED_TAG );
+                    buffer.put( ( byte ) 1 );
+                    buffer.put( ( byte ) modification.getOperation().getValue() );
+
+                    // The modification
+                    buffer.put( UniversalTag.SEQUENCE_TAG );
+                    int localModificationLength = modifyRequest.getModificationLength().get( modificationNumber );
+                    buffer.put( TLV.getBytes( localModificationLength ) );
+
+                    // The modification type
+                    Value.encode( buffer, modification.getAttribute().getId() );
+
+                    // The values
+                    buffer.put( UniversalTag.SET_TAG );
+                    int localValuesLength = modifyRequest.getValuesLength().get( modificationNumber );
+                    buffer.put( TLV.getBytes( localValuesLength ) );
+
+                    if ( modification.getAttribute().size() != 0 )
+                    {
+                        for ( org.apache.directory.shared.ldap.entry.Value<?> value : modification.getAttribute() )
+                        {
+                            if ( !value.isBinary() )
+                            {
+                                Value.encode( buffer, value.getString() );
+                            }
+                            else
+                            {
+                                Value.encode( buffer, value.getBytes() );
+                            }
+                        }
+                    }
+
+                    // Go to the next modification number;
+                    modificationNumber++;
+                }
+            }
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException( I18n.err( I18n.ERR_04005 ) );
+        }
+    }
+
+
+    /**
      * Encode the ModifyResponse message to a PDU.
      * 
      * @param buffer The buffer where to put the PDU
@@ -2087,6 +2302,9 @@ public class LdapProtocolEncoder extends
             case INTERMEDIATE_RESPONSE:
                 return computeIntermediateResponseLength( ( IntermediateResponseImpl ) message );
 
+            case MODIFY_REQUEST:
+                return computeModifyRequestLength( ( ModifyRequestImpl ) message );
+
             case MODIFY_RESPONSE:
                 return computeModifyResponseLength( ( ModifyResponseImpl ) message );
 
@@ -2166,6 +2384,10 @@ public class LdapProtocolEncoder extends
                 encodeIntermediateResponse( bb, ( IntermediateResponseImpl ) message );
                 break;
 
+            case MODIFY_REQUEST:
+                encodeModifyRequest( bb, ( ModifyRequestImpl ) message );
+                break;
+
             case MODIFY_RESPONSE:
                 encodeModifyResponse( bb, ( ModifyResponseImpl ) message );
                 break;

Modified: directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/ModifyRequestImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/ModifyRequestImpl.java?rev=986083&r1=986082&r2=986083&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/ModifyRequestImpl.java (original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/ModifyRequestImpl.java Mon Aug 16 18:11:21 2010
@@ -24,15 +24,20 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Iterator;
+import java.util.LinkedList;
 import java.util.List;
 
 import org.apache.directory.shared.ldap.codec.MessageTypeEnum;
+import org.apache.directory.shared.ldap.entry.DefaultEntryAttribute;
 import org.apache.directory.shared.ldap.entry.DefaultModification;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
 import org.apache.directory.shared.ldap.entry.Modification;
+import org.apache.directory.shared.ldap.entry.ModificationOperation;
 import org.apache.directory.shared.ldap.message.internal.InternalModifyRequest;
 import org.apache.directory.shared.ldap.message.internal.ModifyResponse;
 import org.apache.directory.shared.ldap.message.internal.ResultResponse;
 import org.apache.directory.shared.ldap.name.DN;
+import org.apache.directory.shared.ldap.util.StringTools;
 
 
 /**
@@ -50,19 +55,50 @@ public class ModifyRequestImpl extends A
     /** Sequence of modifications or PDU's <b>modification</b> seqence field */
     private List<Modification> mods = new ArrayList<Modification>();
 
+    /** The associated response */
     private ModifyResponse response;
 
+    /** The current attribute being decoded */
+    private EntryAttribute currentAttribute;
+
+    /** A local storage for the operation */
+    private ModificationOperation currentOperation;
+
+    /** The modify request length */
+    private int modifyRequestLength;
+
+    /** The changes length */
+    private int changesLength;
+
+    /** The list of all change lengths */
+    private List<Integer> changeLength = new LinkedList<Integer>();
+
+    /** The list of all the modification lengths */
+    private List<Integer> modificationLength = new LinkedList<Integer>();
+
+    /** The list of all the value lengths */
+    private List<Integer> valuesLength = new LinkedList<Integer>();
+
 
     // ------------------------------------------------------------------------
     // Constructors
     // ------------------------------------------------------------------------
 
     /**
-     * Creates a Lockable ModifyRequest implementing object used to modify the
+     * Creates a ModifyRequest implementing object used to modify the
+     * attributes of an entry.
+     */
+    public ModifyRequestImpl()
+    {
+        super( -1, TYPE );
+    }
+
+
+    /**
+     * Creates a ModifyRequest implementing object used to modify the
      * attributes of an entry.
      * 
-     * @param id
-     *            the sequential message identifier
+     * @param id the sequential message identifier
      */
     public ModifyRequestImpl( final int id )
     {
@@ -79,7 +115,7 @@ public class ModifyRequestImpl extends A
      * 
      * @return an immutable Collection of Modification instances.
      */
-    public Collection<Modification> getModificationItems()
+    public Collection<Modification> getModifications()
     {
         return Collections.unmodifiableCollection( mods );
     }
@@ -101,8 +137,7 @@ public class ModifyRequestImpl extends A
      * Sets the distinguished name of the entry to be modified by this request.
      * This property represents the PDU's <b>object</b> field.
      * 
-     * @param name
-     *            the DN of the modified entry.
+     * @param name the DN of the modified entry.
      */
     public void setName( DN name )
     {
@@ -122,6 +157,161 @@ public class ModifyRequestImpl extends A
     }
 
 
+    private void addModification( ModificationOperation modOp, String attributeName, byte[]... attributeValue )
+    {
+        EntryAttribute attr = new DefaultEntryAttribute( attributeName, attributeValue );
+        addModification( attr, modOp );
+    }
+
+
+    private void addModification( ModificationOperation modOp, String attributeName, String... attributeValue )
+    {
+        EntryAttribute attr = new DefaultEntryAttribute( attributeName, attributeValue );
+        addModification( attr, modOp );
+    }
+
+
+    public void addModification( EntryAttribute attr, ModificationOperation modOp )
+    {
+        mods.add( new DefaultModification( modOp, attr ) );
+    }
+
+
+    /**
+     *
+     * marks a given attribute for addition in the target entry with the
+     * given values.
+     *
+     * @param attributeName name of the attribute to be added
+     * @param attributeValue values of the attribute
+     */
+    public void add( String attributeName, String... attributeValue )
+    {
+        addModification( ModificationOperation.ADD_ATTRIBUTE, attributeName, attributeValue );
+    }
+
+
+    /**
+     * @see #add(String, String...)
+     */
+    public void add( String attributeName, byte[]... attributeValue )
+    {
+        addModification( ModificationOperation.ADD_ATTRIBUTE, attributeName, attributeValue );
+    }
+
+
+    /**
+     *
+     * marks a given attribute for addition in the target entry.
+     *
+     * @param attr the attribute to be added
+     */
+    public void add( EntryAttribute attr )
+    {
+        addModification( attr, ModificationOperation.ADD_ATTRIBUTE );
+    }
+
+
+    /**
+     * @see #replace(String, String...)
+     */
+    public void replace( String attributeName )
+    {
+        addModification( ModificationOperation.REPLACE_ATTRIBUTE, attributeName, StringTools.EMPTY_STRINGS );
+    }
+
+
+    /**
+     *
+     * marks a given attribute for replacement with the given
+     * values in the target entry.
+     *
+     * @param attributeName name of the attribute to be added
+     * @param attributeValue values of the attribute
+     */
+    public void replace( String attributeName, String... attributeValue )
+    {
+        addModification( ModificationOperation.REPLACE_ATTRIBUTE, attributeName, attributeValue );
+    }
+
+
+    /**
+     * @see #replace(String, String...)
+     */
+    public void replace( String attributeName, byte[]... attributeValue )
+    {
+        addModification( ModificationOperation.REPLACE_ATTRIBUTE, attributeName, attributeValue );
+    }
+
+
+    /**
+     *
+     * marks a given attribute for replacement in the target entry.
+     *
+     * @param attr the attribute to be added
+     */
+    public void replace( EntryAttribute attr )
+    {
+        addModification( attr, ModificationOperation.REPLACE_ATTRIBUTE );
+    }
+
+
+    /**
+     * Store the current operation
+     * 
+     * @param currentOperation The currentOperation to set.
+     */
+    public void setCurrentOperation( int currentOperation )
+    {
+        this.currentOperation = ModificationOperation.getOperation( currentOperation );
+    }
+
+
+    /**
+     * Add a new attributeTypeAndValue
+     * 
+     * @param type The attribute's name
+     */
+    public void addAttributeTypeAndValues( String type )
+    {
+        currentAttribute = new DefaultEntryAttribute( type );
+
+        Modification modification = new DefaultModification( currentOperation, currentAttribute );
+        mods.add( modification );
+    }
+
+
+    /**
+     * Return the current attribute's type
+     */
+    public String getCurrentAttributeType()
+    {
+        return currentAttribute.getId();
+    }
+
+
+    /**
+     * Add a new value to the current attribute
+     * 
+     * @param value The value to add
+     */
+    public void addAttributeValue( byte[] value )
+    {
+        currentAttribute.add( value );
+    }
+
+
+    /**
+     * Add a new value to the current attribute
+     * 
+     * @param value The value to add
+     */
+    public void addAttributeValue( String value )
+    {
+        currentAttribute.add( value );
+    }
+
+
     /**
      * Removes a Modification to the set of modifications composing this
      * modify request.
@@ -134,6 +324,39 @@ public class ModifyRequestImpl extends A
     }
 
 
+    /**
+     * marks a given attribute for removal with the given
+     * values from the target entry.
+     *
+     * @param attributeName name of the attribute to be added
+     * @param attributeValue values of the attribute
+     */
+    public void remove( String attributeName, String... attributeValue )
+    {
+        addModification( ModificationOperation.REMOVE_ATTRIBUTE, attributeName, attributeValue );
+    }
+
+
+    /**
+     * @see #remove(String, String...)
+     */
+    public void remove( String attributeName, byte[]... attributeValue )
+    {
+        addModification( ModificationOperation.REMOVE_ATTRIBUTE, attributeName, attributeValue );
+    }
+
+
+    /**
+     * marks a given attribute for removal from the target entry.
+     *
+     * @param attr the attribute to be added
+     */
+    public void remove( EntryAttribute attr )
+    {
+        addModification( attr, ModificationOperation.REMOVE_ATTRIBUTE );
+    }
+
+
     // ------------------------------------------------------------------------
     // SingleReplyRequest Interface Method Implementations
     // ------------------------------------------------------------------------
@@ -167,6 +390,101 @@ public class ModifyRequestImpl extends A
 
 
     /**
+     * @return The encoded ModifyRequest's length
+     */
+    /* No Qualifier*/void setModifyRequestLength( int modifyRequestLength )
+    {
+        this.modifyRequestLength = modifyRequestLength;
+    }
+
+
+    /**
+     * Stores the encoded length for the ModifyRequest
+     * @param modifyRequestLength The encoded length
+     */
+    /* No Qualifier*/int getModifyRequestLength()
+    {
+        return modifyRequestLength;
+    }
+
+
+    /**
+     * @return The encoded Changes length
+     */
+    /* No Qualifier*/void setChangesLength( int changesLength )
+    {
+        this.changesLength = changesLength;
+    }
+
+
+    /**
+     * Stores the encoded length for the Changes
+     * @param changesLength The encoded length
+     */
+    /* No Qualifier*/int getChangesLength()
+    {
+        return changesLength;
+    }
+
+
+    /**
+     * @return The list of encoded Change length
+     */
+    /* No Qualifier*/void setChangeLength( List<Integer> changeLength )
+    {
+        this.changeLength = changeLength;
+    }
+
+
+    /**
+     * Stores the list of encoded change length
+     * @param changeLength The list of encoded Change length
+     */
+    /* No Qualifier*/List<Integer> getChangeLength()
+    {
+        return changeLength;
+    }
+
+
+    /**
+     * @return The list of encoded Modification length
+     */
+    /* No Qualifier*/void setModificationLength( List<Integer> modificationLength )
+    {
+        this.modificationLength = modificationLength;
+    }
+
+
+    /**
+     * Stores the list of encoded modification length
+     * @param modificationLength The list of encoded Modification length
+     */
+    /* No Qualifier*/List<Integer> getModificationLength()
+    {
+        return modificationLength;
+    }
+
+
+    /**
+     * @return The list of encoded Values length
+     */
+    /* No Qualifier*/void setValuesLength( List<Integer> valuesLength )
+    {
+        this.valuesLength = valuesLength;
+    }
+
+
+    /**
+     * Stores the list of encoded Values length
+     * @param valuesLength The list of encoded Values length
+     */
+    /* No Qualifier*/List<Integer> getValuesLength()
+    {
+        return valuesLength;
+    }
+
+
+    /**
      * {@inheritDoc}
      */
     @Override
@@ -225,12 +543,12 @@ public class ModifyRequestImpl extends A
             return false;
         }
 
-        if ( req.getModificationItems().size() != mods.size() )
+        if ( req.getModifications().size() != mods.size() )
         {
             return false;
         }
 
-        Iterator<Modification> list = req.getModificationItems().iterator();
+        Iterator<Modification> list = req.getModifications().iterator();
 
         for ( int i = 0; i < mods.size(); i++ )
         {
@@ -299,6 +617,9 @@ public class ModifyRequestImpl extends A
             }
         }
 
+        // The controls
+        sb.append( super.toString() );
+
         return sb.toString();
     }
 }

Modified: directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/internal/InternalModifyRequest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/internal/InternalModifyRequest.java?rev=986083&r1=986082&r2=986083&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/internal/InternalModifyRequest.java (original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/internal/InternalModifyRequest.java Mon Aug 16 18:11:21 2010
@@ -23,7 +23,9 @@ package org.apache.directory.shared.ldap
 import java.util.Collection;
 
 import org.apache.directory.shared.ldap.codec.MessageTypeEnum;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
 import org.apache.directory.shared.ldap.entry.Modification;
+import org.apache.directory.shared.ldap.entry.ModificationOperation;
 import org.apache.directory.shared.ldap.message.SingleReplyRequest;
 import org.apache.directory.shared.ldap.name.DN;
 
@@ -130,7 +132,7 @@ public interface InternalModifyRequest e
      * 
      * @return an immutable Collection of Modification instances.
      */
-    Collection<Modification> getModificationItems();
+    Collection<Modification> getModifications();
 
 
     /**
@@ -149,4 +151,87 @@ public interface InternalModifyRequest e
      * @param mod a Modification to remove.
      */
     void removeModification( Modification mod );
+
+
+    /**
+     *
+     * marks a given attribute for removal with the given
+     * values from the target entry.
+     *
+     * @param attributeName name of the attribute to be added
+     * @param attributeValue values of the attribute
+     */
+    void remove( String attributeName, String... attributeValue );
+
+
+    /**
+     * @see #remove(String, String...)
+     */
+    void remove( String attributeName, byte[]... attributeValue );
+
+
+    /**
+     *
+     * marks a given attribute for removal from the target entry.
+     *
+     * @param attr the attribute to be added
+     */
+    void remove( EntryAttribute attr );
+
+
+    void addModification( EntryAttribute attr, ModificationOperation modOp );
+
+
+    /**
+     * marks a given attribute for addition in the target entry with the
+     * given values.
+     *
+     * @param attributeName name of the attribute to be added
+     * @param attributeValue values of the attribute
+     */
+    void add( String attributeName, String... attributeValue );
+
+
+    /**
+     * @see #add(String, String...)
+     */
+    void add( String attributeName, byte[]... attributeValue );
+
+
+    /**
+     * marks a given attribute for addition in the target entry.
+     *
+     * @param attr the attribute to be added
+     */
+    void add( EntryAttribute attr );
+
+
+    /**
+     * @see #replace(String, String...)
+     */
+    void replace( String attributeName );
+
+
+    /**
+     * marks a given attribute for replacement with the given
+     * values in the target entry.
+     *
+     * @param attributeName name of the attribute to be added
+     * @param attributeValue values of the attribute
+     */
+    void replace( String attributeName, String... attributeValue );
+
+
+    /**
+     * @see #replace(String, String...)
+     */
+    void replace( String attributeName, byte[]... attributeValue );
+
+
+    /**
+     * marks a given attribute for replacement in the target entry.
+     *
+     * @param attr the attribute to be added
+     */
+    void replace( EntryAttribute attr );
 }

Modified: directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/modify/ModifyRequestTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/modify/ModifyRequestTest.java?rev=986083&r1=986082&r2=986083&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/modify/ModifyRequestTest.java (original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/modify/ModifyRequestTest.java Mon Aug 16 18:11:21 2010
@@ -25,7 +25,8 @@ import static org.junit.Assert.assertTru
 import static org.junit.Assert.fail;
 
 import java.nio.ByteBuffer;
-import java.util.List;
+import java.util.Collection;
+import java.util.Map;
 
 import org.apache.directory.junit.tools.Concurrent;
 import org.apache.directory.junit.tools.ConcurrentJunitRunner;
@@ -33,16 +34,17 @@ import org.apache.directory.shared.asn1.
 import org.apache.directory.shared.asn1.ber.IAsn1Container;
 import org.apache.directory.shared.asn1.codec.DecoderException;
 import org.apache.directory.shared.asn1.codec.EncoderException;
-import org.apache.directory.shared.ldap.codec.LdapMessageCodec;
 import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
 import org.apache.directory.shared.ldap.codec.ResponseCarryingException;
 import org.apache.directory.shared.ldap.entry.EntryAttribute;
 import org.apache.directory.shared.ldap.entry.Modification;
 import org.apache.directory.shared.ldap.exception.LdapException;
+import org.apache.directory.shared.ldap.message.LdapProtocolEncoder;
 import org.apache.directory.shared.ldap.message.ModifyResponseImpl;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.message.control.Control;
 import org.apache.directory.shared.ldap.message.internal.InternalMessage;
+import org.apache.directory.shared.ldap.message.internal.InternalModifyRequest;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -57,6 +59,10 @@ import org.junit.runner.RunWith;
 @Concurrent()
 public class ModifyRequestTest
 {
+    /** The encoder instance */
+    LdapProtocolEncoder encoder = new LdapProtocolEncoder();
+
+
     /**
      * Test the decoding of a ModifyRequest
      */
@@ -68,39 +74,37 @@ public class ModifyRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x54 );
 
         stream.put( new byte[]
-            {
-            0x30, 0x52,                 // LDAPMessage ::= SEQUENCE {
-              0x02, 0x01, 0x01,         // messageID MessageID
-              0x66, 0x4d,               // CHOICE { ..., modifyRequest ModifyRequest, ...
-                                        // ModifyRequest ::= [APPLICATION 6] SEQUENCE {
-                                        // object LDAPDN,
-                0x04, 0x20, 
-                  'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
-                  's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm', 0x30, 0x29, 
-                                        // modification SEQUENCE OF SEQUENCE {
-                0x30, 0x11, 
-                  0x0A, 0x01, 0x02,     // operation ENUMERATED {
-                                        // add (0),
-                                        // delete (1),
-                                        // replace (2) },
-                                        // modification AttributeTypeAndValues } }
-                  0x30, 0x0c,           // AttributeTypeAndValues ::= SEQUENCE {
-                    0x04, 0x01, 'l',    // type AttributeDescription,
-                    0x31, 0x07,         // vals SET OF AttributeValue }
-                      0x04, 0x05, 'P', 'a', 'r', 'i', 's',
-
-                0x30, 0x14,             // modification SEQUENCE OF *SEQUENCE* {
-                  0x0A, 0x01, 0x00,     // operation ENUMERATED {
-                                        // add (0),
-                                        // delete (1),
-                                        // replace (2) },
-                                        // modification AttributeTypeAndValues } }
-                  0x30, 0x0f,           // AttributeTypeAndValues ::= SEQUENCE {
-                                        // type AttributeDescription,
-                    0x04, 0x05, 'a', 't', 't', 'r', 's', 
-                    0x31, 0x06,         // vals SET OF AttributeValue }
-                      0x04, 0x04, 't', 'e', 's', 't' 
-            } );
+            { 0x30,
+                0x52, // LDAPMessage ::= SEQUENCE {
+                0x02, 0x01,
+                0x01, // messageID MessageID
+                0x66,
+                0x4d, // CHOICE { ..., modifyRequest ModifyRequest, ...
+                // ModifyRequest ::= [APPLICATION 6] SEQUENCE {
+                // object LDAPDN,
+                0x04, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
+                's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm', 0x30, 0x29,
+                // modification SEQUENCE OF SEQUENCE {
+                0x30, 0x11, 0x0A, 0x01, 0x02, // operation ENUMERATED {
+                // add (0),
+                // delete (1),
+                // replace (2) },
+                // modification AttributeTypeAndValues } }
+                0x30, 0x0c, // AttributeTypeAndValues ::= SEQUENCE {
+                0x04, 0x01, 'l', // type AttributeDescription,
+                0x31, 0x07, // vals SET OF AttributeValue }
+                0x04, 0x05, 'P', 'a', 'r', 'i', 's',
+
+                0x30, 0x14, // modification SEQUENCE OF *SEQUENCE* {
+                0x0A, 0x01, 0x00, // operation ENUMERATED {
+                // add (0),
+                // delete (1),
+                // replace (2) },
+                // modification AttributeTypeAndValues } }
+                0x30, 0x0f, // AttributeTypeAndValues ::= SEQUENCE {
+                // type AttributeDescription,
+                0x04, 0x05, 'a', 't', 't', 'r', 's', 0x31, 0x06, // vals SET OF AttributeValue }
+                0x04, 0x04, 't', 'e', 's', 't' } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
         stream.flip();
@@ -120,19 +124,19 @@ public class ModifyRequestTest
         }
 
         // Check the decoded PDU
-        ModifyRequestCodec modifyRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getModifyRequest();
+        InternalModifyRequest modifyRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getModifyRequest();
 
         assertEquals( 1, modifyRequest.getMessageId() );
-        assertEquals( "cn=testModify,ou=users,ou=system", modifyRequest.getObject().toString() );
+        assertEquals( "cn=testModify,ou=users,ou=system", modifyRequest.getName().toString() );
 
-        List<Modification> modifications = modifyRequest.getModifications();
+        Collection<Modification> modifications = modifyRequest.getModifications();
 
         assertEquals( 2, modifications.size() );
 
-        for ( Modification modification:modifications )
+        for ( Modification modification : modifications )
         {
-            EntryAttribute attribute =  modification.getAttribute();
-            
+            EntryAttribute attribute = modification.getAttribute();
+
             if ( "l".equalsIgnoreCase( attribute.getId() ) )
             {
                 String attrValue = attribute.getString();
@@ -145,13 +149,13 @@ public class ModifyRequestTest
             }
         }
 
-        // Check the length
-        assertEquals( 0x54, modifyRequest.computeLength() );
-
         // Check the encoding
         try
         {
-            ByteBuffer bb = modifyRequest.encode();
+            ByteBuffer bb = encoder.encodeMessage( modifyRequest );
+
+            // Check the length
+            assertEquals( 0x54, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 
@@ -164,6 +168,7 @@ public class ModifyRequestTest
         }
     }
 
+
     /**
      * Test the decoding of a ModifyRequest
      */
@@ -175,39 +180,37 @@ public class ModifyRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x54 );
 
         stream.put( new byte[]
-            {
-            0x30, 0x52,                 // LDAPMessage ::= SEQUENCE {
-              0x02, 0x01, 0x01,         // messageID MessageID
-              0x66, 0x4d,               // CHOICE { ..., modifyRequest ModifyRequest, ...
-                                        // ModifyRequest ::= [APPLICATION 6] SEQUENCE {
-                                        // object LDAPDN,
-                0x04, 0x20, 
-                  'c', 'n', ':', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
-                  's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm', 0x30, 0x29, 
-                                        // modification SEQUENCE OF SEQUENCE {
-                0x30, 0x11, 
-                  0x0A, 0x01, 0x02,     // operation ENUMERATED {
-                                        // add (0),
-                                        // delete (1),
-                                        // replace (2) },
-                                        // modification AttributeTypeAndValues } }
-                  0x30, 0x0c,           // AttributeTypeAndValues ::= SEQUENCE {
-                    0x04, 0x01, 'l',    // type AttributeDescription,
-                    0x31, 0x07,         // vals SET OF AttributeValue }
-                      0x04, 0x05, 'P', 'a', 'r', 'i', 's',
-
-                0x30, 0x14,             // modification SEQUENCE OF *SEQUENCE* {
-                  0x0A, 0x01, 0x00,     // operation ENUMERATED {
-                                        // add (0),
-                                        // delete (1),
-                                        // replace (2) },
-                                        // modification AttributeTypeAndValues } }
-                  0x30, 0x0f,           // AttributeTypeAndValues ::= SEQUENCE {
-                                        // type AttributeDescription,
-                    0x04, 0x05, 'a', 't', 't', 'r', 's', 
-                    0x31, 0x06,         // vals SET OF AttributeValue }
-                      0x04, 0x04, 't', 'e', 's', 't' 
-            } );
+            { 0x30,
+                0x52, // LDAPMessage ::= SEQUENCE {
+                0x02, 0x01,
+                0x01, // messageID MessageID
+                0x66,
+                0x4d, // CHOICE { ..., modifyRequest ModifyRequest, ...
+                // ModifyRequest ::= [APPLICATION 6] SEQUENCE {
+                // object LDAPDN,
+                0x04, 0x20, 'c', 'n', ':', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
+                's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm', 0x30, 0x29,
+                // modification SEQUENCE OF SEQUENCE {
+                0x30, 0x11, 0x0A, 0x01, 0x02, // operation ENUMERATED {
+                // add (0),
+                // delete (1),
+                // replace (2) },
+                // modification AttributeTypeAndValues } }
+                0x30, 0x0c, // AttributeTypeAndValues ::= SEQUENCE {
+                0x04, 0x01, 'l', // type AttributeDescription,
+                0x31, 0x07, // vals SET OF AttributeValue }
+                0x04, 0x05, 'P', 'a', 'r', 'i', 's',
+
+                0x30, 0x14, // modification SEQUENCE OF *SEQUENCE* {
+                0x0A, 0x01, 0x00, // operation ENUMERATED {
+                // add (0),
+                // delete (1),
+                // replace (2) },
+                // modification AttributeTypeAndValues } }
+                0x30, 0x0f, // AttributeTypeAndValues ::= SEQUENCE {
+                // type AttributeDescription,
+                0x04, 0x05, 'a', 't', 't', 'r', 's', 0x31, 0x06, // vals SET OF AttributeValue }
+                0x04, 0x04, 't', 'e', 's', 't' } );
 
         stream.flip();
 
@@ -222,15 +225,17 @@ public class ModifyRequestTest
         catch ( DecoderException de )
         {
             assertTrue( de instanceof ResponseCarryingException );
-            InternalMessage response = ((ResponseCarryingException)de).getResponse();
+            InternalMessage response = ( ( ResponseCarryingException ) de ).getResponse();
             assertTrue( response instanceof ModifyResponseImpl );
-            assertEquals( ResultCodeEnum.INVALID_DN_SYNTAX, ((ModifyResponseImpl)response).getLdapResult().getResultCode() );
+            assertEquals( ResultCodeEnum.INVALID_DN_SYNTAX, ( ( ModifyResponseImpl ) response ).getLdapResult()
+                .getResultCode() );
             return;
         }
 
         fail( "We should not reach this point" );
     }
 
+
     /**
      * Test the decoding of a ModifyRequest, with different operations
      */
@@ -242,35 +247,34 @@ public class ModifyRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x18C );
 
         stream.put( new byte[]
-            { 
-            0x30, ( byte ) 0x81, ( byte ) 0x89, 
-              0x02, 0x01, 0x15, 
-              0x66, 0x67,               
-                0x04, 0x2B,             // ModifyRequest object : cn=Tori Amos,ou=playground,dc=apache,dc=org
-                  'c', 'n', '=', 'T', 'o', 'r', 'i', ' ', 'A', 'm', 'o', 's', ',', 'o', 'u', 
-                  '=', 'p', 'l', 'a', 'y', 'g', 'r', 'o', 'u', 'n', 'd', ',', 'd', 'c', '=',
-                  'a', 'p', 'a', 'c', 'h', 'e', ',', 'd', 'c', '=', 'o', 'r', 'g',
-                0x30, 0x38,             // Modifications
-                  0x30, 0x24,           // Modification
-                    0x0A, 0x01, 0x00,   // Operation = ADD
-                    0x30, 0x1F,         // type : telephoneNumber
-                      0x04, 0x0F,
-                        't', 'e', 'l', 'e', 'p', 'h', 'o', 'n', 'e', 'N', 'u', 'm', 'b', 'e', 'r',
-                      0x31, 0x0C,         // vals : 1234567890
-                        0x04, 0x0A, 
-                          '1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
-                  0x30, 0x10,           // Modification
-                    0x0A, 0x01, 0x02,   // Operation = REPLACE
-                    0x30, 0x0B,         // type : cn
-                      0x04, 0x02, 'c', 'n', 
-                      0x31, 0x05,       // vals : XXX
-                        0x04, 0x03, 'X', 'X', 'X', 
-              ( byte ) 0xA0, 0x1B,      // Control : 2.16.840.1.113730.3.4.2
-                0x30, 0x19, 
-                  0x04, 0x17,
-                    '2', '.', '1', '6', '.', '8', '4', '0', '.', '1', '.', 
-                    '1', '1', '3', '7', '3', '0', '.', '3', '.', '4', '.', '2'
-            } );
+            { 0x30, ( byte ) 0x81, ( byte ) 0x89, 0x02, 0x01, 0x15, 0x66,
+                0x67,
+                0x04,
+                0x2B, // ModifyRequest object : cn=Tori Amos,ou=playground,dc=apache,dc=org
+                'c', 'n', '=', 'T', 'o', 'r', 'i', ' ', 'A', 'm', 'o', 's', ',', 'o', 'u', '=', 'p', 'l', 'a', 'y',
+                'g', 'r', 'o', 'u', 'n', 'd', ',', 'd', 'c', '=', 'a', 'p', 'a', 'c', 'h', 'e', ',', 'd', 'c', '=',
+                'o', 'r', 'g', 0x30,
+                0x38, // Modifications
+                0x30,
+                0x24, // Modification
+                0x0A, 0x01,
+                0x00, // Operation = ADD
+                0x30,
+                0x1F, // type : telephoneNumber
+                0x04, 0x0F, 't', 'e', 'l', 'e', 'p', 'h', 'o', 'n', 'e', 'N', 'u', 'm', 'b', 'e', 'r', 0x31,
+                0x0C, // vals : 1234567890
+                0x04, 0x0A, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 0x30,
+                0x10, // Modification
+                0x0A, 0x01,
+                0x02, // Operation = REPLACE
+                0x30,
+                0x0B, // type : cn
+                0x04, 0x02, 'c', 'n', 0x31,
+                0x05, // vals : XXX
+                0x04, 0x03, 'X', 'X', 'X', ( byte ) 0xA0,
+                0x1B, // Control : 2.16.840.1.113730.3.4.2
+                0x30, 0x19, 0x04, 0x17, '2', '.', '1', '6', '.', '8', '4', '0', '.', '1', '.', '1', '1', '3', '7', '3',
+                '0', '.', '3', '.', '4', '.', '2' } );
 
         stream.flip();
 
@@ -289,16 +293,16 @@ public class ModifyRequestTest
         }
 
         // Check the decoded PDU
-        ModifyRequestCodec modifyRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getModifyRequest();
+        InternalModifyRequest modifyRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getModifyRequest();
 
         assertEquals( 21, modifyRequest.getMessageId() );
-        assertEquals( "cn=Tori Amos,ou=playground,dc=apache,dc=org", modifyRequest.getObject().toString() );
+        assertEquals( "cn=Tori Amos,ou=playground,dc=apache,dc=org", modifyRequest.getName().toString() );
 
-        List<Modification> modifications = modifyRequest.getModifications();
+        Object[] modifications = modifyRequest.getModifications().toArray();
 
-        assertEquals( 2, modifications.size() );
+        assertEquals( 2, modifications.length );
 
-        Modification modification = modifications.get( 0 );
+        Modification modification = ( Modification ) modifications[0];
         EntryAttribute attributeValue = modification.getAttribute();
 
         assertEquals( "telephonenumber", attributeValue.getId().toLowerCase() );
@@ -306,7 +310,7 @@ public class ModifyRequestTest
         String attrValue = attributeValue.getString();
         assertEquals( "1234567890", attrValue );
 
-        modification = modifications.get( 1 );
+        modification = ( Modification ) modifications[1];
         attributeValue = modification.getAttribute();
 
         assertEquals( "cn", attributeValue.getId().toLowerCase() );
@@ -314,13 +318,14 @@ public class ModifyRequestTest
         attrValue = attributeValue.getString();
         assertEquals( "XXX", attrValue );
 
-        // Check the length
-        assertEquals( 0x8C, modifyRequest.computeLength() );
-
         // Check the encoding, by decoding and re-encoding the result
         try
         {
-            ByteBuffer bb = modifyRequest.encode();
+            ByteBuffer bb = encoder.encodeMessage( modifyRequest );
+
+            // Check the length
+            assertEquals( 0x8C, bb.limit() );
+
             String decodedPdu1 = StringTools.dumpBytes( bb.array() );
 
             try
@@ -333,10 +338,10 @@ public class ModifyRequestTest
                 fail( de.getMessage() );
             }
 
-            LdapMessageCodec message2 = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+            InternalModifyRequest modifyRequest2 = ( ( LdapMessageContainer ) ldapMessageContainer ).getModifyRequest();
 
-            ByteBuffer bb2 = message2.encode();
-            String decodedPdu2 = StringTools.dumpBytes( bb2.array() );
+            bb = encoder.encodeMessage( modifyRequest2 );
+            String decodedPdu2 = StringTools.dumpBytes( bb.array() );
 
             assertEquals( decodedPdu1, decodedPdu2 );
         }
@@ -359,41 +364,50 @@ public class ModifyRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x18C );
 
         stream.put( new byte[]
-            { 
-            0x30, ( byte ) 0x81, ( byte ) 0xB6,     // LdapMessage
-              0x02, 0x01, 0x31,                     // Message ID : 49
-              0x66, ( byte ) 0x81, ( byte ) 0x93,   // ModifyRequest
-                0x04, 0x2B,                         // object : cn=Tori Amos,ou=playground,dc=apache,dc=org
-                  'c', 'n', '=', 'T', 'o', 'r', 'i', ' ', 'A', 'm', 'o', 's', ',', 'o', 'u', 
-                  '=', 'p', 'l', 'a', 'y', 'g', 'r', 'o', 'u', 'n', 'd', ',', 'd', 'c', '=',
-                  'a', 'p', 'a', 'c', 'h', 'e', ',', 'd', 'c', '=', 'o', 'r', 'g',
-                0x30, 0x64,                         // Modifications
-                  0x30, 0x14,                       // Modification
-                    0x0A, 0x01, 0x01,               // Operation : Delete
-                    0x30, 0x0F,                     // type : description
-                      0x04, 0x0B, 
-                        0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6F, 0x6E, 
-                    0x31, 0x00,                     // Vals = null
-                  0x30, 0x25,                       // Modification
-                    0x0A, 0x01, 0x00,               // Operation : Add
-                    0x30, 0x20,                     // type : telephoneNumber
-                      0x04, 0x0F, 
-                        't', 'e', 'l', 'e', 'p', 'h', 'o', 'n', 'e', 'N', 'u', 'm', 'b', 'e', 'r',
-                      0x31, 0x0D,                   // Vals : 01234567890
-                        0x04, 0x0B, '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
-                  0x30, 0x25,                       // Modification
-                    0x0A, 0x01, 0x00,               // Operation : Add
-                    0x30, 0x20,                     // type : telephoneNumber
-                      0x04, 0x0F, 
-                      't', 'e', 'l', 'e', 'p', 'h', 'o', 'n', 'e', 'N', 'u', 'm', 'b', 'e', 'r',
-                      0x31, 0x0D,                   // Vals : 01234567890
-                        0x04, 0x0B, '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 
-              ( byte ) 0xA0, 0x1B,                  // Controls : 2.16.840.1.113730.3.4.2
-                0x30, 0x19, 
-                  0x04, 0x17,
-                    '2', '.', '1', '6', '.', '8', '4', '0', '.', '1', '.', 
-                    '1', '1', '3', '7', '3', '0', '.', '3', '.', '4', '.', '2'
-            } );
+            {
+                0x30,
+                ( byte ) 0x81,
+                ( byte ) 0xB6, // LdapMessage
+                0x02,
+                0x01,
+                0x31, // Message ID : 49
+                0x66,
+                ( byte ) 0x81,
+                ( byte ) 0x93, // ModifyRequest
+                0x04,
+                0x2B, // object : cn=Tori Amos,ou=playground,dc=apache,dc=org
+                'c', 'n', '=', 'T', 'o', 'r', 'i', ' ', 'A', 'm', 'o', 's', ',', 'o', 'u', '=', 'p', 'l', 'a', 'y',
+                'g', 'r', 'o', 'u', 'n', 'd', ',', 'd', 'c', '=', 'a', 'p', 'a', 'c', 'h', 'e', ',', 'd', 'c', '=',
+                'o', 'r', 'g', 0x30,
+                0x64, // Modifications
+                0x30,
+                0x14, // Modification
+                0x0A, 0x01,
+                0x01, // Operation : Delete
+                0x30,
+                0x0F, // type : description
+                0x04, 0x0B, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6F, 0x6E, 0x31,
+                0x00, // Vals = null
+                0x30,
+                0x25, // Modification
+                0x0A, 0x01,
+                0x00, // Operation : Add
+                0x30,
+                0x20, // type : telephoneNumber
+                0x04, 0x0F, 't', 'e', 'l', 'e', 'p', 'h', 'o', 'n', 'e', 'N', 'u', 'm', 'b', 'e', 'r', 0x31,
+                0x0D, // Vals : 01234567890
+                0x04, 0x0B, '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 0x30,
+                0x25, // Modification
+                0x0A, 0x01,
+                0x00, // Operation : Add
+                0x30,
+                0x20, // type : telephoneNumber
+                0x04, 0x0F, 't', 'e', 'l', 'e', 'p', 'h', 'o', 'n', 'e', 'N', 'u', 'm', 'b', 'e', 'r', 0x31,
+                0x0D, // Vals : 01234567890
+                0x04, 0x0B, '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', ( byte ) 0xA0,
+                0x1B, // Controls : 2.16.840.1.113730.3.4.2
+                0x30, 0x19, 0x04, 0x17, '2', '.', '1', '6', '.', '8', '4', '0', '.', '1', '.', '1', '1', '3', '7', '3',
+                '0', '.', '3', '.', '4', '.', '2' } );
 
         stream.flip();
 
@@ -412,22 +426,22 @@ public class ModifyRequestTest
         }
 
         // Check the decoded PDU
-        ModifyRequestCodec modifyRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getModifyRequest();
+        InternalModifyRequest modifyRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getModifyRequest();
 
         assertEquals( 49, modifyRequest.getMessageId() );
-        assertEquals( "cn=Tori Amos,ou=playground,dc=apache,dc=org", modifyRequest.getObject().toString() );
+        assertEquals( "cn=Tori Amos,ou=playground,dc=apache,dc=org", modifyRequest.getName().toString() );
 
-        List<Modification> modifications = modifyRequest.getModifications();
+        Object[] modifications = modifyRequest.getModifications().toArray();
 
-        assertEquals( 3, modifications.size() );
+        assertEquals( 3, modifications.length );
 
-        Modification modification = modifications.get( 0 );
+        Modification modification = ( Modification ) modifications[0];
         EntryAttribute attributeValue = modification.getAttribute();
 
         assertEquals( "description", attributeValue.getId().toLowerCase() );
         assertEquals( 0, attributeValue.size() );
 
-        modification = modifications.get( 1 );
+        modification = ( Modification ) modifications[1];
         attributeValue = modification.getAttribute();
 
         String attrValue = attributeValue.getString();
@@ -436,7 +450,7 @@ public class ModifyRequestTest
 
         assertEquals( "01234567890", attrValue );
 
-        modification = modifications.get( 2 );
+        modification = ( Modification ) modifications[2];
         attributeValue = modification.getAttribute();
 
         attrValue = attributeValue.getString();
@@ -446,13 +460,14 @@ public class ModifyRequestTest
         attrValue = attributeValue.getString();
         assertEquals( "01234567890", attrValue );
 
-        // Check the length
-        assertEquals( 0xB9, modifyRequest.computeLength() );
-
         // Check the encoding, by decoding and re-encoding the result
         try
         {
-            ByteBuffer bb = modifyRequest.encode();
+            ByteBuffer bb = encoder.encodeMessage( modifyRequest );
+
+            // Check the length
+            assertEquals( 0xB9, bb.limit() );
+
             String decodedPdu1 = StringTools.dumpBytes( bb.array() );
 
             try
@@ -465,10 +480,10 @@ public class ModifyRequestTest
                 fail( de.getMessage() );
             }
 
-            LdapMessageCodec message2 = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+            InternalModifyRequest modifyRequest2 = ( ( LdapMessageContainer ) ldapMessageContainer ).getModifyRequest();
 
-            ByteBuffer bb2 = message2.encode();
-            String decodedPdu2 = StringTools.dumpBytes( bb2.array() );
+            bb = encoder.encodeMessage( modifyRequest2 );
+            String decodedPdu2 = StringTools.dumpBytes( bb.array() );
 
             assertEquals( decodedPdu1, decodedPdu2 );
         }
@@ -491,39 +506,34 @@ public class ModifyRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x5C );
 
         stream.put( new byte[]
-            {
-            0x30, 0x5A,                 // LDAPMessage ::= SEQUENCE {
-              0x02, 0x01, 0x01,         // messageID MessageID
-              0x66, 0x55,               // CHOICE { ..., modifyRequest ModifyRequest, ...
-                                        // ModifyRequest ::= [APPLICATION 6] SEQUENCE {
-                                        // object LDAPDN,
-                0x04, 0x20, 
-                  'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
-                  's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm', 
-                0x30, 0x31,             // modification SEQUENCE OF SEQUENCE {
-                  0x30, 0x19, 
-                    0x0A, 0x01, 0x02,   // operation ENUMERATED {
-                                        // add (0),
-                                        // delete (1),
-                                        // replace (2) },
-                                        // modification AttributeTypeAndValues } }
-                    0x30, 0x14,         // AttributeTypeAndValues ::= SEQUENCE {
-                      0x04, 0x01, 'l',  // type AttributeDescription,
-                      0x31, 0x0F,       // vals SET OF AttributeValue }
-                        0x04, 0x05, 'P', 'a', 'r', 'i', 's', 
-                        0x04, 0x06, 'L', 'o', 'n', 'd', 'o', 'n', 
-                  0x30, 0x14,           // modification SEQUENCE OF *SEQUENCE*  {
-                    0x0A, 0x01, 0x00,   // operation ENUMERATED {
-                                        // add (0),
-                                        // delete (1),
-                                        // replace (2) },
-                                        // modification AttributeTypeAndValues } }
-                    0x30, 0x0f,         // AttributeTypeAndValues ::= SEQUENCE {
-                                        // type AttributeDescription,
-                      0x04, 0x05, 'a', 't', 't', 'r', 's', 
-                      0x31, 0x06,       // vals SET OF AttributeValue }
-                        0x04, 0x04, 't', 'e', 's', 't' 
-            } );
+            { 0x30,
+                0x5A, // LDAPMessage ::= SEQUENCE {
+                0x02, 0x01,
+                0x01, // messageID MessageID
+                0x66,
+                0x55, // CHOICE { ..., modifyRequest ModifyRequest, ...
+                // ModifyRequest ::= [APPLICATION 6] SEQUENCE {
+                // object LDAPDN,
+                0x04, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
+                's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm', 0x30, 0x31, // modification SEQUENCE OF SEQUENCE {
+                0x30, 0x19, 0x0A, 0x01, 0x02, // operation ENUMERATED {
+                // add (0),
+                // delete (1),
+                // replace (2) },
+                // modification AttributeTypeAndValues } }
+                0x30, 0x14, // AttributeTypeAndValues ::= SEQUENCE {
+                0x04, 0x01, 'l', // type AttributeDescription,
+                0x31, 0x0F, // vals SET OF AttributeValue }
+                0x04, 0x05, 'P', 'a', 'r', 'i', 's', 0x04, 0x06, 'L', 'o', 'n', 'd', 'o', 'n', 0x30, 0x14, // modification SEQUENCE OF *SEQUENCE*  {
+                0x0A, 0x01, 0x00, // operation ENUMERATED {
+                // add (0),
+                // delete (1),
+                // replace (2) },
+                // modification AttributeTypeAndValues } }
+                0x30, 0x0f, // AttributeTypeAndValues ::= SEQUENCE {
+                // type AttributeDescription,
+                0x04, 0x05, 'a', 't', 't', 'r', 's', 0x31, 0x06, // vals SET OF AttributeValue }
+                0x04, 0x04, 't', 'e', 's', 't' } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
         stream.flip();
@@ -543,16 +553,16 @@ public class ModifyRequestTest
         }
 
         // Check the decoded PDU
-        ModifyRequestCodec modifyRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getModifyRequest();
+        InternalModifyRequest modifyRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getModifyRequest();
 
         assertEquals( 1, modifyRequest.getMessageId() );
-        assertEquals( "cn=testModify,ou=users,ou=system", modifyRequest.getObject().toString() );
+        assertEquals( "cn=testModify,ou=users,ou=system", modifyRequest.getName().toString() );
 
-        List<Modification> modifications = modifyRequest.getModifications();
+        Object[] modifications = modifyRequest.getModifications().toArray();
 
-        assertEquals( 2, modifications.size() );
+        assertEquals( 2, modifications.length );
 
-        Modification modification = modifications.get( 0 );
+        Modification modification = ( Modification ) modifications[0];
         EntryAttribute attributeValue = modification.getAttribute();
 
         assertEquals( "l", attributeValue.getId().toLowerCase() );
@@ -563,7 +573,7 @@ public class ModifyRequestTest
         attrValue = attributeValue.get( 1 ).getString();
         assertEquals( "London", attrValue );
 
-        modification = modifications.get( 1 );
+        modification = ( Modification ) modifications[1];
         attributeValue = modification.getAttribute();
 
         assertEquals( "attrs", attributeValue.getId().toLowerCase() );
@@ -571,13 +581,13 @@ public class ModifyRequestTest
         attrValue = attributeValue.getString();
         assertEquals( "test", attrValue );
 
-        // Check the length
-        assertEquals( 0x5C, modifyRequest.computeLength() );
-
         // Check the encoding
         try
         {
-            ByteBuffer bb = modifyRequest.encode();
+            ByteBuffer bb = encoder.encodeMessage( modifyRequest );
+
+            // Check the length
+            assertEquals( 0x5C, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 
@@ -604,10 +614,9 @@ public class ModifyRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x07 );
 
         stream.put( new byte[]
-            { 
-            0x30, 0x05,                 // LdapMessage
-              0x02, 0x01, 0x31,         // Message ID : 49
-              0x66, 0x00                // ModifyRequest
+            { 0x30, 0x05, // LdapMessage
+                0x02, 0x01, 0x31, // Message ID : 49
+                0x66, 0x00 // ModifyRequest
             } );
 
         stream.flip();
@@ -639,12 +648,10 @@ public class ModifyRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x09 );
 
         stream.put( new byte[]
-            { 
-            0x30, 0x07,                 // LdapMessage
-              0x02, 0x01, 0x31,         // Message ID : 49
-              0x66, 0x02,               // ModifyRequest
-                0x04, 0x00 
-            } );
+            { 0x30, 0x07, // LdapMessage
+                0x02, 0x01, 0x31, // Message ID : 49
+                0x66, 0x02, // ModifyRequest
+                0x04, 0x00 } );
 
         stream.flip();
 
@@ -675,14 +682,14 @@ public class ModifyRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x29 );
 
         stream.put( new byte[]
-            { 
-            0x30, 0x27,                 // LdapMessage
-              0x02, 0x01, 0x31,         // Message ID : 49
-              0x66, 0x22,               // ModifyRequest
-                0x04, 0x20, 
-                  'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
-                  's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm' 
-            } );
+            { 0x30,
+                0x27, // LdapMessage
+                0x02, 0x01,
+                0x31, // Message ID : 49
+                0x66,
+                0x22, // ModifyRequest
+                0x04, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
+                's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm' } );
 
         stream.flip();
 
@@ -713,15 +720,14 @@ public class ModifyRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x2B );
 
         stream.put( new byte[]
-            { 
-            0x30, 0x29,                 // LdapMessage
-              0x02, 0x01, 0x31,         // Message ID : 49
-              0x66, 0x24,               // ModifyRequest
-                0x04, 0x20, 
-                  'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
-                  's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm', 
-                0x30, 0x00 
-            } );
+            { 0x30,
+                0x29, // LdapMessage
+                0x02, 0x01,
+                0x31, // Message ID : 49
+                0x66,
+                0x24, // ModifyRequest
+                0x04, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
+                's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm', 0x30, 0x00 } );
 
         stream.flip();
 
@@ -752,16 +758,14 @@ public class ModifyRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x2D );
 
         stream.put( new byte[]
-            { 
-            0x30, 0x2B,                 // LdapMessage
-              0x02, 0x01, 0x31,         // Message ID : 49
-              0x66, 0x26,               // ModifyRequest
-                0x04, 0x20, 
-                  'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
-                  's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm', 
-                0x30, 0x02, 
-                  0x30, 0x00 
-            } );
+            { 0x30,
+                0x2B, // LdapMessage
+                0x02, 0x01,
+                0x31, // Message ID : 49
+                0x66,
+                0x26, // ModifyRequest
+                0x04, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
+                's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm', 0x30, 0x02, 0x30, 0x00 } );
 
         stream.flip();
 
@@ -792,17 +796,17 @@ public class ModifyRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x2F );
 
         stream.put( new byte[]
-            { 
-            0x30, 0x2D,                 // LdapMessage
-              0x02, 0x01, 0x31,         // Message ID : 49
-              0x66, 0x28,               // ModifyRequest
-                0x04, 0x20, 
-                  'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
-                  's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm', 
-                0x30, 0x04, 
-                  0x30, 0x02, 
-                    0x0A, 0x00 
-            } );
+            {
+                0x30,
+                0x2D, // LdapMessage
+                0x02,
+                0x01,
+                0x31, // Message ID : 49
+                0x66,
+                0x28, // ModifyRequest
+                0x04, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
+                's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm', 0x30, 0x04, 0x30, 0x02, 0x0A,
+                0x00 } );
 
         stream.flip();
 
@@ -833,17 +837,17 @@ public class ModifyRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x30 );
 
         stream.put( new byte[]
-            { 
-            0x30, 0x2E,                 // LdapMessage
-              0x02, 0x01, 0x31,         // Message ID : 49
-              0x66, 0x29,               // ModifyRequest
-                0x04, 0x20, 
-                  'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
-                  's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm', 
-                0x30, 0x05, 
-                  0x30, 0x03, 
-                    0x0A, 0x01, 0x04 
-            } );
+            {
+                0x30,
+                0x2E, // LdapMessage
+                0x02,
+                0x01,
+                0x31, // Message ID : 49
+                0x66,
+                0x29, // ModifyRequest
+                0x04, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
+                's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm', 0x30, 0x05, 0x30, 0x03, 0x0A,
+                0x01, 0x04 } );
 
         stream.flip();
 
@@ -875,17 +879,17 @@ public class ModifyRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x30 );
 
         stream.put( new byte[]
-            { 
-            0x30, 0x2E,                 // LdapMessage
-              0x02, 0x01, 0x31,         // Message ID : 49
-              0x66, 0x29,               // ModifyRequest
-                0x04, 0x20, 
-                  'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
-                  's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm', 
-                0x30, 0x05, 
-                  0x30, 0x03, 
-                    0x0A, 0x01, 0x00 
-            } );
+            {
+                0x30,
+                0x2E, // LdapMessage
+                0x02,
+                0x01,
+                0x31, // Message ID : 49
+                0x66,
+                0x29, // ModifyRequest
+                0x04, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
+                's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm', 0x30, 0x05, 0x30, 0x03, 0x0A,
+                0x01, 0x00 } );
 
         stream.flip();
 
@@ -917,18 +921,17 @@ public class ModifyRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x32 );
 
         stream.put( new byte[]
-            { 
-            0x30, 0x30,                 // LdapMessage
-              0x02, 0x01, 0x31,         // Message ID : 49
-              0x66, 0x2B,               // ModifyRequest
-                0x04, 0x20, 
-                  'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
-                  's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm', 
-                0x30, 0x07, 
-                  0x30, 0x05, 
-                    0x0A, 0x01, 0x00, 
-                  0x30, 0x00 
-            } );
+            {
+                0x30,
+                0x30, // LdapMessage
+                0x02,
+                0x01,
+                0x31, // Message ID : 49
+                0x66,
+                0x2B, // ModifyRequest
+                0x04, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
+                's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm', 0x30, 0x07, 0x30, 0x05, 0x0A,
+                0x01, 0x00, 0x30, 0x00 } );
 
         stream.flip();
 
@@ -960,19 +963,17 @@ public class ModifyRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x34 );
 
         stream.put( new byte[]
-            { 
-            0x30, 0x32,                 // LdapMessage
-              0x02, 0x01, 0x31,         // Message ID : 49
-              0x66, 0x2D,               // ModifyRequest
-                0x04, 0x20, 
-                  'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
-                  's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm', 
-                0x30, 0x09, 
-                  0x30, 0x07, 
-                    0x0A, 0x01, 0x00, 
-                    0x30, 0x02, 
-                      0x04, 0x00 
-            } );
+            {
+                0x30,
+                0x32, // LdapMessage
+                0x02,
+                0x01,
+                0x31, // Message ID : 49
+                0x66,
+                0x2D, // ModifyRequest
+                0x04, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
+                's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm', 0x30, 0x09, 0x30, 0x07, 0x0A,
+                0x01, 0x00, 0x30, 0x02, 0x04, 0x00 } );
 
         stream.flip();
 
@@ -988,9 +989,10 @@ public class ModifyRequestTest
         catch ( DecoderException de )
         {
             assertTrue( de instanceof ResponseCarryingException );
-            InternalMessage response = ((ResponseCarryingException)de).getResponse();
+            InternalMessage response = ( ( ResponseCarryingException ) de ).getResponse();
             assertTrue( response instanceof ModifyResponseImpl );
-            assertEquals( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, ((ModifyResponseImpl)response).getLdapResult().getResultCode() );
+            assertEquals( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, ( ( ModifyResponseImpl ) response ).getLdapResult()
+                .getResultCode() );
             return;
         }
     }
@@ -1008,19 +1010,17 @@ public class ModifyRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x35 );
 
         stream.put( new byte[]
-            { 
-            0x30, 0x33,                 // LdapMessage
-              0x02, 0x01, 0x31,         // Message ID : 49
-              0x66, 0x2E,               // ModifyRequest
-                0x04, 0x20, 
-                  'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
-                  's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm', 
-                0x30, 0x0A, 
-                  0x30, 0x08, 
-                    0x0A, 0x01, 0x00, 
-                    0x30, 0x03, 
-                    0x04, 0x01, 'l' 
-            } );
+            {
+                0x30,
+                0x33, // LdapMessage
+                0x02,
+                0x01,
+                0x31, // Message ID : 49
+                0x66,
+                0x2E, // ModifyRequest
+                0x04, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
+                's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm', 0x30, 0x0A, 0x30, 0x08, 0x0A,
+                0x01, 0x00, 0x30, 0x03, 0x04, 0x01, 'l' } );
 
         stream.flip();
 
@@ -1052,20 +1052,17 @@ public class ModifyRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x37 );
 
         stream.put( new byte[]
-            { 
-            0x30, 0x35,                 // LdapMessage
-              0x02, 0x01, 0x31,         // Message ID : 49
-              0x66, 0x30,               // ModifyRequest
-                0x04, 0x20, 
-                  'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
-                  's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm', 
-                0x30, 0x0C, 
-                  0x30, 0x0A, 
-                    0x0A, 0x01, 0x00, 
-                    0x30, 0x05, 
-                      0x04, 0x01, 'l', 
-                      0x31, 0x00 
-            } );
+            {
+                0x30,
+                0x35, // LdapMessage
+                0x02,
+                0x01,
+                0x31, // Message ID : 49
+                0x66,
+                0x30, // ModifyRequest
+                0x04, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
+                's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm', 0x30, 0x0C, 0x30, 0x0A, 0x0A,
+                0x01, 0x00, 0x30, 0x05, 0x04, 0x01, 'l', 0x31, 0x00 } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
         stream.flip();
@@ -1085,28 +1082,28 @@ public class ModifyRequestTest
         }
 
         // Check the decoded PDU
-        ModifyRequestCodec modifyRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getModifyRequest();
+        InternalModifyRequest modifyRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getModifyRequest();
 
         assertEquals( 49, modifyRequest.getMessageId() );
-        assertEquals( "cn=testModify,ou=users,ou=system", modifyRequest.getObject().toString() );
+        assertEquals( "cn=testModify,ou=users,ou=system", modifyRequest.getName().toString() );
 
-        List<Modification> modifications = modifyRequest.getModifications();
+        Object[] modifications = modifyRequest.getModifications().toArray();
 
-        assertEquals( 1, modifications.size() );
+        assertEquals( 1, modifications.length );
 
-        Modification modification = modifications.get( 0 );
+        Modification modification = ( Modification ) modifications[0];
         EntryAttribute attributeValue = modification.getAttribute();
 
         assertEquals( "l", attributeValue.getId().toLowerCase() );
         assertEquals( 0, attributeValue.size() );
 
-        // Check the length
-        assertEquals( 0x37, modifyRequest.computeLength() );
-
         // Check the encoding
         try
         {
-            ByteBuffer bb = modifyRequest.encode();
+            ByteBuffer bb = encoder.encodeMessage( modifyRequest );
+
+            // Check the length
+            assertEquals( 0x37, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 
@@ -1132,23 +1129,20 @@ public class ModifyRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x54 );
 
         stream.put( new byte[]
-            { 
-            0x30, 0x52,                 // LdapMessage
-              0x02, 0x01, 0x31,         // Message ID : 49
-              0x66, 0x30,               // ModifyRequest
-                0x04, 0x20, 
-                  'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
-                  's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm', 
-                0x30, 0x0C, 
-                  0x30, 0x0A, 
-                    0x0A, 0x01, 0x00, 
-                    0x30, 0x05, 
-                      0x04, 0x01, 'l', 
-                      0x31, 0x00, 
-              ( byte ) 0xA0, 0x1B,      // A control
+            {
+                0x30,
+                0x52, // LdapMessage
+                0x02,
+                0x01,
+                0x31, // Message ID : 49
+                0x66,
+                0x30, // ModifyRequest
+                0x04, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
+                's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm', 0x30, 0x0C, 0x30, 0x0A, 0x0A,
+                0x01, 0x00, 0x30, 0x05, 0x04, 0x01, 'l', 0x31, 0x00, ( byte ) 0xA0,
+                0x1B, // A control
                 0x30, 0x19, 0x04, 0x17, 0x32, 0x2E, 0x31, 0x36, 0x2E, 0x38, 0x34, 0x30, 0x2E, 0x31, 0x2E, 0x31, 0x31,
-                0x33, 0x37, 0x33, 0x30, 0x2E, 0x33, 0x2E, 0x34, 0x2E, 0x32 
-            } );
+                0x33, 0x37, 0x33, 0x30, 0x2E, 0x33, 0x2E, 0x34, 0x2E, 0x32 } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
         stream.flip();
@@ -1168,37 +1162,37 @@ public class ModifyRequestTest
         }
 
         // Check the decoded PDU
-        ModifyRequestCodec modifyRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getModifyRequest();
+        InternalModifyRequest modifyRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getModifyRequest();
 
         assertEquals( 49, modifyRequest.getMessageId() );
-        assertEquals( "cn=testModify,ou=users,ou=system", modifyRequest.getObject().toString() );
+        assertEquals( "cn=testModify,ou=users,ou=system", modifyRequest.getName().toString() );
 
-        List<Modification> modifications = modifyRequest.getModifications();
+        Object[] modifications = modifyRequest.getModifications().toArray();
 
-        assertEquals( 1, modifications.size() );
+        assertEquals( 1, modifications.length );
 
-        Modification modification = modifications.get( 0 );
+        Modification modification = ( Modification ) modifications[0];
         EntryAttribute attributeValue = modification.getAttribute();
 
         assertEquals( "l", attributeValue.getId().toLowerCase() );
         assertEquals( 0, attributeValue.size() );
 
         // Check the Control
-        List<Control> controls = modifyRequest.getControls();
+        Map<String, Control> controls = modifyRequest.getControls();
 
         assertEquals( 1, controls.size() );
 
-        Control control = modifyRequest.getControls( 0 );
+        Control control = modifyRequest.getControl( "2.16.840.1.113730.3.4.2" );
         assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() );
         assertEquals( "", StringTools.dumpBytes( ( byte[] ) control.getValue() ) );
 
-        // Check the length
-        assertEquals( 0x54, modifyRequest.computeLength() );
-
         // Check the encoding
         try
         {
-            ByteBuffer bb = modifyRequest.encode();
+            ByteBuffer bb = encoder.encodeMessage( modifyRequest );
+
+            // Check the length
+            assertEquals( 0x54, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 
@@ -1224,22 +1218,17 @@ public class ModifyRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x3D );
 
         stream.put( new byte[]
-            { 
-            0x30, 0x3B,                 // LdapMessage
-              0x02, 0x01, 0x31,         // Message ID : 49
-              0x66, 0x36,               // ModifyRequest
-                0x04, 0x20, 
-                  'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
-                  's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm', 
-                0x30, 0x12, 
-                  0x30, 0x10, 
-                    0x0A, 0x01, 0x00, 
-                    0x30, 0x0B, 
-                      0x04, 0x01, 'l', 
-                      0x31, 0x06, 
-                        0x04, 0x01, 'a', 
-                        0x04, 0x01, 'b' 
-            } );
+            {
+                0x30,
+                0x3B, // LdapMessage
+                0x02,
+                0x01,
+                0x31, // Message ID : 49
+                0x66,
+                0x36, // ModifyRequest
+                0x04, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
+                's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm', 0x30, 0x12, 0x30, 0x10, 0x0A,
+                0x01, 0x00, 0x30, 0x0B, 0x04, 0x01, 'l', 0x31, 0x06, 0x04, 0x01, 'a', 0x04, 0x01, 'b' } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
         stream.flip();
@@ -1259,16 +1248,16 @@ public class ModifyRequestTest
         }
 
         // Check the decoded PDU
-        ModifyRequestCodec modifyRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getModifyRequest();
+        InternalModifyRequest modifyRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getModifyRequest();
 
         assertEquals( 49, modifyRequest.getMessageId() );
-        assertEquals( "cn=testModify,ou=users,ou=system", modifyRequest.getObject().toString() );
+        assertEquals( "cn=testModify,ou=users,ou=system", modifyRequest.getName().toString() );
 
-        List<Modification> modifications = modifyRequest.getModifications();
+        Object[] modifications = modifyRequest.getModifications().toArray();
 
-        assertEquals( 1, modifications.size() );
+        assertEquals( 1, modifications.length );
 
-        Modification modification = modifications.get( 0 );
+        Modification modification = ( Modification ) modifications[0];
         EntryAttribute attributeValue = modification.getAttribute();
 
         assertEquals( "l", attributeValue.getId().toLowerCase() );
@@ -1280,13 +1269,13 @@ public class ModifyRequestTest
         attrValue = attributeValue.get( 1 ).getString();
         assertEquals( "b", attrValue );
 
-        // Check the length
-        assertEquals( 0x3D, modifyRequest.computeLength() );
-
         // Check the encoding
         try
         {
-            ByteBuffer bb = modifyRequest.encode();
+            ByteBuffer bb = encoder.encodeMessage( modifyRequest );
+
+            // Check the length
+            assertEquals( 0x3D, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 

Modified: directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/ModifyRequestImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/ModifyRequestImplTest.java?rev=986083&r1=986082&r2=986083&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/ModifyRequestImplTest.java (original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/ModifyRequestImplTest.java Mon Aug 16 18:11:21 2010
@@ -290,7 +290,7 @@ public class ModifyRequestImplTest
     {
         InternalModifyRequest req0 = new InternalModifyRequest()
         {
-            public Collection<Modification> getModificationItems()
+            public Collection<Modification> getModifications()
             {
                 List<Modification> list = new ArrayList<Modification>();
                 EntryAttribute attr = new DefaultEntryAttribute( "attr0" );
@@ -466,6 +466,73 @@ public class ModifyRequestImplTest
             public void setMessageId( int messageId )
             {
             }
+
+
+            public void addModification( EntryAttribute attr, ModificationOperation modOp )
+            {
+            }
+
+
+            public void replace( String attributeName )
+            {
+            }
+
+
+            public void replace( String attributeName, String... attributeValue )
+            {
+            }
+
+
+            public void replace( String attributeName, byte[]... attributeValue )
+            {
+            }
+
+
+            public void replace( EntryAttribute attr )
+            {
+            }
+
+
+            public void add( String attributeName, String... attributeValue )
+            {
+                // TODO Auto-generated method stub
+
+            }
+
+
+            public void add( String attributeName, byte[]... attributeValue )
+            {
+                // TODO Auto-generated method stub
+
+            }
+
+
+            public void add( EntryAttribute attr )
+            {
+                // TODO Auto-generated method stub
+
+            }
+
+
+            public void remove( String attributeName, String... attributeValue )
+            {
+                // TODO Auto-generated method stub
+
+            }
+
+
+            public void remove( String attributeName, byte[]... attributeValue )
+            {
+                // TODO Auto-generated method stub
+
+            }
+
+
+            public void remove( EntryAttribute attr )
+            {
+                // TODO Auto-generated method stub
+
+            }
         };
 
         ModifyRequestImpl req1 = getRequest();



Mime
View raw message