directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 36416 - incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder
Date Sun, 15 Aug 2004 19:22:10 GMT
Author: akarasulu
Date: Sun Aug 15 12:22:10 2004
New Revision: 36416

Modified:
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/LdapResultEncoder.java
Log:
toying with tree based determinate encoding

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/LdapResultEncoder.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/LdapResultEncoder.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/LdapResultEncoder.java
Sun Aug 15 12:22:10 2004
@@ -16,17 +16,17 @@
  */
 package org.apache.snickers.ldap.encoder;
 
-import org.apache.snickers.ber.TupleEventProducer;
-import org.apache.snickers.ber.TupleEventConsumer;
-import org.apache.snickers.ber.Tuple;
-import org.apache.snickers.ber.Length;
+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;
 
 
 /**
@@ -104,5 +104,93 @@
 
             consumer.finish( referrals );
         }
+    }
+
+
+    /**
+     * Encodes an LdapResult fields into TupleNodes adding them to the top
+     * argument.
+     *
+     * @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() );
+
+        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( refs );
     }
 }

Mime
View raw message