directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r209019 - /directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/LdapMessage.java
Date Mon, 04 Jul 2005 06:38:33 GMT
Author: elecharny
Date: Sun Jul  3 23:38:32 2005
New Revision: 209019

URL: http://svn.apache.org/viewcvs?rev=209019&view=rev
Log:
Changed from Controls[] to ArrayList, and reflect the renaming of Controls to Control

Modified:
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/LdapMessage.java

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/LdapMessage.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/LdapMessage.java?rev=209019&r1=209018&r2=209019&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/LdapMessage.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/LdapMessage.java
Sun Jul  3 23:38:32 2005
@@ -16,15 +16,18 @@
  */
 package org.apache.asn1.ldap.pojo;
 
-import java.nio.ByteBuffer;
-
 import org.apache.asn1.Asn1Object;
-import org.apache.asn1.ber.tlv.Length;
 import org.apache.asn1.EncoderException;
+import org.apache.asn1.ber.tlv.Length;
+
+import java.nio.ByteBuffer;
+
+import java.util.ArrayList;
+
 
 /**
  * The main ldapObject : every Ldap Message are encapsulated in it. It has a
- * messageId and Controls.
+ * messageId and Control.
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
@@ -39,7 +42,7 @@
     private Asn1Object protocolOp;
 
     /** The controls */
-    private Controls[] controls;
+    private ArrayList controls;
 
     //~ Constructors -------------------------------------------------------------------------------
 
@@ -60,20 +63,19 @@
      *
      * @return The selected Control Object
      */
-    public Controls getControls( int i )
+    public Control getControls( int i )
     {
-
-        return controls[i];
+        return (Control)controls.get( i );
     }
 
     /**
-     * Set the Controls array
+     * Set the Control array
      *
-     * @param controls The Controls array to store
+     * @param control The Control array to store
      */
-    public void setControls( Controls[] controls )
+    public void addControl( Control control )
     {
-        this.controls = controls;
+        this.controls.add( control );
     }
 
     /**
@@ -115,7 +117,7 @@
      */
     public BindResponse getBindResponse()
     {
-        return (BindResponse)protocolOp;
+        return ( BindResponse ) protocolOp;
     }
 
     /**
@@ -126,7 +128,7 @@
      */
     public BindRequest getBindRequest()
     {
-        return (BindRequest)protocolOp;
+        return ( BindRequest ) protocolOp;
     }
 
     /**
@@ -137,7 +139,7 @@
      */
     public SearchRequest getSearchRequest()
     {
-        return (SearchRequest)protocolOp;
+        return ( SearchRequest ) protocolOp;
     }
 
     /**
@@ -148,7 +150,7 @@
      */
     public SearchResultEntry getSearchResultEntry()
     {
-        return (SearchResultEntry)protocolOp;
+        return ( SearchResultEntry ) protocolOp;
     }
 
     /**
@@ -159,7 +161,7 @@
      */
     public SearchResultReference getSearchResultReference()
     {
-        return (SearchResultReference)protocolOp;
+        return ( SearchResultReference ) protocolOp;
     }
 
     /**
@@ -170,7 +172,7 @@
      */
     public ModifyRequest getModifyRequest()
     {
-        return (ModifyRequest)protocolOp;
+        return ( ModifyRequest ) protocolOp;
     }
 
     /**
@@ -181,7 +183,7 @@
      */
     public ModifyDNRequest getModifyDNRequest()
     {
-        return (ModifyDNRequest)protocolOp;
+        return ( ModifyDNRequest ) protocolOp;
     }
 
     /**
@@ -192,7 +194,7 @@
      */
     public DelRequest getDelRequest()
     {
-        return (DelRequest)protocolOp;
+        return ( DelRequest ) protocolOp;
     }
 
     /**
@@ -203,7 +205,7 @@
      */
     public CompareRequest getCompareRequest()
     {
-        return (CompareRequest)protocolOp;
+        return ( CompareRequest ) protocolOp;
     }
 
     /**
@@ -214,7 +216,7 @@
      */
     public AddRequest getAddRequest()
     {
-        return (AddRequest)protocolOp;
+        return ( AddRequest ) protocolOp;
     }
 
     /**
@@ -225,7 +227,7 @@
      */
     public ExtendedRequest getExtendedRequest()
     {
-        return (ExtendedRequest)protocolOp;
+        return ( ExtendedRequest ) protocolOp;
     }
 
     /**
@@ -236,7 +238,7 @@
      */
     public ExtendedResponse getExtendedResponse()
     {
-        return (ExtendedResponse)protocolOp;
+        return ( ExtendedResponse ) protocolOp;
     }
 
     /**
@@ -261,22 +263,44 @@
      * @return A ByteBuffer that contaons the PDU
      * @throws EncoderException If anything goes wrong.
      */
-    public Object encode(Object object) throws EncoderException
+    public Object encode( Object object ) throws EncoderException
     {
+
         // Compute the LdapMessage length. It will be the sum of each
-        // element, plus the length of the Length part plus 1 byte for 
+        // element, plus the length of the Length part plus 1 byte for
         // the tag.
         int ldapMessageLength = 0;
-        
+
         // The length of the MessageId.
-        ldapMessageLength += Length.getNbBytes(messageId) ;
-        
+        ldapMessageLength += Length.getNbBytes( messageId );
+
         int protocolOpLength = 0;
-        
-        // Allocate the bytes buffer.  
-        ByteBuffer bb = ByteBuffer.allocate(ldapMessageLength + Length.getNbBytes(protocolOpLength)
+ 1 );
+
+        // Allocate the bytes buffer.
+        ByteBuffer bb = ByteBuffer.allocate(
+                ldapMessageLength + Length.getNbBytes( protocolOpLength ) + 1 );
 
         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( "    messageId : " ).append( messageId ).append( '\n' );
+        sb.append( protocolOp.toString() ).append( '\n' );
+
+        for ( int i = 0; i < controls.size(); i++ )
+        {
+            sb.append( ( ( Control ) controls.get( i ) ).toString() ).append( '\n' );
+        }
+
+        return sb.toString();
+    }
 }



Mime
View raw message