directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 36428 - in incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src: java/org/apache/snickers/ldap/encoder test/org/apache/snickers/ldap/encoder/abandon
Date Mon, 16 Aug 2004 02:22:21 GMT
Author: akarasulu
Date: Sun Aug 15 19:22:21 2004
New Revision: 36428

Removed:
   incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/abandon/AbandonRequestEncoderTest.java
Modified:
   incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/EncoderUtils.java
   incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/LdapResultEncoder.java
   incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/SnickersLdapEncoder.java
Log:
no longer needed

Modified: incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/EncoderUtils.java
==============================================================================
--- incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/EncoderUtils.java
(original)
+++ incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/EncoderUtils.java
Sun Aug 15 19:22:21 2004
@@ -16,9 +16,8 @@
  */
 package org.apache.snickers.ldap.encoder;
 
-import org.apache.snickers.ber.TupleEventConsumer;
-import org.apache.snickers.ber.TagEnum;
-import org.apache.snickers.ber.Tuple;
+
+import org.apache.snickers.ber.*;
 import org.apache.snickers.ber.primitives.UniversalTag;
 import org.apache.snickers.ber.primitives.PrimitiveUtils;
 
@@ -26,77 +25,105 @@
 
 
 /**
- * Common utilities used by encoders.
+ * Common utilities used by encoders for encoding primitive types into
+ * TupleNodes.
  * 
  * @author <a href="mailto:directory-dev@incubator.apache.org"> Apache Directory
  *         Project</a> $Rev$
  */
 public class EncoderUtils
 {
-    public static void encodePrimitive( String octets,
-                                        TupleEventConsumer consumer )
+    /**
+     * Encodes a Java String into a TupleNode.  The tag of the Tuple contained
+     * within the returned TupleNode defaults to a UNIVERSAL OCTET_STRING.
+     *
+     * @param octets the String value to encode
+     * @return the TupleNode containing the Tuple for the integer value
+     */
+    public static TupleNode encode( String octets )
     {
-        encodePrimitive( UniversalTag.OCTET_STRING, octets, consumer );
+        return encode( UniversalTag.OCTET_STRING, octets );
     }
 
 
-    public static void encodePrimitive( TagEnum tag, String octets,
-                                        TupleEventConsumer consumer )
+    /**
+     * Encodes a Java String into a TupleNode.
+     *
+     * @param tag the tag enumeration to use for the Tuple
+     * @param octets the String value to encode
+     * @return the TupleNode containing the Tuple for the integer value
+     */
+    public static TupleNode encode( TagEnum tag, String octets )
     {
         Tuple t = new Tuple();
         t.setTag( tag, true );
-        consumer.tag( t );
         ByteBuffer chunk = ByteBuffer.wrap( octets.getBytes() );
         t.setLength( chunk.remaining() );
-        consumer.length( t );
         t.setLastValueChunk( chunk );
-        consumer.chunkedValue( t, chunk );
-        consumer.finish( t );
+        return new DefaultMutableTupleNode( t );
     }
 
 
-    public static void encodePrimitive( int intval,
-                                        TupleEventConsumer consumer )
+    /**
+     * Encodes a primitive Java integer into a TupleNode.  The tag of the Tuple
+     * contained within the returned TupleNode defaults to a UNIVERSAL INTEGER.
+     *
+     * @param intval the integer value to encode
+     * @return the TupleNode containing the Tuple for the integer value
+     */
+    public static TupleNode encode( int intval )
     {
-        encodePrimitive( UniversalTag.INTEGER, intval, consumer );
+        return encode( UniversalTag.INTEGER, intval );
     }
 
 
-    public static void encodePrimitive( TagEnum tag, int intval,
-                                        TupleEventConsumer consumer )
+    /**
+     * Encodes a primitive Java integer into a TupleNode.
+     *
+     * @param tag the tag enumeration to use for the Tuple
+     * @param intval the integer value to encode
+     * @return the TupleNode containing the Tuple for the integer value
+     */
+    public static TupleNode encode( TagEnum tag, int intval )
     {
         Tuple t = new Tuple();
         t.setTag( tag, true );
-        consumer.tag( t );
         ByteBuffer chunk = ByteBuffer.wrap(
                 PrimitiveUtils.encodeInt( intval ) );
         t.setLength( chunk.remaining() );
-        consumer.length( t );
         t.setLastValueChunk( chunk );
-        consumer.chunkedValue( t, chunk );
-        consumer.finish( t );
+        return new DefaultMutableTupleNode( t );
     }
 
 
-    public static void encodePrimitive( boolean bool,
-                                        TupleEventConsumer consumer )
+    /**
+     * Encodes a boolean value into a TupleNode.  The tag defaults in this case
+     * to a UNIVERSAL BOOLEAN.
+     *
+     * @param bool the true or false value to encode
+     * @return the TupleNode containing the Tuple for the boolean value
+     */
+    public static TupleNode encode( boolean bool )
     {
-        encodePrimitive( UniversalTag.BOOLEAN, bool, consumer );
+        return encode( UniversalTag.BOOLEAN, bool );
     }
 
 
-    public static void encodePrimitive( TagEnum tag, boolean bool,
-                                        TupleEventConsumer consumer )
+    /**
+     * Encodes a boolean value into a TupleNode.
+     *
+     * @param tag the tag used for the boolean value
+     * @param bool the boolean value
+     * @return the TupleNode containing the Tuple for the boolean value
+     */
+    public static TupleNode encode( TagEnum tag, boolean bool )
     {
         Tuple t = new Tuple();
         t.setTag( tag, true );
-        consumer.tag( t );
         ByteBuffer chunk = ByteBuffer.wrap(
                 PrimitiveUtils.encodeBoolean( bool ) );
         t.setLength( chunk.remaining() );
-        consumer.length( t );
         t.setLastValueChunk( chunk );
-        consumer.chunkedValue( t, chunk );
-        consumer.finish( t );
+        return new DefaultMutableTupleNode( t );
     }
 }

Modified: incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/LdapResultEncoder.java
==============================================================================
--- incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/LdapResultEncoder.java
(original)
+++ incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/LdapResultEncoder.java
Sun Aug 15 19:22:21 2004
@@ -16,181 +16,47 @@
  */
 package org.apache.snickers.ldap.encoder;
 
+
 import org.apache.snickers.ber.*;
 import org.apache.snickers.ber.primitives.UniversalTag;
-import org.apache.snickers.ber.primitives.PrimitiveUtils;
-import org.apache.snickers.ldap.LdapTag;
 import org.apache.ldap.common.message.LdapResult;
-import org.apache.ldap.common.message.ResultCodeEnum;
-import org.apache.ldap.common.message.Referral;
-
-import java.nio.ByteBuffer;
-import java.util.Iterator;
-import java.util.ArrayList;
 
 
 /**
- * Encodes the elements of an LdapResult into some top level tuple.
+ * Encodes the elements of an LdapResult as TLV tuples into a top level tuple
+ * node.
  *
  * @author <a href="mailto:directory-dev@incubator.apache.org"> Apache Directory
  *         Project</a> $Rev$
  */
-public class LdapResultEncoder implements TupleEventProducer
+public class LdapResultEncoder
 {
-    TupleEventConsumer consumer = null;
-    Tuple tmp = new Tuple();
-
-
-    public void attach( TupleEventConsumer consumer )
-    {
-        this.consumer = consumer;
-    }
-
-
-    public void encode( LdapResult result )
-    {
-        // Encode the result code
-        tmp.setTag( UniversalTag.ENUMERATED, true );
-        ByteBuffer chunk = ByteBuffer.wrap( PrimitiveUtils
-                .encodeInt( result.getResultCode().getValue() ) ) ;
-        consumer.tag( tmp );
-        tmp.setLength( 1 );
-        consumer.length( tmp );
-        tmp.setLastValueChunk( chunk );
-        consumer.chunkedValue( tmp, chunk );
-        consumer.finish( tmp );
-
-        // Encode the matchedDN
-        tmp.setTag( UniversalTag.OCTET_STRING, true );
-        chunk = ByteBuffer.wrap( result.getMatchedDn().getBytes() );
-        consumer.tag( tmp );
-        tmp.setLength( chunk.remaining() );
-        consumer.length( tmp );
-        tmp.setLastValueChunk( chunk );
-        consumer.chunkedValue( tmp, chunk );
-        consumer.finish( tmp );
-
-        // Encode the errorMsg
-        tmp.setTag( UniversalTag.OCTET_STRING, true );
-        chunk = ByteBuffer.wrap( result.getErrorMessage().getBytes() );
-        consumer.tag( tmp );
-        tmp.setLength( chunk.remaining() );
-        consumer.length( tmp );
-        tmp.setLastValueChunk( chunk );
-        consumer.chunkedValue( tmp, chunk );
-        consumer.finish( tmp );
-
-        if ( result.getReferral() != null &&
-                result.getReferral().getLdapUrls().size() > 0 )
-        {
-            Tuple referrals = new Tuple();
-            referrals.setTag( LdapTag.REFERRAL_TAG, false );
-            consumer.tag( referrals );
-            referrals.setLength( Length.INDEFINATE );
-            consumer.length( referrals );
-
-            Iterator list = result.getReferral().getLdapUrls().iterator();
-            while( list.hasNext() )
-            {
-                tmp.setTag( UniversalTag.OCTET_STRING, true );
-                consumer.tag( tmp );
-                chunk = ByteBuffer.wrap( ( (String) list.next() ).getBytes() );
-                tmp.setLength( chunk.remaining() );
-                consumer.length( tmp );
-                tmp.setLastValueChunk( chunk );
-                consumer.chunkedValue( tmp, chunk );
-                consumer.finish( tmp );
-            }
-
-            consumer.finish( referrals );
-        }
-    }
-
+    /**
+     * An instance of this encoder.
+     */
+    public static final LdapResultEncoder INSTANCE = new LdapResultEncoder();
 
     /**
      * Encodes an LdapResult fields into TupleNodes adding them to the top
-     * argument.
+     * argument.  This method is thread safe.
      *
      * @param top the topmost node to add LDAP result fields to
      * @param result the ldap result to encode
      */
     public void encode( DefaultMutableTupleNode top, LdapResult result )
     {
-        encodeResultCode( top, result.getResultCode() );
-        encodeMatchedDn( top, result.getMatchedDn() );
-        encodeErrorMsg( top, result.getErrorMessage() );
+        top.addLast( ( DefaultMutableTupleNode ) EncoderUtils.encode(
+                UniversalTag.ENUMERATED, result.getResultCode().getValue() ) );
+        top.addLast( ( DefaultMutableTupleNode ) EncoderUtils.encode(
+                result.getMatchedDn() ) );
+        top.addLast( ( DefaultMutableTupleNode ) EncoderUtils.encode(
+                result.getErrorMessage() ) );
 
         if ( result.getReferral() != null &&
                 result.getReferral().getLdapUrls().size() > 0 )
         {
-            encodeReferral( top, result.getReferral() );
-        }
-
-    }
-
-
-    private void encodeResultCode( DefaultMutableTupleNode top,
-                                   ResultCodeEnum resultCode )
-    {
-        Tuple tlv = new Tuple();
-        tlv.setTag( UniversalTag.ENUMERATED, true );
-        ByteBuffer chunk = ByteBuffer.wrap( PrimitiveUtils
-                .encodeInt( resultCode.getValue() ) ) ;
-        tlv.setLength( 1 );
-        tlv.setLastValueChunk( chunk );
-        ArrayList list = new ArrayList(1);
-        list.add( chunk );
-        top.addLast( new DefaultMutableTupleNode( tlv, list ) );
-    }
-
-
-    private void encodeMatchedDn( DefaultMutableTupleNode top, String dn )
-    {
-        Tuple tlv = new Tuple();
-        tlv.setTag( UniversalTag.OCTET_STRING, true );
-        ByteBuffer chunk = ByteBuffer.wrap( dn.getBytes() );
-        tlv.setLength( chunk.remaining() );
-        tlv.setLastValueChunk( chunk );
-        ArrayList list = new ArrayList(1);
-        list.add( chunk );
-        top.addLast( new DefaultMutableTupleNode( tlv, list ) );
-    }
-
-
-    private void encodeErrorMsg( DefaultMutableTupleNode top, String msg )
-    {
-        Tuple tlv = new Tuple();
-        tlv.setTag( UniversalTag.OCTET_STRING, true );
-        ByteBuffer chunk = ByteBuffer.wrap( msg.getBytes() );
-        tlv.setLength( chunk.remaining() );
-        tlv.setLastValueChunk( chunk );
-        ArrayList list = new ArrayList(1);
-        list.add( chunk );
-        top.addLast( new DefaultMutableTupleNode( tlv, list ) );
-    }
-
-
-    private void encodeReferral( DefaultMutableTupleNode top, Referral ref )
-    {
-        Tuple referrals = new Tuple();
-        referrals.setTag( LdapTag.REFERRAL_TAG, false );
-        referrals.setLength( Length.INDEFINATE );
-        DefaultMutableTupleNode refs = new DefaultMutableTupleNode( referrals );
-
-        Iterator list = ref.getLdapUrls().iterator();
-        while( list.hasNext() )
-        {
-            Tuple tlv = new Tuple();
-            tlv.setTag( UniversalTag.OCTET_STRING, true );
-            ByteBuffer chunk =
-                    ByteBuffer.wrap( ( ( String ) list.next()).getBytes() );
-            tlv.setLength( chunk.remaining() );
-            tlv.setLastValueChunk( chunk );
-            ArrayList values = new ArrayList(1);
-            values.add( chunk );
-            refs.addLast( new DefaultMutableTupleNode( tlv, values ) );
+            top.addLast( ( DefaultMutableTupleNode )
+                    ReferralEncoder.INSTANCE.encode( result.getReferral() ) );
         }
-
-        top.addLast( refs );
     }
 }

Modified: incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/SnickersLdapEncoder.java
==============================================================================
--- incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/SnickersLdapEncoder.java
(original)
+++ incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/SnickersLdapEncoder.java
Sun Aug 15 19:22:21 2004
@@ -22,12 +22,6 @@
 import org.apache.commons.codec.stateful.EncoderCallback;
 import org.apache.commons.codec.stateful.EncoderMonitor;
 import org.apache.ldap.common.message.*;
-import org.apache.snickers.ldap.encoder.abandon.AbandonRequestEncoder;
-import org.apache.snickers.ldap.encoder.bind.BindRequestEncoder;
-import org.apache.snickers.ldap.encoder.bind.BindResponseEncoder;
-import org.apache.snickers.ldap.encoder.search.SearchRequestEncoder;
-import org.apache.snickers.ldap.encoder.search.SearchResponseDoneEncoder;
-import org.apache.snickers.ldap.encoder.search.SearchResponseEntryEncoder;
 import org.apache.snickers.ber.BEREncoder;
 
 
@@ -41,13 +35,6 @@
  */
 public class SnickersLdapEncoder implements StatefulEncoder
 {
-    AbandonRequestEncoder abandonReqEncoder = null;
-    BindRequestEncoder bindReqEncoder = null;
-    BindResponseEncoder bindRespEncoder = null;
-    SearchRequestEncoder searchReqEncoder = null;
-    SearchResponseDoneEncoder searchRespDoneEncoder = null;
-    SearchResponseEntryEncoder searchRespEntryEncoder = null;
-
     EncoderMonitor monitor;
     BEREncoder encoder = new BEREncoder();
 
@@ -60,57 +47,21 @@
         switch( msg.getType().getValue() )
         {
             case( MessageTypeEnum.ABANDONREQUEST_VAL ):
-                if ( abandonReqEncoder == null )
-                {
-                    abandonReqEncoder = new AbandonRequestEncoder();
-                }
-                abandonReqEncoder.attach( encoder );
-                abandonReqEncoder.encode( ( AbandonRequest ) obj );
                 break;
 
             case( MessageTypeEnum.BINDREQUEST_VAL ):
-                if ( bindReqEncoder == null )
-                {
-                    bindReqEncoder = new BindRequestEncoder();
-                }
-                bindReqEncoder.attach( encoder );
-                bindReqEncoder.encode( ( BindRequest ) obj );
                 break;
 
             case( MessageTypeEnum.BINDRESPONSE_VAL ):
-                if ( bindRespEncoder == null )
-                {
-                    bindRespEncoder = new BindResponseEncoder();
-                }
-                bindRespEncoder.attach( encoder );
-                bindRespEncoder.encode( ( BindResponse ) obj );
                 break;
 
             case( MessageTypeEnum.SEARCHREQUEST_VAL ):
-                if ( searchReqEncoder == null )
-                {
-                    searchReqEncoder = new SearchRequestEncoder();
-                }
-                searchReqEncoder.attach( encoder );
-                searchReqEncoder.encode( ( SearchRequest ) obj );
                 break;
 
             case( MessageTypeEnum.SEARCHRESDONE_VAL ):
-                if ( searchRespDoneEncoder == null )
-                {
-                    searchRespDoneEncoder = new SearchResponseDoneEncoder();
-                }
-                searchRespDoneEncoder.attach( encoder );
-                searchRespDoneEncoder.encode( ( SearchResponseDone ) obj );
                 break;
 
             case( MessageTypeEnum.SEARCHRESENTRY_VAL ):
-                if ( searchRespEntryEncoder == null )
-                {
-                    searchRespEntryEncoder = new SearchResponseEntryEncoder();
-                }
-                searchRespEntryEncoder.attach( encoder );
-                searchRespEntryEncoder.encode( ( SearchResponseEntry ) obj );
                 break;
 
             default:

Mime
View raw message