directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 9815 - in incubator/directory/snickers/trunk/ber: . src/java/org/apache/snickers/ber src/java/org/apache/snickers/ber/digester src/java/org/apache/snickers/ber/primitives src/test/org/apache/snickers/ber
Date Tue, 30 Mar 2004 04:02:51 GMT
Author: akarasulu
Date: Mon Mar 29 20:02:49 2004
New Revision: 9815

Added:
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/TagOctetCollector.java   (contents, props changed)
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/AbstractRule.java   (contents, props changed)
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/BERDigester.java   (contents, props changed)
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/Rule.java   (contents, props changed)
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/Rules.java   (contents, props changed)
Modified:
   incubator/directory/snickers/trunk/ber/project.xml
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/BERDecoder.java
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/Length.java
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/Tag.java
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/TupleTreeDecoder.java
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/primitives/UniversalTag.java
   incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/LengthTest.java
   incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/MultiByteTagTests.java
   incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/TagTest.java
Log:
o Removed the dependency on ArrayByteList in commons primitives
o Using ByteBuffer in LengthDecoder to collect length bytes
o Using a new collector for Tag octets that stores octets in a Java int
o Updated tests to reflect these changes to the core decoder
o Started adding some interfaces to implement a rule based event digester



Modified: incubator/directory/snickers/trunk/ber/project.xml
==============================================================================
--- incubator/directory/snickers/trunk/ber/project.xml	(original)
+++ incubator/directory/snickers/trunk/ber/project.xml	Mon Mar 29 20:02:49 2004
@@ -26,13 +26,6 @@
     </dependency>
 
     <dependency>
-      <groupId>commons-primitives</groupId>
-      <artifactId>commons-primitives</artifactId>
-      <version>1.1-dev</version>
-      <url>http://jakarta.apache.org/commons/primitives/api</url>
-    </dependency>
-
-    <dependency>
       <groupId>commons-codec</groupId>
       <artifactId>commons-codec</artifactId>
       <version>SNAPSHOT</version>

Modified: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/BERDecoder.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/BERDecoder.java	(original)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/BERDecoder.java	Mon Mar 29 20:02:49 2004
@@ -53,7 +53,7 @@
  * callbacks before attempting to interpret their values.  Also this decoder
  * chunks value data returning it in parts rather than in one complete peice
  * in the end.  The value of the TLV Tuple returned is the part of the value
- * that was read from the input fed into the decoder.  These 'chuncks' returned
+ * that was read from the input fed into the decoder.  These 'chunks' returned
  * by callback makes it so there are no size limits to the value of a TLV. Again
  * to reiterate chunking on values is only performed on primitive TLV Tuple 
  * types. 

Modified: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/Length.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/Length.java	(original)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/Length.java	Mon Mar 29 20:02:49 2004
@@ -17,8 +17,9 @@
 package org.apache.snickers.ber ;
 
 
+import java.nio.ByteBuffer ;
+
 import org.apache.commons.codec.DecoderException ;
-import org.apache.commons.collections.primitives.ArrayByteList ;
 
 
 /**
@@ -44,10 +45,9 @@
     /** whether or not this length has been fixated */
     private boolean isFixated = false ;
     /** a byte buffer used to collect the arriving length octets */ 
-    private final ArrayByteList buf = new ArrayByteList( 10 ) ;
+    private final ByteBuffer buf = ByteBuffer.allocate( 5 ) ;
+
 
-    
-    
     /**
      * Checks to see if the length has been fixated.
      * 
@@ -81,6 +81,7 @@
      */
     void fixate() throws DecoderException
     {
+        buf.flip() ;
         value = getLength( buf ) ;
         isFixated = true ;
     }
@@ -99,9 +100,9 @@
             throw new IllegalStateException( "data added to fixated length" ) ;
         }
         
-        buf.add( octet ) ;
+        buf.put( octet ) ;
         
-        if ( buf.size() == 1 )
+        if ( buf.position() == 1 )
         {
             // if its the long form
             if ( END_MASK == ( octet & END_MASK ) && ( octet & 0x7F ) > 0 )
@@ -119,7 +120,7 @@
          * if we have collected all the octets needed for computing the long
          * form length so we need to calculate the length and just fixate
          */
-        else if ( buf.size() >= numOctets + 1 )
+        else if ( buf.position() >= numOctets + 1 )
         {
             fixate() ;
         }
@@ -138,24 +139,13 @@
     
     
     /**
-     * Gets a copy of the octets composing this Length component.
-     * 
-     * @return the octets representing this Length component
-     */
-    public byte[] getOctets()
-    {
-        return buf.toArray() ;
-    }
-    
-    
-    /**
      * Gets the number of octets currently in this Length component.
      * 
      * @return the number of octets currently within this Length component
      */
     public int size()
     {
-        return buf.size() ;
+        return buf.position() ;
     }
 
     
@@ -166,9 +156,9 @@
      * @return the length of the TLV
      * @throws DecoderException if the precision cannot hold the number
      */
-    public static int getLength( ArrayByteList octets ) throws DecoderException
+    public static int getLength( ByteBuffer octets ) throws DecoderException
     {
-        if ( octets.size() >= 6 )
+        if ( octets.remaining() >= 6 )
         {
             /*
              * If this exception is ever thrown which is highly unlikely, then
@@ -178,13 +168,15 @@
             throw new DecoderException( "Length number is too large." ) ;
         }
         
+        byte octet = octets.get() ;
+        
         // if we are using the short form then just return the first octet
-        if ( ( octets.get( 0 ) & END_MASK ) == 0 )
+        if ( ( octet & END_MASK ) == 0 )
         {
-            return octets.get( 0 ) ;
+            return octet ;
         }
         // using the indefinate form
-        else if ( ( octets.get( 0 ) & 0x7F ) == 0 )
+        else if ( ( octet & 0x7F ) == 0 )
         {
             return INDEFINATE ;
         }
@@ -193,11 +185,14 @@
         int length = 0 ;
     
         // calculate tag value w/ long tag format
-        for( int ii = 1 ; ii < octets.size(); ii++ )
-        {    
-            int shift = ( ii - 1 ) * 8 ;
-            length |=  ( 0xFF & ( int ) octets.get( ii ) ) << shift ;
+        
+        int shift = 0 ;
+        do
+        {
+            length |= ( 0xFF & ( int ) octets.get() ) << shift ;
+            shift += 8 ;
         }
+        while ( octets.hasRemaining() ) ;
         
         return length ;
     }

Modified: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/Tag.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/Tag.java	(original)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/Tag.java	Mon Mar 29 20:02:49 2004
@@ -18,7 +18,6 @@
 
 
 import org.apache.commons.codec.DecoderException ;
-import org.apache.commons.collections.primitives.ArrayByteList ;
 
 
 /**
@@ -46,7 +45,7 @@
     /** the type class of this tag */
     private TypeClass typeClass = TypeClass.APPLICATION ;
     /** a byte buffer used to collect the arriving tag octets */
-    private final ArrayByteList buf = new ArrayByteList( 10 ) ;
+    private final TagOctetCollector buf = new TagOctetCollector() ;
 
 
     /**
@@ -92,7 +91,7 @@
             throw new IllegalStateException( "data added to fixated tag" ) ;
         }
         
-        buf.add( octet ) ;
+        buf.put( octet ) ;
         
         if ( buf.size() == 1 )
         {
@@ -236,19 +235,9 @@
      * @throws DecoderException if the id cannot be determined due to
      *      type limitations of this method's return type. 
      */
-    public final static int getTagId( ArrayByteList octets )
+    public final static int getTagId( TagOctetCollector octets )
         throws DecoderException
     {
-        if ( octets.size() > 6 )
-        {
-            /*
-             * If this exception is ever thrown which is highly unlikely, then
-             * we need to switch to another data type to return because after
-             * 5 bytes the int can no longer hold the number.
-             */
-            throw new DecoderException( "Tag number is too large." ) ;
-        }
-        
         int id = octets.get( 0 ) & SHORT_MASK ;
         
         // if bits are not all 1's then return the value which is less than 31

Added: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/TagOctetCollector.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/TagOctetCollector.java	Mon Mar 29 20:02:49 2004
@@ -0,0 +1,182 @@
+/*
+ *   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 java.nio.BufferOverflowException;
+
+import org.apache.commons.lang.ArrayUtils ;
+
+
+/**
+ * Collects up to 4 tag octets.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">
+ * Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class TagOctetCollector
+{
+    /** the int used to store the tag octets */
+    private int intValue = 0 ;
+    /** the number of octets currently stored */
+    private int _size = 0 ;
+    
+    
+    /**
+     * Puts an octet into this collector.
+     * 
+     * @param octet the octet to put into the collector.
+     */
+    public void put( byte octet )
+    {
+        switch( _size )
+        {
+            case(0):
+                intValue = octet << 24 ;
+                _size = 1 ;
+                break ;
+            case(1):
+                intValue |= ( octet << 16 ) & 0x00FF0000 ;
+                _size = 2 ;
+                break ;
+            case(2):
+                intValue |= ( octet << 8 ) & 0x0000FF00 ;
+                _size = 3 ;
+                break ;
+            case(3):
+                intValue |= octet ;
+                _size = 4 ;
+                break ;
+            default:
+                throw new BufferOverflowException() ;
+        }
+    }
+    
+    
+    /**
+     * Clears all the tag octets resetting the tag and size to zero.
+     */
+    public void clear()
+    {
+        intValue = 0 ;
+        _size = 0 ;
+    }
+    
+    
+    /**
+     * Gets the number of octets stored by this TagOctetCollector
+     * 
+     * @return
+     */
+    public int size()
+    {
+        return _size ;
+    }
+    
+    
+    /**
+     * Gets a unique integer value representing the tag octets.
+     * 
+     * @return the integer value of the tag.
+     */
+    public int getIntValue()
+    {
+        return intValue ;
+    }
+    
+    
+    /**
+     * Gets the 4 octets for the tag.
+     * 
+     * @return
+     */
+    public byte[] toArray()
+    {
+        byte[] octets = new byte[_size] ;
+        
+        switch( _size )
+        {
+            case(0):
+                octets = ArrayUtils.EMPTY_BYTE_ARRAY ;
+                break ;
+            case(1):
+                octets[0] = ( byte ) ( ( intValue & 0xff000000 ) >> 24 ) ;
+                break ;
+            case(2):
+                octets[0] = ( byte ) ( ( intValue & 0xff000000 ) >> 24 ) ;
+                octets[1] = ( byte ) ( ( intValue & 0x00ff0000 ) >> 16 ) ;
+                break ;
+            case(3):
+                octets[0] = ( byte ) ( ( intValue & 0xff000000 ) >> 24 ) ;
+                octets[1] = ( byte ) ( ( intValue & 0x00ff0000 ) >> 16 ) ;
+                octets[2] = ( byte ) ( ( intValue & 0x0000ff00 ) >>  8 ) ;
+                break ;
+            case(4):
+                octets[0] = ( byte ) ( ( intValue & 0xff000000 ) >> 24 ) ;
+                octets[1] = ( byte ) ( ( intValue & 0x00ff0000 ) >> 16 ) ;
+                octets[2] = ( byte ) ( ( intValue & 0x0000ff00 ) >>  8 ) ;
+                octets[3] = ( byte )   ( intValue & 0x000000ff ) ;
+                break ;
+            default:
+                throw new IllegalArgumentException( 
+                        "Cannot support more than 4 octets" ) ;
+        }
+        
+        return octets ;
+    }
+    
+    
+    /**
+     * Gets the byte at a specific index.
+     * 
+     * @param index
+     * @return
+     * @throws IndexOutOfBoundsException
+     */
+    public byte get( int index )
+    {
+        byte octet ;
+        
+        if ( index >= _size )
+        {
+            throw new IndexOutOfBoundsException( "accesing index " + index
+                    + " with a size of " + _size ) ;
+        }
+
+        switch( index )
+        {
+            case(0):
+                octet = ( byte ) ( ( intValue & 0xff000000 ) >> 24 ) ;
+                break ;
+            case(1):
+                octet = ( byte ) ( ( intValue & 0x00ff0000 ) >> 16 ) ;
+                break ;
+            case(2):
+                octet = ( byte ) ( ( intValue & 0x0000ff00 ) >>  8 ) ;
+                break ;
+            case(3):
+                octet = ( byte )   ( intValue & 0x000000ff ) ;
+                break ;
+            default:
+                throw new IllegalArgumentException( 
+                        "Cannot support more than 4 octets" ) ;
+        }
+        
+        return octet ;
+    }
+}

Modified: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/TupleTreeDecoder.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/TupleTreeDecoder.java	(original)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/TupleTreeDecoder.java	Mon Mar 29 20:02:49 2004
@@ -17,8 +17,9 @@
 package org.apache.snickers.ber ;
 
 
-import java.util.ArrayList;
 import java.util.Stack ;
+import java.util.ArrayList ;
+
 import java.nio.ByteBuffer ;
 
 import org.apache.commons.codec.DecoderException ;

Added: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/AbstractRule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/AbstractRule.java	Mon Mar 29 20:02:49 2004
@@ -0,0 +1,92 @@
+/*
+ *   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.digester;
+
+
+import java.nio.ByteBuffer ;
+
+import org.apache.snickers.ber.BERDecoder;
+import org.apache.snickers.ber.TypeClass;
+
+
+/**
+ * A rule base class.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">
+ * Apache Directory Project</a>
+ * @version $Rev$
+ */
+public abstract class AbstractRule implements Rule
+{
+    private BERDecoder decoder = null ;
+    
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#getDecoder()
+     */
+    public BERDecoder getDecoder()
+    {
+        return decoder ;
+    }
+    
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#setDecoder(
+     * org.apache.snickers.ber.BERDecoder)
+     */
+    public void setDecoder( BERDecoder decoder )
+    {
+        this.decoder = decoder ;
+    }
+
+    
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#tag(int, boolean, 
+     * org.apache.snickers.ber.TypeClass)
+     */
+    public void tag( int id, boolean isPrimitive, TypeClass typeClass )
+    {
+        // do nothing base class
+    }
+
+    
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#length(int)
+     */
+    public void length( int length )
+    {
+        // do nothing base class
+    }
+
+    
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#value(java.nio.ByteBuffer)
+     */
+    public void value( ByteBuffer buf )
+    {
+        // do nothing base class
+    }
+
+    
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#finish()
+     */
+    public void finish()
+    {
+        // do nothing base class
+    }
+}

Added: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/BERDigester.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/BERDigester.java	Mon Mar 29 20:02:49 2004
@@ -0,0 +1,82 @@
+/*
+ *   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.digester ;
+
+
+import org.apache.snickers.ber.Tuple ;
+import org.apache.snickers.ber.BERDecoderCallback ;
+
+import org.apache.commons.codec.stateful.StatefulDecoder ;
+
+
+/**
+ * A special BER TLV event digester.  This class was inspired by the XML 
+ * digester in Jakarta Commons.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">
+ * Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class BERDigester implements BERDecoderCallback
+{
+    // ------------------------------------------------------------------------
+    // BERDecoderCallback methods 
+    // ------------------------------------------------------------------------
+
+    
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.BERDecoderCallback#tagDecoded(
+     * org.apache.snickers.ber.Tuple)
+     */
+    public void tagDecoded( Tuple tlv )
+    {
+    }
+
+    
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.BERDecoderCallback#lengthDecoded(
+     * org.apache.snickers.ber.Tuple)
+     */
+    public void lengthDecoded( Tuple tlv )
+    {
+    }
+
+    
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.BERDecoderCallback#partialValueDecoded(
+     * org.apache.snickers.ber.Tuple)
+     */
+    public void partialValueDecoded( Tuple tlv )
+    {
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.commons.codec.stateful.DecoderCallback#decodeOccurred(
+     * org.apache.commons.codec.stateful.StatefulDecoder, java.lang.Object)
+     */
+    public void decodeOccurred( StatefulDecoder decoder, Object decoded )
+    {
+    }
+
+
+    // ------------------------------------------------------------------------
+    // BERDecoderCallback methods 
+    // ------------------------------------------------------------------------
+
+    
+}

Added: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/Rule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/Rule.java	Mon Mar 29 20:02:49 2004
@@ -0,0 +1,78 @@
+/*
+ *   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.digester;
+
+
+import java.nio.ByteBuffer ;
+
+import org.apache.snickers.ber.BERDecoder;
+import org.apache.snickers.ber.TypeClass;
+
+
+/**
+ * A BER event processing rule.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">
+ * Apache Directory Project</a>
+ * @version $Rev$
+ */
+public interface Rule
+{
+    /**
+     * Get the <code>BERDecoder</code> with which this <code>Rule</code> has
+     * been associated.
+     * 
+     * @return the associated decoder
+     */
+    BERDecoder getDecoder() ;
+    
+    /**
+     * Set the <code>BERDecoder</code> with which this <code>Rule</code> will
+     * be associated.
+     * 
+     * @param decoder the decoder to associate this rule with
+     */
+    void setDecoder( BERDecoder decoder ) ;
+    
+    /**
+     * Called when the tag of the matched TLV is encountered.
+     * 
+     * @param id the tag's id 
+     * @param isPrimitive whether tlv is primitive or constructed
+     * @param typeClass the tag's type class
+     */
+    void tag( int id, boolean isPrimitive, TypeClass typeClass ) ;
+    
+    /**
+     * Called when the length of a TLV is encountered.
+     * 
+     * @param length the length in bytes of the value
+     */
+    void length( int length ) ;
+    
+    /**
+     * Called when a peice of the value is available.
+     * 
+     * @param buf a portion of the value
+     */
+    void value( ByteBuffer buf ) ;
+    
+    /**
+     * Called when the tlv has been completely consumed.
+     */
+    void finish() ;
+}

Added: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/Rules.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/Rules.java	Mon Mar 29 20:02:49 2004
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2001-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.digester;
+
+
+import java.util.List ;
+
+import org.apache.snickers.ber.BERDecoder;
+
+
+/**
+ * Public interface defining a collection of Rule instances (and corresponding
+ * matching patterns) plus an implementation of a matching policy that selects
+ * the rules that match a particular pattern of nested elements discovered
+ * during parsing.  The interface has been inspired by the digester equivalent.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">
+ * Apache Directory Project</a>
+ * @version $Rev$
+ */
+public interface Rules 
+{
+    /**
+     * Get the <code>BERDecoder</code> instance with which this <code>Rules
+     * </code> instance is associated.
+     * 
+     * @return the BERDecoder associated with this Rules instance
+     */
+    public BERDecoder getDecoder() ;
+
+    /**
+     * Get the <code>BERDecoder</code> instance with which this <code>Rules
+     * </code> instance is associated.
+     * 
+     * @param the new BERDecoder to be associated with this Rules instance
+     */
+    public void setDecoder( BERDecoder decoder ) ;
+
+    /**
+     * Register a new Rule instance matching the specified pattern.
+     *
+     * @param pattern Tag nesting pattern to be matched for this Rule
+     * @param rule Rule instance to be registered
+     */
+    public void add( int[] pattern, Rule rule ) ;
+
+    /**
+     * Clear all existing Rule instance registrations.
+     */
+    public void clear() ;
+
+    /**
+     * Return a List of all registered Rule instances that match the specified
+     * nesting pattern, or a zero-length List if there are no matches.  If more
+     * than one Rule instance matches, they <strong>must</strong> be returned
+     * in the order originally registered through the <code>add()</code>
+     * method.
+     *
+     * @param pattern Nesting pattern to be matched
+     *
+     * @deprecated Call match(namespaceURI,pattern) instead.
+     */
+    public List match( int[] pattern ) ;
+
+    /**
+     * Return a List of all registered Rule instances, or a zero-length List
+     * if there are no registered Rule instances.  If more than one Rule
+     * instance has been registered, they <strong>must</strong> be returned
+     * in the order originally registered through the <code>add()</code>
+     * method.
+     */
+    public List rules() ;
+}

Modified: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/primitives/UniversalTag.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/primitives/UniversalTag.java	(original)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/primitives/UniversalTag.java	Mon Mar 29 20:02:49 2004
@@ -25,8 +25,13 @@
 
 
 /**
- * Type safe enum for ASN.1 UNIVERSAL class tags.  These tags can have one of 
- * the following values:
+ * Type safe enum for ASN.1 UNIVERSAL class tags.  The tags values are 
+ * constructed using the SNACC representation for tags without the 
+ * primitive/constructed bit.  This is done because several bit, octet and 
+ * character string types can be encoded as primitives or as constructed types 
+ * to chunk the value out.
+ * <p>
+ * These tags can have one of the following values:
  * <p>
  * <table border=1 cellspacing=1 width=60% >
  * <tr><th>Id</th><th>Usage</th></tr>
@@ -71,70 +76,69 @@
 public class UniversalTag extends ValuedEnum
 {
     /** value for the tag */
-    public static final int RESERVED0_VAL = 0 ;
-    /** value for the tag */
-    public static final int BOOLEAN_VAL = 1 ;
+    public static final int RESERVED0_VAL =                 0x00000000 ;
     /** value for the tag */
-    public static final int INTEGER_VAL = 2 ;
+    public static final int BOOLEAN_VAL =                   0x01000000 ;
     /** value for the tag */
-    public static final int BIT_STRING_VAL = 3 ;
+    public static final int INTEGER_VAL =                   0x02000000 ;
     /** value for the tag */
-    public static final int OCTET_STRING_VAL = 4 ;
+    public static final int BIT_STRING_VAL =                0x03000000 ;
     /** value for the tag */
-    public static final int NULL_VAL = 5 ;
+    public static final int OCTET_STRING_VAL =              0x04000000 ;
     /** value for the tag */
-    public static final int OBJECT_IDENTIFIER_VAL = 6 ;
+    public static final int NULL_VAL =                      0x05000000 ;
     /** value for the tag */
-    public static final int OBJECT_DESCRIPTOR_VAL = 7 ;
+    public static final int OBJECT_IDENTIFIER_VAL =         0x06000000 ;
     /** value for the tag */
-    public static final int EXTERNAL_INSTANCE_OF_VAL = 8 ;
+    public static final int OBJECT_DESCRIPTOR_VAL =         0x07000000 ;
     /** value for the tag */
-    public static final int REAL_VAL = 9 ;
+    public static final int EXTERNAL_INSTANCE_OF_VAL =      0x08000000 ;
     /** value for the tag */
-    public static final int ENUMERATED_VAL = 10 ;
+    public static final int REAL_VAL =                      0x09000000 ;
     /** value for the tag */
-    public static final int EMBEDDED_PDV_VAL = 11 ;
+    public static final int ENUMERATED_VAL =                0x0a000000 ;
     /** value for the tag */
-    public static final int UTF8_STRING_VAL = 12 ;
+    public static final int EMBEDDED_PDV_VAL =              0x0b000000 ;
     /** value for the tag */
-    public static final int RELATIVE_OID_VAL = 13 ;
+    public static final int UTF8_STRING_VAL =               0x0c000000 ;
     /** value for the tag */
-    public static final int RESERVED14_VAL = 14 ;
+    public static final int RELATIVE_OID_VAL =              0x0d000000 ;
     /** value for the tag */
-    public static final int RESERVED15_VAL = 15 ;
+    public static final int RESERVED14_VAL =                0x0e000000 ;
     /** value for the tag */
-    public static final int SEQUENCE_SEQUENCE_OF_VAL = 16 ;
+    public static final int RESERVED15_VAL =                0x0f000000 ;
     /** value for the tag */
-    public static final int SET_SET_OF_VAL = 17 ;
+    public static final int SEQUENCE_SEQUENCE_OF_VAL =      0x10000000 ;
     /** value for the tag */
-    public static final int NUMERIC_STRING_VAL = 18 ;
+    public static final int SET_SET_OF_VAL =                0x11000000 ;
     /** value for the tag */
-    public static final int PRINTABLE_STRING_VAL = 19 ;
+    public static final int NUMERIC_STRING_VAL =            0x12000000 ;
     /** value for the tag */
-    public static final int TELETEX_STRING_T61_STRING_VAL = 20 ;
+    public static final int PRINTABLE_STRING_VAL =          0x13000000 ;
     /** value for the tag */
-    public static final int VIDEOTEX_STRING_VAL = 21 ;
+    public static final int TELETEX_STRING_VAL =            0x14000000 ;
     /** value for the tag */
-    public static final int IA5_STRING_VAL = 22 ;
+    public static final int VIDEOTEX_STRING_VAL =           0x15000000 ;
     /** value for the tag */
-    public static final int UTC_TIME_VAL = 23 ;
+    public static final int IA5_STRING_VAL =                0x16000000 ;
     /** value for the tag */
-    public static final int GENERALIZED_TIME_VAL = 24 ;
+    public static final int UTC_TIME_VAL =                  0x17000000 ;
     /** value for the tag */
-    public static final int GRAPHIC_STRING_VAL = 25 ;
+    public static final int GENERALIZED_TIME_VAL =          0x18000000 ;
     /** value for the tag */
-    public static final int VISIBLE_STRING_ISO646_STRING_VAL = 26 ;
+    public static final int GRAPHIC_STRING_VAL =            0x19000000 ;
     /** value for the tag */
-    public static final int GENERAL_STRING_VAL = 27 ;
+    public static final int VISIBLE_STRING_VAL =            0x1a000000 ;
     /** value for the tag */
-    public static final int UNIVERSAL_STRING_VAL = 28 ;
+    public static final int GENERAL_STRING_VAL =            0x1b000000 ;
     /** value for the tag */
-    public static final int CHARACTER_STRING_VAL = 29 ;
+    public static final int UNIVERSAL_STRING_VAL =          0x1c000000 ;
     /** value for the tag */
-    public static final int BMP_STRING_VAL = 30 ;
+    public static final int CHARACTER_STRING_VAL =          0x1d000000 ;
     /** value for the tag */
-    public static final int RESERVED31_VAL = 31 ;
+    public static final int BMP_STRING_VAL =                0x1e000000 ;
     /** value for the tag */
+    public static final int RESERVED31_VAL =                0x1f000000 ;
     
     /** enum for the tag */
     public static final UniversalTag BOOLEAN = 
@@ -197,8 +201,8 @@
     public static final UniversalTag PRINTABLE_STRING = 
         new UniversalTag( "PRINTABLE_STRING", PRINTABLE_STRING_VAL ) ; 
     /** enum for the tag */
-    public static final UniversalTag TELETEX_STRING_T61_STRING = 
-        new UniversalTag( "TELETEX_STRING_T61_STRING", TELETEX_STRING_T61_STRING_VAL ) ; 
+    public static final UniversalTag TELETEX_STRING = 
+        new UniversalTag( "TELETEX_STRING", TELETEX_STRING_VAL ) ; 
     /** enum for the tag */
     public static final UniversalTag VIDEOTEX_STRING = 
         new UniversalTag( "VIDEOTEX_STRING", VIDEOTEX_STRING_VAL ) ; 
@@ -215,9 +219,8 @@
     public static final UniversalTag GRAPHIC_STRING = 
         new UniversalTag( "GRAPHIC_STRING", GRAPHIC_STRING_VAL ) ; 
     /** enum for the tag */
-    public static final UniversalTag VISIBLE_STRING_ISO646_STRING = 
-        new UniversalTag( "VISIBLE_STRING_ISO646_STRING", 
-            VISIBLE_STRING_ISO646_STRING_VAL ) ; 
+    public static final UniversalTag VISIBLE_STRING = 
+        new UniversalTag( "VISIBLE_STRING", VISIBLE_STRING_VAL ) ; 
     /** enum for the tag */
     public static final UniversalTag GENERAL_STRING = 
         new UniversalTag( "GENERAL_STRING", GENERAL_STRING_VAL ) ; 
@@ -272,124 +275,7 @@
 
 
     /**
-     * Gets the ASN.1 UNIVERSAL type tag's enum using an id value.
-     * 
-     * @param octet the first octet of the TLV
-     * @return the valued enum for the ASN.1 UNIVERSAL type tag
-     */
-    public static boolean isPrimitive( int value )
-    {
-        boolean isPrimitive = false ;
-        
-        switch ( value )
-        {
-            case( RESERVED0_VAL ):
-                isPrimitive = false ;
-                break ;
-            case( BOOLEAN_VAL ):
-                isPrimitive = true ;
-                break ;
-            case( INTEGER_VAL ):
-                isPrimitive = true ;
-                break ;
-            case( BIT_STRING_VAL ):
-                isPrimitive = true ;
-                break ;
-            case( OCTET_STRING_VAL ):
-                isPrimitive = true ;
-                break ;
-            case( NULL_VAL ):
-                isPrimitive = true ;
-                break ;
-            case( OBJECT_IDENTIFIER_VAL ):
-                isPrimitive = true ;
-                break ;
-            case( OBJECT_DESCRIPTOR_VAL ):
-                isPrimitive = true ;
-                break ;
-            case( EXTERNAL_INSTANCE_OF_VAL ):
-                isPrimitive = true ;
-                break ;
-            case( REAL_VAL ):
-                isPrimitive = true ;
-                break ;
-            case( ENUMERATED_VAL ):
-                isPrimitive = true ;
-                break ;
-            case( EMBEDDED_PDV_VAL ):
-                isPrimitive = false ;
-                break ;
-            case( UTF8_STRING_VAL ):
-                isPrimitive = true ;
-                break ;
-            case( RELATIVE_OID_VAL ):
-                isPrimitive = true ;
-                break ;
-            case( RESERVED14_VAL ):
-                isPrimitive = false ;
-                break ;
-            case( RESERVED15_VAL ):
-                isPrimitive = false ;
-                break ;
-            case( SEQUENCE_SEQUENCE_OF_VAL ):
-                isPrimitive = false ;
-                break ;
-            case( SET_SET_OF_VAL ):
-                isPrimitive = false ;
-                break ;
-            case( NUMERIC_STRING_VAL ):
-                isPrimitive = true ;
-                break ;
-            case( PRINTABLE_STRING_VAL ):
-                isPrimitive = true ;
-                break ;
-            case( TELETEX_STRING_T61_STRING_VAL ):
-                isPrimitive = true ;
-                break ;
-            case( VIDEOTEX_STRING_VAL ):
-                isPrimitive = true ;
-                break ;
-            case( IA5_STRING_VAL ):
-                isPrimitive = true ;
-                break ;
-            case( UTC_TIME_VAL ):
-                isPrimitive = true ;
-                break ;
-            case( GENERALIZED_TIME_VAL ):
-                isPrimitive = true ;
-                break ;
-            case( GRAPHIC_STRING_VAL ):
-                isPrimitive = true ;
-                break ;
-            case( VISIBLE_STRING_ISO646_STRING_VAL ):
-                isPrimitive = true ;
-                break ;
-            case( GENERAL_STRING_VAL ):
-                isPrimitive = true ;
-                break ;
-            case( UNIVERSAL_STRING_VAL ):
-                isPrimitive = true ;
-                break ;
-            case( CHARACTER_STRING_VAL ):
-                isPrimitive = true ;
-                break ;
-            case( BMP_STRING_VAL ):
-                isPrimitive = true ;
-                break ;
-            case( RESERVED31_VAL ):
-                isPrimitive = false ;
-                break ;
-            default:
-                throw new IllegalArgumentException( "Only values between [0-31]"
-                        + " inclusive constitute valid UNIVERSAL Tags" ) ;
-        }
-        
-        return isPrimitive ;
-    }
-
-    
-    /**
-     * Gets the ASN.1 UNIVERSAL type tag's enum using an id value.
+     * Gets the ASN.1 UNIVERSAL type tag's enum using a tag value.
      * 
      * @param octet the first octet of the TLV
      * @return the valued enum for the ASN.1 UNIVERSAL type tag
@@ -397,6 +283,7 @@
     public static UniversalTag getUniversalTag( int value )
     {
         UniversalTag type = null ;
+        value &= 0xdfffffff ;
         
         switch ( value )
         {
@@ -460,8 +347,8 @@
             case( PRINTABLE_STRING_VAL ):
                 type = PRINTABLE_STRING ;
                 break ;
-            case( TELETEX_STRING_T61_STRING_VAL ):
-                type = TELETEX_STRING_T61_STRING ;
+            case( TELETEX_STRING_VAL ):
+                type = TELETEX_STRING ;
                 break ;
             case( VIDEOTEX_STRING_VAL ):
                 type = VIDEOTEX_STRING ;
@@ -478,8 +365,8 @@
             case( GRAPHIC_STRING_VAL ):
                 type = GRAPHIC_STRING ;
                 break ;
-            case( VISIBLE_STRING_ISO646_STRING_VAL ):
-                type = VISIBLE_STRING_ISO646_STRING ;
+            case( VISIBLE_STRING_VAL ):
+                type = VISIBLE_STRING ;
                 break ;
             case( GENERAL_STRING_VAL ):
                 type = GENERAL_STRING ;

Modified: incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/LengthTest.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/LengthTest.java	(original)
+++ incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/LengthTest.java	Mon Mar 29 20:02:49 2004
@@ -17,11 +17,10 @@
 package org.apache.snickers.ber ;
 
 
-import org.apache.commons.collections.primitives.ArrayByteList ;
-import org.apache.commons.lang.ArrayUtils;
-
 import junit.framework.TestCase ;
 
+import java.nio.ByteBuffer ;
+
 
 /**
  * Tests the Length class.
@@ -54,15 +53,15 @@
      */
     public void testGetLength() throws Exception
     {
-        ArrayByteList list = new ArrayByteList() ;
-        list.add( (byte) 0x1 ) ;
-        list.add( (byte) 0x1 ) ;
-        list.add( (byte) 0x1 ) ;
-        list.add( (byte) 0x1 ) ;
-        list.add( (byte) 0x1 ) ;
-        list.add( (byte) 0x1 ) ;
-        list.add( (byte) 0x1 ) ;
-        list.add( (byte) 0x1 ) ;
+        ByteBuffer list = ByteBuffer.allocate( 8 ) ;
+        list.put( (byte) 0x1 ) ;
+        list.put( (byte) 0x1 ) ;
+        list.put( (byte) 0x1 ) ;
+        list.put( (byte) 0x1 ) ;
+        list.put( (byte) 0x1 ) ;
+        list.put( (byte) 0x1 ) ;
+        list.put( (byte) 0x1 ) ;
+        list.put( (byte) 0x1 ) ;
         
         try
         {
@@ -76,7 +75,8 @@
         
         
         list.clear() ;
-        list.add(( byte ) 0x7 ) ;
+        list.put(( byte ) 0x7 ) ;
+        list.flip() ;
         assertEquals( 7, Length.getLength( list ) ) ;
     }
 
@@ -91,18 +91,6 @@
     {
     }
 
-    public void testGetOctets() throws Exception
-    {
-        byte[] bites = { (byte) 0xff, (byte) 0xff, (byte) 0x0f } ;
-        
-        Length length = new Length() ;
-        length.add( bites[0] ) ;
-        length.add( bites[1] ) ;
-        length.add( bites[2] ) ;
-        
-        assertTrue( ArrayUtils.isEquals( bites, length.getOctets() ) ) ;
-    }
-    
     
     public void testGetOctets2() throws Exception
     {

Modified: incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/MultiByteTagTests.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/MultiByteTagTests.java	(original)
+++ incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/MultiByteTagTests.java	Mon Mar 29 20:02:49 2004
@@ -198,33 +198,6 @@
     }
 
     
-    public void testIdShift21() throws Exception
-    {
-        Tuple tlv = decode( "01011111" ) ;
-        assertEquals( 0, tlv.id ) ;
-        assertEquals( 0, tlvList.size() ) ;
-        assertEquals( true, tlv.isPrimitive ) ;
-        assertEquals( TypeClass.APPLICATION, tlv.typeClass ) ;
-        assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
-
-        tlv = decode( "10000000" ) ;
-        assertEquals( 0, tlv.id ) ;
-        assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
-
-        tlv = decode( "10000000" ) ;
-        assertEquals( 0, tlv.id ) ;
-        assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
-
-        tlv = decode( "10000000" ) ;
-        assertEquals( 0, tlv.id ) ;
-        assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
-
-        tlv = decode( "00000001" ) ;
-        assertEquals( BIT_20, tlv.id ) ;
-        assertEquals( BERDecoderState.LENGTH, decoder.getState() ) ;
-    }
-
-
     public void testIdShift21Minus1() throws Exception
     {
         Tuple tlv = decode( "01011111" ) ;
@@ -244,122 +217,6 @@
 
         tlv = decode( "01111111" ) ;
         assertEquals( BIT_20 - 1, tlv.id ) ;
-        assertEquals( BERDecoderState.LENGTH, decoder.getState() ) ;
-    }
-
-
-    public void testIdShift21Plus1() throws Exception
-    {
-        Tuple tlv = decode( "01011111" ) ;
-        assertEquals( 0, tlv.id ) ;
-        assertEquals( 0, tlvList.size() ) ;
-        assertEquals( true, tlv.isPrimitive ) ;
-        assertEquals( TypeClass.APPLICATION, tlv.typeClass ) ;
-        assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
-
-        tlv = decode( "10000001" ) ;
-        assertEquals( 0, tlv.id ) ;
-        assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
-
-        tlv = decode( "10000000" ) ;
-        assertEquals( 0, tlv.id ) ;
-        assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
-
-        tlv = decode( "10000000" ) ;
-        assertEquals( 0, tlv.id ) ;
-        assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
-
-        tlv = decode( "00000001" ) ;
-        assertEquals( BIT_20 + 1, tlv.id ) ;
-        assertEquals( BERDecoderState.LENGTH, decoder.getState() ) ;
-    }
-
-
-    public void testIdShift28() throws Exception
-    {
-        Tuple tlv = decode( "01011111" ) ;
-        assertEquals( 0, tlv.id ) ;
-        assertEquals( 0, tlvList.size() ) ;
-        assertEquals( true, tlv.isPrimitive ) ;
-        assertEquals( TypeClass.APPLICATION, tlv.typeClass ) ;
-        assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
-
-        tlv = decode( "10000000" ) ;
-        assertEquals( 0, tlv.id ) ;
-        assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
-
-        tlv = decode( "10000000" ) ;
-        assertEquals( 0, tlv.id ) ;
-        assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
-
-        tlv = decode( "10000000" ) ;
-        assertEquals( 0, tlv.id ) ;
-        assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
-
-        tlv = decode( "10000000" ) ;
-        assertEquals( 0, tlv.id ) ;
-        assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
-
-        tlv = decode( "00000001" ) ;
-        assertEquals( BIT_27, tlv.id ) ;
-        assertEquals( BERDecoderState.LENGTH, decoder.getState() ) ;
-    }
-
-
-    public void testIdShift28Minus1() throws Exception
-    {
-        Tuple tlv = decode( "01011111" ) ;
-        assertEquals( 0, tlv.id ) ;
-        assertEquals( 0, tlvList.size() ) ;
-        assertEquals( true, tlv.isPrimitive ) ;
-        assertEquals( TypeClass.APPLICATION, tlv.typeClass ) ;
-        assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
-
-        tlv = decode( "11111111" ) ;
-        assertEquals( 0, tlv.id ) ;
-        assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
-
-        tlv = decode( "11111111" ) ;
-        assertEquals( 0, tlv.id ) ;
-        assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
-
-        tlv = decode( "11111111" ) ;
-        assertEquals( 0, tlv.id ) ;
-        assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
-
-        tlv = decode( "01111111" ) ;
-        assertEquals( BIT_27 - 1, tlv.id ) ;
-        assertEquals( BERDecoderState.LENGTH, decoder.getState() ) ;
-    }
-
-
-    public void testIdShift28Plus1() throws Exception
-    {
-        Tuple tlv = decode( "01011111" ) ;
-        assertEquals( 0, tlv.id ) ;
-        assertEquals( 0, tlvList.size() ) ;
-        assertEquals( true, tlv.isPrimitive ) ;
-        assertEquals( TypeClass.APPLICATION, tlv.typeClass ) ;
-        assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
-
-        tlv = decode( "10000001" ) ;
-        assertEquals( 0, tlv.id ) ;
-        assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
-
-        tlv = decode( "10000000" ) ;
-        assertEquals( 0, tlv.id ) ;
-        assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
-
-        tlv = decode( "10000000" ) ;
-        assertEquals( 0, tlv.id ) ;
-        assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
-
-        tlv = decode( "10000000" ) ;
-        assertEquals( 0, tlv.id ) ;
-        assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
-
-        tlv = decode( "00000001" ) ;
-        assertEquals( BIT_27 + 1, tlv.id ) ;
         assertEquals( BERDecoderState.LENGTH, decoder.getState() ) ;
     }
 }

Modified: incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/TagTest.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/TagTest.java	(original)
+++ incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/TagTest.java	Mon Mar 29 20:02:49 2004
@@ -18,7 +18,6 @@
 
 
 import org.apache.commons.lang.ArrayUtils ;
-import org.apache.commons.collections.primitives.ArrayByteList ;
 
 import junit.framework.TestCase ;
 
@@ -32,20 +31,22 @@
  */
 public class TagTest extends TestCase
 {
-
-    private static final int BIT_7 = 0x80;
-    private static final int BIT_6 = 0x40;
-    private static final int BIT_4 = 0x10;
-    private static final int BIT_3 = 0x08;
-    private static final int BIT_2 = 0x04;
-    private static final int BIT_1 = 0x02;
-    private static final int BIT_0 = 0x01;
-    private static final int BIT_5 = 0x20;
-    public static void main(String[] args)
+    private static final int BIT_7 = 0x80 ;
+    private static final int BIT_6 = 0x40 ;
+    private static final int BIT_4 = 0x10 ;
+    private static final int BIT_3 = 0x08 ;
+    private static final int BIT_2 = 0x04 ;
+    private static final int BIT_1 = 0x02 ;
+    private static final int BIT_0 = 0x01 ;
+    private static final int BIT_5 = 0x20 ;
+    
+    
+    public static void main( String[] args )
     {
-        junit.textui.TestRunner.run(TagTest.class);
+        junit.textui.TestRunner.run( TagTest.class ) ;
     }
 
+    
     /*
      * @see TestCase#setUp()
      */
@@ -54,6 +55,7 @@
         super.setUp();
     }
 
+    
     /*
      * @see TestCase#tearDown()
      */
@@ -62,6 +64,7 @@
         super.tearDown();
     }
 
+    
     /**
      * Constructor for TagTest.
      * @param arg0
@@ -77,6 +80,7 @@
         assertEquals( TypeClass.UNIVERSAL, TypeClass.getTypeClass( (byte) 0 ) );
     }
     
+    
     public void testIsPrimitive() throws Exception
     {
         byte octet = BIT_5 ;
@@ -193,29 +197,6 @@
             }
         }
         
-        ArrayByteList list = new ArrayByteList() ;
-        list.add( (byte)1) ;
-        assertEquals( 1, Tag.getTagId( list ) ) ;
-
-        list.add( (byte)1) ;
-        list.add( (byte)1) ;
-        list.add( (byte)1) ;
-        list.add( (byte)1) ;
-        list.add( (byte)1) ;
-        list.add( (byte)1) ;
-        list.add( (byte)1) ;
-        list.add( (byte)1) ;
-        try
-        {
-            Tag.getTagId( list ) ;
-            fail( "should fail before getting here" ) ;
-        }
-        catch ( Throwable t )
-        {
-            assertNotNull( t ) ;
-        }
-
-    
         try
         {
             Tag.getTagId( new byte[56] ) ;
@@ -237,7 +218,8 @@
         tag.add( bites[1] ) ;
         tag.add( bites[2] ) ;
         
-        assertTrue( ArrayUtils.isEquals( bites, tag.getOctets() ) ) ;
+        byte[] octets = tag.getOctets() ;
+        assertTrue( ArrayUtils.isEquals( bites, octets ) ) ;
     }
     
     

Mime
View raw message