directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r400067 [3/7] - in /directory/trunks: apacheds/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/extended/ clients/ldap/ mina/core/src/main/java/org/apache/mina/filter/ mina/core/src/main/java/org/apache/mina/handler/mult...
Date Fri, 05 May 2006 12:52:54 GMT
Modified: directory/trunks/mina/filter-compression/src/test/java/org/apache/mina/filter/CompressionFilterTest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/filter-compression/src/test/java/org/apache/mina/filter/CompressionFilterTest.java?rev=400067&r1=400066&r2=400067&view=diff
==============================================================================
--- directory/trunks/mina/filter-compression/src/test/java/org/apache/mina/filter/CompressionFilterTest.java (original)
+++ directory/trunks/mina/filter-compression/src/test/java/org/apache/mina/filter/CompressionFilterTest.java Fri May  5 05:52:49 2006
@@ -1,210 +1,210 @@
-/*
- *   @(#) $Id$
- *
- *   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.mina.filter;
-
-import org.apache.mina.common.ByteBuffer;
-import org.apache.mina.common.IoFilterChain;
-import org.apache.mina.common.IoSession;
-import org.apache.mina.common.IoFilter.NextFilter;
-import org.apache.mina.filter.support.Zlib;
-import org.apache.mina.common.IoFilter.WriteRequest;
-import org.easymock.MockControl;
-import org.easymock.AbstractMatcher;
-
-import junit.framework.TestCase;
-
-/**
- * @author The Apache Directory Project (mina-dev@directory.apache.org)
- * @version $Rev$, $Date$
- */
-public class CompressionFilterTest extends TestCase
-{
-    private MockControl mockSession;
-    private MockControl mockNextFilter;
-    private MockControl mockIoFilterChain;
-    private IoSession session;
-    private NextFilter nextFilter;
-    private IoFilterChain ioFilterChain;
-    private CompressionFilter filter;
-    private Zlib deflater;
-    private Zlib inflater;
-    private Zlib actualDeflater;
-    private Zlib actualInflater;
-
-    // the sample data to be used for testing
-    String strCompress =
-            "The quick brown fox jumps over the lazy dog.  " +
-            "The quick brown fox jumps over the lazy dog.  " +
-            "The quick brown fox jumps over the lazy dog.  " +
-            "The quick brown fox jumps over the lazy dog.  " +
-            "The quick brown fox jumps over the lazy dog.  " +
-            "The quick brown fox jumps over the lazy dog.  " +
-            "The quick brown fox jumps over the lazy dog.  " +
-            "The quick brown fox jumps over the lazy dog.  " +
-            "The quick brown fox jumps over the lazy dog.  " +
-            "The quick brown fox jumps over the lazy dog.  " +
-            "The quick brown fox jumps over the lazy dog.  " +
-            "The quick brown fox jumps over the lazy dog.  " +
-            "The quick brown fox jumps over the lazy dog.  " +
-            "The quick brown fox jumps over the lazy dog.  " +
-            "The quick brown fox jumps over the lazy dog.  " +
-            "The quick brown fox jumps over the lazy dog.  " +
-            "The quick brown fox jumps over the lazy dog.  " +
-            "The quick brown fox jumps over the lazy dog.  " +
-            "The quick brown fox jumps over the lazy dog.  " +
-            "The quick brown fox jumps over the lazy dog.  " +
-            "The quick brown fox jumps over the lazy dog.  " +
-            "The quick brown fox jumps over the lazy dog.  " +
-            "The quick brown fox jumps over the lazy dog.  " +
-            "The quick brown fox jumps over the lazy dog.  " +
-            "The quick brown fox jumps over the lazy dog.  ";
-
-    protected void setUp()
-    {
-        // create the necessary mock controls.
-        mockSession = MockControl.createControl( IoSession.class );
-        mockNextFilter = MockControl.createControl( NextFilter.class );
-        mockIoFilterChain = MockControl.createControl( IoFilterChain.class );
-
-        // set the default matcher
-        mockNextFilter.setDefaultMatcher( new DataMatcher() );
-
-        session = ( IoSession ) mockSession.getMock();
-        nextFilter = ( NextFilter ) mockNextFilter.getMock();
-        ioFilterChain = ( IoFilterChain ) mockIoFilterChain.getMock();
-
-        // create an instance of the filter
-        filter = new CompressionFilter( CompressionFilter.COMPRESSION_MAX );
-
-        // deflater and inflater that will be used by the filter
-        deflater = new Zlib( Zlib.COMPRESSION_MAX, Zlib.MODE_DEFLATER );
-        inflater = new Zlib( Zlib.COMPRESSION_MAX, Zlib.MODE_INFLATER );
-
-        // create instances of the deflater and inflater to help test the output
-        actualDeflater = new Zlib( Zlib.COMPRESSION_MAX, Zlib.MODE_DEFLATER );
-        actualInflater = new Zlib( Zlib.COMPRESSION_MAX, Zlib.MODE_INFLATER );
-    }
-
-    public void testCompression() throws Exception
-    {
-        // prepare the input data
-        ByteBuffer buf = ByteBuffer.wrap( strCompress.getBytes( "UTF8" ) );
-        ByteBuffer actualOutput = actualDeflater.deflate( buf );
-        WriteRequest writeRequest = new WriteRequest( buf );
-
-        // record all the mock calls
-        ioFilterChain.contains( CompressionFilter.class );
-        mockIoFilterChain.setReturnValue( false );
-
-        ioFilterChain.getSession();
-        mockIoFilterChain.setReturnValue( session );
-
-        session.setAttribute( CompressionFilter.class.getName() + ".Deflater", deflater );
-        mockSession.setDefaultMatcher( new DataMatcher() );
-        mockSession.setReturnValue( null, MockControl.ONE );
-
-        session.setAttribute( CompressionFilter.class.getName() + ".Inflater", inflater );
-        mockSession.setReturnValue( null, MockControl.ONE );
-
-        session.containsAttribute( CompressionFilter.DISABLE_COMPRESSION_ONCE );
-        mockSession.setReturnValue( false );
-
-        session.getAttribute( CompressionFilter.class.getName() + ".Deflater" );
-        mockSession.setReturnValue( deflater );
-
-        nextFilter.filterWrite( session, new WriteRequest( actualOutput ) );
-
-        // switch to playback mode
-        mockSession.replay();
-        mockIoFilterChain.replay();
-        mockNextFilter.replay();
-
-        // make the actual calls on the filter
-        filter.onPreAdd( ioFilterChain, "CompressionFilter", nextFilter );
-        filter.filterWrite( nextFilter, session, writeRequest );
-
-        // verify that all the calls happened as recorded
-        mockNextFilter.verify();
-
-        assertTrue( true );
-    }
-
-    public void testDecompression() throws Exception
-    {
-        // prepare the input data
-        ByteBuffer buf = ByteBuffer.wrap( strCompress.getBytes( "UTF8" ) );
-        ByteBuffer byteInput = actualDeflater.deflate( buf );
-        ByteBuffer actualOutput = actualInflater.inflate( byteInput );
-
-        // record all the mock calls
-        ioFilterChain.contains( CompressionFilter.class );
-        mockIoFilterChain.setReturnValue( false );
-
-        ioFilterChain.getSession();
-        mockIoFilterChain.setReturnValue( session );
-
-        session.setAttribute( CompressionFilter.class.getName() + ".Deflater", deflater );
-        mockSession.setDefaultMatcher( new DataMatcher() );
-        mockSession.setReturnValue( null, MockControl.ONE );
-
-        session.setAttribute( CompressionFilter.class.getName() + ".Inflater", inflater );
-        mockSession.setReturnValue( null, MockControl.ONE );
-
-        session.getAttribute( CompressionFilter.class.getName() + ".Inflater" );
-        mockSession.setReturnValue( inflater );
-
-        nextFilter.messageReceived( session, actualOutput );
-
-        // switch to playback mode
-        mockSession.replay();
-        mockIoFilterChain.replay();
-        mockNextFilter.replay();
-
-        // make the actual calls on the filter
-        filter.onPreAdd( ioFilterChain, "CompressionFilter", nextFilter );
-        filter.messageReceived( nextFilter, session, byteInput );
-
-        // verify that all the calls happened as recorded
-        mockNextFilter.verify();
-
-        assertTrue( true );
-    }
-
-    /**
-     * A matcher used to check if the actual and expected outputs matched
-     * 
-     * @author The Apache Directory MINA subproject (mina-dev@directory.apache.org)
-     */
-    class DataMatcher extends AbstractMatcher
-    {
-        protected boolean argumentMatches( Object arg0, Object arg1 )
-        {
-            // we need to only verify the ByteBuffer output
-            if( arg0 instanceof WriteRequest )
-            {
-                WriteRequest expected = (WriteRequest) arg0;
-                WriteRequest actual = (WriteRequest) arg1;
-                ByteBuffer bExpected = (ByteBuffer) expected.getMessage();
-                ByteBuffer bActual = (ByteBuffer) actual.getMessage();
-                return bExpected.equals( bActual );
-            }
-            return true;
-        }
-    }
-}
+/*
+ *   @(#) $Id$
+ *
+ *   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.mina.filter;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoFilterChain;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.common.IoFilter.NextFilter;
+import org.apache.mina.filter.support.Zlib;
+import org.apache.mina.common.IoFilter.WriteRequest;
+import org.easymock.MockControl;
+import org.easymock.AbstractMatcher;
+
+import junit.framework.TestCase;
+
+/**
+ * @author The Apache Directory Project (mina-dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class CompressionFilterTest extends TestCase
+{
+    private MockControl mockSession;
+    private MockControl mockNextFilter;
+    private MockControl mockIoFilterChain;
+    private IoSession session;
+    private NextFilter nextFilter;
+    private IoFilterChain ioFilterChain;
+    private CompressionFilter filter;
+    private Zlib deflater;
+    private Zlib inflater;
+    private Zlib actualDeflater;
+    private Zlib actualInflater;
+
+    // the sample data to be used for testing
+    String strCompress =
+            "The quick brown fox jumps over the lazy dog.  " +
+            "The quick brown fox jumps over the lazy dog.  " +
+            "The quick brown fox jumps over the lazy dog.  " +
+            "The quick brown fox jumps over the lazy dog.  " +
+            "The quick brown fox jumps over the lazy dog.  " +
+            "The quick brown fox jumps over the lazy dog.  " +
+            "The quick brown fox jumps over the lazy dog.  " +
+            "The quick brown fox jumps over the lazy dog.  " +
+            "The quick brown fox jumps over the lazy dog.  " +
+            "The quick brown fox jumps over the lazy dog.  " +
+            "The quick brown fox jumps over the lazy dog.  " +
+            "The quick brown fox jumps over the lazy dog.  " +
+            "The quick brown fox jumps over the lazy dog.  " +
+            "The quick brown fox jumps over the lazy dog.  " +
+            "The quick brown fox jumps over the lazy dog.  " +
+            "The quick brown fox jumps over the lazy dog.  " +
+            "The quick brown fox jumps over the lazy dog.  " +
+            "The quick brown fox jumps over the lazy dog.  " +
+            "The quick brown fox jumps over the lazy dog.  " +
+            "The quick brown fox jumps over the lazy dog.  " +
+            "The quick brown fox jumps over the lazy dog.  " +
+            "The quick brown fox jumps over the lazy dog.  " +
+            "The quick brown fox jumps over the lazy dog.  " +
+            "The quick brown fox jumps over the lazy dog.  " +
+            "The quick brown fox jumps over the lazy dog.  ";
+
+    protected void setUp()
+    {
+        // create the necessary mock controls.
+        mockSession = MockControl.createControl( IoSession.class );
+        mockNextFilter = MockControl.createControl( NextFilter.class );
+        mockIoFilterChain = MockControl.createControl( IoFilterChain.class );
+
+        // set the default matcher
+        mockNextFilter.setDefaultMatcher( new DataMatcher() );
+
+        session = ( IoSession ) mockSession.getMock();
+        nextFilter = ( NextFilter ) mockNextFilter.getMock();
+        ioFilterChain = ( IoFilterChain ) mockIoFilterChain.getMock();
+
+        // create an instance of the filter
+        filter = new CompressionFilter( CompressionFilter.COMPRESSION_MAX );
+
+        // deflater and inflater that will be used by the filter
+        deflater = new Zlib( Zlib.COMPRESSION_MAX, Zlib.MODE_DEFLATER );
+        inflater = new Zlib( Zlib.COMPRESSION_MAX, Zlib.MODE_INFLATER );
+
+        // create instances of the deflater and inflater to help test the output
+        actualDeflater = new Zlib( Zlib.COMPRESSION_MAX, Zlib.MODE_DEFLATER );
+        actualInflater = new Zlib( Zlib.COMPRESSION_MAX, Zlib.MODE_INFLATER );
+    }
+
+    public void testCompression() throws Exception
+    {
+        // prepare the input data
+        ByteBuffer buf = ByteBuffer.wrap( strCompress.getBytes( "UTF8" ) );
+        ByteBuffer actualOutput = actualDeflater.deflate( buf );
+        WriteRequest writeRequest = new WriteRequest( buf );
+
+        // record all the mock calls
+        ioFilterChain.contains( CompressionFilter.class );
+        mockIoFilterChain.setReturnValue( false );
+
+        ioFilterChain.getSession();
+        mockIoFilterChain.setReturnValue( session );
+
+        session.setAttribute( CompressionFilter.class.getName() + ".Deflater", deflater );
+        mockSession.setDefaultMatcher( new DataMatcher() );
+        mockSession.setReturnValue( null, MockControl.ONE );
+
+        session.setAttribute( CompressionFilter.class.getName() + ".Inflater", inflater );
+        mockSession.setReturnValue( null, MockControl.ONE );
+
+        session.containsAttribute( CompressionFilter.DISABLE_COMPRESSION_ONCE );
+        mockSession.setReturnValue( false );
+
+        session.getAttribute( CompressionFilter.class.getName() + ".Deflater" );
+        mockSession.setReturnValue( deflater );
+
+        nextFilter.filterWrite( session, new WriteRequest( actualOutput ) );
+
+        // switch to playback mode
+        mockSession.replay();
+        mockIoFilterChain.replay();
+        mockNextFilter.replay();
+
+        // make the actual calls on the filter
+        filter.onPreAdd( ioFilterChain, "CompressionFilter", nextFilter );
+        filter.filterWrite( nextFilter, session, writeRequest );
+
+        // verify that all the calls happened as recorded
+        mockNextFilter.verify();
+
+        assertTrue( true );
+    }
+
+    public void testDecompression() throws Exception
+    {
+        // prepare the input data
+        ByteBuffer buf = ByteBuffer.wrap( strCompress.getBytes( "UTF8" ) );
+        ByteBuffer byteInput = actualDeflater.deflate( buf );
+        ByteBuffer actualOutput = actualInflater.inflate( byteInput );
+
+        // record all the mock calls
+        ioFilterChain.contains( CompressionFilter.class );
+        mockIoFilterChain.setReturnValue( false );
+
+        ioFilterChain.getSession();
+        mockIoFilterChain.setReturnValue( session );
+
+        session.setAttribute( CompressionFilter.class.getName() + ".Deflater", deflater );
+        mockSession.setDefaultMatcher( new DataMatcher() );
+        mockSession.setReturnValue( null, MockControl.ONE );
+
+        session.setAttribute( CompressionFilter.class.getName() + ".Inflater", inflater );
+        mockSession.setReturnValue( null, MockControl.ONE );
+
+        session.getAttribute( CompressionFilter.class.getName() + ".Inflater" );
+        mockSession.setReturnValue( inflater );
+
+        nextFilter.messageReceived( session, actualOutput );
+
+        // switch to playback mode
+        mockSession.replay();
+        mockIoFilterChain.replay();
+        mockNextFilter.replay();
+
+        // make the actual calls on the filter
+        filter.onPreAdd( ioFilterChain, "CompressionFilter", nextFilter );
+        filter.messageReceived( nextFilter, session, byteInput );
+
+        // verify that all the calls happened as recorded
+        mockNextFilter.verify();
+
+        assertTrue( true );
+    }
+
+    /**
+     * A matcher used to check if the actual and expected outputs matched
+     * 
+     * @author The Apache Directory MINA subproject (mina-dev@directory.apache.org)
+     */
+    class DataMatcher extends AbstractMatcher
+    {
+        protected boolean argumentMatches( Object arg0, Object arg1 )
+        {
+            // we need to only verify the ByteBuffer output
+            if( arg0 instanceof WriteRequest )
+            {
+                WriteRequest expected = (WriteRequest) arg0;
+                WriteRequest actual = (WriteRequest) arg1;
+                ByteBuffer bExpected = (ByteBuffer) expected.getMessage();
+                ByteBuffer bActual = (ByteBuffer) actual.getMessage();
+                return bExpected.equals( bActual );
+            }
+            return true;
+        }
+    }
+}

Modified: directory/trunks/mina/filter-compression/src/test/java/org/apache/mina/filter/support/ZlibTest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/filter-compression/src/test/java/org/apache/mina/filter/support/ZlibTest.java?rev=400067&r1=400066&r2=400067&view=diff
==============================================================================
--- directory/trunks/mina/filter-compression/src/test/java/org/apache/mina/filter/support/ZlibTest.java (original)
+++ directory/trunks/mina/filter-compression/src/test/java/org/apache/mina/filter/support/ZlibTest.java Fri May  5 05:52:49 2006
@@ -1,134 +1,134 @@
-/*
- *   @(#) $Id$
- *
- *   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.mina.filter.support;
-
-import java.io.IOException;
-import java.nio.charset.Charset;
-
-import org.apache.mina.common.ByteBuffer;
-
-import junit.framework.TestCase;
-
-/**
- * @author The Apache Directory Project (mina-dev@directory.apache.org)
- * @version $Rev$, $Date$
- */
-public class ZlibTest extends TestCase
-{
-    private Zlib deflater = null;
-    private Zlib inflater = null;
-
-    protected void setUp() throws Exception
-    {
-        deflater = new Zlib( Zlib.COMPRESSION_MAX, Zlib.MODE_DEFLATER );
-        inflater = new Zlib( Zlib.COMPRESSION_MAX, Zlib.MODE_INFLATER );
-    }
-
-    public void testCompression() throws Exception
-    {
-        String strInput = "";
-
-        // increase the count to as many as required to generate a long 
-        // string for input
-        for( int i = 0; i < 10; i++ )
-        {
-            strInput += "The quick brown fox jumps over the lazy dog.  ";
-        }
-        ByteBuffer byteInput = ByteBuffer.wrap( strInput.getBytes( "UTF8" ) );
-
-        // increase the count to have the compression and decompression 
-        // done using the same instance of Zlib
-        for( int i = 0; i < 5; i++ )
-        {
-            ByteBuffer byteCompressed = deflater.deflate( byteInput );
-            ByteBuffer byteUncompressed = inflater.inflate( byteCompressed );
-            String strOutput = byteUncompressed.getString( Charset.forName( "UTF8" )
-                    .newDecoder() );
-            assertTrue( strOutput.equals( strInput ) );
-        }
-    }
-
-    public void testCorruptedData() throws Exception
-    {
-        String strInput = "Hello World";
-        ByteBuffer byteInput = ByteBuffer.wrap( strInput.getBytes( "UTF8" ) );
-
-        ByteBuffer byteCompressed = deflater.deflate( byteInput );
-        // change the contents to something else. Since this doesn't check
-        // for integrity, it wont throw an exception
-        byteCompressed.put( 5, (byte) 0xa );
-        ByteBuffer byteUncompressed = inflater.inflate( byteCompressed );
-        String strOutput = byteUncompressed.getString( Charset.forName( "UTF8" )
-                .newDecoder() );
-        assertFalse( strOutput.equals( strInput ) );
-    }
-
-    public void testCorruptedHeader() throws Exception
-    {
-        String strInput = "Hello World";
-        ByteBuffer byteInput = ByteBuffer.wrap( strInput.getBytes( "UTF8" ) );
-
-        ByteBuffer byteCompressed = deflater.deflate( byteInput );
-        // write a bad value into the zlib header. Make sure that
-        // the decompression fails
-        byteCompressed.put( 0, (byte) 0xca );
-        try
-        {
-            inflater.inflate( byteCompressed );
-        }
-        catch( IOException e )
-        {
-            assertTrue( true );
-            return;
-        }
-        assertTrue( false );
-    }
-
-    public void testFragments() throws Exception
-    {
-        String strInput = "";
-        for( int i = 0; i < 10; i++ )
-        {
-            strInput += "The quick brown fox jumps over the lazy dog.  ";
-        }
-        ByteBuffer byteInput = ByteBuffer.wrap( strInput.getBytes( "UTF8" ) );
-        ByteBuffer byteCompressed = null;
-
-        for( int i = 0; i < 5; i++ )
-        {
-            byteCompressed = deflater.deflate( byteInput );
-            if( i == 0 )
-            {
-                // decompress the first compressed output since it contains
-                // the zlib header, which will not be generated for further
-                // compressions done with the same instance
-                ByteBuffer byteUncompressed = inflater.inflate( byteCompressed );
-                String strOutput = byteUncompressed.getString( Charset.forName( "UTF8" )
-                        .newDecoder() );
-                assertTrue( strOutput.equals( strInput ) );
-            }
-        }
-        // check if the last compressed data block can be decompressed
-        // successfully.
-        ByteBuffer byteUncompressed = inflater.inflate( byteCompressed );
-        String strOutput = byteUncompressed.getString( Charset.forName( "UTF8" )
-                .newDecoder() );
-        assertTrue( strOutput.equals( strInput ) );
-    }
-}
+/*
+ *   @(#) $Id$
+ *
+ *   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.mina.filter.support;
+
+import java.io.IOException;
+import java.nio.charset.Charset;
+
+import org.apache.mina.common.ByteBuffer;
+
+import junit.framework.TestCase;
+
+/**
+ * @author The Apache Directory Project (mina-dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class ZlibTest extends TestCase
+{
+    private Zlib deflater = null;
+    private Zlib inflater = null;
+
+    protected void setUp() throws Exception
+    {
+        deflater = new Zlib( Zlib.COMPRESSION_MAX, Zlib.MODE_DEFLATER );
+        inflater = new Zlib( Zlib.COMPRESSION_MAX, Zlib.MODE_INFLATER );
+    }
+
+    public void testCompression() throws Exception
+    {
+        String strInput = "";
+
+        // increase the count to as many as required to generate a long 
+        // string for input
+        for( int i = 0; i < 10; i++ )
+        {
+            strInput += "The quick brown fox jumps over the lazy dog.  ";
+        }
+        ByteBuffer byteInput = ByteBuffer.wrap( strInput.getBytes( "UTF8" ) );
+
+        // increase the count to have the compression and decompression 
+        // done using the same instance of Zlib
+        for( int i = 0; i < 5; i++ )
+        {
+            ByteBuffer byteCompressed = deflater.deflate( byteInput );
+            ByteBuffer byteUncompressed = inflater.inflate( byteCompressed );
+            String strOutput = byteUncompressed.getString( Charset.forName( "UTF8" )
+                    .newDecoder() );
+            assertTrue( strOutput.equals( strInput ) );
+        }
+    }
+
+    public void testCorruptedData() throws Exception
+    {
+        String strInput = "Hello World";
+        ByteBuffer byteInput = ByteBuffer.wrap( strInput.getBytes( "UTF8" ) );
+
+        ByteBuffer byteCompressed = deflater.deflate( byteInput );
+        // change the contents to something else. Since this doesn't check
+        // for integrity, it wont throw an exception
+        byteCompressed.put( 5, (byte) 0xa );
+        ByteBuffer byteUncompressed = inflater.inflate( byteCompressed );
+        String strOutput = byteUncompressed.getString( Charset.forName( "UTF8" )
+                .newDecoder() );
+        assertFalse( strOutput.equals( strInput ) );
+    }
+
+    public void testCorruptedHeader() throws Exception
+    {
+        String strInput = "Hello World";
+        ByteBuffer byteInput = ByteBuffer.wrap( strInput.getBytes( "UTF8" ) );
+
+        ByteBuffer byteCompressed = deflater.deflate( byteInput );
+        // write a bad value into the zlib header. Make sure that
+        // the decompression fails
+        byteCompressed.put( 0, (byte) 0xca );
+        try
+        {
+            inflater.inflate( byteCompressed );
+        }
+        catch( IOException e )
+        {
+            assertTrue( true );
+            return;
+        }
+        assertTrue( false );
+    }
+
+    public void testFragments() throws Exception
+    {
+        String strInput = "";
+        for( int i = 0; i < 10; i++ )
+        {
+            strInput += "The quick brown fox jumps over the lazy dog.  ";
+        }
+        ByteBuffer byteInput = ByteBuffer.wrap( strInput.getBytes( "UTF8" ) );
+        ByteBuffer byteCompressed = null;
+
+        for( int i = 0; i < 5; i++ )
+        {
+            byteCompressed = deflater.deflate( byteInput );
+            if( i == 0 )
+            {
+                // decompress the first compressed output since it contains
+                // the zlib header, which will not be generated for further
+                // compressions done with the same instance
+                ByteBuffer byteUncompressed = inflater.inflate( byteCompressed );
+                String strOutput = byteUncompressed.getString( Charset.forName( "UTF8" )
+                        .newDecoder() );
+                assertTrue( strOutput.equals( strInput ) );
+            }
+        }
+        // check if the last compressed data block can be decompressed
+        // successfully.
+        ByteBuffer byteUncompressed = inflater.inflate( byteCompressed );
+        String strOutput = byteUncompressed.getString( Charset.forName( "UTF8" )
+                .newDecoder() );
+        assertTrue( strOutput.equals( strInput ) );
+    }
+}

Modified: directory/trunks/naming/naming-config/src/java/org/apache/naming/config/Config.java
URL: http://svn.apache.org/viewcvs/directory/trunks/naming/naming-config/src/java/org/apache/naming/config/Config.java?rev=400067&r1=400066&r2=400067&view=diff
==============================================================================
--- directory/trunks/naming/naming-config/src/java/org/apache/naming/config/Config.java (original)
+++ directory/trunks/naming/naming-config/src/java/org/apache/naming/config/Config.java Fri May  5 05:52:49 2006
@@ -12,65 +12,109 @@
  * 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.naming.config;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeSet;
-
-import javax.naming.CompositeName;
+ */ 
+
+
+
+package org.apache.naming.config;
+
+
+
+import java.util.Collection;
+
+import java.util.Collections;
+
+import java.util.HashMap;
+
+import java.util.Iterator;
+
+import java.util.LinkedList;
+
+import java.util.Map;
+
+import java.util.Set;
+
+import java.util.TreeSet;
+
+
+
+import javax.naming.CompositeName;
+
 import javax.naming.InvalidNameException;
-import javax.naming.LinkRef;
-import javax.naming.StringRefAddr;
+import javax.naming.LinkRef;
+
+import javax.naming.StringRefAddr;
+
+
+import org.apache.commons.collections.map.UnmodifiableMap;
+
+import org.apache.commons.lang.builder.ToStringBuilder;
 
-import org.apache.commons.collections.map.UnmodifiableMap;
-import org.apache.commons.lang.builder.ToStringBuilder;
 import org.apache.commons.lang.builder.ToStringStyle;
-
-import org.apache.naming.ResourceRef;
-
-/**
- * Configuration classes. 
- * 
- * @author <a href="brett@apache.org">Brett Porter</a>
- * @version $Id: Config.java,v 1.2 2003/12/01 02:02:45 brett Exp $
- */
-public final class Config
-{
+
+
+import org.apache.naming.ResourceRef;
+
+
+
+/**
+
+ * Configuration classes. 
+
+ * 
+
+ * @author <a href="brett@apache.org">Brett Porter</a>
+
+ * @version $Id: Config.java,v 1.2 2003/12/01 02:02:45 brett Exp $
+
+ */
+
+public final class Config
+
+{
+
     /**
      * Naming context configuration.
      */
-    public static final class Naming
-    {
+    public static final class Naming
+
+    {
+
         /** list of context configurations */
-        private final Collection contextList = new LinkedList();
-        
+        private final Collection contextList = new LinkedList();
+
+        
+
         /**
          *  Adds a new Context configuration to the context list.
          * 
          * @param context Context configuration to add.
          */
-        public void addContext(Context context)
-        {
-            contextList.add(context);
-        }
+        public void addContext(Context context)
+
+        {
+
+            contextList.add(context);
+
+        }
+
         
         /**
          * Returns the context list.
-         * 
-         * @return  context list.
-         */
-        public Collection getContextList()
-        {
-            return Collections.unmodifiableCollection(contextList);
-        }
+         * 
+
+         * @return  context list.
+
+         */
+
+        public Collection getContextList()
+
+        {
+
+            return Collections.unmodifiableCollection(contextList);
+
+        }
+
         
         /**
          * Generates and returns a map, keyed on context name, of sorted sets
@@ -78,103 +122,166 @@
          * 
          * @return map of sets of configured names, keyed on context name.
          * @throws InvalidNameException if an invalid name is encountered
-         */
-        public Map generateSortedSubcontextNameSet() throws InvalidNameException
-        {
-            Map sortedSubcontextNameMap = new HashMap();
-            for (Iterator i = contextList.iterator(); i.hasNext();)
+         */
+
+        public Map generateSortedSubcontextNameSet() throws InvalidNameException
+
+        {
+
+            Map sortedSubcontextNameMap = new HashMap();
+
+            for (Iterator i = contextList.iterator(); i.hasNext();)
+
             {
-                Set sortedSubcontextNameSet = new TreeSet();
-                Context context = (Context) i.next();
+                Set sortedSubcontextNameSet = new TreeSet();
+
+                Context context = (Context) i.next();
+
                 context.addSubContextNames(sortedSubcontextNameSet);
-                sortedSubcontextNameMap.put(context.getName(), sortedSubcontextNameSet);
-            }
-            return UnmodifiableMap.decorate(sortedSubcontextNameMap);
-        }
+                sortedSubcontextNameMap.put(context.getName(), sortedSubcontextNameSet);
+
+            }
+
+            return UnmodifiableMap.decorate(sortedSubcontextNameMap);
+
+        }
+
         
         /**
          * Returns a string representation of the context list.
          * 
          * @return context list as a string.
-         */
-        public String toString()
-        {
-            return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
-            .append("contextList", contextList)
-            .toString();
-        }
-    }
+         */
+
+        public String toString()
+
+        {
+
+            return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
+
+            .append("contextList", contextList)
+
+            .toString();
+
+        }
+
+    }
+
     
     /**
      * Configuration for a Context.  Contexts contain lists of 
      * {@link org.apache.naming.config.Config$Environment} entries,
      * {@link org.apache.naming.config.Config$Resource} references, and
      * {@link org.apache.naming.config.Config$Link} links.
-     */
-    public static final class Context
+     */
+
+    public static final class Context
+
     {
-        /** External name of the context -- key in ContextBindings */
+        /** External name of the context -- key in ContextBindings */
+
         private String name;
         
         /** Base name relative to which property and resource bindings are set up */
         private String base;
-        
-        private final Collection environmentList = new LinkedList();
+        
+
+        private final Collection environmentList = new LinkedList();
+
         private final Collection resourceList = new LinkedList();
-        private final Collection linkList = new LinkedList();
-        
+        private final Collection linkList = new LinkedList();
+
+        
+
         /**
          * Adds an Environment configuration to the environment list.
          * 
          * @param environment environment configuration to add.
          */
-        public void addEnvironment(Environment environment)
-        {
-            environmentList.add(environment);
-        }
-        
+        public void addEnvironment(Environment environment)
+
+        {
+
+            environmentList.add(environment);
+
+        }
+
+        
+
         /**
          * Adds the subcontext names in this Context to the input set.
-         * 
+         * 
+
          * @param sortedSubcontextNameSet  set to be augmented with names from
          *  this context.
          * @throws InvalidNameException  if the configured string name of a
-         * Resource or Environment in this context is not a valid JNDI name.
-         */
-        public void addSubContextNames(Set sortedSubcontextNameSet) throws InvalidNameException
-        {
-            if ((name != null) && !environmentList.iterator().hasNext() && !resourceList.iterator().hasNext())
-            {
-                sortedSubcontextNameSet.add(name);
-            }
-            for (Iterator i = environmentList.iterator(); i.hasNext();)
-            {
-                Environment e = (Environment) i.next();
-                CompositeName name = new CompositeName(e.getName());
-                addSubContextNames(name, sortedSubcontextNameSet);
-            }
-            for (Iterator i = resourceList.iterator(); i.hasNext();)
-            {
-                Resource r = (Resource) i.next();
-                CompositeName name = new CompositeName(r.getName());
-                addSubContextNames(name, sortedSubcontextNameSet);
-            }
-        }
-        
-        private void addSubContextNames(CompositeName name, Set sortedSubcontextNameSet) {
-            for (int j = 1; j <= name.size() - 1; j++) {
-                sortedSubcontextNameSet.add(name.getPrefix(j).toString());
-            }
-        }
+         * Resource or Environment in this context is not a valid JNDI name.
+
+         */
+
+        public void addSubContextNames(Set sortedSubcontextNameSet) throws InvalidNameException
+
+        {
+
+            if ((name != null) && !environmentList.iterator().hasNext() && !resourceList.iterator().hasNext())
+
+            {
+
+                sortedSubcontextNameSet.add(name);
+
+            }
+
+            for (Iterator i = environmentList.iterator(); i.hasNext();)
+
+            {
+
+                Environment e = (Environment) i.next();
+
+                CompositeName name = new CompositeName(e.getName());
+
+                addSubContextNames(name, sortedSubcontextNameSet);
+
+            }
+
+            for (Iterator i = resourceList.iterator(); i.hasNext();)
+
+            {
+
+                Resource r = (Resource) i.next();
+
+                CompositeName name = new CompositeName(r.getName());
+
+                addSubContextNames(name, sortedSubcontextNameSet);
+
+            }
+
+        }
+
+        
+
+        private void addSubContextNames(CompositeName name, Set sortedSubcontextNameSet) {
+
+            for (int j = 1; j <= name.size() - 1; j++) {
+
+                sortedSubcontextNameSet.add(name.getPrefix(j).toString());
+
+            }
+
+        }
+
         
         /**
          * Adds a Resource configuration to the resource list.
          * 
          * @param resource resource configuration to add.
-         */
-        public void addResource(Resource resource)
-        {
-            resourceList.add(resource);
+         */
+
+        public void addResource(Resource resource)
+
+        {
+
+            resourceList.add(resource);
+
         }
         
         /**
@@ -192,40 +299,59 @@
          * Returns the environment list.
          * 
          * @return list of Environment configurations in the Context
-         */
-        public Collection getEnvironmentList()
-        {
-            return Collections.unmodifiableCollection(environmentList);
-        }
+         */
+
+        public Collection getEnvironmentList()
+
+        {
+
+            return Collections.unmodifiableCollection(environmentList);
+
+        }
+
         
         /**
          * Returns the name of this context.
          * 
          * @return context name
-         */
-        public String getName()
-        {
-            return name;
-        }
+         */
+
+        public String getName()
+
+        {
+
+            return name;
+
+        }
+
         
         /**
          * Sets the name of this context.
          * 
          * @param name  the name
-         */
-        public void setName(String name)
-        {
-            this.name = name;
-        }
+         */
+
+        public void setName(String name)
+
+        {
+
+            this.name = name;
+
+        }
+
         
         /**
          * Returns the resource list.
          * 
          * @return list of Resource configurations in the Context.
-         */
-        public Collection getResourceList()
-        {
-            return Collections.unmodifiableCollection(resourceList);
+         */
+
+        public Collection getResourceList()
+
+        {
+
+            return Collections.unmodifiableCollection(resourceList);
+
         }
         
         /**
@@ -236,22 +362,32 @@
         public Collection getLinkList()
         {
             return Collections.unmodifiableCollection(linkList);
-        }
+        }
+
         
         /**
          * Returns a string representation of the name, environment list and
          * resource list of this context.
          * 
          * @return string representation of this context.
-         */
-        public String toString()
-        {
-            return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
-            .append("name", name)
-            .append("environmentList", environmentList)
-            .append("resourceList", resourceList)
-            .toString();
-        }
+         */
+
+        public String toString()
+
+        {
+
+            return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
+
+            .append("name", name)
+
+            .append("environmentList", environmentList)
+
+            .append("resourceList", resourceList)
+
+            .toString();
+
+        }
+
         /**
          * @return Returns the base.
          */
@@ -266,96 +402,143 @@
             this.base = base;
         }
         
-    }
+    }
+
     
     /**
      * Configuration for an Environment entry.  Environment entries represent
      * JNDI environment properties that take values that are primitive java
      *  types.  The Environment configuration includes the type, the value and
      * the JNDI name as a string, relative to the initial context.
-     */
-    public static final class Environment
-    {
-        private String name;
-        private String value;
-        private String type;
+     */
+
+    public static final class Environment
+
+    {
+
+        private String name;
+
+        private String value;
+
+        private String type;
+
         
         /**
          * Gets the name of this environment.
          * 
          * @return name  the name
          */
-        public String getName()
-        {
-            return name;
-        }
+        public String getName()
+
+        {
+
+            return name;
+
+        }
+
         
         /**
          * Sets the name of this environment.
          * 
          * @param name  the name
-         */
-        public void setName(String name)
-        {
-            this.name = name;
-        }
+         */
+
+        public void setName(String name)
+
+        {
+
+            this.name = name;
+
+        }
+
         
         /**
          * Returns the class name of this environment entry.
          * 
          * @return Environment entry class name
-         */
-        public String getType()
-        {
-            return type;
-        }
+         */
+
+        public String getType()
+
+        {
+
+            return type;
+
+        }
+
         
         /**
          * Sets the class name of this environment entry.
          * 
          * @param type  class name
-         */
-        public void setType(String type)
-        {
-            this.type = type;
-        }
+         */
+
+        public void setType(String type)
+
+        {
+
+            this.type = type;
+
+        }
+
         
         /**
          * Returns the value of this environment entry as a String.
          * 
          * @return String representation of the value
-         */
-        public String getValue()
-        {
-            return value;
-        }
+         */
+
+        public String getValue()
+
+        {
+
+            return value;
+
+        }
+
         
         /**
          * Sets the (String) value of this environment entry.
          * 
          * @param value
-         */
-        public void setValue(String value)
-        {
-            this.value = value;
-        }
+         */
+
+        public void setValue(String value)
+
+        {
+
+            this.value = value;
+
+        }
+
         
         /**
          * Returns the JNDI name, type and value of this environment entry as
          * as String.
          * 
          * @return String representation of this environment entry.
-         */
-        public String toString()
-        {
-            return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
-            .append("name", name)
-            .append("type", type)
-            .append("value", value)
-            .toString();
-        }
-        
-        /**
+         */
+
+        public String toString()
+
+        {
+
+            return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
+
+            .append("name", name)
+
+            .append("type", type)
+
+            .append("value", value)
+
+            .toString();
+
+        }
+
+        
+
+        /**
+
          * Tries to create an instance of type <code>this.type</code> using 
          * <code>this.value</code>. 
          * <p> 
@@ -363,157 +546,257 @@
          * <code>valueOf</code> methods are used and runtime exceptions
          *  are not handled.  If <code>this.type</code> is not a primitive type,
          * <code>null</code> is returned.
-         * 
-         * @return object instance
-         */
+         * 
+
+         * @return object instance
+
+         */
+
         public Object createValue()
-        //TODO: handle / rethrow exceptions, support more types?
-        {
-            if (type.equals(String.class.getName()))
-            {
-                return value;
-            }
-            else if (type.equals(Boolean.class.getName()))
-            {
-                return Boolean.valueOf(value);
-            }
-            else if (type.equals(Integer.class.getName()))
-            {
-                return Integer.valueOf(value);
-            }
-            else if (type.equals(Short.class.getName()))
-            {
-                return Short.valueOf(value);
-            }
-            else if (type.equals(Character.class.getName()))
-            {
-                return new Character(value.charAt(0));
-            }
-            else if (type.equals(Double.class.getName()))
-            {
-                return Double.valueOf(value);
-            }
-            else if (type.equals(Float.class.getName()))
-            {
-                return Float.valueOf(value);
-            }
-            else if (type.equals(Byte.class.getName()))
-            {
-                return Byte.valueOf(value);
-            }
-            else if (type.equals(Long.class.getName()))
-            {
-                return Long.valueOf(value);
-            }
-            return null;
-        }
-    }
+        //TODO: handle / rethrow exceptions, support more types?
+
+        {
+
+            if (type.equals(String.class.getName()))
+
+            {
+
+                return value;
+
+            }
+
+            else if (type.equals(Boolean.class.getName()))
+
+            {
+
+                return Boolean.valueOf(value);
+
+            }
+
+            else if (type.equals(Integer.class.getName()))
+
+            {
+
+                return Integer.valueOf(value);
+
+            }
+
+            else if (type.equals(Short.class.getName()))
+
+            {
+
+                return Short.valueOf(value);
+
+            }
+
+            else if (type.equals(Character.class.getName()))
+
+            {
+
+                return new Character(value.charAt(0));
+
+            }
+
+            else if (type.equals(Double.class.getName()))
+
+            {
+
+                return Double.valueOf(value);
+
+            }
+
+            else if (type.equals(Float.class.getName()))
+
+            {
+
+                return Float.valueOf(value);
+
+            }
+
+            else if (type.equals(Byte.class.getName()))
+
+            {
+
+                return Byte.valueOf(value);
+
+            }
+
+            else if (type.equals(Long.class.getName()))
+
+            {
+
+                return Long.valueOf(value);
+
+            }
+
+            return null;
+
+        }
+
+    }
+
     
     /**
      * Configuration for a JNDI resource reference.  Resource references 
      * include the type of the resource, the parameters to be used in creating
      * the resource instance and the JNDI name of the resource as a string, 
      * relative to the initial context.
-     */
-    public static final class Resource
-    {
-        private String name;
-        private String type;
-        private final Map parameters = new HashMap();
+     */
+
+    public static final class Resource
+
+    {
+
+        private String name;
+
+        private String type;
+
+        private final Map parameters = new HashMap();
+
         
         /**
          * Adds a name-value pair to the parameters associated with this resource.
          * 
          * @param name parameter name
          * @param value parameter value
-         */
-        public void addParameter(String name, String value)
-        {
-            parameters.put(name, value);
+         */
+
+        public void addParameter(String name, String value)
+
+        {
+
+            parameters.put(name, value);
+
         }
         
         /**
          * Returns the name of this resource.
          *
          *  @return name
-         */
-        public String getName()
-        {
-            return name;
-        }
+         */
+
+        public String getName()
+
+        {
+
+            return name;
+
+        }
+
         
         /**
          * Sets the name of this resource.
          * 
          * @param name name.
-         */
-        public void setName(String name)
-        {
-            this.name = name;
-        }
+         */
+
+        public void setName(String name)
+
+        {
+
+            this.name = name;
+
+        }
+
         
         /**
          * Returns the parameters associated with this resource as a Map.
          * The keys of the map are the parameter names.
          * 
          * @return parameters
-         */
-        public Map getParameters()
-        {
-            return parameters;
-        }
+         */
+
+        public Map getParameters()
+
+        {
+
+            return parameters;
+
+        }
+
         
         /**
          * Returns the type of this resource.
          * 
          * @return class name
-         */
-        public String getType()
-        {
-            return type;
-        }
+         */
+
+        public String getType()
+
+        {
+
+            return type;
+
+        }
+
         
         /**
          * Sets the type of this resource.
          * 
          * @param type  class name.
-         */
-        public void setType(String type)
-        {
-            this.type = type;
-        }
-        
+         */
+
+        public void setType(String type)
+
+        {
+
+            this.type = type;
+
+        }
+
+        
+
         /**
          * Creates a {@link ResourceRef} based on the configuration
          * properties of this resource.
          * 
          * @return ResourceRef instance.
-         */
+         */
+
         public Object createValue()
-        //TODO: exceptions?
-        {
-            ResourceRef ref = new ResourceRef(type, null, null, null);
-            for (Iterator i = parameters.keySet().iterator(); i.hasNext();)
-            {
-                String name = (String) i.next();
-                String value = (String) parameters.get(name);
-                ref.add(new StringRefAddr(name, value));
-            }
-            return ref;
-        }
+        //TODO: exceptions?
+
+        {
+
+            ResourceRef ref = new ResourceRef(type, null, null, null);
+
+            for (Iterator i = parameters.keySet().iterator(); i.hasNext();)
+
+            {
+
+                String name = (String) i.next();
+
+                String value = (String) parameters.get(name);
+
+                ref.add(new StringRefAddr(name, value));
+
+            }
+
+            return ref;
+
+        }
+
         
         /**
          * Returns the name, type and parameter list as a String.
          * 
          * @return String representation of this resource reference configuration.
-         */
-        public String toString()
-        {
-            return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
-            .append("name", name)
-            .append("type", type)
-            .append("parameters", parameters)
-            .toString();
+         */
+
+        public String toString()
+
+        {
+
+            return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
+
+            .append("name", name)
+
+            .append("type", type)
+
+            .append("parameters", parameters)
+
+            .toString();
+
         }
     }
     
@@ -586,6 +869,9 @@
             this.context = context;
         }
 
-    }
-}
-
+    }
+
+}
+
+
+

Modified: directory/trunks/naming/naming-config/src/test/org/apache/naming/config/XmlConfiguratorTest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/naming/naming-config/src/test/org/apache/naming/config/XmlConfiguratorTest.java?rev=400067&r1=400066&r2=400067&view=diff
==============================================================================
--- directory/trunks/naming/naming-config/src/test/org/apache/naming/config/XmlConfiguratorTest.java (original)
+++ directory/trunks/naming/naming-config/src/test/org/apache/naming/config/XmlConfiguratorTest.java Fri May  5 05:52:49 2006
@@ -12,18 +12,28 @@
  * 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.naming.config;
-
-import java.sql.Connection;
-import java.sql.ResultSet;
+ */ 
+
+
+
+
+
+package org.apache.naming.config;
+
+
+
+import java.sql.Connection;
+
+import java.sql.ResultSet;
+
 import java.sql.Statement;
 
-import java.util.Hashtable;
-
-import javax.naming.Context;
+import java.util.Hashtable;
+
+
+
+import javax.naming.Context;
+
 import javax.naming.InitialContext;
 
 import javax.naming.directory.Attributes;
@@ -36,40 +46,71 @@
 import javax.mail.internet.InternetAddress;
 import javax.mail.internet.MimeMessage;
 import javax.mail.internet.MimePartDataSource;
-
-import javax.sql.DataSource;
-
+
+
+import javax.sql.DataSource;
+
+
+
 import junit.framework.TestCase;
 
 import org.apache.naming.ContextBindings;
-import org.apache.naming.NamingContextFactory;
-
-/**
- * Test case for the XML configuration methods, testing environment entries
- * and database connection resource factories.
- * 
- * @author <a href="brett@apache.org">Brett Porter</a>
- * @version $Id: XmlConfiguratorTest.java,v 1.2 2003/12/01 02:02:45 brett Exp $
- */
-public class XmlConfiguratorTest extends TestCase
-{
-    public XmlConfiguratorTest(String name) {
-        super(name);
-    }
-
-    /*
-     * @see TestCase#setUp()
-     */
-    protected void setUp() throws Exception {
-        super.setUp();
-    }
-
-    /*
-     * @see TestCase#tearDown()
-     */
-    protected void tearDown() throws Exception {
-        super.tearDown();
-        XmlConfigurator.destroyInitialContext();
+import org.apache.naming.NamingContextFactory;
+
+
+
+/**
+
+ * Test case for the XML configuration methods, testing environment entries
+
+ * and database connection resource factories.
+
+ * 
+
+ * @author <a href="brett@apache.org">Brett Porter</a>
+
+ * @version $Id: XmlConfiguratorTest.java,v 1.2 2003/12/01 02:02:45 brett Exp $
+
+ */
+
+public class XmlConfiguratorTest extends TestCase
+
+{
+
+    public XmlConfiguratorTest(String name) {
+
+        super(name);
+
+    }
+
+
+
+    /*
+
+     * @see TestCase#setUp()
+
+     */
+
+    protected void setUp() throws Exception {
+
+        super.setUp();
+
+    }
+
+
+
+    /*
+
+     * @see TestCase#tearDown()
+
+     */
+
+    protected void tearDown() throws Exception {
+
+        super.tearDown();
+
+        XmlConfigurator.destroyInitialContext();
+
     }
     
     /** 
@@ -83,8 +124,10 @@
      * Alternate root context name specified in test-jndi2.xml.  Must match
      * name attribute of top-level context element in test-jndi2.xml
      */
-    protected static String ALT_ROOT="alt/root/context";
-
+    protected static String ALT_ROOT="alt/root/context";
+
+
+
     /**
      * Test for correctly configured environment entries.
      * 
@@ -386,6 +429,9 @@
         msg.setSubject("authenticated mail session test");
         msg.setContent("this is a test", "text/plain");
         Transport.send(msg);
-    }
-}
-
+    }
+
+}
+
+
+

Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/NotImplementedException.java
URL: http://svn.apache.org/viewcvs/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/NotImplementedException.java?rev=400067&r1=400066&r2=400067&view=diff
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/NotImplementedException.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/NotImplementedException.java Fri May  5 05:52:49 2006
@@ -1,64 +1,64 @@
-/*
- *   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.
- *
- */
-
-/*
+/*
+ *   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.
+ *
+ */
+
+/*
  $Id$
-
- -- (c) LDAPd Group                                                    --
- -- Please refer to the LICENSE.txt file in the root directory of      --
+
+ -- (c) LDAPd Group                                                    --
+ -- Please refer to the LICENSE.txt file in the root directory of      --
  -- any LDAPd project for copyright and distribution information.      --
-
- */
-
-package org.apache.directory.shared.ldap;
-
-
-/**
- * This exception is thrown when a Backend operation is either temporarily
- * unsupported or perminantly unsupported as part of its implementation. Write
- * operations on a backend set to readonly throw a type of unsupported exception
- * called ReadOnlyException.
- * 
- * @author <a href="mailto:aok123@bellsouth.net">Alex Karasulu</a>
- * @author $Author: akarasulu $
- * @version $Revision$
- */
-public class NotImplementedException extends RuntimeException
-{
-    static final long serialVersionUID = -5899307402675964298L;
-
-
-    /**
-     * Constructs an Exception with a detailed message.
-     */
-    public NotImplementedException()
-    {
-        super( "N O T   I M P L E M E N T E D   Y E T !" );
-    }
-
-
-    /**
-     * Constructs an Exception with a detailed message.
-     * 
-     * @param a_msg
-     *            The message associated with the exception.
-     */
-    public NotImplementedException(String a_msg)
-    {
-        super( "N O T   I M P L E M E N T E D   Y E T !\n" + a_msg );
-    }
-}
+
+ */
+
+package org.apache.directory.shared.ldap;
+
+
+/**
+ * This exception is thrown when a Backend operation is either temporarily
+ * unsupported or perminantly unsupported as part of its implementation. Write
+ * operations on a backend set to readonly throw a type of unsupported exception
+ * called ReadOnlyException.
+ * 
+ * @author <a href="mailto:aok123@bellsouth.net">Alex Karasulu</a>
+ * @author $Author: akarasulu $
+ * @version $Revision$
+ */
+public class NotImplementedException extends RuntimeException
+{
+    static final long serialVersionUID = -5899307402675964298L;
+
+
+    /**
+     * Constructs an Exception with a detailed message.
+     */
+    public NotImplementedException()
+    {
+        super( "N O T   I M P L E M E N T E D   Y E T !" );
+    }
+
+
+    /**
+     * Constructs an Exception with a detailed message.
+     * 
+     * @param a_msg
+     *            The message associated with the exception.
+     */
+    public NotImplementedException(String a_msg)
+    {
+        super( "N O T   I M P L E M E N T E D   Y E T !\n" + a_msg );
+    }
+}

Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/StoredProcedure.java
URL: http://svn.apache.org/viewcvs/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/StoredProcedure.java?rev=400067&r1=400066&r2=400067&view=diff
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/StoredProcedure.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/StoredProcedure.java Fri May  5 05:52:49 2006
@@ -1,328 +1,328 @@
-/*
- *   Copyright 2006 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.directory.shared.ldap.codec.extended.operations;
-
-
-import java.nio.BufferOverflowException;
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.apache.directory.shared.asn1.Asn1Object;
-import org.apache.directory.shared.asn1.ber.tlv.Length;
-import org.apache.directory.shared.asn1.ber.tlv.UniversalTag;
-import org.apache.directory.shared.asn1.ber.tlv.Value;
-import org.apache.directory.shared.asn1.codec.EncoderException;
-import org.apache.directory.shared.ldap.util.StringTools;
-
-
-/**
- * Stored Procedure Extended Operation bean
- * 
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- */
-public class StoredProcedure extends Asn1Object
-{
-    private String language;
-
-    private byte[] procedure;
-
-    private ArrayList parameters;
-
-    private transient StoredProcedureParameter currentParameter;
-    
-    /** The stored procedure length */
-    private transient int storedProcedureLength;
-    
-    /** The parameters length */
-    private transient int parametersLength;
-
-    /** The list of all parameter lengths */
-    private transient List parameterLength;
-
-    /** The list of all parameter type lengths */
-    private transient List paramTypeLength;
-
-    /** The list of all parameter value lengths */
-    private transient List paramValueLength;
-
-    public String getLanguage()
-    {
-        return language;
-    }
-
-
-    public void setLanguage( String language )
-    {
-        this.language = language;
-    }
-
-
-    public byte[] getProcedure()
-    {
-        return procedure;
-    }
-
-
-    public void setProcedure( byte[] procedure )
-    {
-        this.procedure = procedure;
-    }
-
-
-    public List getParameters()
-    {
-        return parameters;
-    }
-
-
-    public void addParameter( StoredProcedureParameter parameter )
-    {
-        if ( parameters == null )
-        {
-            parameters = new ArrayList();
-        }
-
-        parameters.add( parameter );
-    }
-
-
-    public StoredProcedureParameter getCurrentParameter()
-    {
-        return currentParameter;
-    }
-
-
-    public void setCurrentParameter( StoredProcedureParameter currentParameter )
-    {
-        this.currentParameter = currentParameter;
-    }
-    
-
-    /**
-     * Bean for representing a Stored Procedure Parameter
-     */
-    public static class StoredProcedureParameter
-    {
-        private byte[] type;
-
-        private byte[] value;
-
-
-        public byte[] getType()
-        {
-            return type;
-        }
-
-
-        public void setType( byte[] type )
-        {
-            this.type = type;
-        }
-
-
-        public byte[] getValue()
-        {
-            return value;
-        }
-
-
-        public void setValue( byte[] value )
-        {
-            this.value = value;
-        }
-    }
-
-    /**
-     * Compute the StoredProcedure length 
-     * 
-     * 0x30 L1 
-     *   | 
-     *   +--> 0x04 L2 language
-     *   +--> 0x04 L3 procedure
-     *  [+--> 0x30 L4 (parameters)
-     *          |
-     *          +--> 0x30 L5-1 (parameter)
-     *          |      |
-     *          |      +--> 0x04 L6-1 type
-     *          |      +--> 0x04 L7-1 value
-     *          |      
-     *          +--> 0x30 L5-2 (parameter)
-     *          |      |
-     *          |      +--> 0x04 L6-2 type
-     *          |      +--> 0x04 L7-2 value
-     *          |
-     *          +--> ...
-     *          |      
-     *          +--> 0x30 L5-m (parameter)
-     *                 |
-     *                 +--> 0x04 L6-m type
-     *                 +--> 0x04 L7-m value
-     */
-    public int computeLength()
-    {
-        // The language
-    	byte[] languageBytes = StringTools.getBytesUtf8( language );
-    	
-        int languageLength = 1 + Length.getNbBytes( languageBytes.length )
-            + languageBytes.length;
-    	
-        // The procedure
-        int procedureLength = 1 + Length.getNbBytes( procedure.length )
-            + procedure.length;
-    	
-        //int localParametersLength = 0;
-        
-    	// Compute parameters length value
-    	if ( parameters != null )
-    	{
-            parameterLength = new LinkedList();
-            paramTypeLength = new LinkedList();
-            paramValueLength = new LinkedList();
-            
-    		Iterator params = parameters.iterator();
-    		
-    		while ( params.hasNext() )
-    		{
-    			int localParameterLength = 0;
-    			int localParamTypeLength = 0;
-    			int localParamValueLength = 0;
-    			
-    			StoredProcedureParameter spParam = (StoredProcedureParameter)params.next();
-    			
-    			localParamTypeLength = 1 + Length.getNbBytes( spParam.type.length ) + spParam.type.length;
-    			localParamValueLength = 1 + Length.getNbBytes( spParam.value.length ) + spParam.value.length;
-    			
-    			localParameterLength = localParamTypeLength + localParamValueLength;
-    			
-    			parametersLength += 1 + Length.getNbBytes( localParameterLength ) + localParameterLength;
-    			
-    			parameterLength.add( new Integer( localParameterLength ) );
-    			paramTypeLength.add( new Integer( localParamTypeLength ) );
-    			paramValueLength.add( new Integer( localParamValueLength ) );
-    		}
-    	}
-    	
-    	int localParametersLength = 1 + Length.getNbBytes( parametersLength ) + parametersLength; 
-    	storedProcedureLength = languageLength + procedureLength + localParametersLength;
-
-    	return 1 + Length.getNbBytes( storedProcedureLength ) + storedProcedureLength; 
-    }
-
-    /**
-     * Encode the StoredProcedure message to a PDU. 
-     * 
-     * @param buffer The buffer where to put the PDU
-     * @return The PDU.
-     */
-    public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
-    {
-        // Allocate the bytes buffer.
-        ByteBuffer bb = ByteBuffer.allocate( computeLength() );
-
-        try
-        {
-            // The StoredProcedure Tag
-            bb.put( UniversalTag.SEQUENCE_TAG );
-            bb.put( Length.getBytes( storedProcedureLength ) );
-
-            // The language
-            Value.encode( bb, language );
-
-            // The procedure
-            Value.encode( bb, procedure );
-            
-            // The parameters sequence
-            bb.put( UniversalTag.SEQUENCE_TAG );
-            bb.put( Length.getBytes( parametersLength ) );
-
-            // The parameters list
-            if ( ( parameters != null ) && ( parameters.size() != 0 ) )
-            {
-            	int parameterNumber = 0;
-        		Iterator params = parameters.iterator();
-        		
-        		while ( params.hasNext() )
-        		{
-        			StoredProcedureParameter spParam = (StoredProcedureParameter)params.next();
-
-                    // The parameter sequence
-                    bb.put( UniversalTag.SEQUENCE_TAG );
-                    int localParameterLength = ( ( Integer ) parameterLength.get( parameterNumber ) ).intValue();
-                    bb.put( Length.getBytes( localParameterLength ) );
-
-                    // The parameter type
-                    Value.encode( bb, spParam.type );
-
-                    // The parameter value
-                    Value.encode( bb, spParam.value );
-
-                    // Go to the next parameter;
-                    parameterNumber++;
-                }
-            }
-        }
-        catch ( BufferOverflowException boe )
-        {
-            throw new EncoderException( "The PDU buffer size is too small !" );
-        }
-
-        return bb;
-    }
-
-
-    /**
-     * Returns the StoredProcedure string
-     * 
-     * @return The StoredProcedure string
-     */
-    public String toString()
-    {
-
-        StringBuffer sb = new StringBuffer();
-
-        sb.append( "    StoredProcedure\n" );
-        sb.append( "        Language : '" ).append( language ).append( "'\n" );
-        sb.append( "        Procedure\n" ).append( StringTools.utf8ToString( procedure ) ).append( "'\n" );
-
-        if ( ( parameters == null ) || ( parameters.size() == 0 ) )
-        {
-            sb.append( "        No parameters\n" );
-        }
-        else
-        {
-            sb.append( "        Parameters\n" );
-
-            Iterator params = parameters.iterator();
-            int i = 1;
-    		
-    		while ( params.hasNext() )
-    		{
-    			StoredProcedureParameter spParam = (StoredProcedureParameter)params.next();
-    			
-    			sb.append( "            type[" ).append( i ) .append( "] : '" ).append( spParam.type ).append( "'\n" );
-    			sb.append( "            value[" ).append( i ) .append( "] : '" ).
-    				append( StringTools.dumpBytes( spParam.value ) ).append( "'\n" );
-    		}
-        }
-
-        return sb.toString();
-    }
-}
+/*
+ *   Copyright 2006 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.directory.shared.ldap.codec.extended.operations;
+
+
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.directory.shared.asn1.Asn1Object;
+import org.apache.directory.shared.asn1.ber.tlv.Length;
+import org.apache.directory.shared.asn1.ber.tlv.UniversalTag;
+import org.apache.directory.shared.asn1.ber.tlv.Value;
+import org.apache.directory.shared.asn1.codec.EncoderException;
+import org.apache.directory.shared.ldap.util.StringTools;
+
+
+/**
+ * Stored Procedure Extended Operation bean
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoredProcedure extends Asn1Object
+{
+    private String language;
+
+    private byte[] procedure;
+
+    private ArrayList parameters;
+
+    private transient StoredProcedureParameter currentParameter;
+    
+    /** The stored procedure length */
+    private transient int storedProcedureLength;
+    
+    /** The parameters length */
+    private transient int parametersLength;
+
+    /** The list of all parameter lengths */
+    private transient List parameterLength;
+
+    /** The list of all parameter type lengths */
+    private transient List paramTypeLength;
+
+    /** The list of all parameter value lengths */
+    private transient List paramValueLength;
+
+    public String getLanguage()
+    {
+        return language;
+    }
+
+
+    public void setLanguage( String language )
+    {
+        this.language = language;
+    }
+
+
+    public byte[] getProcedure()
+    {
+        return procedure;
+    }
+
+
+    public void setProcedure( byte[] procedure )
+    {
+        this.procedure = procedure;
+    }
+
+
+    public List getParameters()
+    {
+        return parameters;
+    }
+
+
+    public void addParameter( StoredProcedureParameter parameter )
+    {
+        if ( parameters == null )
+        {
+            parameters = new ArrayList();
+        }
+
+        parameters.add( parameter );
+    }
+
+
+    public StoredProcedureParameter getCurrentParameter()
+    {
+        return currentParameter;
+    }
+
+
+    public void setCurrentParameter( StoredProcedureParameter currentParameter )
+    {
+        this.currentParameter = currentParameter;
+    }
+    
+
+    /**
+     * Bean for representing a Stored Procedure Parameter
+     */
+    public static class StoredProcedureParameter
+    {
+        private byte[] type;
+
+        private byte[] value;
+
+
+        public byte[] getType()
+        {
+            return type;
+        }
+
+
+        public void setType( byte[] type )
+        {
+            this.type = type;
+        }
+
+
+        public byte[] getValue()
+        {
+            return value;
+        }
+
+
+        public void setValue( byte[] value )
+        {
+            this.value = value;
+        }
+    }
+
+    /**
+     * Compute the StoredProcedure length 
+     * 
+     * 0x30 L1 
+     *   | 
+     *   +--> 0x04 L2 language
+     *   +--> 0x04 L3 procedure
+     *  [+--> 0x30 L4 (parameters)
+     *          |
+     *          +--> 0x30 L5-1 (parameter)
+     *          |      |
+     *          |      +--> 0x04 L6-1 type
+     *          |      +--> 0x04 L7-1 value
+     *          |      
+     *          +--> 0x30 L5-2 (parameter)
+     *          |      |
+     *          |      +--> 0x04 L6-2 type
+     *          |      +--> 0x04 L7-2 value
+     *          |
+     *          +--> ...
+     *          |      
+     *          +--> 0x30 L5-m (parameter)
+     *                 |
+     *                 +--> 0x04 L6-m type
+     *                 +--> 0x04 L7-m value
+     */
+    public int computeLength()
+    {
+        // The language
+    	byte[] languageBytes = StringTools.getBytesUtf8( language );
+    	
+        int languageLength = 1 + Length.getNbBytes( languageBytes.length )
+            + languageBytes.length;
+    	
+        // The procedure
+        int procedureLength = 1 + Length.getNbBytes( procedure.length )
+            + procedure.length;
+    	
+        //int localParametersLength = 0;
+        
+    	// Compute parameters length value
+    	if ( parameters != null )
+    	{
+            parameterLength = new LinkedList();
+            paramTypeLength = new LinkedList();
+            paramValueLength = new LinkedList();
+            
+    		Iterator params = parameters.iterator();
+    		
+    		while ( params.hasNext() )
+    		{
+    			int localParameterLength = 0;
+    			int localParamTypeLength = 0;
+    			int localParamValueLength = 0;
+    			
+    			StoredProcedureParameter spParam = (StoredProcedureParameter)params.next();
+    			
+    			localParamTypeLength = 1 + Length.getNbBytes( spParam.type.length ) + spParam.type.length;
+    			localParamValueLength = 1 + Length.getNbBytes( spParam.value.length ) + spParam.value.length;
+    			
+    			localParameterLength = localParamTypeLength + localParamValueLength;
+    			
+    			parametersLength += 1 + Length.getNbBytes( localParameterLength ) + localParameterLength;
+    			
+    			parameterLength.add( new Integer( localParameterLength ) );
+    			paramTypeLength.add( new Integer( localParamTypeLength ) );
+    			paramValueLength.add( new Integer( localParamValueLength ) );
+    		}
+    	}
+    	
+    	int localParametersLength = 1 + Length.getNbBytes( parametersLength ) + parametersLength; 
+    	storedProcedureLength = languageLength + procedureLength + localParametersLength;
+
+    	return 1 + Length.getNbBytes( storedProcedureLength ) + storedProcedureLength; 
+    }
+
+    /**
+     * Encode the StoredProcedure message to a PDU. 
+     * 
+     * @param buffer The buffer where to put the PDU
+     * @return The PDU.
+     */
+    public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
+    {
+        // Allocate the bytes buffer.
+        ByteBuffer bb = ByteBuffer.allocate( computeLength() );
+
+        try
+        {
+            // The StoredProcedure Tag
+            bb.put( UniversalTag.SEQUENCE_TAG );
+            bb.put( Length.getBytes( storedProcedureLength ) );
+
+            // The language
+            Value.encode( bb, language );
+
+            // The procedure
+            Value.encode( bb, procedure );
+            
+            // The parameters sequence
+            bb.put( UniversalTag.SEQUENCE_TAG );
+            bb.put( Length.getBytes( parametersLength ) );
+
+            // The parameters list
+            if ( ( parameters != null ) && ( parameters.size() != 0 ) )
+            {
+            	int parameterNumber = 0;
+        		Iterator params = parameters.iterator();
+        		
+        		while ( params.hasNext() )
+        		{
+        			StoredProcedureParameter spParam = (StoredProcedureParameter)params.next();
+
+                    // The parameter sequence
+                    bb.put( UniversalTag.SEQUENCE_TAG );
+                    int localParameterLength = ( ( Integer ) parameterLength.get( parameterNumber ) ).intValue();
+                    bb.put( Length.getBytes( localParameterLength ) );
+
+                    // The parameter type
+                    Value.encode( bb, spParam.type );
+
+                    // The parameter value
+                    Value.encode( bb, spParam.value );
+
+                    // Go to the next parameter;
+                    parameterNumber++;
+                }
+            }
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException( "The PDU buffer size is too small !" );
+        }
+
+        return bb;
+    }
+
+
+    /**
+     * Returns the StoredProcedure string
+     * 
+     * @return The StoredProcedure string
+     */
+    public String toString()
+    {
+
+        StringBuffer sb = new StringBuffer();
+
+        sb.append( "    StoredProcedure\n" );
+        sb.append( "        Language : '" ).append( language ).append( "'\n" );
+        sb.append( "        Procedure\n" ).append( StringTools.utf8ToString( procedure ) ).append( "'\n" );
+
+        if ( ( parameters == null ) || ( parameters.size() == 0 ) )
+        {
+            sb.append( "        No parameters\n" );
+        }
+        else
+        {
+            sb.append( "        Parameters\n" );
+
+            Iterator params = parameters.iterator();
+            int i = 1;
+    		
+    		while ( params.hasNext() )
+    		{
+    			StoredProcedureParameter spParam = (StoredProcedureParameter)params.next();
+    			
+    			sb.append( "            type[" ).append( i ) .append( "] : '" ).append( spParam.type ).append( "'\n" );
+    			sb.append( "            value[" ).append( i ) .append( "] : '" ).
+    				append( StringTools.dumpBytes( spParam.value ) ).append( "'\n" );
+    		}
+        }
+
+        return sb.toString();
+    }
+}

Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/StoredProcedureContainer.java
URL: http://svn.apache.org/viewcvs/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/StoredProcedureContainer.java?rev=400067&r1=400066&r2=400067&view=diff
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/StoredProcedureContainer.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/StoredProcedureContainer.java Fri May  5 05:52:49 2006
@@ -1,90 +1,90 @@
-/*
- *   Copyright 2006 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.directory.shared.ldap.codec.extended.operations;
-
-
-import org.apache.directory.shared.asn1.ber.AbstractContainer;
-import org.apache.directory.shared.asn1.ber.IAsn1Container;
-import org.apache.directory.shared.asn1.ber.grammar.IGrammar;
-
-
-/**
- * A container for the StoredProcedure codec
- * 
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- */
-public class StoredProcedureContainer extends AbstractContainer implements IAsn1Container
-{
-    // ~ Instance fields
-    // ----------------------------------------------------------------------------
-
-    /** StoredProcedure */
-    private StoredProcedure storedProcedure;
-
-
-    // ~ Constructors
-    // -------------------------------------------------------------------------------
-
-    public StoredProcedureContainer()
-    {
-        super();
-        currentGrammar = 0;
-        grammars = new IGrammar[1];
-        grammarStack = new IGrammar[1];
-        stateStack = new int[1];
-        nbGrammars = 0;
-
-        grammars[StoredProcedureStatesEnum.STORED_PROCEDURE_GRAMMAR] = StoredProcedureGrammar.getInstance();
-
-        grammarStack[currentGrammar] = grammars[StoredProcedureStatesEnum.STORED_PROCEDURE_GRAMMAR];
-
-        states = StoredProcedureStatesEnum.getInstance();
-    }
-
-
-    // ~ Methods
-    // ------------------------------------------------------------------------------------
-    /**
-     * @return Returns the ldapMessage.
-     */
-    public StoredProcedure getStoredProcedure()
-    {
-        return storedProcedure;
-    }
-
-
-    /**
-     * Set a StoredProcedure object into the container. It will be completed by the
-     * ldapDecoder.
-     * 
-     * @param ldapMessage
-     *            The ldapMessage to set.
-     */
-    public void setStoredProcedure( StoredProcedure storedProcedure )
-    {
-        this.storedProcedure = storedProcedure;
-    }
-
-
-    public void clean()
-    {
-        super.clean();
-
-        storedProcedure = null;
-    }
-}
+/*
+ *   Copyright 2006 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.directory.shared.ldap.codec.extended.operations;
+
+
+import org.apache.directory.shared.asn1.ber.AbstractContainer;
+import org.apache.directory.shared.asn1.ber.IAsn1Container;
+import org.apache.directory.shared.asn1.ber.grammar.IGrammar;
+
+
+/**
+ * A container for the StoredProcedure codec
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoredProcedureContainer extends AbstractContainer implements IAsn1Container
+{
+    // ~ Instance fields
+    // ----------------------------------------------------------------------------
+
+    /** StoredProcedure */
+    private StoredProcedure storedProcedure;
+
+
+    // ~ Constructors
+    // -------------------------------------------------------------------------------
+
+    public StoredProcedureContainer()
+    {
+        super();
+        currentGrammar = 0;
+        grammars = new IGrammar[1];
+        grammarStack = new IGrammar[1];
+        stateStack = new int[1];
+        nbGrammars = 0;
+
+        grammars[StoredProcedureStatesEnum.STORED_PROCEDURE_GRAMMAR] = StoredProcedureGrammar.getInstance();
+
+        grammarStack[currentGrammar] = grammars[StoredProcedureStatesEnum.STORED_PROCEDURE_GRAMMAR];
+
+        states = StoredProcedureStatesEnum.getInstance();
+    }
+
+
+    // ~ Methods
+    // ------------------------------------------------------------------------------------
+    /**
+     * @return Returns the ldapMessage.
+     */
+    public StoredProcedure getStoredProcedure()
+    {
+        return storedProcedure;
+    }
+
+
+    /**
+     * Set a StoredProcedure object into the container. It will be completed by the
+     * ldapDecoder.
+     * 
+     * @param ldapMessage
+     *            The ldapMessage to set.
+     */
+    public void setStoredProcedure( StoredProcedure storedProcedure )
+    {
+        this.storedProcedure = storedProcedure;
+    }
+
+
+    public void clean()
+    {
+        super.clean();
+
+        storedProcedure = null;
+    }
+}



Mime
View raw message