directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 22831 - in incubator/directory/snickers/trunk: ber-codec/src/java/org/apache/snickers/ber ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/abandon
Date Mon, 12 Jul 2004 05:25:05 GMT
Author: akarasulu
Date: Sun Jul 11 22:25:05 2004
New Revision: 22831

Added:
   incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/BEREncoder.java
   incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/BEREncoderCallback.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/abandon/AbandonRequestEncoderTest.java
Modified:
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/abandon/AbandonRequestEncoder.java
Log:
may be removed but some initial incorrect ideas on an abandon encoder

Added: incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/BEREncoder.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/BEREncoder.java
Sun Jul 11 22:25:05 2004
@@ -0,0 +1,38 @@
+/*
+ *   Copyright 2004 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.snickers.ber;
+
+
+import org.apache.commons.codec.EncoderException;
+import org.apache.commons.codec.stateful.AbstractStatefulEncoder;
+
+
+/**
+ * Document me.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org"> Apache Directory
+ *         Project</a> $Rev$
+ */
+public class BEREncoder extends AbstractStatefulEncoder
+{
+    public void encode( Object obj ) throws EncoderException
+    {
+    }
+
+
+
+}

Added: incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/BEREncoderCallback.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/BEREncoderCallback.java
Sun Jul 11 22:25:05 2004
@@ -0,0 +1,66 @@
+/*
+ *   Copyright 2004 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.snickers.ber ;
+
+
+import org.apache.commons.codec.stateful.DecoderCallback ;
+import org.apache.commons.codec.stateful.EncoderCallback;
+
+
+/**
+ * A specialized encoder callback that handles specific BER events.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">
+ * Apache Directory Project</a>
+ * @version $Rev: 9765 $
+ */
+public interface BEREncoderCallback extends EncoderCallback
+{
+    /**
+     * Method used to receive notification that a tag was encoded.  The
+     * following tag properties of the TLV tuple are valid at this point:
+     * <ul>
+     * <li>id</li>
+     * <li>isPrimitive</li>
+     * <li>typeClass</li>
+     * </ul>
+     * 
+     * @param tlv the TLV tuple
+     */
+    void tagEncoded( Tuple tlv ) ;
+    
+    /**
+     * Method used to receive notification that a length was encoded.  The
+     * following properties of the TLV tuple are valid at this point:
+     * <ul>
+     * <li>id</li>
+     * <li>isPrimitive</li>
+     * <li>typeClass</li>
+     * <li>length</li>
+     * </ul>
+     * 
+     * @param tlv the TLV tuple
+     */
+    void lengthEncoded( Tuple tlv ) ;
+    
+    /**
+     * Method used to recieve notification that a part of the value was encoded.
+     * 
+     * @param tlv the TLV tuple 
+     */
+    void partialValueEncoded( Tuple tlv ) ;
+}

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/abandon/AbandonRequestEncoder.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/abandon/AbandonRequestEncoder.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/abandon/AbandonRequestEncoder.java
Sun Jul 11 22:25:05 2004
@@ -20,13 +20,19 @@
 import org.apache.commons.codec.EncoderException;
 import org.apache.commons.codec.stateful.AbstractStatefulEncoder;
 import org.apache.snickers.ber.Tuple;
+import org.apache.snickers.ber.Tag;
+import org.apache.snickers.ber.TypeClass;
+import org.apache.snickers.ber.Length;
 import org.apache.snickers.ber.primitives.PrimitiveUtils;
+import org.apache.snickers.ber.primitives.UniversalTag;
 import org.apache.snickers.ldap.LdapTag;
 import org.apache.ldap.common.message.AbandonRequest;
 
+import java.nio.ByteBuffer;
+
 
 /**
- * BER encoder used to encode an AbandonRequeswt
+ * BER encoder used to encode an AbandonRequest.
  * 
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
  *         Project</a>
@@ -40,10 +46,20 @@
     {
         AbandonRequest req = ( AbandonRequest ) obj;
 
-        byte[] encoded = PrimitiveUtils.encodeInt( req.getAbandoned() );
+        tlv.setTag( UniversalTag.SEQUENCE_SEQUENCE_OF, false );
+        tlv.setLength( Length.INDEFINATE );
+        super.encodeOccurred( tlv );
+
+        byte[] encoded = PrimitiveUtils.encodeInt( req.getMessageId() );
+        tlv.setTag( UniversalTag.INTEGER, true );
+        tlv.setLength( encoded.length );
+        tlv.setLastValueChunk( ByteBuffer.wrap( encoded ) );
+        super.encodeOccurred( tlv );
+
+        encoded = PrimitiveUtils.encodeInt( req.getAbandoned() );
         tlv.setTag( LdapTag.ABANDON_REQUEST );
-//        tlv.setLength( encoded.length );
-//        tlv.setValue( encoded );
+        tlv.setLength( encoded.length );
+        tlv.setLastValueChunk( ByteBuffer.wrap( encoded ) );
         super.encodeOccurred( tlv );
     }
 }

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/abandon/AbandonRequestEncoderTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/abandon/AbandonRequestEncoderTest.java
Sun Jul 11 22:25:05 2004
@@ -0,0 +1,101 @@
+/*
+ *   Copyright 2004 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.snickers.ldap.encoder.abandon;
+
+import junit.framework.TestCase;
+import org.apache.commons.codec.stateful.EncoderCallback;
+import org.apache.commons.codec.stateful.StatefulEncoder;
+import org.apache.commons.codec.stateful.DecoderCallback;
+import org.apache.commons.codec.stateful.StatefulDecoder;
+import org.apache.snickers.ber.Tuple;
+import org.apache.snickers.ldap.BufferUtils;
+import org.apache.ldap.common.message.AbandonRequestImpl;
+import org.apache.ldap.common.message.MessageDecoder;
+import org.apache.ldap.common.message.AbandonRequest;
+
+import java.util.ArrayList;
+import java.nio.ByteBuffer;
+import java.io.ByteArrayInputStream;
+
+/**
+ * Document me.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org"> Apache Directory
+ *         Project</a> $Rev$
+ */
+public class AbandonRequestEncoderTest extends TestCase
+        implements EncoderCallback, DecoderCallback
+{
+    AbandonRequestEncoder encoder = null;
+    Tuple tlv = null;
+
+
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+        encoder = new AbandonRequestEncoder();
+        encoder.setCallback( this );
+    }
+
+
+    protected void tearDown() throws Exception
+    {
+        super.tearDown();
+        encoder = null;
+    }
+
+
+    /**
+     * Callback to deliver a fully encoded object.
+     *
+     * @param encoder the stateful encoder driving the callback
+     * @param encoded the object that was encoded
+     */
+    public void encodeOccurred( StatefulEncoder encoder, Object encoded )
+    {
+        tlv = ( Tuple ) encoded;
+    }
+
+
+    /**
+     * Callback to deliver a fully decoded object.
+     *
+     * @param decoder the stateful decoder driving the callback
+     * @param decoded the object that was decoded
+     */
+    public void decodeOccurred( StatefulDecoder decoder, Object decoded )
+    {
+    }
+
+
+    public void testEncode() throws Exception
+    {
+        AbandonRequestImpl req = new AbandonRequestImpl( 5 );
+        req.setAbandoned( 23 );
+        encoder.encode( req );
+
+        ArrayList valueChuncks = new ArrayList() ;
+        valueChuncks.add( tlv.getLastValueChunk() );
+        ByteBuffer encoded = tlv.toEncodedBuffer( valueChuncks );
+        MessageDecoder decoder = new MessageDecoder();
+
+        byte[] encodedBytes = BufferUtils.getArray( encoded );
+        ByteArrayInputStream in = new ByteArrayInputStream( encodedBytes );
+
+        AbandonRequest decodedReq = ( AbandonRequest ) decoder.decode(null,in);
+    }
+}

Mime
View raw message