directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 10084 - in incubator/directory/snickers/trunk/ber/src: java/org/apache/snickers/ber java/org/apache/snickers/ber/digester test/org/apache/snickers/ber/digester test/org/apache/snickers/ber/digester/rules
Date Sun, 18 Apr 2004 17:18:51 GMT
Author: akarasulu
Date: Sun Apr 18 10:18:50 2004
New Revision: 10084

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/digester/BERDigester.java
   incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/digester/BERDigesterTest.java
   incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/digester/rules/PrimitiveIntDecodeRuleTest.java
Log:
Commit changes ...

o noticed that Tuple.clear() was not reseting the rawTag so it was corrected
o corrected major digester bug where nesting of tlvs were causing the matched
  value to be overwritten - now we reset the match value at before every tag 
  and every finish event.
o removed extra code that called the finish() of all rules when the object 
  stack cleared - this was not right so we blew it away.



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	Sun
Apr 18 10:18:50 2004
@@ -314,6 +314,7 @@
     {
         this.id = 0 ;
         this.index = 0 ;
+        this.rawTag = 0 ;
         this.isPrimitive = true ;
         this.length = Length.UNDEFINED ;
         this.typeClass = TypeClass.APPLICATION ;
@@ -567,7 +568,6 @@
      * Sets the length bytes.
      * 
      * @param octets the byte [] to set length in
-     * @param offset the offset in the array to start the length section in
      * @param lengthBytes the number bytes for the length section
      */
     void setLength( ByteBuffer octets, int lengthBytes )

Modified: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/BERDigester.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/BERDigester.java
(original)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/digester/BERDigester.java
Sun Apr 18 10:18:50 2004
@@ -187,21 +187,27 @@
          */
         public void decodeOccurred( StatefulDecoder decoder, Object decoded )
         {
+            /*
+             * must reset the matched rules here because the nested TLVs
+             * overwrite the matched rules of a constructed TLV so it must
+             * be set once again
+             */
+            matched = rules.match( tagStack ) ;
             fireFinishEvent() ;
         }
     }
 
 
     // ------------------------------------------------------------------------
-    // Digester like methods 
+    // Digester like methods
     // ------------------------------------------------------------------------
 
 
     /**
      * Register a new <code>Rule</code> matching the specified pattern.
-     * 
+     *
      * @param pattern tag nesting pattern
-     * @param rule the Rule to add to this BERDigester 
+     * @param rule the Rule to add to this BERDigester
      */
     public void addRule( int[] pattern, Rule rule )
     {
@@ -1049,7 +1055,10 @@
             try 
             {
                 rule.value( buf ) ;
-            } 
+
+                // need to rewind the buffer after rule exhausts it
+                buf.rewind() ;
+            }
             catch ( RuntimeException e )
             {
                 monitor.ruleFailed( this, rule, "Rule.value() threw exception", e ) ;
@@ -1079,7 +1088,7 @@
                 
                 try 
                 {
-                    rule = ( Rule ) matched.get( j ) ;
+                    rule = ( Rule ) matched.remove( j ) ;
                     rule.finish() ;
                     tagStack.pop() ;
                     monitor.ruleCompleted( this, rule ) ;
@@ -1090,38 +1099,6 @@
                     monitor.ruleFailed( this, rule, "Rule.finish() threw exception", e )
;
                     throw e ;
                 }
-                catch ( Error e ) 
-                {
-                    monitor.ruleFailed( this, rule, "Rule.finish() threw error", e ) ;
-                    throw e ;
-                }
-            }
-        }
-
-
-        if ( tagStack.empty() )
-        {
-            // Fire "finish" events for all defined rules minues those seen
-            Iterator rules = getRules().rules().iterator() ;
-        
-            while ( rules.hasNext() ) 
-            {
-                rule = ( Rule ) rules.next() ;
-
-                if ( seen != null && seen.contains( rule ) )
-                {
-                    continue ;
-                }
-                
-                try 
-                {
-                    rule.finish() ;
-                } 
-                catch ( RuntimeException e )
-                {
-                    monitor.ruleFailed( this, rule, "Rule.finish() threw exception", e )
;
-                    throw e ;
-                } 
                 catch ( Error e ) 
                 {
                     monitor.ruleFailed( this, rule, "Rule.finish() threw error", e ) ;

Modified: incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/digester/BERDigesterTest.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/digester/BERDigesterTest.java
(original)
+++ incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/digester/BERDigesterTest.java
Sun Apr 18 10:18:50 2004
@@ -842,7 +842,7 @@
     public void testNestedTlvsWithErrors() throws Exception
     {
         int[] pat0 = { 0x14000000, 0x10000000 } ;
-        int[] pat1 = { 0x11000000 } ;
+        int[] pat1 = { 0x14000000 } ;
         ErrorRule rule0 = new ErrorRule() ;
         ErrorRule rule1 = new ErrorRule() ;
         digester.addRule( pat0, rule0 ) ;
@@ -865,7 +865,6 @@
         }
         catch( Error e )
         {
-            assertNotNull( e ) ;
             return ;
         }
 

Modified: incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/digester/rules/PrimitiveIntDecodeRuleTest.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/digester/rules/PrimitiveIntDecodeRuleTest.java
(original)
+++ incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/digester/rules/PrimitiveIntDecodeRuleTest.java
Sun Apr 18 10:18:50 2004
@@ -45,12 +45,15 @@
         rule = new PrimitiveIntDecodeRule() ;
         digester = new BERDigester() ;
         rule.setDigester( digester ) ;
+        int[] pattern = { 0x10000000, 0x02000000 } ;
+        digester.addRule( pattern, rule ) ;
     }
 
 
     protected void tearDown() throws Exception
     {
         super.tearDown() ;
+        rule.setDigester( null ) ;
         rule = null ;
         digester = null ;
     }
@@ -439,5 +442,14 @@
         BigInteger big = new BigInteger( bitesUsed ) ;
         assertEquals( big.intValue(), digester.popInt() ) ;
         assertEquals( 0, digester.getIntCount() ) ;
+    }
+
+
+    public void testByDecoding() throws Exception
+    {
+        byte[] data = { 0x30, 0x03, 0x02, 0x01, 0x0f } ;
+        ByteBuffer buf = ByteBuffer.wrap( data ) ;
+        digester.decode( buf ) ;
+        assertEquals( 0x0f, digester.peekInt() ) ;
     }
 }

Mime
View raw message