directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r1063971 - in /directory/shared/trunk/ldap/src: main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/ test/java/org/apache/directory/shared/ldap/codec/search/controls/
Date Thu, 27 Jan 2011 03:18:03 GMT
Author: akarasulu
Date: Thu Jan 27 03:18:00 2011
New Revision: 1063971

URL: http://svn.apache.org/viewvc?rev=1063971&view=rev
Log:
cleanup after extracting interface for PagedResults control

Modified:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsContainer.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsDecoder.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsDecorator.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsGrammar.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/SimplePagedResults.java
    directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/search/controls/PagedSearchControlTest.java

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsContainer.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsContainer.java?rev=1063971&r1=1063970&r2=1063971&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsContainer.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsContainer.java
Thu Jan 27 03:18:00 2011
@@ -48,15 +48,42 @@ public class PagedResultsContainer exten
 
 
     /**
+     * Creates a new PagedSearchControl container object to contain a PagedResults
+     * Control, which is optionally decorated if is not a decorator already. If it
+     * is a decorator then it is used as the decorator for this container.
+     *
+     * @param control A PagedResults Control to optionally be wrapped.
+     */
+    public PagedResultsContainer( PagedResults control )
+    {
+        this();
+        decorate( control );
+    }
+
+
+    /**
      * @return Returns the paged search control.
      */
-    public PagedResultsDecorator getPagedSearchControl()
+    public PagedResultsDecorator getDecorator()
     {
 
         return control;
     }
 
 
+    public void decorate( PagedResults control )
+    {
+        if ( control instanceof PagedResultsDecorator )
+        {
+            this.control = ( PagedResultsDecorator ) control;
+        }
+        else
+        {
+            this.control = new PagedResultsDecorator( control );
+        }
+    }
+
+
     /**
      * Set a PagedSearchControl Object into the container. It will be completed by
      * the ldapDecoder.

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsDecoder.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsDecoder.java?rev=1063971&r1=1063970&r2=1063971&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsDecoder.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsDecoder.java
Thu Jan 27 03:18:00 2011
@@ -39,6 +39,7 @@ public class PagedResultsDecoder extends
     /** An instance of this decoder */
     private static final Asn1Decoder decoder = new Asn1Decoder();
 
+
     /**
      * Decode the paged search control
      * 
@@ -46,15 +47,13 @@ public class PagedResultsDecoder extends
      * 
      * @return A valid PagedSearch object
      * 
-     * @throws org.apache.directory.shared.asn1.DecoderException If the decoding found an
error
-     * @throws NamingException It will never be throw by this method
+     * @throws DecoderException It will never be throw by this method
      */
     public Asn1Object decode( byte[] controlBytes, Control control ) throws DecoderException
     {
         ByteBuffer bb = ByteBuffer.wrap( controlBytes );
-        PagedResultsContainer container = new PagedResultsContainer();
-        container.setPagedSearchControl( (PagedResultsDecorator )control );
+        PagedResultsContainer container = new PagedResultsContainer( (PagedResults ) control
);
         decoder.decode( bb, container );
-        return container.getPagedSearchControl();
+        return container.getDecorator();
     }
 }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsDecorator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsDecorator.java?rev=1063971&r1=1063970&r2=1063971&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsDecorator.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsDecorator.java
Thu Jan 27 03:18:00 2011
@@ -29,7 +29,6 @@ import org.apache.directory.shared.asn1.
 import org.apache.directory.shared.asn1.ber.tlv.Value;
 import org.apache.directory.shared.i18n.I18n;
 import org.apache.directory.shared.ldap.codec.controls.ControlDecorator;
-import org.apache.directory.shared.util.StringConstants;
 import org.apache.directory.shared.util.Strings;
 
 
@@ -38,28 +37,31 @@ import org.apache.directory.shared.util.
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class PagedResultsDecorator extends ControlDecorator
+public class PagedResultsDecorator extends ControlDecorator implements PagedResults
 {
-
-    /** The number of entries to return, or returned */
-    private int size;
-
-    /** The exchanged cookie */
-    private byte[] cookie;
-
     /** The entry change global length */
     private int pscSeqLength;
 
 
     /**
-     * 
-     * Creates a new instance of PagedResultsDecorator.
-     *
+     * Creates a new instance of PagedResultsDecorator with a newly created decorated
+     * PagedResults Control.
      */
     public PagedResultsDecorator()
     {
-        super( new SimplePagedResults(), new PagedResultsDecoder() );
-        cookie = StringConstants.EMPTY_BYTES;
+        this( new SimplePagedResults() );
+    }
+
+
+    /**
+     * Creates a new instance of PagedResultsDecorator using the supplied PagedResults
+     * Control to be decorated.
+     *
+     * @param  pagedResults The PagedResults Control to be decorated.
+     */
+    public PagedResultsDecorator( PagedResults pagedResults )
+    {
+        super( pagedResults, new PagedResultsDecoder() );
     }
 
 
@@ -78,13 +80,13 @@ public class PagedResultsDecorator exten
      */
     public int computeLength()
     {
-        int sizeLength = 1 + 1 + Value.getNbBytes( size );
+        int sizeLength = 1 + 1 + Value.getNbBytes( getSize() );
 
         int cookieLength;
 
-        if ( cookie != null )
+        if ( getCookie() != null )
         {
-            cookieLength = 1 + TLV.getNbBytes( cookie.length ) + cookie.length;
+            cookieLength = 1 + TLV.getNbBytes( getCookie().length ) + getCookie().length;
         }
         else
         {
@@ -124,8 +126,8 @@ public class PagedResultsDecorator exten
         buffer.put( UniversalTag.SEQUENCE.getValue() );
         buffer.put( TLV.getBytes( pscSeqLength ) );
 
-        Value.encode( buffer, size );
-        Value.encode( buffer, cookie );
+        Value.encode( buffer, getSize() );
+        Value.encode( buffer, getCookie() );
 
         return buffer;
     }
@@ -147,8 +149,8 @@ public class PagedResultsDecorator exten
                 buffer.put( UniversalTag.SEQUENCE.getValue() );
                 buffer.put( TLV.getBytes( pscSeqLength ) );
 
-                Value.encode( buffer, size );
-                Value.encode( buffer, cookie );
+                Value.encode( buffer, getSize() );
+                Value.encode( buffer, getCookie() );
 
                 getDecorated().setValue( buffer.array() );
             }
@@ -162,12 +164,19 @@ public class PagedResultsDecorator exten
     }
 
 
+    private PagedResults getPagedResults()
+    {
+        return ( PagedResults ) getDecorated();
+    }
+
+
+
     /**
      * @return The requested or returned number of entries
      */
     public int getSize()
     {
-        return size;
+        return getPagedResults().getSize();
     }
 
 
@@ -178,7 +187,7 @@ public class PagedResultsDecorator exten
      */
     public void setSize( int size )
     {
-        this.size = size;
+        getPagedResults().setSize( size );
     }
 
 
@@ -187,7 +196,7 @@ public class PagedResultsDecorator exten
      */
     public byte[] getCookie()
     {
-        return cookie;
+        return getPagedResults().getCookie();
     }
 
 
@@ -198,7 +207,7 @@ public class PagedResultsDecorator exten
      */
     public void setCookie( byte[] cookie )
     {
-        this.cookie = cookie;
+        getPagedResults().setCookie( cookie );
     }
 
 
@@ -209,23 +218,24 @@ public class PagedResultsDecorator exten
     {
         int value = 0;
 
-        switch ( cookie.length )
+        switch ( getCookie().length )
         {
             case 1:
-                value = cookie[0] & 0x00FF;
+                value = getCookie()[0] & 0x00FF;
                 break;
 
             case 2:
-                value = ( ( cookie[0] & 0x00FF ) << 8 ) + ( cookie[1] & 0x00FF
);
+                value = ( ( getCookie()[0] & 0x00FF ) << 8 ) + ( getCookie()[1]
& 0x00FF );
                 break;
 
             case 3:
-                value = ( ( cookie[0] & 0x00FF ) << 16 ) + ( ( cookie[1] &
0x00FF ) << 8 ) + ( cookie[2] & 0x00FF );
+                value = ( ( getCookie()[0] & 0x00FF ) << 16 ) + ( ( getCookie()[1]
& 0x00FF ) << 8 )
+                        + ( getCookie()[2] & 0x00FF );
                 break;
 
             case 4:
-                value = ( ( cookie[0] & 0x00FF ) << 24 ) + ( ( cookie[1] &
0x00FF ) << 16 )
-                    + ( ( cookie[2] & 0x00FF ) << 8 ) + ( cookie[3] & 0x00FF
);
+                value = ( ( getCookie()[0] & 0x00FF ) << 24 ) + ( ( getCookie()[1]
& 0x00FF ) << 16 )
+                        + ( ( getCookie()[2] & 0x00FF ) << 8 ) + ( getCookie()[3]
& 0x00FF );
                 break;
 
         }
@@ -246,9 +256,9 @@ public class PagedResultsDecorator exten
             return false;
         }
 
-        PagedResultsDecorator otherControl = ( PagedResultsDecorator ) o;
+        PagedResults otherControl = ( PagedResults ) o;
 
-        return ( size == otherControl.size ) && Arrays.equals( cookie, otherControl.cookie
);
+        return ( getSize() == otherControl.getSize() ) && Arrays.equals( getCookie(),
otherControl.getCookie() );
     }
 
 
@@ -262,8 +272,8 @@ public class PagedResultsDecorator exten
         sb.append( "    Paged Search Control\n" );
         sb.append( "        oid : " ).append( getOid() ).append( '\n' );
         sb.append( "        critical : " ).append( isCritical() ).append( '\n' );
-        sb.append( "        size   : '" ).append( size ).append( "'\n" );
-        sb.append( "        cookie   : '" ).append( Strings.dumpBytes(cookie) ).append( "'\n"
);
+        sb.append( "        size   : '" ).append( getSize() ).append( "'\n" );
+        sb.append( "        cookie   : '" ).append( Strings.dumpBytes( getCookie() ) ).append(
"'\n" );
 
         return sb.toString();
     }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsGrammar.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsGrammar.java?rev=1063971&r1=1063970&r2=1063971&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsGrammar.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/PagedResultsGrammar.java
Thu Jan 27 03:18:00 2011
@@ -121,7 +121,7 @@ public final class PagedResultsGrammar e
                             LOG.debug( "size = " + size );
                         }
 
-                        pagedSearchContainer.getPagedSearchControl().setSize( size );
+                        pagedSearchContainer.getDecorator().setSize( size );
                     }
                     catch ( IntegerDecoderException e )
                     {
@@ -153,11 +153,11 @@ public final class PagedResultsGrammar e
 
                     if ( pagedSearchContainer.getCurrentTLV().getLength() == 0 )
                     {
-                        pagedSearchContainer.getPagedSearchControl().setCookie( StringConstants.EMPTY_BYTES
);
+                        pagedSearchContainer.getDecorator().setCookie( StringConstants.EMPTY_BYTES
);
                     }
                     else
                     {
-                        pagedSearchContainer.getPagedSearchControl().setCookie( value.getData()
);
+                        pagedSearchContainer.getDecorator().setCookie( value.getData() );
                     }
 
                     // We can have an END transition

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/SimplePagedResults.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/SimplePagedResults.java?rev=1063971&r1=1063970&r2=1063971&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/SimplePagedResults.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/pagedSearch/SimplePagedResults.java
Thu Jan 27 03:18:00 2011
@@ -65,7 +65,7 @@ public class SimplePagedResults extends 
     private int size;
 
     /** The exchanged cookie */
-    private byte[] cookie;
+    private byte[] cookie = StringConstants.EMPTY_BYTES;
 
 
     /**
@@ -74,8 +74,6 @@ public class SimplePagedResults extends 
     public SimplePagedResults()
     {
         super( OID );
-
-        cookie = StringConstants.EMPTY_BYTES;
     }
 
 
@@ -135,6 +133,8 @@ public class SimplePagedResults extends 
     /**
      * @see Object#equals(Object)
      */
+    @SuppressWarnings( { "EqualsWhichDoesntCheckParameterClass" } )
+    @Override
     public boolean equals( Object o )
     {
         if ( !super.equals( o ) )
@@ -142,9 +142,9 @@ public class SimplePagedResults extends 
             return false;
         }
 
-        SimplePagedResults otherControl = ( SimplePagedResults ) o;
+        PagedResults otherControl = ( PagedResults ) o;
 
-        return ( size == otherControl.size ) && Arrays.equals( cookie, otherControl.cookie
);
+        return ( size == otherControl.getSize() ) && Arrays.equals( cookie, otherControl.getCookie()
);
     }
 
 

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/search/controls/PagedSearchControlTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/search/controls/PagedSearchControlTest.java?rev=1063971&r1=1063970&r2=1063971&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/search/controls/PagedSearchControlTest.java
(original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/search/controls/PagedSearchControlTest.java
Thu Jan 27 03:18:00 2011
@@ -79,7 +79,7 @@ public class PagedSearchControlTest
             fail( de.getMessage() );
         }
 
-        PagedResultsDecorator pagedSearch = container.getPagedSearchControl();
+        PagedResultsDecorator pagedSearch = container.getDecorator();
         assertEquals( 32, pagedSearch.getSize() );
         assertTrue( Arrays.equals( Strings.getBytesUtf8("test"),
             pagedSearch.getCookie() ) );
@@ -230,7 +230,7 @@ public class PagedSearchControlTest
             fail( de.getMessage() );
         }
 
-        PagedResultsDecorator pagedSearch = container.getPagedSearchControl();
+        PagedResultsDecorator pagedSearch = container.getDecorator();
         assertEquals( Integer.MAX_VALUE, pagedSearch.getSize() );
         assertTrue( Arrays.equals( Strings.getBytesUtf8("test"),
             pagedSearch.getCookie() ) );
@@ -324,7 +324,7 @@ public class PagedSearchControlTest
             fail( de.getMessage() );
         }
 
-        PagedResultsDecorator pagedSearch = container.getPagedSearchControl();
+        PagedResultsDecorator pagedSearch = container.getDecorator();
         assertEquals( 32, pagedSearch.getSize() );
         assertNotNull( pagedSearch.getCookie() );
         assertEquals( StringConstants.EMPTY_BYTES, pagedSearch.getCookie() );



Mime
View raw message