directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 22774 - in incubator/directory/snickers/trunk: ber-codec/src/java/org/apache/snickers/ber ber-codec/src/java/org/apache/snickers/ber/primitives ber-codec/src/test/org/apache/snickers/ber ber-codec/src/test/org/apache/snickers/ber/primitives codec-stateful/src/java/org/apache/commons/codec/stateful ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/abandon ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/bind
Date Sat, 10 Jul 2004 01:43:01 GMT
Author: akarasulu
Date: Fri Jul  9 18:43:00 2004
New Revision: 22774

Added:
   incubator/directory/snickers/trunk/codec-stateful/src/java/org/apache/commons/codec/stateful/AbstractStatefulEncoder.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/SnickersLdapEncoder.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/abandon/
   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/bind/
Modified:
   incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/Tag.java
   incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/Tuple.java
   incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/primitives/PrimitiveUtils.java
   incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/TagTest.java
   incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/primitives/PrimitiveUtilsTest.java
   incubator/directory/snickers/trunk/codec-stateful/src/java/org/apache/commons/codec/stateful/AbstractStatefulDecoder.java
Log:
Commit changes ...

 o added abstract stateful encoder class
 o fixed a couple things in abstract decoder 
 o added stub to do primitive int encoding not finished yet 
 o added methods to create and alter tags in Tag and Tuple
 o started work on an Abandon encoder



Modified: incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/Tag.java
==============================================================================
--- incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/Tag.java
(original)
+++ incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/Tag.java
Fri Jul  9 18:43:00 2004
@@ -213,46 +213,37 @@
 
 
     /**
+     * Sets the id of a tag encoded as a Java primitive integer.
      *
-     *
-     * @param type
-     * @param id
-     * @param isConstructed
-     * @return
+     * @param encodedTag the tag encoded as a Java primitive integer
+     * @param id the new tag id to set within the encodedTag
+     * @return the modified Java primitive int encoded tag with the new tag id
      */
-    public final static int
-            getIntEncodedTag( TypeClass type, int id, boolean isConstructed )
+    public final static int setIntEncodedId( int encodedTag, int id )
     {
-        int value = type.getValue() << 24 ;
-
-        if ( isConstructed )
-        {
-            value |= ( CONSTRUCTED_FLAG << 24 ) ;
-        }
-
         if ( id <= ONE_OCTET_IDMAX )
         {
-            value |= ( id << 24 ) ;
+            encodedTag |= ( id << 24 ) ;
         }
         else if ( id <= TWO_OCTET_IDMAX )
         {
-            value |= ( SHORT_MASK << 24 ) ;
-            value |= ( id & 0x0000007F ) << 16 ;
+            encodedTag |= ( SHORT_MASK << 24 ) ;
+            encodedTag |= ( id & 0x0000007F ) << 16 ;
         }
         else if ( id <= THREE_OCTET_IDMAX )
         {
-            value |= ( SHORT_MASK << 24 ) ;
-            value |= ( id & 0x00003F80 ) << 9 ;
-            value |= ( id & 0x0000007F ) << 8 ;
-            value |= 0x00800000 ;
+            encodedTag |= ( SHORT_MASK << 24 ) ;
+            encodedTag |= ( id & 0x00003F80 ) << 9 ;
+            encodedTag |= ( id & 0x0000007F ) << 8 ;
+            encodedTag |= 0x00800000 ;
         }
         else if ( id <= FOUR_OCTET_IDMAX )
         {
-            value |= ( SHORT_MASK << 24 ) ;
-            value |= ( id & 0x001FC000 ) << 2 ;
-            value |= ( id & 0x00003F80 ) << 1 ;
-            value |= ( id & 0x0000007F ) ;
-            value |= 0x00808000 ;
+            encodedTag |= ( SHORT_MASK << 24 ) ;
+            encodedTag |= ( id & 0x001FC000 ) << 2 ;
+            encodedTag |= ( id & 0x00003F80 ) << 1 ;
+            encodedTag |= ( id & 0x0000007F ) ;
+            encodedTag |= 0x00808000 ;
         }
         else
         {
@@ -262,19 +253,43 @@
             throw new IllegalArgumentException( msg ) ;
         }
 
-        return value ;
+        return encodedTag;
     }
 
 
+    /**
+     * Assembles the Java primitive int based encoding for a tag using a set
+     * of parameters.
+     *
+     * @param type
+     * @param id
+     * @param isConstructed
+     * @return
+     */
+    public final static int
+            getIntEncodedTag( TypeClass type, int id, boolean isConstructed )
+    {
+        int value = type.getValue() << 24 ;
+
+        if ( isConstructed )
+        {
+            value |= ( CONSTRUCTED_FLAG << 24 ) ;
+        }
+
+        value = setIntEncodedId( value, id );
+
+        return value ;
+    }
+
 
     /**
      * Gets the tag id of a TLV from tag octets.
-     * 
-     * @param octets the set of octets needed to determine the tag value 
+     *
+     * @param octets the set of octets needed to determine the tag value
      *      (a.k.a identifier octets)
      * @return the tag id
      * @throws DecoderException if the id cannot be determined due to
-     *      type limitations of this method's return type. 
+     *      type limitations of this method's return type.
      */
     public final static int getTagId( byte[] octets )
         throws DecoderException
@@ -288,25 +303,83 @@
              */
             throw new DecoderException( "Tag number is too large." ) ;
         }
-        
+
         int id = octets[0] & SHORT_MASK ;
-        
+
         // if bits are not all 1's then return the value which is less than 31
         if ( id != SHORT_MASK && octets.length == 1 )
         {
             return id ;
         }
-        
+
         // clear the id now
         id = 0 ;
-    
+
         // calculate tag value w/ long tag format
         for( int ii = 1 ; ii < octets.length; ii++ )
-        {    
+        {
             int shift = ( ii - 1 ) * 7 ;
             id |= ( octets[ii] & LONG_MASK ) << shift ;
         }
-        
+
+        return id ;
+    }
+
+
+    /**
+     * Gets the tag id of a TLV from tag octets encoded as a Java primitive int.
+     *
+     * @param octets the tag octets encoded as a Java primitive int
+     * @return the tag id
+     */
+    public final static int getTagId( int octets )
+    {
+        // set id to the most significant octet in the int
+        int id = ( octets >> 24 ) & SHORT_MASK;
+
+        // if bits are not all 1's then return the value which is less than 31
+        if ( id != SHORT_MASK )
+        {
+            return id;
+        }
+
+        // clear the id now to prepare for long tag form
+        id = 0;
+
+        // get the second most significant octet from int and apply it to the id
+        int octet = ( octets & 0x00ff0000 ) >> 16;
+        id |= octet & LONG_MASK ;
+
+        // if this is the last octet in long form return
+        if ( ( octet & 0x80 ) == 0 )
+        {
+            return id ;
+        }
+
+        // clear octet and get the third most significant octet and apply it
+        octet = 0;
+        octet = ( octets & 0x0000ff00 ) >> 8;
+
+        if ( octet == 0 )
+        {
+            return id << 7 ;
+        }
+
+        id <<= 7;
+        id |= octet & LONG_MASK;
+
+        // if this is the last octet in long form return
+        if ( ( octet & 0x80 ) == 0 )
+        {
+            return id ;
+        }
+
+        // clear octet and get the least significant octet and apply it
+        octet = 0;
+        octet = octets & 0x000000ff;
+        id <<= 7;
+        id |= octet & LONG_MASK;
+
         return id ;
     }
 
@@ -363,5 +436,16 @@
     public final static boolean isConstructed( int octet )
     {
         return ( octet & CONSTRUCTED_FLAG ) == CONSTRUCTED_FLAG ;
+    }
+
+
+    public static boolean isRawTagConstructed( int rawTag )
+    {
+        if ( ( rawTag & 0x20000000 ) > 0 )
+        {
+            return true;
+        }
+
+        return false;
     }
 }

Modified: incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/Tuple.java
==============================================================================
--- incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/Tuple.java
(original)
+++ incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/Tuple.java
Fri Jul  9 18:43:00 2004
@@ -84,7 +84,7 @@
     /**
      * Empty do nothing tuple.
      */
-    Tuple() 
+    public Tuple()
     {
     }
     
@@ -173,7 +173,7 @@
     
     
     // ------------------------------------------------------------------------
-    // Public Accessors
+    // Public Accessors and Mutators
     // ------------------------------------------------------------------------
     
     
@@ -186,8 +186,20 @@
     {
         return id ;
     }
-    
-    
+
+
+    /**
+     * Sets the id of this Tuple and as a side effect the rawTag.
+     *
+     * @param id the new tag id to set
+     */
+    public void setId( int id )
+    {
+        this.id = id ;
+        rawTag = Tag.setIntEncodedId( rawTag, id );
+    }
+
+
     /**
      * Gets the raw tag as it is stuffed into a primitive int.
      * 
@@ -198,7 +210,51 @@
         return rawTag ;
     }
 
-    
+
+    /**
+     * Sets the raw tag encoded as a primitive int and as a side effect this
+     * call also effects the
+     *
+     * @param rawTag
+     */
+    public void setRawTag( int rawTag )
+    {
+        this.rawTag = rawTag;
+        this.id = Tag.getTagId( rawTag );
+        this.isPrimitive = ! Tag.isRawTagConstructed( rawTag );
+    }
+
+
+    /**
+     * Sets the tag parameters using a tag enumeration type.  This operation
+     * sets the id, isPrimitive, and rawTag fields at the same time.
+     *
+     * @param tag the tag enumeration constant
+     */
+    public void setTag( TagEnum tag )
+    {
+        this.rawTag = tag.getValue();
+        this.id = tag.getTagId();
+        this.isPrimitive = ! Tag.isRawTagConstructed( tag.getValue() ) ;
+    }
+
+
+    /**
+     * Sets the tag parameters using a tag enumeration type explicitly setting
+     * the primitive/constructed bit.  This operation sets the id, isPrimitive,
+     * and rawTag fields at the same time.
+     *
+     * @param tag the tag enumeration constant
+     * @param isPrimitive primitive/constructed bit override
+     */
+    public void setTag( TagEnum tag, boolean isPrimitive )
+    {
+        this.rawTag = tag.getValue();
+        this.id = tag.getTagId();
+        this.isPrimitive = isPrimitive;
+    }
+
+
     /**
      * Gets the raw tag with the primitive/constructed flag dubbed out.  
      * Effectively this makes every tag appear primitive and is done
@@ -310,7 +366,7 @@
     /**
      * Clears the values of this tuple.
      */
-    void clear()
+    public void clear()
     {
         this.id = 0 ;
         this.index = 0 ;
@@ -460,7 +516,7 @@
      * @param octets the buffer to set the tag in
      * @param tagLength the length of the tag section
      */
-    void setTag( ByteBuffer octets, int tagLength )
+    public void setTag( ByteBuffer octets, int tagLength )
     {
         octets.put( ( byte ) typeClass.getValue() ) ;
         
@@ -571,7 +627,7 @@
      * @param octets the byte [] to set length in
      * @param lengthBytes the number bytes for the length section
      */
-    void setLength( ByteBuffer octets, int lengthBytes )
+    public void setLength( ByteBuffer octets, int lengthBytes )
     {
         if ( length == Length.INDEFINATE )
         {

Modified: incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/primitives/PrimitiveUtils.java
==============================================================================
--- incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/primitives/PrimitiveUtils.java
(original)
+++ incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/primitives/PrimitiveUtils.java
Fri Jul  9 18:43:00 2004
@@ -17,6 +17,9 @@
 package org.apache.snickers.ber.primitives ;
 
 
+import org.apache.commons.lang.NotImplementedException;
+
+
 /**
  * Utilities for decoding and encoding primitive constructs.
  *
@@ -53,6 +56,19 @@
                     + " A value of " + value + " is not allowed!" ;
             throw new IllegalArgumentException( msg ) ;
         }
+    }
+
+
+    public static byte[] encodeInt( int source )
+    {
+        throw new NotImplementedException( "STUB" ) ;
+//        byte[] encoded = null;
+//                                      s
+//        if ( source > -129 && source < 128 )
+//        {
+//        }
+//
+//        return encoded;
     }
 
 

Modified: incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/TagTest.java
==============================================================================
--- incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/TagTest.java
(original)
+++ incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/TagTest.java
Fri Jul  9 18:43:00 2004
@@ -120,15 +120,55 @@
     }
     
     
-    public void testGetTagId() throws Exception
+    public void testGetTagIdInt() throws Exception
+    {
+        int rawTag = Tag.getIntEncodedTag( TypeClass.UNIVERSAL, 0, false );
+        assertEquals( Tag.getTagId( rawTag ), 0 );
+
+        rawTag = Tag.getIntEncodedTag( TypeClass.UNIVERSAL, 3, false );
+        assertEquals( Tag.getTagId( rawTag ), 3 );
+
+        rawTag = Tag.getIntEncodedTag( TypeClass.UNIVERSAL, 30, false );
+        assertEquals( Tag.getTagId( rawTag ), 30 );
+
+        rawTag = Tag.getIntEncodedTag( TypeClass.UNIVERSAL, 31, false );
+        assertEquals( Tag.getTagId( rawTag ), 31 );
+
+        rawTag = Tag.getIntEncodedTag( TypeClass.UNIVERSAL, 126, false );
+        assertEquals( Tag.getTagId( rawTag ), 126 );
+
+        rawTag = Tag.getIntEncodedTag( TypeClass.UNIVERSAL, 127, false );
+        assertEquals( Tag.getTagId( rawTag ), 127 );
+
+        rawTag = Tag.getIntEncodedTag( TypeClass.UNIVERSAL, 128, false );
+        assertEquals( Tag.getTagId( rawTag ), 128 );
+
+        rawTag = Tag.getIntEncodedTag( TypeClass.UNIVERSAL, 16382, false );
+        assertEquals( Tag.getTagId( rawTag ), 16382 );
+
+        rawTag = Tag.getIntEncodedTag( TypeClass.UNIVERSAL, 16383, false );
+        assertEquals( Tag.getTagId( rawTag ), 16383 );
+
+        rawTag = Tag.getIntEncodedTag( TypeClass.UNIVERSAL, 16384, false );
+        assertEquals( Tag.getTagId( rawTag ), 16384 );
+
+        rawTag = Tag.getIntEncodedTag( TypeClass.UNIVERSAL, 2097150, false );
+        assertEquals( Tag.getTagId( rawTag ), 2097150 );
+
+        rawTag = Tag.getIntEncodedTag( TypeClass.UNIVERSAL, 2097151, false );
+        assertEquals( Tag.getTagId( rawTag ), 2097151 );
+    }
+
+
+    public void testGetTagIdByteArray() throws Exception
     {
         byte[] octets = new byte[1] ;
-        
+
         for ( int ii = 0 ; ii < 128; ii++ )
         {
             octets[0] = ( byte ) ii ;
-            
-            if ( ii < 31 ) 
+
+            if ( ii < 31 )
             {
                 assertEquals( Tag.getTagId( octets ), ii ) ;
             }
@@ -137,16 +177,16 @@
                 assertTrue( Tag.getTagId( octets ) != ii ) ;
             }
         }
-        
+
         octets = new byte[2] ;
         octets[0] = 31 ;
         octets[1] = 0 ;
-        
+
         for ( int ii = 31 ; ii < 255; ii++ )
         {
             octets[1] = ( byte ) ii ;
-            
-            if ( ii < 128 ) 
+
+            if ( ii < 128 )
             {
                 assertEquals( Tag.getTagId( octets ), ii ) ;
             }
@@ -155,18 +195,18 @@
                 assertTrue( Tag.getTagId( octets ) != ii ) ;
             }
         }
-        
+
         octets = new byte[3] ;
         octets[0] = 31 ;
         octets[1] = 0 ;
         octets[2] = 0 ;
-        
+
         for ( int ii = 128 ; ii < 20000; ii++ )
         {
             octets[1] = ( byte ) ( ii & Tag.LONG_MASK ) ;
             octets[2] = ( byte ) ( ( ii >> 7 ) & Tag.LONG_MASK ) ;
-            
-            if ( ii < 16384 ) 
+
+            if ( ii < 16384 )
             {
                 assertEquals( Tag.getTagId( octets ), ii ) ;
             }
@@ -187,8 +227,8 @@
             octets[1] = ( byte ) ( ii & Tag.LONG_MASK ) ;
             octets[2] = ( byte ) ( ( ii >> 7 ) & Tag.LONG_MASK ) ;
             octets[3] = ( byte ) ( ( ii >> 14 ) & Tag.LONG_MASK ) ;
-            
-            if ( ii < 2097152 ) 
+
+            if ( ii < 2097152 )
             {
                 assertEquals( Tag.getTagId( octets ), ii ) ;
             }
@@ -197,7 +237,7 @@
                 assertTrue( Tag.getTagId( octets ) != ii ) ;
             }
         }
-        
+
         try
         {
             Tag.getTagId( new byte[5] ) ;
@@ -219,8 +259,24 @@
             assertNotNull( t ) ;
         }
     }
-    
-    
+
+
+    public void testIsRawTagConstructed()
+    {
+        int rawTag = Tag.getIntEncodedTag( TypeClass.APPLICATION, 1234, true );
+        assertTrue( Tag.isRawTagConstructed( rawTag ) );
+
+        rawTag = Tag.getIntEncodedTag( TypeClass.APPLICATION, 1234, false );
+        assertFalse( Tag.isRawTagConstructed( rawTag ) );
+
+        rawTag = Tag.getIntEncodedTag( TypeClass.CONTEXT_SPECIFIC, 128, true );
+        assertTrue( Tag.isRawTagConstructed( rawTag ) );
+
+        rawTag = Tag.getIntEncodedTag( TypeClass.PRIVATE, 234, false );
+        assertFalse( Tag.isRawTagConstructed( rawTag ) );
+    }
+
+
     public void testTagLimits() throws Exception
     {
         byte[] bites = { (byte) 0xff, (byte) 0xff, (byte) 0x8f, (byte) 0x0f } ;

Modified: incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/primitives/PrimitiveUtilsTest.java
==============================================================================
--- incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/primitives/PrimitiveUtilsTest.java
(original)
+++ incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/primitives/PrimitiveUtilsTest.java
Fri Jul  9 18:43:00 2004
@@ -21,6 +21,8 @@
 
 import java.math.BigInteger ;
 
+import org.apache.commons.lang.ArrayUtils;
+
 
 /**
  * Tests the PrimitiveUtil methods.
@@ -43,6 +45,17 @@
         bites0, bites1, bites2, bites3, bites4, bites5, bites6, bites7
     } ;
 
+    public static int[] values = {
+        ( new BigInteger( bites0 ) ).intValue(),
+        ( new BigInteger( bites1 ) ).intValue(),
+        ( new BigInteger( bites2 ) ).intValue(),
+        ( new BigInteger( bites3 ) ).intValue(),
+        ( new BigInteger( bites4 ) ).intValue(),
+        ( new BigInteger( bites5 ) ).intValue(),
+        ( new BigInteger( bites6 ) ).intValue(),
+        ( new BigInteger( bites7 ) ).intValue()
+    };
+
 
     /**
      * Tests the PrimitiveUtils.decodeInt(byte[], int, int) method.
@@ -57,8 +70,7 @@
         {
             int value = PrimitiveUtils.decodeInt( byteArrays[ii], 0,
                     byteArrays[ii].length ) ;
-            BigInteger big = new BigInteger( byteArrays[ii] ) ;
-            assertEquals( big.intValue(), value ) ;
+            assertEquals( values[ii], value ) ;
         }
 
         try
@@ -70,5 +82,25 @@
         {
             assertNotNull( e ) ;
         }
+    }
+
+
+    public void testEncodeInt()
+    {
+//        for ( int ii = 0; ii < values.length; ii++ )
+//        {
+//            byte[] encoded = PrimitiveUtils.encodeInt( values[ii] ) ;
+//            assertTrue( ArrayUtils.isEquals( byteArrays[ii], encoded ) );
+//        }
+//
+//        try
+//        {
+//            PrimitiveUtils.encodeInt( values[0] ) ;
+//            fail( "should never get here due to an exception" ) ;
+//        }
+//        catch( IllegalArgumentException e )
+//        {
+//            assertNotNull( e ) ;
+//        }
     }
 }

Modified: incubator/directory/snickers/trunk/codec-stateful/src/java/org/apache/commons/codec/stateful/AbstractStatefulDecoder.java
==============================================================================
--- incubator/directory/snickers/trunk/codec-stateful/src/java/org/apache/commons/codec/stateful/AbstractStatefulDecoder.java
(original)
+++ incubator/directory/snickers/trunk/codec-stateful/src/java/org/apache/commons/codec/stateful/AbstractStatefulDecoder.java
Fri Jul  9 18:43:00 2004
@@ -94,6 +94,11 @@
     {
         DecoderCallback old = this.cb ;
         this.cb = cb ;
+
+        if ( this.monitor != null )
+        {
+            this.monitor.callbackSet( this, old, cb );
+        }
     }
     
 

Added: incubator/directory/snickers/trunk/codec-stateful/src/java/org/apache/commons/codec/stateful/AbstractStatefulEncoder.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/codec-stateful/src/java/org/apache/commons/codec/stateful/AbstractStatefulEncoder.java
Fri Jul  9 18:43:00 2004
@@ -0,0 +1,140 @@
+/*
+ *   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.commons.codec.stateful ;
+
+
+/**
+ * Convenience class to not have to reimplement the two setter methods everytime
+ * one starts a new encoder.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">
+ * Apache Directory Project</a>
+ * @version $Rev: 21099 $
+ */
+public abstract class AbstractStatefulEncoder implements StatefulEncoder
+{
+    /** this encoder's callback */
+    private EncoderCallback cb = null ;
+    /** this encoder's monitor */
+    private EncoderMonitor monitor = null ;
+    
+    
+    // ------------------------------------------------------------------------
+    // constructors
+    // ------------------------------------------------------------------------
+    
+    
+    /**
+     * Creates a stateful encoder where the callback and monitor must be set.
+     */
+    public AbstractStatefulEncoder() 
+    { 
+    }
+    
+    
+    /**
+     * Creates a stateful encoder with a callback.
+     * 
+     * @param cb the callback to use for this encoder
+     */
+    public AbstractStatefulEncoder( EncoderCallback cb )
+    {
+        setCallback( cb ) ;
+    }
+
+    
+    /**
+     * Creates a stateful encoder with a monitor but no callback.
+     * 
+     * @param monitor the monitor to use for this encoder
+     */
+    public AbstractStatefulEncoder( EncoderMonitor monitor )
+    {
+        this.monitor = monitor ;
+    }
+    
+    
+    /**
+     * Creates a stateful encoder.
+     * 
+     * @param cb the callback to use for this encoder
+     * @param monitor the monitor to use for this encoder
+     */
+    public AbstractStatefulEncoder( EncoderCallback cb, EncoderMonitor monitor )
+    {
+        this.monitor = monitor ;
+        setCallback( cb ) ;
+    }
+    
+    
+    // ------------------------------------------------------------------------
+    // StatefulEncoder methods
+    // ------------------------------------------------------------------------
+    
+    
+    /* (non-Javadoc)
+     * @see org.apache.commons.codec.stateful.StatefulEncoder#setCallback(
+     * org.apache.commons.codec.stateful.EncoderCallback)
+     */
+    public void setCallback( EncoderCallback cb )
+    {
+        EncoderCallback old = this.cb ;
+        this.cb = cb ;
+        this.monitor.callbackSet( this, old, cb );
+    }
+    
+
+    /* (non-Javadoc)
+     * @see org.apache.commons.codec.stateful.StatefulEncoder#setEncoderMonitor(
+     * org.apache.commons.codec.stateful.EncoderMonitor)
+     */
+    public void setEncoderMonitor( EncoderMonitor monitor )
+    {
+        this.monitor = monitor ;
+    }
+    
+    
+    // ------------------------------------------------------------------------
+    // protected methods
+    // ------------------------------------------------------------------------
+    
+    
+    /**
+     * Notifies via the callback if one has been set that this encoder has
+     * encoded a unit of encoded data.
+     * 
+     * @param encoded the encoded byproduct.
+     */
+    protected void encodeOccurred( Object encoded )
+    {
+        if ( cb != null )
+        {    
+            cb.encodeOccurred( this, encoded ) ;
+        }
+    }
+    
+    
+    /**
+     * Gets the encoder's monitor.
+     * 
+     * @return the monitor for this StatefulEncoder
+     */
+    protected EncoderMonitor getEncoderMonitor()
+    {
+        return monitor ;
+    }
+}

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/SnickersLdapEncoder.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/SnickersLdapEncoder.java
Fri Jul  9 18:43:00 2004
@@ -0,0 +1,50 @@
+/*
+ *   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;
+
+
+import org.apache.commons.codec.EncoderException;
+import org.apache.commons.codec.stateful.AbstractStatefulEncoder;
+import org.apache.commons.codec.stateful.StatefulEncoder;
+import org.apache.ldap.common.message.Message;
+import org.apache.ldap.common.message.MessageTypeEnum;
+import org.apache.snickers.ldap.encoder.abandon.AbandonRequestEncoder;
+
+import java.util.HashMap;
+
+
+/**
+ * A Snickers based LDAP message encoder.  The generated events via the callback
+ * are TLV tuples.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class SnickersLdapEncoder extends AbstractStatefulEncoder
+{
+    private HashMap encoderMap = new HashMap();
+
+    public SnickersLdapEncoder()
+    {
+        StatefulEncoder encoder = new AbandonRequestEncoder() ;
+    }
+
+    public void encode( Object obj ) throws EncoderException
+    {
+        Message msg = ( Message ) obj;
+    }
+}

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/abandon/AbandonRequestEncoder.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/abandon/AbandonRequestEncoder.java
Fri Jul  9 18:43:00 2004
@@ -0,0 +1,49 @@
+/*
+ *   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 org.apache.commons.codec.EncoderException;
+import org.apache.commons.codec.stateful.AbstractStatefulEncoder;
+import org.apache.snickers.ber.Tuple;
+import org.apache.snickers.ber.primitives.PrimitiveUtils;
+import org.apache.snickers.ldap.LdapTag;
+import org.apache.ldap.common.message.AbandonRequest;
+
+
+/**
+ * BER encoder used to encode an AbandonRequeswt
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
+ *         Project</a>
+ * @version $Rev$
+ */
+public class AbandonRequestEncoder extends AbstractStatefulEncoder
+{
+    Tuple tlv = new Tuple();
+
+    public void encode( Object obj ) throws EncoderException
+    {
+        AbandonRequest req = ( AbandonRequest ) obj;
+
+        byte[] encoded = PrimitiveUtils.encodeInt( req.getAbandoned() );
+        tlv.setTag( LdapTag.ABANDON_REQUEST );
+//        tlv.setLength( encoded.length );
+//        tlv.setValue( encoded );
+        super.encodeOccurred( tlv );
+    }
+}

Mime
View raw message