directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r226643 - in /directory/sandbox/trunk/asn1-new-codec/src: java/org/apache/asn1/ldap/codec/ java/org/apache/asn1/ldap/codec/grammars/ java/org/apache/asn1/ldap/pojo/ test/org/apache/asn1/ldap/codec/
Date Sun, 31 Jul 2005 13:56:43 GMT
Author: elecharny
Date: Sun Jul 31 06:56:34 2005
New Revision: 226643

URL: http://svn.apache.org/viewcvs?rev=226643&view=rev
Log:
Added the encode method for DelRequest and SearchResultDone

Modified:
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapConstants.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/DelRequestGrammar.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/SearchResultDoneGrammar.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SearchResultDone.java
    directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/DelRequestTest.java
    directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/SearchResultDoneTest.java

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapConstants.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapConstants.java?rev=226643&r1=226642&r2=226643&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapConstants.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapConstants.java
Sun Jul 31 06:56:34 2005
@@ -51,8 +51,10 @@
     public static final byte SET_TAG = 0x31;
 
     /** LDAP contextual tags */
-    public static final byte ABANDON_REQUEST_TAG = 0x50;
     public static final byte UNBIND_REQUEST_TAG  = 0x42;
+    public static final byte DEL_REQUEST_TAG  = 0x4A;
+    public static final byte ABANDON_REQUEST_TAG = 0x50;
+    public static final byte SEARCH_RESULT_DONE_TAG = 0x65;
     public static final byte MODIFY_RESPONSE_TAG = 0x67;
     public static final byte ADD_RESPONSE_TAG = 0x69;
     public static final byte DEL_RESPONSE_TAG = 0x6B;

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/DelRequestGrammar.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/DelRequestGrammar.java?rev=226643&r1=226642&r2=226643&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/DelRequestGrammar.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/DelRequestGrammar.java
Sun Jul 31 06:56:34 2005
@@ -23,6 +23,7 @@
 import org.apache.asn1.ber.grammar.GrammarTransition;
 import org.apache.asn1.ber.grammar.IGrammar;
 import org.apache.asn1.ber.tlv.TLV;
+import org.apache.asn1.ldap.codec.LdapConstants;
 import org.apache.asn1.ldap.codec.LdapMessageContainer;
 import org.apache.asn1.ldap.codec.primitives.LdapDN;
 import org.apache.asn1.ldap.pojo.DelRequest;
@@ -69,13 +70,13 @@
         //============================================================================================
         // DelRequestGrammar ::= [APPLICATION 10] LDAPDN { (Tag)
         // Nothing to do
-        super.transitions[LdapStatesEnum.DEL_REQUEST_TAG][0x4A] = new GrammarTransition(
+        super.transitions[LdapStatesEnum.DEL_REQUEST_TAG][LdapConstants.DEL_REQUEST_TAG]
= new GrammarTransition(
                 LdapStatesEnum.DEL_REQUEST_TAG,
                 LdapStatesEnum.DEL_REQUEST_VALUE, null );
 
         // DelRequestGrammar ::= [APPLICATION 10] LDAPDN { (Value)
         // Initialise the del request pojo and store the DN to be deleted
-        super.transitions[LdapStatesEnum.DEL_REQUEST_VALUE][0x4A] = new GrammarTransition(
+        super.transitions[LdapStatesEnum.DEL_REQUEST_VALUE][LdapConstants.DEL_REQUEST_TAG]
= new GrammarTransition(
                 LdapStatesEnum.DEL_REQUEST_VALUE, LdapStatesEnum.END_STATE,
                 new GrammarAction( "Init del Request" )
                 {

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/SearchResultDoneGrammar.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/SearchResultDoneGrammar.java?rev=226643&r1=226642&r2=226643&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/SearchResultDoneGrammar.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/SearchResultDoneGrammar.java
Sun Jul 31 06:56:34 2005
@@ -22,6 +22,7 @@
 import org.apache.asn1.ber.grammar.GrammarAction;
 import org.apache.asn1.ber.grammar.GrammarTransition;
 import org.apache.asn1.ber.grammar.IGrammar;
+import org.apache.asn1.ldap.codec.LdapConstants;
 import org.apache.asn1.ldap.codec.LdapMessageContainer;
 import org.apache.asn1.ldap.pojo.LdapMessage;
 import org.apache.asn1.ldap.pojo.SearchResultDone;
@@ -67,14 +68,14 @@
         // LdapMessage ::= ... SearchResultDone ...
         // SearchResultDone ::= [APPLICATION 5] LDAPResult (Tag)
         // Nothing to do.
-        super.transitions[LdapStatesEnum.SEARCH_RESULT_DONE_TAG][0x65] = new GrammarTransition(
+        super.transitions[LdapStatesEnum.SEARCH_RESULT_DONE_TAG][LdapConstants.SEARCH_RESULT_DONE_TAG]
= new GrammarTransition(
                 LdapStatesEnum.SEARCH_RESULT_DONE_TAG, LdapStatesEnum.SEARCH_RESULT_DONE_VALUE,
null );
 
         // LdapMessage ::= ... SearchResultDone ...
         // SearchResultDone ::= [APPLICATION 5] LDAPResult (Value)
         // The next Tag will be the LDAPResult Tag (0x0A).
         // We will switch the grammar then.
-        super.transitions[LdapStatesEnum.SEARCH_RESULT_DONE_VALUE][0x65] = new GrammarTransition(
+        super.transitions[LdapStatesEnum.SEARCH_RESULT_DONE_VALUE][LdapConstants.SEARCH_RESULT_DONE_TAG]
= new GrammarTransition(
                 LdapStatesEnum.SEARCH_RESULT_DONE_VALUE, LdapStatesEnum.SEARCH_RESULT_DONE_LDAP_RESULT,

                 new GrammarAction( "Init search Result Done" )
                 {
@@ -94,7 +95,7 @@
         // LdapMessage ::= ... SearchResultDone ...
         // SearchResultDone ::= [APPLICATION 5] LDAPResult (Value)
         // Ok, we have a LDAPResult Tag (0x0A). So we have to switch the grammar.
-        super.transitions[LdapStatesEnum.SEARCH_RESULT_DONE_LDAP_RESULT][0x0A] = new GrammarTransition(
+        super.transitions[LdapStatesEnum.SEARCH_RESULT_DONE_LDAP_RESULT][LdapConstants.ENUMERATED_TAG]
= new GrammarTransition(
                 LdapStatesEnum.SEARCH_RESULT_DONE_LDAP_RESULT, LdapStatesEnum.LDAP_RESULT_GRAMMAR_SWITCH,
null );
     }
 

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SearchResultDone.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SearchResultDone.java?rev=226643&r1=226642&r2=226643&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SearchResultDone.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SearchResultDone.java
Sun Jul 31 06:56:34 2005
@@ -16,7 +16,12 @@
  */
 package org.apache.asn1.ldap.pojo;
 
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+
+import org.apache.asn1.EncoderException;
 import org.apache.asn1.ber.tlv.Length;
+import org.apache.asn1.ldap.codec.LdapConstants;
 
 /**
  * A SearchResultDone Message. Its syntax is :
@@ -56,6 +61,34 @@
         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);
     }
     
     /**

Modified: directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/DelRequestTest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/DelRequestTest.java?rev=226643&r1=226642&r2=226643&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/DelRequestTest.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/DelRequestTest.java
Sun Jul 31 06:56:34 2005
@@ -21,10 +21,12 @@
 import javax.naming.NamingException;
 
 import org.apache.asn1.DecoderException;
+import org.apache.asn1.EncoderException;
 import org.apache.asn1.ber.Asn1Decoder;
 import org.apache.asn1.ber.containers.IAsn1Container;
 import org.apache.asn1.ldap.pojo.DelRequest;
 import org.apache.asn1.ldap.pojo.LdapMessage;
+import org.apache.asn1.util.StringUtils;
 import org.apache.log4j.Logger;
 import org.apache.log4j.PropertyConfigurator;
 
@@ -66,6 +68,7 @@
 				0x4A, 0x22, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', ' ',
'o', 'u', '=', 'u', 's', 'e', 'r', 's', ',', ' ', 'o', 'u', '=', 's', 'y', 's', 't', 'e',
'm'
             } );
 
+        String decodedPdu = StringUtils.dumpBytes( stream.array() );
         stream.flip();
 
         // Allocate a LdapMessage Container
@@ -91,6 +94,21 @@
 
         // Check the length
         Assert.assertEquals(0x29, message.computeLength());
+
+        // Check the encoding
+        try
+        {
+            ByteBuffer bb = message.encode( null );
+            
+            String encodedPdu = StringUtils.dumpBytes( bb.array() ); 
+            
+            Assert.assertEquals(encodedPdu, decodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            ee.printStackTrace();
+            Assert.fail( ee.getMessage() );
+        }
     }
 
     /**

Modified: directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/SearchResultDoneTest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/SearchResultDoneTest.java?rev=226643&r1=226642&r2=226643&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/SearchResultDoneTest.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/SearchResultDoneTest.java
Sun Jul 31 06:56:34 2005
@@ -19,10 +19,12 @@
 import java.nio.ByteBuffer;
 
 import org.apache.asn1.DecoderException;
+import org.apache.asn1.EncoderException;
 import org.apache.asn1.ber.Asn1Decoder;
 import org.apache.asn1.ber.containers.IAsn1Container;
 import org.apache.asn1.ldap.pojo.LdapMessage;
 import org.apache.asn1.ldap.pojo.SearchResultDone;
+import org.apache.asn1.util.StringUtils;
 import org.apache.log4j.Logger;
 import org.apache.log4j.PropertyConfigurator;
 
@@ -71,6 +73,7 @@
 									// }
             } );
 
+        String decodedPdu = StringUtils.dumpBytes( stream.array() );
         stream.flip();
 
         // Allocate a BindRequest Container
@@ -96,5 +99,20 @@
         
         // Check the length
         Assert.assertEquals(0x2D, message.computeLength());
+
+        // Check the encoding
+        try
+        {
+            ByteBuffer bb = message.encode( null );
+            
+            String encodedPdu = StringUtils.dumpBytes( bb.array() ); 
+            
+            Assert.assertEquals(encodedPdu, decodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            ee.printStackTrace();
+            Assert.fail( ee.getMessage() );
+        }
     }
 }



Mime
View raw message