directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r234264 [9/11] - in /directory/shared/ldap/branches/new-codec-integration/apache2-provider/src: ./ java/ java/main/ java/main/org/ java/main/org/apache/ java/main/org/apache/asn1new/ java/main/org/apache/asn1new/ldap/ java/main/org/apache/a...
Date Sun, 21 Aug 2005 16:54:00 GMT
Added: directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/ExtendedResponse.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/ExtendedResponse.java?rev=234264&view=auto
==============================================================================
--- directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/ExtendedResponse.java (added)
+++ directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/ExtendedResponse.java Sun Aug 21 09:53:27 2005
@@ -0,0 +1,226 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed 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.
+ *
+ */
+package org.apache.asn1new.ldap.pojo;
+
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+
+import org.apache.asn1new.EncoderException;
+import org.apache.asn1new.ber.tlv.Length;
+import org.apache.asn1new.primitives.OID;
+import org.apache.asn1new.primitives.OctetString;
+import org.apache.asn1new.ldap.codec.LdapConstants;
+
+
+/**
+ * A ExtendedResponse Message. Its syntax is :
+ *   ExtendedResponse ::= [APPLICATION 24] SEQUENCE {
+ *              COMPONENTS OF LDAPResult,
+ *              responseName     [10] LDAPOID OPTIONAL,
+ *              response         [11] OCTET STRING OPTIONAL }
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ExtendedResponse extends LdapResponse
+{
+    //~ Instance fields ----------------------------------------------------------------------------
+
+    /** The name */
+    private OID responseName;
+
+    /** The response */
+    private OctetString response;
+    
+    /** The extended response length */
+    private transient int extendedResponseLength;
+
+    //~ Constructors -------------------------------------------------------------------------------
+
+    /**
+     * Creates a new ExtendedResponse object.
+     */
+    public ExtendedResponse()
+    {
+        super( );
+    }
+
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * Get the extended response name
+     *
+     * @return Returns the name.
+     */
+    public String getResponseName()
+    {
+        return ( ( responseName == null ) ? "" : responseName.toString() );
+    }
+
+    /**
+     * Set the extended response name
+     *
+     * @param name The name to set.
+     */
+    public void setResponseName( OID responseName )
+    {
+        this.responseName = responseName;
+    }
+
+    /**
+     * Get the extended response
+     *
+     * @return Returns the response.
+     */
+    public OctetString getResponse()
+    {
+        return response;
+    }
+
+    /**
+     * Set the extended response
+     *
+     * @param response The response to set.
+     */
+    public void setResponse( OctetString response )
+    {
+        this.response = response;
+    }
+
+    /**
+     * Compute the ExtendedResponse length
+     * 
+     * ExtendedResponse :
+     * 
+     * 0x78 L1
+     *  |
+     *  +--> LdapResult
+     * [+--> 0x8A L2 name
+     * [+--> 0x8B L3 response]]
+     * 
+     * L1 = Length(LdapResult)
+     *      [ + Length(0x8A) + Length(L2) + L2
+     *       [ + Length(0x8B) + Length(L3) + L3]]
+     * 
+     * Length(ExtendedResponse) = Length(0x78) + Length(L1) + L1
+     * @return The ExtendedResponse length
+    */
+    public int computeLength()
+    {
+
+        extendedResponseLength = super.computeLength();
+
+        if ( responseName != null )
+        {
+            extendedResponseLength += 1 + Length.getNbBytes( responseName.getOIDLength() ) +
+            responseName.getOIDLength();
+
+            if ( response != null )
+            {
+                extendedResponseLength += 1 + Length.getNbBytes( response.getLength() ) +
+                    response.getLength();
+            }
+        }
+
+        return 1 + Length.getNbBytes( extendedResponseLength ) + extendedResponseLength;
+    }
+
+    /**
+     * Encode the ExtendedResponse message to a PDU.
+     * 
+     * ExtendedResponse :
+     * 
+     * LdapResult.encode()
+     * [0x8A LL response name]
+     * [0x8B LL response]
+     * 
+     * @param buffer The buffer where to put the PDU
+     * @return The PDU.
+     */
+    public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
+    {
+        if (buffer == null)
+        {
+            throw new EncoderException("Cannot put a PDU in a null buffer !");
+        }
+
+        try 
+        {
+            // The BindResponse Tag
+            buffer.put( LdapConstants.EXTENDED_RESPONSE_TAG );
+            buffer.put( Length.getBytes( extendedResponseLength ) );
+            
+            // The LdapResult
+            super.encode(buffer);
+
+            // The responseName, if any
+            if ( responseName != null )
+            {
+                buffer.put( (byte)LdapConstants.EXTENDED_RESPONSE_RESPONSE_NAME_TAG );
+                buffer.put( Length.getBytes( responseName.getOIDLength() ) );
+                
+                if ( responseName.getOIDLength() != 0 )
+                {
+                    buffer.put( responseName.getOID() );
+                }
+            }
+
+            // The response, if any
+            if ( response != null )
+            {
+                buffer.put( (byte)LdapConstants.EXTENDED_RESPONSE_RESPONSE_TAG );
+                buffer.put( Length.getBytes( response.getLength() ) );
+                
+                if ( response.getLength() != 0 )
+                {
+                    buffer.put( response.getValue() );
+                }
+            }
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException("The PDU buffer size is too small !"); 
+        }
+            
+        return buffer;
+    }
+
+    /**
+     * Get a String representation of an ExtendedResponse
+     *
+     * @return An ExtendedResponse String 
+     */
+    public String toString()
+    {
+
+        StringBuffer sb = new StringBuffer();
+
+        sb.append( "    Extended Response\n" );
+        sb.append( super.toString() );
+
+        if ( responseName != null )
+        {
+            sb.append( "        Response name :'" ).append( responseName.toString() ).append( "'\n" );
+        }
+
+        if ( response != null )
+        {
+            sb.append( "        Response :'" ).append( response.toString() ).append( "'\n" );
+        }
+
+        return sb.toString();
+    }
+}

Added: directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/LdapMessage.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/LdapMessage.java?rev=234264&view=auto
==============================================================================
--- directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/LdapMessage.java (added)
+++ directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/LdapMessage.java Sun Aug 21 09:53:27 2005
@@ -0,0 +1,547 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed 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.
+ *
+ */
+package org.apache.asn1new.ldap.pojo;
+
+import org.apache.asn1new.Asn1Object;
+import org.apache.asn1new.EncoderException;
+import org.apache.asn1new.ber.tlv.Length;
+import org.apache.asn1new.ber.tlv.UniversalTag;
+import org.apache.asn1new.ber.tlv.Value;
+import org.apache.asn1new.ldap.codec.LdapConstants;
+
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+/**
+ * The main ldapObject : every Ldap Message are encapsulated in it. It contains
+ * a message Id, a operation (protocolOp) and one ore more Controls.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class LdapMessage extends Asn1Object
+{
+    //~ Instance fields ----------------------------------------------------------------------------
+
+    /** The message ID */
+    private int messageId;
+
+    /** The request or response being carried by the message */
+    private Asn1Object protocolOp;
+
+    /** The controls */
+    private ArrayList controls;
+    
+    /** The current control */
+    private transient Control currentControl;
+    
+    /** The LdapMessage length */
+    private transient int ldapMessageLength;
+    
+    /** The controls length */
+    private transient int controlsLength;
+    
+    /** The controls sequence length */
+    private transient int controlsSequenceLength;
+
+    //~ Constructors -------------------------------------------------------------------------------
+
+    /**
+     * Creates a new LdapMessage object.
+     */
+    public LdapMessage()
+    {
+        // We should not create this kind of object directly
+    }
+
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * Get the Control Object at a specific index 
+     *
+     * @param i The index of the Control Object to get
+     *
+     * @return The selected Control Object
+     */
+    public Control getControls( int i )
+    {
+        return (Control)controls.get( i );
+    }
+
+    /**
+     * Get the current Control Object 
+     *
+     * @return The current Control Object
+     */
+    public Control getCurrentControl()
+    {
+        return currentControl;
+    }
+
+    /**
+     * Add a control to the Controls array
+     *
+     * @param control The Control to add
+     */
+    public void addControl( Control control )
+    {
+        currentControl = control;
+        this.controls.add( control );
+    }
+
+    /**
+     * Init the controls array
+     */
+    public void initControl(  )
+    {
+        controls = new ArrayList();
+    }
+
+    /**
+     * Get the message ID
+     *
+     * @return The message ID
+     */
+    public int getMessageId()
+    {
+        return messageId;
+    }
+
+    /**
+     * Set the message ID
+     *
+     * @param messageId The message ID
+     */
+    public void setMessageId( int messageId )
+    {
+        this.messageId = messageId;
+    }
+
+    /**
+     * Get the encapsulated Ldap response.
+     *
+     * @return Returns the Ldap response.
+     */
+    public LdapResponse getLdapResponse()
+    {
+        return ( LdapResponse )protocolOp;
+    }
+
+    /**
+     * Get a AbandonRequest ldapObject, assuming that the caller knows that
+     * it is the LdapMessage exact type.
+     *
+     * @return Returns the AbandonRequest ldapObject.
+     */
+    public AbandonRequest getAbandonRequest()
+    {
+        return ( AbandonRequest ) protocolOp;
+    }
+
+    /**
+     * Get a AddRequest ldapObject, assuming that the caller knows that
+     * it is the LdapMessage exact type.
+     *
+     * @return Returns the AddRequest ldapObject.
+     */
+    public AddRequest getAddRequest()
+    {
+        return ( AddRequest ) protocolOp;
+    }
+
+    /**
+     * Get a AddResponse ldapObject, assuming that the caller knows that
+     * it is the LdapMessage exact type.
+     *
+     * @return Returns the AddResponse ldapObject.
+     */
+    public AddResponse getAddResponse()
+    {
+        return ( AddResponse ) protocolOp;
+    }
+
+    /**
+     * Get a BindRequest ldapObject, assuming that the caller knows that
+     * it is the LdapMessage exact type.
+     *
+     * @return Returns the BindRequest ldapObject.
+     */
+    public BindRequest getBindRequest()
+    {
+        return ( BindRequest ) protocolOp;
+    }
+
+    /**
+     * Get a BindResponse ldapObject, assuming that the caller knows that
+     * it is the LdapMessage exact type.
+     *
+     * @return Returns the BindResponse ldapObject.
+     */
+    public BindResponse getBindResponse()
+    {
+        return ( BindResponse ) protocolOp;
+    }
+
+    /**
+     * Get a CompareRequest ldapObject, assuming that the caller knows that
+     * it is the LdapMessage exact type.
+     *
+     * @return Returns the CompareRequest ldapObject.
+     */
+    public CompareRequest getCompareRequest()
+    {
+        return ( CompareRequest ) protocolOp;
+    }
+
+    /**
+     * Get a CompareResponse ldapObject, assuming that the caller knows that
+     * it is the LdapMessage exact type.
+     *
+     * @return Returns the CompareResponse ldapObject.
+     */
+    public CompareResponse getCompareResponse()
+    {
+        return ( CompareResponse ) protocolOp;
+    }
+
+    /**
+     * Get a DelRequest ldapObject, assuming that the caller knows that
+     * it is the LdapMessage exact type.
+     *
+     * @return Returns the DelRequest ldapObject.
+     */
+    public DelRequest getDelRequest()
+    {
+        return ( DelRequest ) protocolOp;
+    }
+
+    /**
+     * Get a DelResponse ldapObject, assuming that the caller knows that
+     * it is the LdapMessage exact type.
+     *
+     * @return Returns the DelResponse ldapObject.
+     */
+    public DelResponse getDelResponse()
+    {
+        return ( DelResponse ) protocolOp;
+    }
+
+    /**
+     * Get a ExtendedRequest ldapObject, assuming that the caller knows that
+     * it is the LdapMessage exact type.
+     *
+     * @return Returns the ExtendedRequest ldapObject.
+     */
+    public ExtendedRequest getExtendedRequest()
+    {
+        return ( ExtendedRequest ) protocolOp;
+    }
+
+    /**
+     * Get a ExtendedResponse ldapObject, assuming that the caller knows that
+     * it is the LdapMessage exact type.
+     *
+     * @return Returns the ExtendedResponse ldapObject.
+     */
+    public ExtendedResponse getExtendedResponse()
+    {
+        return ( ExtendedResponse ) protocolOp;
+    }
+
+    /**
+     * Get a ModifyDNRequest ldapObject, assuming that the caller knows that
+     * it is the LdapMessage exact type.
+     *
+     * @return Returns the ModifyDNRequest ldapObject.
+     */
+    public ModifyDNRequest getModifyDNRequest()
+    {
+        return ( ModifyDNRequest ) protocolOp;
+    }
+
+    /**
+     * Get a ModifyDNResponse ldapObject, assuming that the caller knows that
+     * it is the LdapMessage exact type.
+     *
+     * @return Returns the ModifyDNResponse ldapObject.
+     */
+    public ModifyDNResponse getModifyDNResponse()
+    {
+        return ( ModifyDNResponse ) protocolOp;
+    }
+
+    /**
+     * Get a ModifyRequest ldapObject, assuming that the caller knows that
+     * it is the LdapMessage exact type.
+     *
+     * @return Returns the ModifyRequest ldapObject.
+     */
+    public ModifyRequest getModifyRequest()
+    {
+        return ( ModifyRequest ) protocolOp;
+    }
+
+    /**
+     * Get a ModifyResponse ldapObject, assuming that the caller knows that
+     * it is the LdapMessage exact type.
+     *
+     * @return Returns the ModifyResponse ldapObject.
+     */
+    public ModifyResponse getModifyResponse()
+    {
+        return ( ModifyResponse ) protocolOp;
+    }
+
+    /**
+     * Get a SearchRequest ldapObject, assuming that the caller knows that
+     * it is the LdapMessage exact type.
+     *
+     * @return Returns the SearchRequest ldapObject.
+     */
+    public SearchRequest getSearchRequest()
+    {
+        return ( SearchRequest ) protocolOp;
+    }
+
+    /**
+     * Get a SearchResultDone ldapObject, assuming that the caller knows that
+     * it is the LdapMessage exact type.
+     *
+     * @return Returns the SearchRequestDone ldapObject.
+     */
+    public SearchResultDone getSearchResultDone()
+    {
+        return ( SearchResultDone ) protocolOp;
+    }
+
+    /**
+     * Get a SearchResultEntry ldapObject, assuming that the caller knows that
+     * it is the LdapMessage exact type.
+     *
+     * @return Returns the SearchResultEntry ldapObject.
+     */
+    public SearchResultEntry getSearchResultEntry()
+    {
+        return ( SearchResultEntry ) protocolOp;
+    }
+
+    /**
+     * Get a SearchResultReference ldapObject, assuming that the caller knows that
+     * it is the LdapMessage exact type.
+     *
+     * @return Returns the SearchResultReference ldapObject.
+     */
+    public SearchResultReference getSearchResultReference()
+    {
+        return ( SearchResultReference ) protocolOp;
+    }
+
+    /**
+     * Get a UnBindRequest ldapObject, assuming that the caller knows that
+     * it is the LdapMessage exact type.
+     *
+     * @return Returns the UnBindRequest ldapObject.
+     */
+    public UnBindRequest getUnBindRequest()
+    {
+        return ( UnBindRequest ) protocolOp;
+    }
+
+    /**
+     * Set the ProtocolOP
+     *
+     * @param protocolOp The protocolOp to set.
+     */
+    public void setProtocolOP( Asn1Object protocolOp )
+    {
+        this.protocolOp = protocolOp;
+    }
+
+    /**
+     * Compute the LdapMessage length
+     * 
+     * LdapMessage :
+     * 
+     * 0x30 L1
+     *  |
+     *  +--> 0x02 0x0(1-4) [0..2^31-1] (MessageId)
+     *  +--> protocolOp
+     * [+--> Controls]
+     * 
+     * MessageId length = Length(0x02) + length(MessageId) + MessageId.length
+     * L1 = length(ProtocolOp)
+     * LdapMessage length = Length(0x30) + Length(L1) + MessageId length + L1
+     */
+    public int computeLength()
+    {
+        // The length of the MessageId. It's the sum of
+        // - the tag (0x02), 1 byte
+        // - the length of the Id length, 1 byte
+        // - the Id length, 1 to 4 bytes
+        ldapMessageLength = 1 + 1 + Value.getNbBytes(messageId);
+        
+        // Get the protocolOp length
+        int protocolOpLength = protocolOp.computeLength();
+
+        // Add the protocol length to the message length
+        ldapMessageLength += protocolOpLength;
+
+        // Do the same thing for Controls, if any.
+        if (controls != null)
+        {
+            // Controls :
+            // 0x90 L3
+            //  |
+            //  +--> 0x30 L4
+            //        |
+            //        +--> 0x30 L5
+            //        +--> 0x30 L6
+            //        +--> ...
+            //        +--> 0x30 Li
+            //        +--> ...
+            //        +--> 0x30 Ln
+            //
+            // L3 = Length(0x30) + Length(L4) + L4
+            // L4 = Length(0x30) + Length(L5) + L5
+            //      + Length(0x30) + Length(L6) + L6
+            //      + ...
+            //      + Length(0x30) + Length(Li) + Li
+            //      + ...
+            //      + Length(0x30) + Length(Ln) + Ln
+            //
+            // LdapMessageLength = LdapMessageLength + Length(0x90) 
+            //                     + Length(L3) + L3 
+            controlsSequenceLength = 0;
+            
+            Iterator controlIterator = controls.iterator();
+            
+            // We may have more than one control. ControlsLength is L4.
+            while (controlIterator.hasNext())
+            {
+                controlsSequenceLength += ((Control)controlIterator.next()).computeLength();
+            }
+            
+            // Computes the controls length
+            controlsLength = 1 + Length.getNbBytes( controlsSequenceLength ) + controlsSequenceLength; 
+                
+            // Now, add the tag and the length of the controls length
+            ldapMessageLength += 1 + Length.getNbBytes( controlsLength ) + controlsLength;
+        }
+        
+        // finally, calculate the global message size :
+        // length(Tag) + Length(length) + length
+        
+        return 1 + ldapMessageLength + Length.getNbBytes(ldapMessageLength);
+    }
+
+    /**
+     * Generate the PDU which contains the encoded object.
+     * 
+     * The generation is done in two phases :
+     * - first, we compute the length of each part and the
+     *   global PDU length
+     * - second, we produce the PDU.
+     * 
+     * 0x30 L1
+     *   |
+     *   +--> 0x02 L2 MessageId (L2 = Length(MessageId)
+     *   +--> ProtocolOp
+     *   +--> Controls
+     *   
+     * L1 = Length(0x02) + Length(L2) + L2 
+     *      + Length(ProtocolOp) + Length(Controls)
+     * 
+     * LdapMessageLength = Length(0x30) + Length(L1) + L1
+     *   
+     * @param object The encoded PDU
+     * @return A ByteBuffer that contaons the PDU
+     * @throws EncoderException If anything goes wrong.
+     */
+    public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
+    {
+        // Allocate the bytes buffer.
+        ByteBuffer bb = ByteBuffer.allocate( computeLength() );
+
+        try 
+        {
+            // The LdapMessage Sequence
+            bb.put( UniversalTag.SEQUENCE_TAG );
+            
+            // The length has been calculated by the computeLength method
+            bb.put( Length.getBytes( ldapMessageLength ) );
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException("The PDU buffer size is too small !"); 
+        }
+            
+        
+        // The message Id
+        Value.encode( bb, messageId);
+        
+        // Add the protocolOp part
+        protocolOp.encode(bb);
+        
+        // Do the same thing for Controls, if any.
+        if (controls != null)
+        {
+            // Encode the controls
+            bb.put( (byte)LdapConstants.CONTROLS_TAG );
+            bb.put( Length.getBytes( controlsLength ) );
+
+            // Encode the control's sequence
+            bb.put( UniversalTag.SEQUENCE_TAG );
+            bb.put( Length.getBytes( controlsSequenceLength ) );
+
+            // Encode each control
+            Iterator controlIterator = controls.iterator();
+            
+            while (controlIterator.hasNext())
+            {
+                ((Control)controlIterator.next()).encode( bb );
+            }
+        }
+
+        return bb;
+    }
+
+    /**
+     * Get a String representation of a LdapMessage
+     *
+     * @return A LdapMessage String 
+     */
+    public String toString()
+    {
+        StringBuffer sb = new StringBuffer();
+
+        sb.append( "LdapMessage\n" );
+        sb.append( "    message Id : " ).append( messageId ).append( '\n' );
+        sb.append( protocolOp.toString() );
+
+        if ( controls != null )
+        {
+	        for ( int i = 0; i < controls.size(); i++ )
+	        {
+	            sb.append( ( ( Control ) controls.get( i ) ).toString() );
+	        }
+        }
+
+        return sb.toString();
+    }
+}

Added: directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/LdapResponse.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/LdapResponse.java?rev=234264&view=auto
==============================================================================
--- directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/LdapResponse.java (added)
+++ directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/LdapResponse.java Sun Aug 21 09:53:27 2005
@@ -0,0 +1,122 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed 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.
+ *
+ */
+package org.apache.asn1new.ldap.pojo;
+
+import java.nio.ByteBuffer;
+
+import org.apache.asn1new.EncoderException;
+
+
+/**
+ * A generic LdapResponse Object. It will contain the LdapResult.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class LdapResponse extends LdapMessage
+{
+    //~ Instance fields ----------------------------------------------------------------------------
+
+    /** The LdapResult element */
+    private LdapResult ldapResult;
+    
+    /** The response length */
+    private transient int ldapResponseLength;
+
+    //~ Constructors -------------------------------------------------------------------------------
+
+    /**
+     * Creates a new LdapResponse object.
+     */
+    public LdapResponse()
+    {
+        super( );
+    }
+
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * Get the LdapResult
+     *
+     * @return Returns the ldapResult.
+     */
+    public LdapResult getLdapResult()
+    {
+        return ldapResult;
+    }
+
+    /**
+     * Set the ldap result
+     * 
+     * @param ldapResult The ldapResult to set.
+     */
+    public void setLdapResult( LdapResult ldapResult )
+    {
+        this.ldapResult = ldapResult;
+    }
+    
+    /**
+     * @return Returns the ldapResponseLength.
+     */
+    public int getLdapResponseLength()
+    {
+        return ldapResponseLength;
+    }
+    
+    /**
+     * Compute the LdapResponse length
+     * 
+     * LdapResponse :
+     * 
+     * LdapResult
+     */
+    public int computeLength()
+    {
+        ldapResponseLength = ldapResult.computeLength();
+        
+        return ldapResponseLength;
+    }
+    
+    /**
+     * Encode the AddResponse message to a PDU.
+     * 
+     * @param buffer The buffer where to put the PDU
+     * @return The PDU.
+     */
+    public ByteBuffer encode( ByteBuffer buffer )  throws EncoderException
+    {
+        if (buffer == null)
+        {
+            throw new EncoderException("Cannot put a PDU in a null buffer !");
+        }
+        
+        // The ldapResult
+        ldapResult.encode( buffer );
+        
+        // The ldapResult
+        return buffer;
+    }
+
+    /**
+     * Get a String representation of an Response
+     *
+     * @return An Response String 
+     */
+    public String toString()
+    {
+        return ldapResult.toString();
+    }
+}

Added: directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/LdapResult.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/LdapResult.java?rev=234264&view=auto
==============================================================================
--- directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/LdapResult.java (added)
+++ directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/LdapResult.java Sun Aug 21 09:53:27 2005
@@ -0,0 +1,584 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed 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.
+ *
+ */
+package org.apache.asn1new.ldap.pojo;
+
+import org.apache.asn1new.Asn1Object;
+import org.apache.asn1new.EncoderException;
+import org.apache.asn1new.ber.tlv.Length;
+import org.apache.asn1new.ber.tlv.UniversalTag;
+import org.apache.asn1new.ber.tlv.Value;
+import org.apache.asn1new.ldap.codec.LdapConstants;
+import org.apache.asn1new.ldap.codec.primitives.LdapDN;
+import org.apache.asn1new.ldap.codec.primitives.LdapString;
+import org.apache.asn1new.ldap.codec.primitives.LdapURL;
+
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+/**
+ * A ldapObject to store the LdapResult
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class LdapResult extends Asn1Object
+{
+    //~ Instance fields ----------------------------------------------------------------------------
+
+    /** The result code. The different values are :
+     *  success                      (0),
+     *  operationsError              (1),
+     *  protocolError                (2),
+     *  timeLimitExceeded            (3),
+     *  sizeLimitExceeded            (4),
+     *  compareFalse                 (5),
+     *  compareTrue                  (6),
+     *  authMethodNotSupported       (7),
+     *  strongAuthRequired           (8),
+     *  -- 9 reserved --
+     *  referral                     (10),  -- new
+     *  adminLimitExceeded           (11),  -- new
+     *  unavailableCriticalExtension (12),  -- new
+     *  confidentialityRequired      (13),  -- new
+     *  saslBindInProgress           (14),  -- new
+     *  noSuchAttribute              (16),
+     *  undefinedAttributeType       (17),
+     *  inappropriateMatching        (18),
+     *  constraintViolation          (19),
+     *  attributeOrValueExists       (20),
+     *  invalidAttributeSyntax       (21),
+     *  -- 22-31 unused --
+     *  noSuchObject                 (32),
+     *  aliasProblem                 (33),
+     *  invalidDNSyntax              (34),
+     *  -- 35 reserved for undefined isLeaf --
+     *  aliasDereferencingProblem    (36),
+     *  -- 37-47 unused --
+     *  inappropriateAuthentication  (48),
+     *  invalidCredentials           (49),
+     *  insufficientAccessRights     (50),
+     *  busy                         (51),
+     *  unavailable                  (52),
+     *  unwillingToPerform           (53),
+     *  loopDetect                   (54),
+     *  -- 55-63 unused --
+     *  namingViolation              (64),
+     *  objectClassViolation         (65),
+     *  notAllowedOnNonLeaf          (66),
+     *  notAllowedOnRDN              (67),
+     *  entryAlreadyExists           (68),
+     *  objectClassModsProhibited    (69),
+     *  -- 70 reserved for CLDAP --
+     *  affectsMultipleDSAs          (71), -- new
+     *  -- 72-79 unused --
+     *  other                        (80) },
+     *  -- 81-90 reserved for APIs --
+     */
+    private int           resultCode;
+
+    /** The DN that is matched by the Bind */
+    private LdapDN        matchedDN;
+
+    /** The error message */
+    private LdapString    errorMessage;
+
+    /** The referrals, if any. This is an optional element */
+    private ArrayList     referrals;
+
+    /** The inner size of the referrals sequence */
+    private transient int referralsLength;
+
+    //~ Constructors -------------------------------------------------------------------------------
+
+    /**
+     * Creates a new BindResponse object.
+     */
+    public LdapResult()
+    {
+        referrals = new ArrayList();
+    }
+
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * Get the error message
+     *
+     * @return Returns the errorMessage.
+     */
+    public String getErrorMessage()
+    {
+        return ( ( errorMessage == null ) ? null : errorMessage.toString() );
+    }
+
+    /**
+     * Set the error message
+     *
+     * @param errorMessage The errorMessage to set.
+     */
+    public void setErrorMessage( LdapString errorMessage )
+    {
+        this.errorMessage = errorMessage;
+    }
+
+    /**
+     * Get the matched DN
+     *
+     * @return Returns the matchedDN.
+     */
+    public String getMatchedDN()
+    {
+        return ( ( matchedDN == null ) ? null : matchedDN.toString() );
+    }
+
+    /**
+     * Set the Matched DN
+     * 
+     * @param matchedDN The matchedDN to set.
+     */
+    public void setMatchedDN( LdapDN matchedDN )
+    {
+        this.matchedDN = matchedDN;
+    }
+
+    /**
+     * Get the referrals
+     *
+     * @return Returns the referrals.
+     */
+    public ArrayList getReferrals()
+    {
+        return referrals;
+    }
+
+    /**
+     * Add a referral
+     *
+     * @param referral The referral to add.
+     */
+    public void addReferral( LdapURL referral )
+    {
+        referrals.add( referral );
+    }
+
+    /**
+     * Get the result code
+     *
+     * @return Returns the resultCode.
+     */
+    public int getResultCode()
+    {
+        return resultCode;
+    }
+
+    /**
+     * Set the result code
+     *
+     * @param resultCode The resultCode to set.
+     */
+    public void setResultCode( int resultCode )
+    {
+        this.resultCode = resultCode;
+    }
+
+    /**
+     * Compute the LdapResult length
+     * 
+     * LdapResult :
+     * 
+     * 0x0A 01 resultCode 	(0..80)
+     * 0x04 L1 matchedDN 	(L1 = Length(matchedDN))
+     * 0x04 L2 errorMessage (L2 = Length(errorMessage))
+     * [0x83 L3] referrals
+     *   |
+     *   +--> 0x04 L4 referral
+     *   +--> 0x04 L5 referral
+     *   +--> ...
+     *   +--> 0x04 Li referral
+     *   +--> ...
+     *   +--> 0x04 Ln referral
+     * 
+     * L1 = Length(matchedDN)
+     * L2 = Length(errorMessage)
+     * L3 = n*Length(0x04) + sum(Length(L4) .. Length(Ln)) + sum(L4..Ln)
+     * L4..n = Length(0x04) + Length(Li) + Li
+     * 
+     * Length(LdapResult) = Length(0x0x0A) + Length(0x01) + 1
+     *                      + Length(0x04) + Length(L1) + L1
+     *                      + Length(0x04) + Length(L2) + L2
+     *                      + Length(0x83) + Length(L3) + L3
+     */
+    public int computeLength()
+    {
+        int ldapResultLength = 0;
+
+        // The result code : always 3 bytes
+        ldapResultLength = 1 + 1 + 1;
+
+        // The matchedDN length
+        ldapResultLength += 1 + Length.getNbBytes( matchedDN.getLength() ) + matchedDN.getLength();
+
+        // The errorMessage length
+        ldapResultLength += 1 + Length.getNbBytes( errorMessage.getLength() ) + errorMessage.getLength();
+
+        if ( ( referrals != null ) && ( referrals.size() != 0 ) )
+        {
+            Iterator referralIterator = referrals.iterator();
+
+            referralsLength = 0;
+
+            // Each referral
+            while ( referralIterator.hasNext() )
+            {
+                LdapURL referral = ( LdapURL ) referralIterator.next();
+
+                referralsLength += 1 + Length.getNbBytes( referral.getLength() ) + referral.getLength();
+            }
+
+            // The referrals
+            ldapResultLength += 1 + Length.getNbBytes( referralsLength ) + referralsLength;
+        }
+
+        return ldapResultLength;
+    }
+
+    /**
+     * Encode the LdapResult message to a PDU.
+     * 
+     * @param buffer The buffer where to put the PDU
+     * @return The PDU.
+     */
+    public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
+    {
+        if ( buffer == null )
+        {
+            throw new EncoderException( "Cannot put a PDU in a null buffer !" );
+        }
+
+        try 
+        {
+            // The result code
+            buffer.put( UniversalTag.ENUMERATED_TAG );
+            buffer.put( ( byte ) 1 );
+            buffer.put( ( byte ) resultCode );
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException("The PDU buffer size is too small !"); 
+        }
+
+        // The matchedDN 
+        Value.encode( buffer, matchedDN);
+
+        // The error message
+        Value.encode( buffer, errorMessage);
+
+        // The referrals, if any
+        if ( ( referrals != null ) && ( referrals.size() != 0 ) )
+        {
+            // Encode the referrals sequence
+            // The referrals length MUST have been computed before !
+            buffer.put( (byte)LdapConstants.LDAP_RESULT_REFERRAL_SEQUENCE_TAG );
+            buffer.put( Length.getBytes( referralsLength ) );
+
+            // Each referral
+            Iterator referralIterator = referrals.iterator();
+
+            while ( referralIterator.hasNext() )
+            {
+                LdapURL referral = ( LdapURL ) referralIterator.next();
+
+                // Ecode the current referral
+                Value.encode( buffer, referral);
+            }
+        }
+
+        return buffer;
+    }
+
+    /**
+     * Get a String representation of a LdapResult
+     *
+     * @return A LdapResult String 
+     */
+    public String toString()
+    {
+
+        StringBuffer sb = new StringBuffer();
+
+        sb.append( "        Ldap Result\n" );
+        sb.append( "            Result code : (" ).append( resultCode ).append( ')' );
+
+        switch ( resultCode )
+        {
+
+            case 0 :
+                sb.append( " success\n" );
+                break;
+
+            case 1 :
+                sb.append( " operationsError\n" );
+                break;
+
+            case 2 :
+                sb.append( " protocolError\n" );
+                break;
+
+            case 3 :
+                sb.append( " timeLimitExceeded\n" );
+                break;
+
+            case 4 :
+                sb.append( " sizeLimitExceeded\n" );
+                break;
+
+            case 5 :
+                sb.append( " compareFalse\n" );
+                break;
+
+            case 6 :
+                sb.append( " compareTrue\n" );
+                break;
+
+            case 7 :
+                sb.append( " authMethodNotSupported\n" );
+                break;
+
+            case 8 :
+                sb.append( " strongAuthRequired\n" );
+                break;
+
+            case 9 :
+                sb.append( " -- 9 reserved --\n" );
+                break;
+
+            case 10 :
+                sb.append( " referral -- new\n" );
+                break;
+
+            case 11 :
+                sb.append( " adminLimitExceeded -- new\n" );
+                break;
+
+            case 12 :
+                sb.append( " unavailableCriticalExtension -- new\n" );
+                break;
+
+            case 13 :
+                sb.append( " confidentialityRequired -- new\n" );
+                break;
+
+            case 14 :
+                sb.append( " saslBindInProgress -- new\n" );
+                break;
+
+            case 15 :
+                sb.append( " !! Unknow error code\n" );
+                break;
+
+            case 16 :
+                sb.append( " noSuchAttribute\n" );
+                break;
+
+            case 17 :
+                sb.append( " undefinedAttributeType\n" );
+                break;
+
+            case 18 :
+                sb.append( " inappropriateMatching\n" );
+                break;
+
+            case 19 :
+                sb.append( " constraintViolation\n" );
+                break;
+
+            case 20 :
+                sb.append( " attributeOrValueExists\n" );
+                break;
+
+            case 21 :
+                sb.append( " invalidAttributeSyntax\n" );
+                break;
+
+            case 22 :
+            case 23 :
+            case 24 :
+            case 25 :
+            case 26 :
+            case 27 :
+            case 28 :
+            case 29 :
+            case 30 :
+            case 31 :
+                sb.append( " -- 22-31 unused --\n" );
+                break;
+
+            case 32 :
+                sb.append( " noSuchObject\n" );
+                break;
+
+            case 33 :
+                sb.append( " aliasProblem\n" );
+                break;
+
+            case 34 :
+                sb.append( " invalidDNSyntax\n" );
+                break;
+
+            case 35 :
+                sb.append( " -- 35 reserved for undefined isLeaf --\n" );
+                break;
+
+            case 36 :
+                sb.append( " aliasDereferencingProblem\n" );
+                break;
+
+            case 37 :
+            case 38 :
+            case 39 :
+            case 40 :
+            case 41 :
+            case 42 :
+            case 43 :
+            case 44 :
+            case 45 :
+            case 46 :
+            case 47 :
+                sb.append( " -- 37-47 unused --\n" );
+                break;
+
+            case 48 :
+                sb.append( " inappropriateAuthentication\n" );
+                break;
+
+            case 49 :
+                sb.append( " invalidCredentials\n" );
+                break;
+
+            case 50 :
+                sb.append( " insufficientAccessRights\n" );
+                break;
+
+            case 51 :
+                sb.append( " busy\n" );
+                break;
+
+            case 52 :
+                sb.append( " unavailable\n" );
+                break;
+
+            case 53 :
+                sb.append( " unwillingToPerform\n" );
+                break;
+
+            case 54 :
+                sb.append( " loopDetect\n" );
+                break;
+
+            case 55 :
+            case 56 :
+            case 57 :
+            case 58 :
+            case 59 :
+            case 60 :
+            case 61 :
+            case 62 :
+            case 63 :
+                sb.append( " -- 55-63 unused --\n" );
+                break;
+
+            case 64 :
+                sb.append( " namingViolation\n" );
+                break;
+
+            case 65 :
+                sb.append( " objectClassViolation\n" );
+                break;
+
+            case 66 :
+                sb.append( " notAllowedOnNonLeaf\n" );
+                break;
+
+            case 67 :
+                sb.append( " notAllowedOnRDN\n" );
+                break;
+
+            case 68 :
+                sb.append( " entryAlreadyExists\n" );
+                break;
+
+            case 69 :
+                sb.append( " objectClassModsProhibited\n" );
+                break;
+
+            case 70 :
+                sb.append( " -- 70 reserved for CLDAP --\n" );
+                break;
+
+            case 71 :
+                sb.append( " affectsMultipleDSAs -- new\n" );
+                break;
+
+            case 72 :
+            case 73 :
+            case 74 :
+            case 75 :
+            case 76 :
+            case 77 :
+            case 78 :
+            case 79 :
+                sb.append( " -- 72-79 unused --\n" );
+                break;
+
+            case 80 :
+                sb.append( " other\n" );
+                break;
+
+            case 81 :
+            case 82 :
+            case 83 :
+            case 84 :
+            case 85 :
+            case 86 :
+            case 87 :
+            case 88 :
+            case 89 :
+            case 90 :
+                sb.append( " -- 81-90 reserved for APIs --" );
+                break;
+        }
+
+        sb.append( "            Matched DN : '" ).append( matchedDN.toString() ).append( "'\n" );
+        sb.append( "            Error message : '" ).append( errorMessage.toString() ).append( "'\n" );
+
+        if ( referrals.size() != 0 )
+        {
+            sb.append( "            Referrals :\n" );
+
+            for ( int i = 0; i < referrals.size(); i++ )
+            {
+
+                LdapURL referral = ( LdapURL ) referrals.get( i );
+
+                sb.append( "                Referral[" ).append( i ).append( "] :" ).append( referral.toString() )
+                        .append( '\n' );
+            }
+        }
+
+        return sb.toString();
+    }
+}

Added: directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/ModifyDNRequest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/ModifyDNRequest.java?rev=234264&view=auto
==============================================================================
--- directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/ModifyDNRequest.java (added)
+++ directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/ModifyDNRequest.java Sun Aug 21 09:53:27 2005
@@ -0,0 +1,267 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed 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.
+ *
+ */
+package org.apache.asn1new.ldap.pojo;
+
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+
+import org.apache.asn1new.Asn1Object;
+import org.apache.asn1new.EncoderException;
+import org.apache.asn1new.ber.tlv.Length;
+import org.apache.asn1new.ber.tlv.Value;
+import org.apache.asn1new.ldap.codec.LdapConstants;
+import org.apache.asn1new.ldap.codec.primitives.LdapDN;
+import org.apache.asn1new.ldap.codec.primitives.RelativeLdapDN;
+
+
+/**
+ * A ModifyDNRequest Message. Its syntax is :
+ * ModifyDNRequest ::= [APPLICATION 12] SEQUENCE {
+ *                 entry           LDAPDN,
+ *                 newrdn          RelativeLDAPDN,
+ *                 deleteoldrdn    BOOLEAN,
+ *                 newSuperior     [0] LDAPDN OPTIONAL }
+ *  
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ModifyDNRequest extends Asn1Object
+{
+    //~ Instance fields ----------------------------------------------------------------------------
+
+    /** The DN to be modified. */
+    private LdapDN entry;
+
+    /** The new RDN to be added to the RDN or to the new superior, if present */
+    private RelativeLdapDN newRDN;
+
+    /** If the previous RDN is to be deleted, this flag will be set to true */
+    private boolean deleteOldRDN;
+
+    /** The optional superior, which will be concatened to the newRdn */
+    private LdapDN newSuperior;
+    
+    /** The modify DN request length */
+    private transient int modifyDNRequestLength;
+
+    //~ Constructors -------------------------------------------------------------------------------
+
+    /**
+     * Creates a new ModifyDNRequest object.
+     */
+    public ModifyDNRequest()
+    {
+        super( );
+    }
+
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * Get the modification's DN
+     * @return Returns the entry.
+     */
+    public String getEntry()
+    {
+        return ( ( entry == null ) ? "" : entry.toString() );
+    }
+
+    /**
+     * Set the modification DN.
+     * @param entry The entry to set.
+     */
+    public void setEntry( LdapDN entry )
+    {
+        this.entry = entry;
+    }
+
+    /**
+     * Tells if the old RDN is to be deleted
+     *
+     * @return Returns the deleteOldRDN.
+     */
+    public boolean isDeleteOldRDN()
+    {
+        return deleteOldRDN;
+    }
+
+    /**
+     * Set the flag to delete the old RDN
+     *
+     * @param deleteOldRDN The deleteOldRDN to set.
+     */
+    public void setDeleteOldRDN( boolean deleteOldRDN )
+    {
+        this.deleteOldRDN = deleteOldRDN;
+    }
+
+    /**
+     * Get the new RDN
+     *
+     * @return Returns the newRDN.
+     */
+    public String getNewRDN()
+    {
+        return ( ( newRDN == null ) ? "" : newRDN.toString() );
+    }
+
+    /**
+     * Set the new RDN
+     *
+     * @param newRDN The newRDN to set.
+     */
+    public void setNewRDN( RelativeLdapDN newRDN )
+    {
+        this.newRDN = newRDN;
+    }
+
+    /**
+     * Get the newSuperior
+     *
+     * @return Returns the newSuperior.
+     */
+    public String getNewSuperior()
+    {
+        return ( ( newSuperior == null ) ? "" : newSuperior.toString() );
+    }
+
+    /**
+     * Set the new superior
+     *
+     * @param newSuperior The newSuperior to set.
+     */
+    public void setNewSuperior( LdapDN newSuperior )
+    {
+        this.newSuperior = newSuperior;
+    }
+
+    /**
+     * Compute the ModifyDNRequest length
+     * 
+     * ModifyDNRequest :
+     * 
+     * 0x6C L1
+     *  |
+     *  +--> 0x04 L2 entry
+     *  +--> 0x04 L3 newRDN
+     *  +--> 0x01 0x01 (true/false) deleteOldRDN (3 bytes)
+     * [+--> 0x80 L4 newSuperior ] 
+     * 
+     * L2 = Length(0x04) + Length(Length(entry)) + Length(entry) 
+     * L3 = Length(0x04) + Length(Length(newRDN)) + Length(newRDN) 
+     * L4 = Length(0x80) + Length(Length(newSuperior)) + Length(newSuperior)
+     * L1 = L2 + L3 + 3 [+ L4] 
+     * 
+     * Length(ModifyDNRequest) = Length(0x6C) + Length(L1) + L1
+     * @return DOCUMENT ME!
+    */
+    public int computeLength()
+    {
+
+        modifyDNRequestLength =
+            1 + Length.getNbBytes( entry.getLength() ) + entry.getLength() +
+            1 + Length.getNbBytes( newRDN.getLength() ) + newRDN.getLength() +
+            1 + 1 + 1; // deleteOldRDN
+
+        if ( newSuperior != null )
+        {
+            modifyDNRequestLength += 1 + Length.getNbBytes( newSuperior.getLength() ) +
+                newSuperior.getLength();
+        }
+
+        return 1 + Length.getNbBytes( modifyDNRequestLength ) + modifyDNRequestLength;
+    }
+
+    /**
+     * Encode the ModifyDNRequest message to a PDU.
+     * 
+     * ModifyDNRequest :
+     * 
+     * 0x6C LL
+     *   0x04 LL entry
+     *   0x04 LL newRDN
+     *   0x01 0x01 deleteOldRDN
+     *   [0x80 LL newSuperior]
+     * 
+     * @param buffer The buffer where to put the PDU
+     * @return The PDU.
+     */
+    public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
+    {
+        if ( buffer == null )
+        {
+            throw new EncoderException( "Cannot put a PDU in a null buffer !" );
+        }
+
+        try 
+        {
+            // The ModifyDNRequest Tag
+            buffer.put( LdapConstants.MODIFY_DN_REQUEST_TAG );
+            buffer.put( Length.getBytes( modifyDNRequestLength ) ) ;
+
+            // The entry
+            Value.encode( buffer, entry );
+            
+            // The newRDN
+            Value.encode( buffer, newRDN );
+            
+            // The flag deleteOldRdn
+            Value.encode( buffer, deleteOldRDN );
+            
+            // The new superior, if any
+            if ( newSuperior != null )
+            {
+                // Encode the reference
+                buffer.put( (byte)LdapConstants.MODIFY_DN_REQUEST_NEW_SUPERIOR_TAG );
+                buffer.put( Length.getBytes( newSuperior.getLength() ) );
+                
+                if ( newSuperior.getLength() != 0 )
+                {
+                    buffer.put( newSuperior.getData() );
+                }
+            }
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException("The PDU buffer size is too small !"); 
+        }
+
+        return buffer;
+    }
+
+    /**
+     * Get a String representation of a ModifyDNRequest
+     *
+     * @return A ModifyDNRequest String 
+     */
+    public String toString()
+    {
+
+        StringBuffer sb = new StringBuffer();
+
+        sb.append( "    ModifyDN Response\n" );
+        sb.append( "        Entry : '" ).append( entry ).append( "'\n" );
+        sb.append( "        New RDN : '" ).append( newRDN.toString() ).append( "'\n" );
+        sb.append( "        Delete old RDN : " ).append( deleteOldRDN ).append( "\n" );
+
+        if ( newSuperior != null )
+        {
+            sb.append( "        New superior : '" ).append( newSuperior.toString() ).append(
+                "'\n" );
+        }
+
+        return sb.toString();
+    }
+}

Added: directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/ModifyDNResponse.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/ModifyDNResponse.java?rev=234264&view=auto
==============================================================================
--- directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/ModifyDNResponse.java (added)
+++ directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/ModifyDNResponse.java Sun Aug 21 09:53:27 2005
@@ -0,0 +1,107 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed 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.
+ *
+ */
+package org.apache.asn1new.ldap.pojo;
+
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+
+import org.apache.asn1new.EncoderException;
+import org.apache.asn1new.ber.tlv.Length;
+import org.apache.asn1new.ldap.codec.LdapConstants;
+
+/**
+ * An ModifyDNResponse Message. Its syntax is :
+ *   ModifyDNResponse ::= [APPLICATION 13] LDAPResult
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ModifyDNResponse extends LdapResponse
+{
+    //~ Constructors -------------------------------------------------------------------------------
+
+    /**
+     * Creates a new ModifyDNResponse object.
+     */
+    public ModifyDNResponse()
+    {
+        super( );
+    }
+
+    /**
+     * Compute the ModifyDNResponse length
+     * 
+     * ModifyDNResponse :
+     * 
+     * 0x6D L1
+     *  |
+     *  +--> LdapResult
+     * 
+     * L1 = Length(LdapResult)
+     * 
+     * Length(ModifyDNResponse) = Length(0x6D) + Length(L1) + L1
+     */
+    public int computeLength()
+    {
+        int ldapResponseLength = super.computeLength();
+        
+        return 1 + Length.getNbBytes( ldapResponseLength ) + ldapResponseLength;
+    }
+
+    /**
+     * Encode the ModifyDNResponse message to a PDU.
+     * 
+     * @param buffer The buffer where to put the PDU
+     * @return The PDU.
+     */
+    public ByteBuffer encode( ByteBuffer buffer )  throws EncoderException
+    {
+        if (buffer == null)
+        {
+            throw new EncoderException("Cannot put a PDU in a null buffer !");
+        }
+        
+        try
+        {
+            // The tag
+            buffer.put( LdapConstants.MODIFY_DN_RESPONSE_TAG );
+            buffer.put( Length.getBytes( getLdapResponseLength() ) );
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException("The PDU buffer size is too small !"); 
+        }
+        
+        // The ldapResult
+        return super.encode( buffer);
+    }
+
+    /**
+     * Get a String representation of a ModifyDNResponse
+     *
+     * @return A ModifyDNResponse String 
+     */
+    public String toString()
+    {
+
+        StringBuffer sb = new StringBuffer();
+
+        sb.append( "    Modify DN Response\n" );
+        sb.append( super.toString() );
+
+        return sb.toString();
+    }
+}

Added: directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/ModifyRequest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/ModifyRequest.java?rev=234264&view=auto
==============================================================================
--- directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/ModifyRequest.java (added)
+++ directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/ModifyRequest.java Sun Aug 21 09:53:27 2005
@@ -0,0 +1,543 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed 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.
+ *
+ */
+package org.apache.asn1new.ldap.pojo;
+
+import org.apache.asn1new.Asn1Object;
+import org.apache.asn1new.EncoderException;
+import org.apache.asn1new.ber.tlv.Length;
+import org.apache.asn1new.ber.tlv.UniversalTag;
+import org.apache.asn1new.ber.tlv.Value;
+import org.apache.asn1new.primitives.OctetString;
+import org.apache.asn1new.ldap.codec.LdapConstants;
+import org.apache.asn1new.ldap.codec.primitives.LdapDN;
+import org.apache.asn1new.ldap.codec.primitives.LdapString;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.ModificationItem;
+
+
+/**
+ * A ModifyRequest Message. Its syntax is :
+ *   ModifyRequest ::= [APPLICATION 6] SEQUENCE {
+ *              object          LDAPDN,
+ *              modification    SEQUENCE OF SEQUENCE {
+ *                      operation       ENUMERATED {
+ *                                              add     (0),
+ *                                              delete  (1),
+ *                                              replace (2) },
+ *                      modification    AttributeTypeAndValues } }
+ *
+ *   AttributeTypeAndValues ::= SEQUENCE {
+ *              type    AttributeDescription,
+ *              vals    SET OF AttributeValue }
+ * 
+ *   AttributeValue ::= OCTET STRING
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ModifyRequest extends Asn1Object
+{
+    //~ Static fields/initializers -----------------------------------------------------------------
+
+    /** The logger */
+    private static final transient Logger log = LoggerFactory.getLogger( ModifyRequest.class );
+
+    /** Logging speed up  */
+    private static final transient boolean DEBUG = log.isDebugEnabled();
+
+    //~ Instance fields ----------------------------------------------------------------------------
+
+    /** The DN to be modified. */
+    private LdapDN object;
+
+    /** The modifications list. This is an array of ModificationItem. */
+    private ArrayList modifications;
+
+    /** The current attribute being decoded */
+    private transient Attribute currentAttribute;
+
+    /** A local storage for the operation */
+    private transient int currentOperation;
+
+    /** The modify request length */
+    private transient int modifyRequestLength;
+    
+    /** The modifications length */
+    private transient int modificationsLength;
+    
+    /** The modification sequence length */
+    private transient List modificationSequenceLength;
+    
+    /** The list of all modification length */
+    private transient List modificationLength;
+    
+    /** The list of all vals length */
+    private transient List valuesLength;
+
+    //~ Constructors -------------------------------------------------------------------------------
+
+    /**
+     * Creates a new ModifyRequest object.
+     */
+    public ModifyRequest()
+    {
+        super( );
+    }
+
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * Initialize the ArrayList for modifications.
+     */
+    public void initModifications()
+    {
+        modifications = new ArrayList();
+    }
+
+    /**
+     * Get the entry's attributes
+     *
+     * @return Returns the modifications.
+     */
+    public ArrayList getModifications()
+    {
+        return modifications;
+    }
+
+    /**
+     * Add a new modification to the list
+     *
+     * @param operation The type of operation (add, delete or replace)
+    */
+    public void addModification( int operation )
+    {
+        currentOperation = operation;
+
+        if ( currentAttribute == null )
+        {
+            modifications = new ArrayList();
+        }
+    }
+
+    /**
+     * Add a new attributeTypeAndValue
+     * 
+     * @param type The attribute's name
+     */
+    public void addAttributeTypeAndValues( LdapString type )
+    {
+        currentAttribute = new BasicAttribute( type.toString().toLowerCase() );
+
+        int operation = 0;
+
+        switch ( currentOperation )
+        {
+
+            case LdapConstants.OPERATION_ADD : // add
+                operation = DirContext.ADD_ATTRIBUTE;
+                break;
+
+            case LdapConstants.OPERATION_DELETE : // delete
+                operation = DirContext.REMOVE_ATTRIBUTE;
+                break;
+
+            case LdapConstants.OPERATION_REPLACE : // replace
+                operation = DirContext.REPLACE_ATTRIBUTE;
+                break;
+        }
+
+        ModificationItem modification = new ModificationItem( operation, currentAttribute );
+        modifications.add( modification );
+    }
+
+    /**
+     * Add a new value to the current attribute
+     * 
+     * @param value The value to add
+     */
+    public void addAttributeValue( OctetString value )
+    {
+        currentAttribute.add( value );
+    }
+
+    /**
+     * Get the modification's DN
+     * 
+     * @return Returns the object.
+     */
+    public String getObject()
+    {
+        return ( ( object == null ) ? "" : object.toString() );
+    }
+
+    /**
+     * Set the modification DN.
+     * 
+     * @param object The DN to set.
+     */
+    public void setObject( LdapDN object )
+    {
+        this.object = object;
+    }
+
+    /**
+     * Get the current operation
+     * 
+     * @return Returns the currentOperation.
+     */
+    public int getCurrentOperation()
+    {
+        return currentOperation;
+    }
+
+    /**
+     * Store the current operation
+     * 
+     * @param currentOperation The currentOperation to set.
+     */
+    public void setCurrentOperation( int currentOperation )
+    {
+        this.currentOperation = currentOperation;
+    }
+
+    /**
+     * 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
+     * 
+     * 
+     */
+    public int computeLength()
+    {
+        // Initialized with object
+        modifyRequestLength = 1 + Length.getNbBytes( object.getLength() ) + object.getLength();
+        
+        // Modifications
+        modificationsLength = 0;
+        
+        if ( ( modifications != null ) && ( modifications.size() != 0 ) )
+        {
+            Iterator modificationsIterator = modifications.iterator();
+            modificationSequenceLength = new LinkedList();
+            modificationLength = new LinkedList();
+            valuesLength = new LinkedList();
+            
+            while ( modificationsIterator.hasNext() )
+            {
+                // Modification sequence length initialized with the operation
+                int localModificationSequenceLength = 1 + 1 + 1;
+                int localValuesLength = 0;
+                
+                ModificationItem modification = (ModificationItem)modificationsIterator.next();
+                
+                // Modification length initialized with the type
+                int typeLength = modification.getAttribute().getID().length();
+                int localModificationLength = 1 + Length.getNbBytes( typeLength ) + typeLength;
+                
+                try
+                {
+                    
+                    NamingEnumeration values = modification.getAttribute().getAll();
+
+                    // Get all the values
+                    if ( values.hasMoreElements() )
+                    {
+                        while ( values.hasMore() )
+                        {
+                            OctetString value = (OctetString)values.next();
+                            
+                            localValuesLength += 1 + Length.getNbBytes( value.getLength() ) + value.getLength();
+                        }
+                    }
+                    
+                    localModificationLength += 1 + Length.getNbBytes( localValuesLength ) + localValuesLength;
+                }
+                catch (NamingException ne)
+                {
+                    continue;
+                }
+                
+                // Compute the modificationSequenceLength
+                localModificationSequenceLength += 1 + Length.getNbBytes( localModificationLength ) + localModificationLength;
+                
+                // Add the tag and the length
+                modificationsLength += 1 + Length.getNbBytes( localModificationSequenceLength ) + localModificationSequenceLength;
+                
+                // Store the arrays of values
+                valuesLength.add( new Integer( localValuesLength ) );
+                modificationLength.add( new Integer( localModificationLength ) );
+                modificationSequenceLength.add( new Integer( localModificationSequenceLength ) );
+            }
+            
+            // Add the modifications length to the modificationRequestLength
+            modifyRequestLength += 1 + Length.getNbBytes( modificationsLength ) + modificationsLength;
+        }
+
+        return 1 + Length.getNbBytes( modifyRequestLength ) + modifyRequestLength;
+    }
+
+    /**
+     * Encode the ModifyRequest message to a PDU.
+     * 
+     * AddRequest :
+     * 
+     * 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
+     * 
+     * @param buffer The buffer where to put the PDU
+     * @return The PDU.
+     */
+    public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
+    {
+        if ( buffer == null )
+        {
+            throw new EncoderException( "Cannot put a PDU in a null buffer !" );
+        }
+
+        try 
+        {
+            // The AddRequest Tag
+            buffer.put( LdapConstants.MODIFY_REQUEST_TAG );
+            buffer.put( Length.getBytes( modifyRequestLength ) ) ;
+            
+            // The entry
+            Value.encode( buffer, object );
+            
+            // The modifications sequence
+            buffer.put( UniversalTag.SEQUENCE_TAG );
+            buffer.put( Length.getBytes( modificationsLength ) ) ;
+
+            // The modifications list
+            if ( ( modifications != null ) && ( modifications.size() != 0 ) )
+            {
+                Iterator modificationIterator = modifications.iterator();
+                int modificationNumber = 0;
+                
+                // Compute the modifications length
+                while ( modificationIterator.hasNext() )
+                {
+                    ModificationItem modification = (ModificationItem)modificationIterator.next();
+                    
+                    // The modification sequence
+                    buffer.put( UniversalTag.SEQUENCE_TAG );
+                    int localModificationSequenceLength = ( (Integer)modificationSequenceLength.get( modificationNumber ) ).intValue();
+                    buffer.put( Length.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 );
+                    
+                    switch ( modification.getModificationOp() )
+                    {
+
+                        case DirContext.ADD_ATTRIBUTE : // add
+                            buffer.put( (byte)LdapConstants.OPERATION_ADD );
+                            break;
+
+                        case DirContext.REMOVE_ATTRIBUTE : // delete
+                            buffer.put( (byte)LdapConstants.OPERATION_DELETE );
+                            break;
+
+                        case DirContext.REPLACE_ATTRIBUTE : // replace
+                            buffer.put( (byte)LdapConstants.OPERATION_REPLACE );
+                            break;
+                    }
+
+                    // The modification
+                    buffer.put( UniversalTag.SEQUENCE_TAG );
+                    int localModificationLength = ( (Integer)modificationLength.get( modificationNumber ) ).intValue();
+                    buffer.put( Length.getBytes( localModificationLength ) );
+                    
+                    // The modification type
+                    Value.encode( buffer, modification.getAttribute().getID() );
+                    
+                    // The values
+                    buffer.put( UniversalTag.SET_TAG );
+                    int localValuesLength = ( (Integer)valuesLength.get( modificationNumber ) ).intValue();
+                    buffer.put( Length.getBytes( localValuesLength ) );
+                    
+                    try
+                    {
+                        NamingEnumeration values = modification.getAttribute().getAll();
+                        
+                        if ( values.hasMoreElements() )
+                        {
+                            while ( values.hasMoreElements() )
+                            {
+                                OctetString value = (OctetString)values.next();
+                                
+                                Value.encode( buffer, value );
+                            }
+                        }
+                        
+                    }
+                    catch (NamingException ne)
+                    {
+                        throw new EncoderException("Cannot enumerate the values");
+                    }
+                    
+                    // Go to the next modification number;
+                    modificationNumber++;
+                }
+            }
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException("The PDU buffer size is too small !"); 
+        }
+
+        return buffer;
+    }
+
+    /**
+     * Get a String representation of a ModifyRequest
+     *
+     * @return A ModifyRequest String 
+     */
+    public String toString()
+    {
+
+        StringBuffer sb = new StringBuffer();
+
+        sb.append( "    Modify Request\n" );
+        sb.append( "        Object : '" ).append( object ).append( "'\n" );
+
+        if ( modifications != null )
+        {
+
+            for ( int i = 0; i < modifications.size(); i++ )
+            {
+
+                ModificationItem modification = ( ModificationItem ) modifications.get( i );
+
+                sb.append( "            Modification[" ).append( i ).append( "]\n" );
+                sb.append( "                Operation : " );
+
+                switch ( modification.getModificationOp() )
+                {
+
+                    case DirContext.ADD_ATTRIBUTE :
+                        sb.append( " add\n" );
+                        break;
+
+                    case DirContext.REPLACE_ATTRIBUTE :
+                        sb.append( " replace\n" );
+                        break;
+
+                    case DirContext.REMOVE_ATTRIBUTE :
+                        sb.append( " delete\n" );
+                        break;
+                }
+
+                sb.append( "                Modification\n" );
+
+                Attribute attribute = modification.getAttribute();
+
+                try
+                {
+                    sb.append( "                    Type : '" ).append( attribute.getID() ).append(
+                        "'\n" );
+                    sb.append( "                    Vals\n" );
+
+                    for ( int j = 0; j < attribute.size(); j++ )
+                    {
+
+
+                        OctetString attributeValue = ( OctetString ) attribute.get( j );
+                        sb.append( "                        Val[" ).append( j ).append( "] : '" )
+                          .append( attributeValue.toString() ).append( "' \n" );
+
+                    }
+                }
+                catch ( NamingException ne )
+                {
+                    log.error( "Naming exception will printing the '" + attribute.getID() +
+                        "'" );
+                }
+            }
+        }
+
+        return sb.toString();
+    }
+}

Added: directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/ModifyResponse.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/ModifyResponse.java?rev=234264&view=auto
==============================================================================
--- directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/ModifyResponse.java (added)
+++ directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/ModifyResponse.java Sun Aug 21 09:53:27 2005
@@ -0,0 +1,107 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed 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.
+ *
+ */
+package org.apache.asn1new.ldap.pojo;
+
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+
+import org.apache.asn1new.EncoderException;
+import org.apache.asn1new.ber.tlv.Length;
+import org.apache.asn1new.ldap.codec.LdapConstants;
+
+/**
+ * An ModifyResponse Message. Its syntax is :
+ *   ModifyResponse ::= [APPLICATION 7] LDAPResult
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ModifyResponse extends LdapResponse
+{
+    //~ Constructors -------------------------------------------------------------------------------
+
+    /**
+     * Creates a new ModifyResponse object.
+     */
+    public ModifyResponse()
+    {
+        super( );
+    }
+
+    /**
+     * Compute the ModifyResponse length
+     * 
+     * ModifyResponse :
+     * 
+     * 0x67 L1
+     *  |
+     *  +--> LdapResult
+     * 
+     * L1 = Length(LdapResult)
+     * 
+     * Length(ModifyResponse) = Length(0x67) + Length(L1) + L1
+     */
+    public int computeLength()
+    {
+        int ldapResponseLength = super.computeLength();
+        
+        return 1 + Length.getNbBytes( ldapResponseLength ) + ldapResponseLength;
+    }
+
+    /**
+     * Encode the ModifyResponse message to a PDU.
+     * 
+     * @param buffer The buffer where to put the PDU
+     * @return The PDU.
+     */
+    public ByteBuffer encode( ByteBuffer buffer )  throws EncoderException
+    {
+        if (buffer == null)
+        {
+            throw new EncoderException("Cannot put a PDU in a null buffer !");
+        }
+        
+        try
+        {
+            // The tag
+            buffer.put( LdapConstants.MODIFY_RESPONSE_TAG );
+            buffer.put( Length.getBytes( getLdapResponseLength() ) );
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException("The PDU buffer size is too small !"); 
+        }
+        
+        // The ldapResult
+        return super.encode( buffer);
+    }
+
+    /**
+     * Get a String representation of a ModifyResponse
+     *
+     * @return A ModifyResponse String 
+     */
+    public String toString()
+    {
+
+        StringBuffer sb = new StringBuffer();
+
+        sb.append( "    Modify Response\n" );
+        sb.append( super.toString() );
+
+        return sb.toString();
+    }
+}

Added: directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/SaslCredentials.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/SaslCredentials.java?rev=234264&view=auto
==============================================================================
--- directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/SaslCredentials.java (added)
+++ directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/SaslCredentials.java Sun Aug 21 09:53:27 2005
@@ -0,0 +1,179 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed 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.
+ *
+ */
+package org.apache.asn1new.ldap.pojo;
+
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+
+import org.apache.asn1new.Asn1Object;
+import org.apache.asn1new.EncoderException;
+import org.apache.asn1new.ber.tlv.Length;
+import org.apache.asn1new.ber.tlv.Value;
+import org.apache.asn1new.primitives.OctetString;
+import org.apache.asn1new.ldap.codec.LdapConstants;
+import org.apache.asn1new.ldap.codec.primitives.LdapString;
+
+
+/**
+ * A ldapObject which stores the SASL authentication of a BindRequest.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SaslCredentials extends Asn1Object
+{
+    //~ Instance fields ----------------------------------------------------------------------------
+
+    /** Any mechanism defined in RFC 2222 :
+     * KERBEROS_V4,
+     * GSSAPI,
+     * SKEY,
+     * EXTERNAL
+     **/
+    private LdapString mechanism;
+
+    /** optional credentials of the user */
+    private OctetString credentials;
+
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * Get the credentials
+     *
+     * @return The credentials
+     */
+    public OctetString getCredentials()
+    {
+        return credentials;
+    }
+
+    /**
+     * Set the credentials
+     *
+     * @param credentials The credentials
+     */
+    public void setCredentials( OctetString credentials )
+    {
+        this.credentials = credentials;
+    }
+
+    /**
+     * Get the mechanism
+     *
+     * @return The mechanism
+     */
+    public String getMechanism()
+    {
+
+        return ( ( mechanism == null ) ? null : mechanism.toString() );
+    }
+
+    /**
+     * Set the mechanism
+     *
+     * @param mechanism The mechanism
+     */
+    public void setMechanism( LdapString mechanism )
+    {
+        this.mechanism = mechanism;
+    }
+
+    /**
+     * Compute the Sasl authentication length
+     * 
+     * Sasl authentication :
+     * 
+     * 0x83 L1 mechanism
+     * [0x04 L2 credentials]
+     * 
+     * L1 = Length(mechanism)
+     * L2 = Length(credentials)
+     * 
+     * Length(Sasl authentication) = Length(0x83) + Length(L1) + Length(mechanism)
+     *                               [+ Length(0x04) + Length(L2) + Length(credentials)]
+     */
+    public int computeLength()
+    {
+        int saslLength = 1 + Length.getNbBytes( mechanism.getLength() ) + mechanism.getLength();
+        
+        if (credentials != null)
+        {
+            saslLength += 1 + Length.getNbBytes( credentials.getLength() ) + credentials.getLength();
+        }
+        
+        return saslLength;
+    }
+    
+    /**
+     * Encode the sasl authentication to a PDU.
+     * 
+     * SimpleAuthentication :
+     * 
+     * 0x83 LL mechanism
+     * [0x04 LL credentials]
+     * 
+     * @param buffer The buffer where to put the PDU
+     * @return The PDU.
+     */
+    public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
+    {
+        if ( buffer == null )
+        {
+            throw new EncoderException( "Cannot put a PDU in a null buffer !" );
+        }
+
+        try 
+        {
+            // The simpleAuthentication Tag
+            buffer.put( (byte)LdapConstants.BIND_REQUEST_SASL_TAG );
+            buffer.put( Length.getBytes( mechanism.getLength() ) ) ;
+            buffer.put( mechanism.getData() ) ;
+            
+            if ( credentials != null )
+            {
+                Value.encode( buffer, credentials );
+            }
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException("The PDU buffer size is too small !"); 
+        }
+
+        return buffer;
+    }
+
+    /**
+     * Get a String representation of a SaslCredential
+     *
+     * @return A SaslCredential String 
+     */
+    public String toString()
+    {
+
+        StringBuffer sb = new StringBuffer();
+
+        sb.append( "        Sasl credentials\n" );
+        sb.append( "            Mechanism :'" ).append( mechanism.toString() ).append( "'\n" );
+
+        if ( credentials != null )
+        {
+            sb.append( "            Credentials :'" ).append( credentials.toString() ).append(
+                "'\n" );
+        }
+
+        return sb.toString();
+    }
+}



Mime
View raw message