directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 30899 - in incubator/directory/snickers/trunk/ldap-ber-provider/src: java/org/apache/snickers/ldap java/org/apache/snickers/ldap/encoder test/org/apache/snickers/ldap test/org/apache/snickers/ldap/decoder/testutils test/org/apache/snickers/ldap/encoder
Date Thu, 29 Jul 2004 05:05:26 GMT
Author: akarasulu
Date: Wed Jul 28 22:05:25 2004
New Revision: 30899

Modified:
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/SnickersDecoder.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/SnickersProvider.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/test/org/apache/snickers/ldap/SnickersDecoderTest.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/SnickersEncoderTest.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/decoder/testutils/RuleTestCase.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/decoder/testutils/TestUtils.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/AbstractEncoderTest.java
Log:
with snickers as default we must specify snacc4j provider
 while our tests are still dependent on snacc4j

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/SnickersDecoder.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/SnickersDecoder.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/SnickersDecoder.java
Wed Jul 28 22:05:25 2004
@@ -147,7 +147,7 @@
                     break;
                 }
 
-                digester.decode( ByteBuffer.wrap( buf ) );
+                digester.decode( ByteBuffer.wrap( buf, 0, amount ) );
             } while( amount >= 0 );
         }
         catch( Exception e )

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/SnickersProvider.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/SnickersProvider.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/SnickersProvider.java
Wed Jul 28 22:05:25 2004
@@ -17,6 +17,7 @@
 package org.apache.snickers.ldap;
 
 import org.apache.ldap.common.message.spi.*;
+import org.apache.ldap.common.berlib.snacc.SnaccProvider;
 
 
 /**
@@ -35,13 +36,35 @@
     /**
      * Creates an instance of a Snickers based LDAP BER Provider.
      */
-    public SnickersProvider()
+    private SnickersProvider()
     {
         super( "Snickers LDAP BER Provider", "Apache Directory Project" );
         decoder = new SnickersDecoder( this );
         encoder = new SnickersEncoder( this );
         transformer = new SnickersTransformer( this );
     }
+
+
+    /** the singleton SnickersProvider instance */
+	private static SnickersProvider singleton ;
+
+
+    /**
+     * Gets a handle on the singleton SnaccProvider.  Only one instance should
+     * have to be instantiated for the entire jvm.
+     *
+     * @return the singleton SnaccProvider instance
+     */
+    public static Provider getProvider()
+    {
+        if( singleton == null )
+        {
+            singleton = new SnickersProvider() ;
+        }
+
+        return singleton ;
+    }
+
 
 
     /**

Modified: 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/SnickersLdapEncoder.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/SnickersLdapEncoder.java
Wed Jul 28 22:05:25 2004
@@ -116,7 +116,11 @@
             default:
                 IllegalArgumentException e = new IllegalArgumentException(
                         "Unable to encode unrecognized object: " + obj ) ;
-                monitor.error( this, e );
+                if ( monitor != null )
+                {
+                    monitor.error( this, e );
+                }
+                
                 throw e;
         }
     }

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/SnickersDecoderTest.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/SnickersDecoderTest.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/SnickersDecoderTest.java
Wed Jul 28 22:05:25 2004
@@ -20,11 +20,13 @@
 
 import java.io.InputStream;
 import java.io.ByteArrayInputStream;
+import java.util.Properties;
 
 import org.apache.ldap.common.message.Message;
 import org.apache.ldap.common.message.MessageEncoder;
 import org.apache.ldap.common.message.BindRequestImpl;
 import org.apache.ldap.common.message.BindRequest;
+import org.apache.ldap.common.message.spi.Provider;
 import org.apache.commons.lang.ArrayUtils;
 
 
@@ -44,7 +46,7 @@
     {
         super.setUp();
 
-        SnickersProvider provider = new SnickersProvider();
+        SnickersProvider provider = ( SnickersProvider ) Provider.getProvider();
         decoder = ( SnickersDecoder ) provider.getDecoder();
     }
 
@@ -78,7 +80,12 @@
 
     private InputStream encode( Message msg )
     {
-        MessageEncoder encoder = new MessageEncoder();
+        // @todo replace this with the Snickers encoder or use serialized
+        // PDUs stubs for test cases rather than decoding live.
+        Properties env = new Properties();
+        env.setProperty( Provider.BERLIB_PROVIDER,
+                "org.apache.ldap.common.berlib.snacc.SnaccProvider" );
+        MessageEncoder encoder = new MessageEncoder( env );
         return new ByteArrayInputStream( encoder.encode( msg ) );
     }
 }

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/SnickersEncoderTest.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/SnickersEncoderTest.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/SnickersEncoderTest.java
Wed Jul 28 22:05:25 2004
@@ -18,9 +18,10 @@
 
 import junit.framework.TestCase;
 
-import java.io.InputStream;
 import java.io.ByteArrayInputStream;
+import java.util.Properties;
 
+import org.apache.ldap.common.message.spi.Provider;
 import org.apache.ldap.common.message.*;
 import org.apache.commons.lang.ArrayUtils;
 
@@ -41,7 +42,7 @@
     {
         super.setUp();
 
-        SnickersProvider provider = new SnickersProvider();
+        SnickersProvider provider = ( SnickersProvider ) Provider.getProvider();
         encoder = ( SnickersEncoder ) provider.getEncoder();
     }
 
@@ -74,7 +75,12 @@
 
     private Message decode( byte[] bites )
     {
-        MessageDecoder decoder = new MessageDecoder();
+        // @todo replace this with the Snickers encoder or use serialized
+        // PDUs stubs for test cases rather than decoding live.
+        Properties env = new Properties();
+        env.setProperty( Provider.BERLIB_PROVIDER,
+                "org.apache.ldap.common.berlib.snacc.SnaccProvider" );
+        MessageDecoder decoder = new MessageDecoder( env );
         ByteArrayInputStream in = new ByteArrayInputStream( bites );
         return ( Message ) decoder.decode( null, in );
     }

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/decoder/testutils/RuleTestCase.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/decoder/testutils/RuleTestCase.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/decoder/testutils/RuleTestCase.java
Wed Jul 28 22:05:25 2004
@@ -18,11 +18,12 @@
 
 
 import java.nio.ByteBuffer ;
+import java.util.Properties;
 
 import junit.framework.TestCase ;
 import org.apache.ldap.common.message.Message ;
-import org.apache.ldap.common.message.UnbindRequest;
 import org.apache.ldap.common.message.MessageEncoder;
+import org.apache.ldap.common.message.spi.Provider;
 import org.apache.snickers.ber.digester.BERDigester;
 import org.apache.snickers.ldap.decoder.LdapDigesterFactory;
 import org.apache.commons.codec.stateful.CallbackHistory;
@@ -73,7 +74,12 @@
     {
         ByteBuffer buf = null ;
 
-        MessageEncoder encoder = new MessageEncoder( ) ;
+        // @todo replace this with the Snickers encoder or use serialized
+        // PDUs stubs for test cases rather than decoding live.
+        Properties env = new Properties();
+        env.setProperty( Provider.BERLIB_PROVIDER,
+                "org.apache.ldap.common.berlib.snacc.SnaccProvider" );
+        MessageEncoder encoder = new MessageEncoder( env );
         buf = ByteBuffer.wrap( encoder.encode( req ) ) ;
 
         return buf ;

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/decoder/testutils/TestUtils.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/decoder/testutils/TestUtils.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/decoder/testutils/TestUtils.java
Wed Jul 28 22:05:25 2004
@@ -18,11 +18,13 @@
 
 
 import java.nio.ByteBuffer ;
+import java.util.Properties;
 
 import org.apache.commons.codec.stateful.CallbackHistory ;
 
 import org.apache.ldap.common.message.Message ;
 import org.apache.ldap.common.message.MessageEncoder ;
+import org.apache.ldap.common.message.spi.Provider;
 
 import org.apache.snickers.ber.TupleTreeDecoder ;
 import org.apache.snickers.ber.DefaultMutableTupleNode ;
@@ -48,7 +50,13 @@
             throws Exception
     {
         DefaultMutableTupleNode node = null ;
-        MessageEncoder encoder = new MessageEncoder() ;
+
+        // @todo replace this with the Snickers encoder or use serialized
+        // PDUs stubs for test cases rather than decoding live.
+        Properties env = new Properties();
+        env.setProperty( Provider.BERLIB_PROVIDER,
+                "org.apache.ldap.common.berlib.snacc.SnaccProvider" );
+        MessageEncoder encoder = new MessageEncoder( env );
         ByteBuffer buf = ByteBuffer.wrap( encoder.encode( pdu ) ) ;
         TupleTreeDecoder decoder = new TupleTreeDecoder() ;
         CallbackHistory cb = new CallbackHistory() ;

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/AbstractEncoderTest.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/AbstractEncoderTest.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/AbstractEncoderTest.java
Wed Jul 28 22:05:25 2004
@@ -18,15 +18,15 @@
 
 import junit.framework.TestCase;
 import org.apache.snickers.ber.*;
-import org.apache.snickers.ber.primitives.UniversalTag;
-import org.apache.snickers.ber.primitives.PrimitiveUtils;
 import org.apache.snickers.ldap.BufferUtils;
 import org.apache.ldap.common.message.*;
+import org.apache.ldap.common.message.spi.Provider;
 import org.apache.commons.codec.stateful.EncoderCallback;
 import org.apache.commons.codec.stateful.StatefulEncoder;
 
 import java.nio.ByteBuffer;
 import java.io.ByteArrayInputStream;
+import java.util.Properties;
 
 
 /**
@@ -83,7 +83,13 @@
 
     public static Message decodeEncoded( ByteBuffer encoded )
     {
-        MessageDecoder decoder = new MessageDecoder();
+        // @todo replace this with the Snickers encoder or use serialized
+        // PDUs stubs for test cases rather than decoding live.
+        Properties env = new Properties();
+        env.setProperty( Provider.BERLIB_PROVIDER,
+                "org.apache.ldap.common.berlib.snacc.SnaccProvider" );
+        MessageDecoder decoder = new MessageDecoder( env );
+        
         byte[] encodedBytes = BufferUtils.getArray( encoded );
         ByteArrayInputStream in = new ByteArrayInputStream( encodedBytes );
         return ( Message ) decoder.decode( null, in );

Mime
View raw message