You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2005/09/09 23:43:24 UTC

svn commit: r279887 [11/15] - in /directory/shared/ldap/branches/elecharny-cleanup/apache2-provider: ./ conf/ perfs/ perfs/org/ perfs/org/apache/ perfs/org/apache/asn1new/ perfs/org/apache/asn1new/ber/ src/ src/java/ src/java/main/ src/java/main/org/ s...

Added: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/ModifyRequest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/ModifyRequest.java?rev=279887&view=auto
==============================================================================
--- directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/ModifyRequest.java (added)
+++ directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/ModifyRequest.java Fri Sep  9 14:41:22 2005
@@ -0,0 +1,549 @@
+/*
+ *   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.asn1.codec.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 LdapMessage
+{
+    //~ Static fields/initializers -----------------------------------------------------------------
+
+    /** The logger */
+    private static final transient Logger log = LoggerFactory.getLogger( ModifyRequest.class );
+
+    //~ 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 ------------------------------------------------------------------------------------
+
+    /**
+     * Get the message type
+     *
+     * @return Returns the type.
+     */
+    public int getMessageType()
+    {
+        return LdapConstants.MODIFY_REQUEST;
+    }
+
+    /**
+     * 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();
+    }
+}

Propchange: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/ModifyRequest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/ModifyResponse.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/ModifyResponse.java?rev=279887&view=auto
==============================================================================
--- directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/ModifyResponse.java (added)
+++ directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/ModifyResponse.java Fri Sep  9 14:41:22 2005
@@ -0,0 +1,117 @@
+/*
+ *   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.asn1.codec.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( );
+    }
+
+    /**
+     * Get the message type
+     *
+     * @return Returns the type.
+     */
+    public int getMessageType()
+    {
+        return LdapConstants.MODIFY_RESPONSE;
+    }
+
+    /**
+     * 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();
+    }
+}

Propchange: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/ModifyResponse.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/SaslCredentials.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/SaslCredentials.java?rev=279887&view=auto
==============================================================================
--- directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/SaslCredentials.java (added)
+++ directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/SaslCredentials.java Fri Sep  9 14:41:22 2005
@@ -0,0 +1,190 @@
+/*
+ *   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.asn1.codec.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;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * 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 LdapAuthentication
+{
+	/** The logger */
+    private static Logger log = LoggerFactory.getLogger( SimpleAuthentication.class );
+
+    //~ 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();
+        }
+        
+    	if ( log.isDebugEnabled() )
+    	{
+    		log.debug( "SASL Authentication length : " + saslLength );
+    	}
+
+    	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 )
+        {
+        	log.error( "Cannot put a PDU in a null buffer !" );
+            throw new EncoderException( "Cannot put a PDU in a null buffer !" );
+        }
+
+        try 
+        {
+            // The saslAuthentication 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 )
+        {
+        	log.error( "The PDU buffer size is too small !" );
+            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();
+    }
+}

Propchange: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/SaslCredentials.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/SearchRequest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/SearchRequest.java?rev=279887&view=auto
==============================================================================
--- directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/SearchRequest.java (added)
+++ directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/SearchRequest.java Fri Sep  9 14:41:22 2005
@@ -0,0 +1,555 @@
+/*
+ *   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.asn1.codec.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.pojo.filters.Filter;
+
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+
+import javax.naming.NamingEnumeration;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
+
+/**
+ * A SearchRequest ldapObject. It's a sub-class of Asn1Object, and it implements
+ * the ldapObject class to be seen as a member of the LdapMessage
+ * CHOICE.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SearchRequest extends LdapMessage
+{
+    //~ Instance fields ----------------------------------------------------------------------------
+
+    /** The base DN */
+    private LdapDN baseObject;
+
+    /** The scope. It could be baseObject, singleLevel or wholeSubtree. */
+    private int scope;
+
+    /** The deref alias could be neverDerefAliases, derefInSearching, 
+     * derefFindingBaseObj or derefAlways. */
+    private int derefAliases;
+
+    /** The size limit (number of objects returned)*/
+    private int sizeLimit;
+
+    /** The time limit (max time to process the response before returning the result) */
+    private int timeLimit;
+
+    /** An indicator as to whether search results will contain
+     both attribute types and values, or just attribute types.  Setting
+     this field to TRUE causes only attribute types (no values) to be
+     returned.  Setting this field to FALSE causes both attribute types
+     and values to be returned. */
+    private boolean typesOnly;
+
+    /** The filter tree */
+    private Filter filter;
+
+    /** The list of attributes to get */
+    private Attributes attributes;
+
+    /** The current filter. This is used while decoding a PDU */
+    private transient Filter currentFilter;
+    
+    /** The searchRequest length */
+    private transient int searchRequestLength;
+    
+    /** The attributeDescriptionList length */
+    private transient int attributeDescriptionListLength;
+
+    //~ Constructors -------------------------------------------------------------------------------
+
+    /**
+     * Creates a new SearchRequest object.
+     */
+    public SearchRequest()
+    {
+        super( );
+
+        currentFilter = null;
+    }
+
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * Get the message type
+     *
+     * @return Returns the type.
+     */
+    public int getMessageType()
+    {
+        return LdapConstants.SEARCH_REQUEST;
+    }
+
+    /**
+     * Get the list of attributes
+     *
+     * @return Returns the attributes.
+     */
+    public Attributes getAttributes()
+    {
+        return attributes;
+    }
+
+    /**
+     * Add an attribute to the attributes list.
+     * 
+     * @param attribute The attribute to add to the list
+     */
+    public void addAttribute( LdapString attribute )
+    {
+        attributes.put( new BasicAttribute( attribute.toString().toLowerCase() ) );
+    }
+
+    /**
+     * Initialize the attributes list
+     */
+    public void initAttributes()
+    {
+        attributes = new BasicAttributes( true );
+    }
+
+    /**
+     * Get the base object
+     *
+     * @return Returns the baseObject.
+     */
+    public String getBaseObject()
+    {
+        return ( ( baseObject == null ) ? null : baseObject.toString() );
+    }
+
+    /**
+     * Set the base object
+     *
+     * @param baseObject The baseObject to set.
+     */
+    public void setBaseObject( LdapDN baseObject )
+    {
+        this.baseObject = baseObject;
+    }
+
+    /**
+     * Get the derefAliases flag
+     *
+     * @return Returns the derefAliases.
+     */
+    public int getDerefAliases()
+    {
+        return derefAliases;
+    }
+
+    /**
+     * Set the derefAliases flag
+     *
+     * @param derefAliases The derefAliases to set.
+     */
+    public void setDerefAliases( int derefAliases )
+    {
+        this.derefAliases = derefAliases;
+    }
+
+    /**
+     * Get the filter
+     *
+     * @return Returns the filter.
+     */
+    public Filter getFilter()
+    {
+        return filter;
+    }
+
+    /**
+     * Set the filter
+     *
+     * @param filter The filter to set.
+     */
+    public void setFilter( Filter filter )
+    {
+        this.filter = filter;
+    }
+
+    /**
+     * Get the search scope
+     *
+     * @return Returns the scope.
+     */
+    public int getScope()
+    {
+        return scope;
+    }
+
+    /**
+     * Set the search scope
+     *
+     * @param scope The scope to set.
+     */
+    public void setScope( int scope )
+    {
+        this.scope = scope;
+    }
+
+    /**
+     * Get the size limit
+     *
+     * @return Returns the sizeLimit.
+     */
+    public int getSizeLimit()
+    {
+        return sizeLimit;
+    }
+
+    /**
+     * Set the size limit
+     *
+     * @param sizeLimit The sizeLimit to set.
+     */
+    public void setSizeLimit( int sizeLimit )
+    {
+        this.sizeLimit = sizeLimit;
+    }
+
+    /**
+     * Get the time limit
+     *
+     * @return Returns the timeLimit.
+     */
+    public int getTimeLimit()
+    {
+        return timeLimit;
+    }
+
+    /**
+     * Set the time limit
+     *
+     * @param timeLimit The timeLimit to set.
+     */
+    public void setTimeLimit( int timeLimit )
+    {
+        this.timeLimit = timeLimit;
+    }
+
+    /**
+     * Get the typesOnly flag
+     *
+     * @return Returns the typesOnly.
+     */
+    public boolean isTypesOnly()
+    {
+        return typesOnly;
+    }
+
+    /**
+     * Set the typesOnly flag
+     *
+     * @param typesOnly The typesOnly to set.
+     */
+    public void setTypesOnly( boolean typesOnly )
+    {
+        this.typesOnly = typesOnly;
+    }
+
+    /**
+     * Get the current dilter
+     *
+     * @return Returns the currentFilter.
+     */
+    public Filter getCurrentFilter()
+    {
+        return currentFilter;
+    }
+
+    /**
+     * Set the current dilter
+     *
+     * @param currentFilter The currentFilter to set.
+     */
+    public void setCurrentFilter( Filter currentFilter )
+    {
+        this.currentFilter = currentFilter;
+    }
+    
+    /**
+     * Compute the SearchRequest length
+     * 
+     * SearchRequest :
+     * 
+     * 0x63 L1
+     *  |
+     *  +--> 0x04 L2 baseObject
+     *  +--> 0x0A 0x01 scope
+     *  +--> 0x0A 0x01 derefAliases
+     *  +--> 0x02 0x0(1..4) sizeLimit
+     *  +--> 0x02 0x0(1..4) timeLimit
+     *  +--> 0x01 0x01 typesOnly
+     *  +--> filter.computeLength()
+     *  +--> 0x30 L3 (Attribute description list)
+     *        |
+     *        +--> 0x04 L4-1 Attribute description 
+     *        +--> 0x04 L4-2 Attribute description 
+     *        +--> ... 
+     *        +--> 0x04 L4-i Attribute description 
+     *        +--> ... 
+     *        +--> 0x04 L4-n Attribute description 
+     * 
+     */
+    public int computeLength()
+    {
+        searchRequestLength = 0;
+        
+        // The baseObject
+        searchRequestLength += 1 + Length.getNbBytes( baseObject.getLength() ) + baseObject.getLength();
+        
+        // The scope
+        searchRequestLength += 1 + 1 + 1;
+        
+        // The derefAliases
+        searchRequestLength += 1 + 1 + 1;
+        
+        // The sizeLimit
+        searchRequestLength += 1 + 1 + Value.getNbBytes(sizeLimit);
+        
+        // The timeLimit
+        searchRequestLength += 1 + 1 + Value.getNbBytes(timeLimit);
+        
+        // The typesOnly
+        searchRequestLength += 1 + 1 + 1;
+        
+        // The filter
+        searchRequestLength += filter.computeLength();
+        
+        // The attributes description list
+        attributeDescriptionListLength = 0;
+        
+        if ( ( attributes != null ) && ( attributes.size() != 0 ) )
+        {
+            NamingEnumeration attributeIterator = attributes.getAll();
+            
+            // Compute the attributes length
+            while ( attributeIterator.hasMoreElements() )
+            {
+                Attribute attribute = (BasicAttribute)attributeIterator.nextElement();
+                
+                // add the attribute length to the attributes length
+                int idLength = attribute.getID().getBytes().length;
+                attributeDescriptionListLength += 1 + Length.getNbBytes( idLength ) + idLength;
+            }
+        }
+        
+        searchRequestLength += 1 + Length.getNbBytes( attributeDescriptionListLength ) + attributeDescriptionListLength;
+
+        // Return the result.
+        return 1 + Length.getNbBytes( searchRequestLength ) + searchRequestLength;
+    }
+    
+    /**
+     * Encode the SearchRequest message to a PDU.
+     * 
+     * SearchRequest :
+     * 
+     * 0x63 LL
+     *   0x04 LL baseObject
+     *   0x0A 01 scope
+     *   0x0A 01 derefAliases
+     *   0x02 0N sizeLimit
+     *   0x02 0N timeLimit
+     *   0x01 0x01 typesOnly
+     *   filter.encode()
+     *   0x30 LL attributeDescriptionList
+     *     0x04 LL attributeDescription
+     *     ... 
+     *     0x04 LL attributeDescription
+     * 
+     * @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 SearchRequest Tag
+            buffer.put( LdapConstants.SEARCH_REQUEST_TAG );
+            buffer.put( Length.getBytes( searchRequestLength ) ) ;
+            
+            // The baseObject
+            Value.encode( buffer, baseObject );
+            
+            // The scope
+            Value.encodeEnumerated( buffer, scope );
+
+            // The derefAliases
+            Value.encodeEnumerated( buffer, derefAliases );
+
+            // The sizeLimit
+            Value.encode( buffer, sizeLimit );
+
+            // The timeLimit
+            Value.encode( buffer, timeLimit );
+
+            // The typesOnly
+            Value.encode( buffer, typesOnly );
+
+            // The filter
+            filter.encode( buffer );
+            
+            // The attributeDescriptionList
+            buffer.put( UniversalTag.SEQUENCE_TAG );
+            buffer.put( Length.getBytes( attributeDescriptionListLength ) );
+            
+            if ( ( attributes != null ) && ( attributes.size() != 0 ) )
+            {
+                NamingEnumeration attributeIterator = attributes.getAll();
+                
+                // encode each attribute
+                while ( attributeIterator.hasMoreElements() )
+                {
+                    Attribute attribute = (BasicAttribute)attributeIterator.nextElement();
+                    
+                    Value.encode( buffer, attribute.getID() );
+                }
+            }
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException("The PDU buffer size is too small !"); 
+        }
+
+        return buffer;
+    }
+
+    /**
+     * 
+     * @return A string that represent the Filter
+     */
+    private String buildFilter()
+    {
+        if (filter == null)
+        {
+            return "";
+        }
+        
+        StringBuffer sb = new StringBuffer();
+        
+        sb.append("(");
+
+        sb.append( filter.toString() );
+        
+        sb.append(")");
+        
+        return sb.toString();
+    }
+    
+    /**
+     * Return a string the represent a SearchRequest
+     */
+    public String toString()
+    {
+        StringBuffer sb = new StringBuffer();
+        
+        sb.append( "    Search Request\n" );
+        sb.append( "        Base Object : '" ).append( baseObject ).append( "'\n" );
+        sb.append( "        Scope : " );
+        
+        switch (scope)
+        {
+        	case LdapConstants.SCOPE_BASE_OBJECT : 
+        	    sb.append("base object");
+        	    break;
+        	    
+        	case LdapConstants.SCOPE_SINGLE_LEVEL :
+        		sb.append("single level");
+    	    	break;
+    	    	
+        	case LdapConstants.SCOPE_WHOLE_SUBTREE :
+    	    	sb.append("whole subtree");
+    	    	break;
+        }
+
+        sb.append( "\n" );
+        
+        sb.append( "        Deref Aliases : " );
+        
+        switch (derefAliases)
+        {
+    		case LdapConstants.NEVER_DEREF_ALIASES :
+    		    sb.append("never Deref Aliases");
+	    		break;
+
+        	case LdapConstants.DEREF_IN_SEARCHING :
+    	    	sb.append("deref In Searching");
+    	    	break;
+
+        	case LdapConstants.DEREF_FINDING_BASE_OBJ :
+        		sb.append("deref Finding Base Obj");
+    	    	break;
+    	    	
+        	case LdapConstants.DEREF_ALWAYS : 
+        	    sb.append("deref Always");
+        	    break;
+        }
+
+        sb.append( "\n" );
+        
+        sb.append( "        Size Limit : " );
+        
+        if ( sizeLimit == 0 ) 
+        {
+            sb.append( "no limit" );
+        }
+        else
+        {
+            sb.append( sizeLimit );
+        }
+        
+        sb.append( "\n" );
+        
+        sb.append( "        Time Limit : " );
+        
+        if ( timeLimit == 0 ) 
+        {
+            sb.append( "no limit" );
+        }
+        else
+        {
+            sb.append( timeLimit );
+        }
+        
+        sb.append( "\n" );
+        
+        sb.append( "        Types Only : " ).append( typesOnly ).append( "\n" );
+        sb.append( "        Filter : '" ).append( buildFilter() ).append( "'\n" );
+        
+        return sb.toString();
+    }
+}

Propchange: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/SearchRequest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/SearchResultDone.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/SearchResultDone.java?rev=279887&view=auto
==============================================================================
--- directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/SearchResultDone.java (added)
+++ directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/SearchResultDone.java Fri Sep  9 14:41:22 2005
@@ -0,0 +1,119 @@
+/*
+ *   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.asn1.codec.EncoderException;
+import org.apache.asn1new.ber.tlv.Length;
+import org.apache.asn1new.ldap.codec.LdapConstants;
+
+/**
+ * A SearchResultDone Message. Its syntax is :
+ *   SearchResultDone ::= [APPLICATION 5] LDAPResult
+ * 
+ * It's a Response, so it inherites from LdapResponse.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SearchResultDone extends LdapResponse
+{
+    //~ Constructors -------------------------------------------------------------------------------
+
+    /**
+     * Creates a new SearchResultDone object.
+     */
+    public SearchResultDone()
+    {
+        super( );
+    }
+
+    /**
+     * Get the message type
+     *
+     * @return Returns the type.
+     */
+    public int getMessageType()
+    {
+        return LdapConstants.SEARCH_RESULT_DONE;
+    }
+
+    /**
+     * Compute the SearchResultDone length
+     * 
+     * SearchResultDone :
+     * 
+     * 0x65 L1
+     *  |
+     *  +--> LdapResult
+     * 
+     * L1 = Length(LdapResult)
+     * 
+     * Length(SearchResultDone) = Length(0x65) + Length(L1) + L1
+     */
+    public int computeLength()
+    {
+        int ldapResponseLength = super.computeLength();
+        
+        return 1 + Length.getNbBytes( ldapResponseLength ) + ldapResponseLength;
+    }
+    
+    /**
+     * Encode the SearchResultDone 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.SEARCH_RESULT_DONE_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 SearchResultDone
+     *
+     * @return A SearchResultDone String 
+     */
+    public String toString()
+    {
+
+        StringBuffer sb = new StringBuffer();
+
+        sb.append( "    Search Result Done\n" );
+        sb.append( super.toString() );
+
+        return sb.toString();
+    }
+}

Propchange: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/SearchResultDone.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/SearchResultEntry.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/SearchResultEntry.java?rev=279887&view=auto
==============================================================================
--- directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/SearchResultEntry.java (added)
+++ directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/SearchResultEntry.java Fri Sep  9 14:41:22 2005
@@ -0,0 +1,478 @@
+/*
+ *   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.asn1.codec.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.util.StringUtils;
+import org.apache.asn1new.ldap.codec.LdapConstants;
+import org.apache.asn1new.ldap.codec.primitives.LdapDN;
+import org.apache.asn1new.ldap.codec.primitives.LdapString;
+
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+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.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
+
+
+/**
+ * A SearchResultEntry Message. Its syntax is :
+ *   SearchResultEntry ::= [APPLICATION 4] SEQUENCE {
+ *       objectName      LDAPDN,
+ *       attributes      PartialAttributeList }
+ * 
+ *   PartialAttributeList ::= SEQUENCE OF SEQUENCE {
+ *       type    AttributeDescription,
+ *       vals    SET OF AttributeValue }
+ * 
+ *   AttributeDescription ::= LDAPString
+ * 
+ *   AttributeValue ::= OCTET STRING
+ * 
+ * It contains an entry, with all its attributes, and all the attributes
+ * values. If a search request is submited, all the results are sent one
+ * by one, followed by a searchResultDone message.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SearchResultEntry extends LdapMessage
+{
+    //~ Instance fields ----------------------------------------------------------------------------
+
+    /** The DN of the returned entry */
+    private LdapDN objectName;
+
+    /** The attributes list. It contains javax.naming.directory.Attribute */
+    private Attributes partialAttributeList;
+
+    /** The current attribute being decoded */
+    private transient Attribute currentAttributeValue;
+    
+    /** The search result entry length */
+    private transient int searchResultEntryLength;
+    
+    /** The partial attributes length */
+    private transient int attributesLength;
+    
+    /** The list of all attributes length */
+    private transient List attributeLength;
+    
+    /** The list of all vals length */
+    private transient List valsLength;
+
+    //~ Constructors -------------------------------------------------------------------------------
+
+    /**
+     * Creates a new SearchResultEntry object.
+     */
+    public SearchResultEntry()
+    {
+        super( );
+    }
+
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * Get the message type
+     *
+     * @return Returns the type.
+     */
+    public int getMessageType()
+    {
+        return LdapConstants.SEARCH_RESULT_ENTRY;
+    }
+
+    /**
+     * Get the entry DN
+     *
+     * @return Returns the objectName.
+     */
+    public String getObjectName()
+    {
+        return ( ( objectName == null ) ? null : objectName.toString() );
+    }
+
+    /**
+     * Set the entry DN
+     *
+     * @param objectName The objectName to set.
+     */
+    public void setObjectName( LdapDN objectName )
+    {
+        this.objectName = objectName;
+    }
+
+    /**
+     * Get the entry's attributes
+     *
+     * @return Returns the partialAttributeList.
+     */
+    public Attributes getPartialAttributeList()
+    {
+        return partialAttributeList;
+    }
+
+    /**
+     * Initialize the partial Attribute list.
+     *
+     */
+    public void setPartialAttributeList(Attributes partialAttributeList)
+    {
+
+        this.partialAttributeList = (Attributes)partialAttributeList;
+    }
+
+    /**
+     * Initialize the partial Attribute list if needed, otherwise add the current
+     * Attribute Value to the list.
+     *
+     */
+    public void addPartialAttributeList()
+    {
+
+        if ( currentAttributeValue == null )
+        {
+            partialAttributeList = new BasicAttributes( true );
+        }
+    }
+
+    /**
+     * Create a new attributeValue
+     * @param type The attribute's name
+     */
+    public void addAttributeValues( LdapString type )
+    {
+        currentAttributeValue = new BasicAttribute( type.toString().toLowerCase() );
+
+        partialAttributeList.put( currentAttributeValue );
+    }
+
+    /**
+     * Add a new value to the current attribute
+     * @param value
+     */
+    public void addAttributeValue( OctetString value )
+    {
+        currentAttributeValue.add( value );
+    }
+
+    /**
+     * Compute the SearchResultEntry length
+     * 
+     * SearchResultEntry :
+     * 
+     * 0x64 L1
+     *  |
+     *  +--> 0x04 L2 objectName
+     *  +--> 0x30 L3 (attributes)
+     *        |
+     *        +--> 0x30 L4-1 (partial attributes list)
+     *        |     |
+     *        |     +--> 0x04 L5-1 type
+     *        |     +--> 0x31 L6-1 (values)
+     *        |           |
+     *        |           +--> 0x04 L7-1-1 value
+     *        |           +--> ...
+     *        |           +--> 0x04 L7-1-n value
+     *        |
+     *        +--> 0x30 L4-2 (partial attributes list)
+     *        |     |
+     *        |     +--> 0x04 L5-2 type
+     *        |     +--> 0x31 L6-2 (values)
+     *        |           |
+     *        |           +--> 0x04 L7-2-1 value
+     *        |           +--> ...
+     *        |           +--> 0x04 L7-2-n value
+     *        |
+     *        +--> ...
+     *        |
+     *        +--> 0x30 L4-m (partial attributes list)
+     *              |
+     *              +--> 0x04 L5-m type
+     *              +--> 0x31 L6-m (values)
+     *                    |
+     *                    +--> 0x04 L7-m-1 value
+     *                    +--> ...
+     *                    +--> 0x04 L7-m-n value
+     * 
+     */
+    public int computeLength()
+    {
+        // The entry
+        searchResultEntryLength = 1 + Length.getNbBytes( objectName.getLength() ) + objectName.getLength();
+        
+        // The attributes sequence
+        attributesLength = 0;
+        
+        if ( ( partialAttributeList != null ) && ( partialAttributeList.size() != 0 ) )
+        {
+            NamingEnumeration attributes = partialAttributeList.getAll();
+            attributeLength = new LinkedList();
+            valsLength = new LinkedList();
+            
+            // Compute the attributes length
+            while ( attributes.hasMoreElements() )
+            {
+                Attribute attribute = (Attribute)attributes.nextElement();
+                int localAttributeLength = 0;
+                int localValuesLength = 0;
+                
+                // Get the type length
+                int idLength = attribute.getID().getBytes().length;
+                localAttributeLength = 1 + Length.getNbBytes( idLength ) + idLength;
+                
+                // The values
+                try
+                {
+	                NamingEnumeration values = attribute.getAll();
+	                
+	                if ( values.hasMoreElements() )
+	                {
+                        localValuesLength = 0;
+	                    
+		                while ( values.hasMoreElements() )
+		                {
+		                    Object value = (Object)values.next();
+		                    
+		                    if ( value instanceof String )
+		                    {
+		                    	String stringValue = (String)value;
+	                            localValuesLength += 1 + Length.getNbBytes( stringValue.length() ) + stringValue.getBytes().length;
+		                    }
+		                    else if ( value instanceof OctetString )
+		                    {
+		                    	OctetString octetStringValue = (OctetString)value;
+	                            localValuesLength += 1 + Length.getNbBytes( octetStringValue.getValue().length ) + octetStringValue.getLength();
+		                    }
+		                    else
+		                    {
+		                    	byte[] binaryValue = (byte[])value;
+	                            localValuesLength += 1 + Length.getNbBytes( binaryValue.length ) + binaryValue.length;
+		                    }
+		                    
+		                }
+
+                        localAttributeLength += 1 + Length.getNbBytes( localValuesLength ) + localValuesLength; 
+	                }
+	                
+                }
+                catch (NamingException ne)
+                {
+                    return 0;
+                }
+                
+                // add the attribute length to the attributes length
+                attributesLength += 1 + Length.getNbBytes( localAttributeLength ) + localAttributeLength;
+                
+                attributeLength.add( new Integer( localAttributeLength ) );
+                valsLength.add( new Integer( localValuesLength ) );
+            }
+        }
+        
+        searchResultEntryLength += 1 + Length.getNbBytes( attributesLength ) + attributesLength;
+
+        // Return the result.
+        return 1 + Length.getNbBytes( searchResultEntryLength ) + searchResultEntryLength;
+    }
+    
+    /**
+     * Encode the SearchResultEntry message to a PDU.
+     * 
+     * SearchResultEntry :
+     * 
+     * 0x64 LL
+     *   0x04 LL objectName
+     *   0x30 LL attributes
+     *     0x30 LL partialAttributeList
+     *       0x04 LL type
+     *       0x31 LL vals
+     *         0x04 LL attributeValue
+     *         ... 
+     *         0x04 LL attributeValue
+     *     ... 
+     *     0x30 LL partialAttributeList
+     *       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 SearchResultEntry Tag
+            buffer.put( LdapConstants.SEARCH_RESULT_ENTRY_TAG );
+            buffer.put( Length.getBytes( searchResultEntryLength ) ) ;
+            
+            // The objectName
+            Value.encode( buffer, objectName );
+            
+            // The attributes sequence
+            buffer.put( UniversalTag.SEQUENCE_TAG );
+            buffer.put( Length.getBytes( attributesLength ) ) ;
+
+            // The partial attribute list
+            if ( ( partialAttributeList != null ) && ( partialAttributeList.size() != 0 ) )
+            {
+                NamingEnumeration attributes = partialAttributeList.getAll();
+                int attributeNumber = 0;
+                
+                // Compute the attributes length
+                while ( attributes.hasMoreElements() )
+                {
+                    Attribute attribute = (Attribute)attributes.nextElement();
+                    
+                    // The partial attribute list sequence
+                    buffer.put( UniversalTag.SEQUENCE_TAG );
+                    int localAttributeLength = ( (Integer)attributeLength.get( attributeNumber ) ).intValue();
+                    buffer.put( Length.getBytes( localAttributeLength ) );
+
+                    // The attribute type
+                    Value.encode( buffer, attribute.getID() );
+                    
+                    // The values
+                    buffer.put( UniversalTag.SET_TAG );
+                    int localValuesLength = ( (Integer)valsLength.get( attributeNumber ) ).intValue();
+                    buffer.put( Length.getBytes( localValuesLength ) );
+                    
+                    try
+                    {
+                        NamingEnumeration values = attribute.getAll();
+                        
+                        if ( values.hasMoreElements() )
+                        {
+                            while ( values.hasMoreElements() )
+                            {
+                                Object value = values.next();
+                                
+                                if ( value instanceof String )
+                                {
+                                	Value.encode( buffer, (String)value );
+                                }
+                                else if ( value instanceof OctetString )
+                                {
+                                	Value.encode( buffer, (OctetString)value );
+                                }
+                                else
+                                {
+                                	Value.encode( buffer, (byte[])value );
+                                }
+                            }
+                        }
+                        
+                    }
+                    catch (NamingException ne)
+                    {
+                        throw new EncoderException("Cannot enumerate the values");
+                    }
+                    
+                    // Go to the next attribute number;
+                    attributeNumber++;
+                }
+            }
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException("The PDU buffer size is too small !"); 
+        }
+
+        return buffer;
+    }
+
+    /**
+     * Returns the Search Result Entry string
+     *
+     * @return The Search Result Entry string 
+     */
+    public String toString()
+    {
+
+        StringBuffer sb = new StringBuffer();
+
+        sb.append( "    Search Result Entry\n" );
+        sb.append( "        Object Name : '" ).append( objectName.toString() ).append( "'\n" );
+        sb.append( "        Attributes\n" );
+
+        if ( ( partialAttributeList == null ) || ( partialAttributeList.size() == 0 ) )
+        {
+            sb.append( "            No attributes\n" );
+        }
+        else
+        {
+
+            NamingEnumeration attributes = partialAttributeList.getAll();
+
+            while ( attributes.hasMoreElements() )
+            {
+
+                Attribute attribute = ( Attribute ) attributes.nextElement();
+
+                sb.append( "            Name : '" ).append( attribute.getID() ).append( "'\n" );
+
+                try
+                {
+
+                    NamingEnumeration values = attribute.getAll();
+
+                    if ( values.hasMoreElements() )
+                    {
+                        sb.append( "            Values\n" );
+
+                        while ( values.hasMore() )
+                        {
+                        	Object value = values.nextElement();
+                        	sb.append( "                '" );
+                        	
+                       		sb.append( StringUtils.dumpBytes( ( (OctetString)value ).getValue() ) );
+
+                            sb.append("'\n" );
+                        }
+                    }
+                    else
+                    {
+                        sb.append( "            No Values\n" );
+                    }
+                }
+                catch ( NamingException ne )
+                {
+                    sb.append( "            Error while reading attribute.\n " );
+                }
+            }
+        }
+
+        return sb.toString();
+    }
+}

Propchange: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/SearchResultEntry.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/SearchResultReference.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/SearchResultReference.java?rev=279887&view=auto
==============================================================================
--- directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/SearchResultReference.java (added)
+++ directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/SearchResultReference.java Fri Sep  9 14:41:22 2005
@@ -0,0 +1,199 @@
+/*
+ *   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.asn1.codec.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.LdapURL;
+
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+
+/**
+ * A SearchResultReference Message. Its syntax is :
+ *   SearchResultReference ::= [APPLICATION 19] SEQUENCE OF LDAPURL
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SearchResultReference extends LdapMessage
+{
+    //~ Instance fields ----------------------------------------------------------------------------
+
+    /** The set of LdapURLs */
+    private ArrayList searchResultReferences;
+    
+    /** The search result reference length */
+    private transient int searchResultReferenceLength;
+
+    //~ Constructors -------------------------------------------------------------------------------
+
+    /**
+     * Creates a new SearchResultEntry object.
+     */
+    public SearchResultReference()
+    {
+        super( );
+        searchResultReferences = new ArrayList();
+    }
+
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * Get the message type
+     *
+     * @return Returns the type.
+     */
+    public int getMessageType()
+    {
+        return LdapConstants.SEARCH_RESULT_REFERENCE;
+    }
+
+    /**
+     * Add a new reference to the list.
+     * @param searchResultReference The search result reference
+    */
+    public void addSearchResultReference( LdapURL searchResultReference )
+    {
+        searchResultReferences.add( searchResultReference );
+    }
+
+    /**
+     * Get the list of references
+     * @return An ArrayList of SearchResultReferences
+     */
+    public ArrayList getSearchResultReferences()
+    {
+        return searchResultReferences;
+    }
+
+    /**
+     * Compute the SearchResultReference length
+     * 
+     * SearchResultReference :
+     * 
+     * 0x73 L1
+     *  |
+     *  +--> 0x04 L2 reference
+     *  +--> 0x04 L3 reference
+     *  +--> ...
+     *  +--> 0x04 Li reference
+     *  +--> ...
+     *  +--> 0x04 Ln reference
+     * 
+     * L1 = n*Length(0x04) + sum(Length(Li)) + sum(Length(reference[i]))
+     * 
+     * Length(SearchResultReference) = Length(0x73 + Length(L1) + L1
+     */
+    public int computeLength()
+    {
+        searchResultReferenceLength = 0;
+        
+        Iterator referencesIterator = searchResultReferences.iterator();
+        
+        // We may have more than one reference.
+        while (referencesIterator.hasNext())
+        {
+            int ldapUrlLength = ((LdapURL)referencesIterator.next()).getLength();
+            searchResultReferenceLength += 1 + Length.getNbBytes( ldapUrlLength ) + ldapUrlLength;
+        }
+        
+        return 1 + Length.getNbBytes( searchResultReferenceLength ) + searchResultReferenceLength;
+    }
+
+    /**
+     * Encode the SearchResultReference message to a PDU.
+     * 
+     * SearchResultReference :
+     * 
+     * 0x73 LL
+     *   0x04 LL reference
+     *   [0x04 LL reference]*
+     * 
+     * @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 SearchResultReference Tag
+            buffer.put( LdapConstants.SEARCH_RESULT_REFERENCE_TAG );
+            buffer.put( Length.getBytes( searchResultReferenceLength ) ) ;
+
+            // The references. We must at least have one reference
+            Iterator referencesIterator = searchResultReferences.iterator();
+            
+            // We may have more than one reference.
+            while (referencesIterator.hasNext())
+            {
+                LdapURL reference = ((LdapURL)referencesIterator.next());
+                
+                // Encode the reference
+                Value.encode( buffer, reference );
+            }
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException("The PDU buffer size is too small !"); 
+        }
+
+        return buffer;
+    }
+
+    /**
+     * Returns the Search Result Reference string
+     *
+     * @return The Search Result Reference string 
+     */
+    public String toString()
+    {
+
+        StringBuffer sb = new StringBuffer();
+
+        sb.append( "    Search Result Reference\n" );
+
+        if ( ( searchResultReferences == null ) || ( searchResultReferences.size() == 0 ) )
+        {
+            sb.append( "        No Reference\n" );
+        }
+        else
+        {
+            sb.append( "        References\n" );
+
+            Iterator referencesIterator = searchResultReferences.iterator();
+
+            while ( referencesIterator.hasNext() )
+            {
+                sb.append( "            '" )
+                  .append( ( ( LdapURL ) referencesIterator.next() ).toString() ).append( "'\n" );
+            }
+        }
+
+        return sb.toString();
+    }
+}

Propchange: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/SearchResultReference.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/SimpleAuthentication.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/SimpleAuthentication.java?rev=279887&view=auto
==============================================================================
--- directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/SimpleAuthentication.java (added)
+++ directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/SimpleAuthentication.java Fri Sep  9 14:41:22 2005
@@ -0,0 +1,133 @@
+/*
+ *   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.asn1.codec.EncoderException;
+import org.apache.asn1new.ber.tlv.Length;
+import org.apache.asn1new.primitives.OctetString;
+import org.apache.asn1new.ldap.codec.LdapConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * A ldapObject which stores the Simple authentication for a BindRequest.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SimpleAuthentication  extends LdapAuthentication
+{
+	/** The logger */
+    private static Logger log = LoggerFactory.getLogger( SimpleAuthentication.class );
+
+    //~ Instance fields ----------------------------------------------------------------------------
+
+    /** The simple authentication password */
+    private OctetString simple;
+
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * Get the simple password
+     *
+     * @return The password
+     */
+    public OctetString getSimple()
+    {
+        return simple;
+    }
+
+    /**
+     * Set the simple password
+     *
+     * @param simple The simple password
+     */
+    public void setSimple( OctetString simple )
+    {
+        this.simple = simple;
+    }
+
+    /**
+     * Compute the Simple authentication length
+     * 
+     * Simple authentication :
+     * 
+     * 0x80 L1 simple
+     * 
+     * L1 = Length(simple)
+     * 
+     * Length(Simple authentication) = Length(0x80) + Length(L1) + Length(simple)
+     */
+    public int computeLength()
+    {
+    	int length = 1 + Length.getNbBytes( simple.getLength() ) + simple.getLength();
+
+    	if ( log.isDebugEnabled() )
+    	{
+    		log.debug( "Simple Authentication length : " + length );
+    	}
+
+    	return length;
+    }
+    
+    /**
+     * Encode the simple authentication to a PDU.
+     * 
+     * SimpleAuthentication :
+     * 
+     * 0x80 LL simple
+     * 
+     * @param buffer The buffer where to put the PDU
+     * @return The PDU.
+     */
+    public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
+    {
+        if ( buffer == null )
+        {
+        	log.error( "Cannot put a PDU in a null buffer !" );
+            throw new EncoderException( "Cannot put a PDU in a null buffer !" );
+        }
+
+        try 
+        {
+            // The simpleAuthentication Tag
+            buffer.put( (byte)LdapConstants.BIND_REQUEST_SIMPLE_TAG );
+            buffer.put( Length.getBytes( simple.getLength() ) ) ;
+            buffer.put( simple.getValue() ) ;
+        }
+        catch ( BufferOverflowException boe )
+        {
+        	log.error( "The PDU buffer size is too small !" );
+            throw new EncoderException("The PDU buffer size is too small !"); 
+        }
+
+        return buffer;
+    }
+
+    /**
+     * Return the simple authentication as a string
+     *
+     * @return The simple authentication string.
+     */
+    public String toString()
+    {
+        return ( ( simple == null ) ? "null" : simple.toString() );
+    }
+}

Propchange: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/SimpleAuthentication.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/UnBindRequest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/UnBindRequest.java?rev=279887&view=auto
==============================================================================
--- directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/UnBindRequest.java (added)
+++ directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/UnBindRequest.java Fri Sep  9 14:41:22 2005
@@ -0,0 +1,114 @@
+/*
+ *   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.asn1.codec.EncoderException;
+import org.apache.asn1new.ldap.codec.LdapConstants;
+
+/**
+ * A UnBindRequest ldapObject. Its syntax is :
+ * 	UnbindRequest ::= [APPLICATION 2] NULL
+ * 
+ * This ldapObject is empty.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class UnBindRequest extends LdapMessage
+{
+    //~ Instance fields ----------------------------------------------------------------------------
+
+    //~ Constructors -------------------------------------------------------------------------------
+
+    /**
+     * Creates a new BindRequest object.
+     */
+    public UnBindRequest()
+    {
+        super( );
+    }
+
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * Get the message type
+     *
+     * @return Returns the type.
+     */
+    public int getMessageType()
+    {
+        return LdapConstants.UNBIND_REQUEST;
+    }
+
+    /**
+     * Compute the UnBindRequest length
+     * 
+     * UnBindRequest :
+     * 
+     * 0x42 00
+     */
+    public int computeLength()
+    {
+        return 2; // Always 2
+    }
+    
+    /**
+     * Encode the UnbindRequest 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.UNBIND_REQUEST_TAG);
+            
+            // The length is always null.
+            buffer.put( (byte)0 );
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException("The PDU buffer size is too small !"); 
+        }
+        
+        return buffer;
+    }
+
+    /**
+     * Get a String representation of a UnBindRequest
+     *
+     * @return A UnBindRequest String 
+     */
+    public String toString()
+    {
+
+        StringBuffer sb = new StringBuffer();
+
+        sb.append( "    UnBind Request\n" );
+
+        return sb.toString();
+    }
+}

Propchange: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/UnBindRequest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/filters/AndFilter.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/filters/AndFilter.java?rev=279887&view=auto
==============================================================================
--- directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/filters/AndFilter.java (added)
+++ directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/filters/AndFilter.java Fri Sep  9 14:41:22 2005
@@ -0,0 +1,120 @@
+/*
+ *   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.filters;
+
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+
+import org.apache.asn1.codec.EncoderException;
+import org.apache.asn1new.ber.tlv.Length;
+import org.apache.asn1new.ldap.codec.LdapConstants;
+
+/**
+ * And Filter Object to store the And filter.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AndFilter extends ConnectorFilter
+{
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * The constructor. We wont initialize the ArrayList as they may not be used. 
+     */
+    public AndFilter()
+    {
+        super();
+    }
+    
+    /**
+     * Get the AndFilter.
+     *
+     * @return Returns the andFilter.
+     */
+    public ArrayList getAndFilter()
+    {
+        return filterSet;
+    }
+    
+    /**
+     * Compute the AndFilter length
+     * 
+     * AndFilter :
+     * 
+     * 0xA0 L1 super.computeLength()
+     * 
+     * Length(AndFilter) = Length(0xA0) + Length(super.computeLength()) + super.computeLength()
+     * 
+     */
+    public int computeLength()
+    {
+        filtersLength = super.computeLength();
+        
+        return 1 + Length.getNbBytes( filtersLength ) + filtersLength;
+    }
+    
+    /**
+     * Encode the AndFilter message to a PDU.
+     * 
+     * AndFilter :
+     * 
+     * 0xA0 LL 
+     * filter.encode()
+     * ...
+     * filter.encode()
+     * 
+     * @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 AndFilter Tag
+            buffer.put( (byte)LdapConstants.AND_FILTER_TAG );
+            buffer.put( Length.getBytes( filtersLength ) );
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException("The PDU buffer size is too small !"); 
+        }
+        
+        super.encode( buffer );
+
+        return buffer;
+    }
+
+    /**
+     * Return a string compliant with RFC 2254 representing an AND filter
+     *
+     * @return The AND filter string
+     */
+    public String toString()
+    {
+        StringBuffer sb = new StringBuffer();
+        
+        sb.append('&').append(super.toString());
+        
+        return sb.toString();
+    }
+}

Propchange: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/filters/AndFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native