directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 9442 - in incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers: . ber
Date Sat, 13 Mar 2004 23:22:02 GMT
Author: akarasulu
Date: Sat Mar 13 15:22:01 2004
New Revision: 9442

Modified:
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/SnickersDecoder.java
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/DefaultMutableTupleNode.java
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/Tuple.java
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/TupleNode.java
Log:
Added the recursive encode and size calculation facility to the tuple node
implementation.  Still need to document and test.


Modified: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/SnickersDecoder.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/SnickersDecoder.java
(original)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/SnickersDecoder.java
Sat Mar 13 15:22:01 2004
@@ -17,6 +17,8 @@
 package org.apache.snickers ;
 
 
+import java.nio.ByteBuffer ;
+import java.nio.channels.Pipe ;
 import java.io.ByteArrayInputStream ;
 
 import org.apache.commons.codec.DecoderException ;
@@ -72,7 +74,14 @@
                     return ;
                 }
                 
-                decode( ( TupleNode ) arg ) ;
+                try
+                {
+                    decode( ( TupleNode ) arg ) ;
+                }
+                catch( DecoderException e )
+                {
+                    monitor.error( SnickersDecoder.this, e ) ;
+                }
             }
         } ;
         
@@ -82,13 +91,22 @@
     
     /**
      * Synchronously decodes a tlv tuple tree into an LDAP message envelope.
+     * Wasteful but what are we going to do until we have snickers up fully?
      * 
+     * @todo get snickers done and remove this attrocity!!!
      * @param root the root of the tlv tuple tree 
      * @return the decoded message envelope
      */
-    public synchronized Message decode( TupleNode root )
+    public synchronized Message decode( TupleNode root ) throws DecoderException
     {
-        ByteArrayInputStream in = new ByteArrayInputStream( root.encode() ) ;
+        Pipe pipe = null ;
+        ByteBuffer buf = ByteBuffer.allocate( root.size() ) ;
+        root.encode( buf ) ;
+        buf.flip() ;
+
+        byte[] bites = new byte[buf.remaining()] ;
+        buf.get( bites ) ;
+        ByteArrayInputStream in = new ByteArrayInputStream( bites ) ;
         Message msg = msgDecoder.decode( null, in ) ;
         
         if ( cb != null )

Modified: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/DefaultMutableTupleNode.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/DefaultMutableTupleNode.java
(original)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/DefaultMutableTupleNode.java
Sat Mar 13 15:22:01 2004
@@ -17,6 +17,7 @@
 package org.apache.snickers.ber ;
 
 
+import java.nio.ByteBuffer;
 import java.util.Iterator ;
 import java.util.ArrayList ;
 import java.util.Enumeration ;
@@ -26,7 +27,6 @@
 import javax.swing.tree.MutableTreeNode ;
 
 import org.apache.commons.lang.StringUtils ;
-import org.apache.commons.lang.NotImplementedException ;
 
 
 /**
@@ -186,10 +186,13 @@
         {
             int size = tuple.size() ;
             
-            for ( int ii = 0; ii < children.size(); ii++ )
-            {
-                TupleNode node = ( TupleNode ) children.get( ii ) ;
-                size += node.getTuple().size() ;
+            if ( tuple.isIndefinate() )
+            {    
+                for ( int ii = 0; ii < children.size(); ii++ )
+                {
+                    TupleNode child = ( TupleNode ) children.get( ii ) ;
+                    size += child.size() ;
+                }
             }
 
             return size ;
@@ -211,9 +214,37 @@
      * 
      * @see org.apache.snickers.ber.TupleNode#encode()
      */
-    public byte[] encode()
+    public void encode( ByteBuffer dest )
     {
-        throw new NotImplementedException( "STUB" ) ;
+        dest.put( tuple.encode() ) ;
+        
+        if ( tuple.isPrimitive() )
+        {
+            return ;
+        }
+        
+        TupleNode child = null ;
+        for ( int ii = 0; ii < children.size(); ii++ )
+        {
+            child = ( TupleNode ) children.get( ii ) ;
+            child.encode( dest ) ;
+        }
+        
+        if ( child == null )
+        {
+            Tuple childTuple = child.getTuple() ;
+            if ( childTuple.isIndefinateTerminator() )
+            {
+                return ;
+            }
+        }
+        
+        if ( tuple.isIndefinate() ) 
+        {
+            // lay down the termination
+            dest.put( ( byte ) 0 ) ;
+            dest.put( ( byte ) 0 ) ;
+        }
     }
     
     

Modified: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/Tuple.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/Tuple.java	(original)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/Tuple.java	Sat
Mar 13 15:22:01 2004
@@ -199,7 +199,7 @@
     
     
     /**
-     * Gets the tag id for this TLV Tuple.
+     * Gets the tag id (T-part) for this TLV Tuple.
      * 
      * @return the tag id
      */
@@ -208,6 +208,42 @@
         return id ;
     }
     
+    
+    /**
+     * Gets the length component or field (L-part) for this TLV Tuple.
+     * 
+     * @return the length field for this TLV Tuple
+     */
+    public int getLength()
+    {
+        return length ;
+    }
+    
+    
+    /**
+     * Get's whether or not this tuples's length is indefinate.
+     * 
+     * @return whether or not this tuple's length is indefinate
+     */
+    public boolean isIndefinate()
+    {
+        return length == BERDecoder.INDEFINATE ;
+    }
+    
+
+    /**
+     * Get's whether or not this tuple terminates an indefinate constructed 
+     * tuple.  This means that length == 0 && isPrimitive = true && id ==
0
+     * and the type class is universal.
+     * 
+     * @return whether or not this node's length is indefinate
+     */
+    public boolean isIndefinateTerminator()
+    {
+        return isPrimitive && ( id + length ) == 0 && 
+            typeClass.equals( TypeClass.UNIVERSAL ) ;
+    }
+    
 
     /**
      * Gets whether or not this TLV tuple is primitive or constructed.
@@ -243,7 +279,7 @@
 
     
     /**
-     * Gets the value field for this TLV Tuple.
+     * Gets the value field (V-part) for this TLV Tuple.
      * 
      * @return the value field for this TLV Tuple
      */

Modified: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/TupleNode.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/TupleNode.java
(original)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/TupleNode.java
Sat Mar 13 15:22:01 2004
@@ -18,6 +18,7 @@
 
 
 import java.util.Iterator ;
+import java.nio.ByteBuffer ;
 
 
 /**
@@ -36,5 +37,5 @@
     int getChildCount() ;
     int size() ;
     Tuple getTuple() ;
-    byte[] encode() ;
+    void encode( ByteBuffer buf ) ;
 }

Mime
View raw message