directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1579091 - in /directory/shared/trunk/ldap/extras: codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/gracefulDisconnect/ codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/certGeneration/ codec/sr...
Date Tue, 18 Mar 2014 23:43:56 GMT
Author: elecharny
Date: Tue Mar 18 23:43:55 2014
New Revision: 1579091

URL: http://svn.apache.org/r1579091
Log:
o Removal of useless classes
o Refactoring of the code to reflect this removal

Removed:
    directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulDisconnect/GracefulAction.java
    directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulDisconnect/GracefulDisconnect.java
    directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulShutdown/GracefulShutdown.java
Modified:
    directory/shared/trunk/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/gracefulDisconnect/GracefulDisconnectResponse.java
    directory/shared/trunk/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/gracefulDisconnect/GracefulDisconnectResponseImpl.java
    directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/certGeneration/CertGenerationContainer.java
    directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/certGeneration/CertGenerationDecoder.java
    directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/certGeneration/CertGenerationGrammar.java
    directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulDisconnect/GracefulDisconnectContainer.java
    directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulDisconnect/GracefulDisconnectDecoder.java
    directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulDisconnect/GracefulDisconnectFactory.java
    directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulDisconnect/GracefulDisconnectGrammar.java
    directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulDisconnect/GracefulDisconnectResponseDecorator.java
    directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulShutdown/GracefulShutdownContainer.java
    directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulShutdown/GracefulShutdownDecoder.java
    directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulShutdown/GracefulShutdownGrammar.java
    directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulShutdown/GracefulShutdownRequestDecorator.java
    directory/shared/trunk/ldap/extras/codec/src/test/java/org/apache/directory/api/ldap/extras/extended/ads_impl/CertGenerationRequestTest.java
    directory/shared/trunk/ldap/extras/codec/src/test/java/org/apache/directory/api/ldap/extras/extended/ads_impl/GracefulDisconnectTest.java
    directory/shared/trunk/ldap/extras/codec/src/test/java/org/apache/directory/api/ldap/extras/extended/ads_impl/GracefulShutdownTest.java

Modified: directory/shared/trunk/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/gracefulDisconnect/GracefulDisconnectResponse.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/gracefulDisconnect/GracefulDisconnectResponse.java?rev=1579091&r1=1579090&r2=1579091&view=diff
==============================================================================
--- directory/shared/trunk/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/gracefulDisconnect/GracefulDisconnectResponse.java (original)
+++ directory/shared/trunk/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/gracefulDisconnect/GracefulDisconnectResponse.java Tue Mar 18 23:43:55 2014
@@ -77,4 +77,12 @@ public interface GracefulDisconnectRespo
      * @return the replicated contexts
      */
     Referral getReplicatedContexts();
+
+
+    /**
+     * Add a new URL of a replicated server
+     * 
+     * @param replicatedContext The replicated server to add.
+     */
+    void addReplicatedContexts( String replicatedContext );
 }
\ No newline at end of file

Modified: directory/shared/trunk/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/gracefulDisconnect/GracefulDisconnectResponseImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/gracefulDisconnect/GracefulDisconnectResponseImpl.java?rev=1579091&r1=1579090&r2=1579091&view=diff
==============================================================================
--- directory/shared/trunk/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/gracefulDisconnect/GracefulDisconnectResponseImpl.java (original)
+++ directory/shared/trunk/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/gracefulDisconnect/GracefulDisconnectResponseImpl.java Tue Mar 18 23:43:55 2014
@@ -107,9 +107,8 @@ public class GracefulDisconnectResponseI
     // -----------------------------------------------------------------------
     // Parameters of the Extended Response Value
     // -----------------------------------------------------------------------
-
-    /* (non-Javadoc)
-     * @see org.apache.directory.api.ldap.extras.extended.GracefulDisconnectResponse#getDelay()
+    /**
+     * {@inheritDoc}
      */
     public int getDelay()
     {
@@ -117,8 +116,8 @@ public class GracefulDisconnectResponseI
     }
 
 
-    /* (non-Javadoc)
-     * @see org.apache.directory.api.ldap.extras.extended.GracefulDisconnectResponse#setDelay(int)
+    /**
+     * {@inheritDoc}
      */
     public void setDelay( int delay )
     {
@@ -126,8 +125,8 @@ public class GracefulDisconnectResponseI
     }
 
 
-    /* (non-Javadoc)
-     * @see org.apache.directory.api.ldap.extras.extended.GracefulDisconnectResponse#getTimeOffline()
+    /**
+     * {@inheritDoc}
      */
     public int getTimeOffline()
     {
@@ -135,8 +134,8 @@ public class GracefulDisconnectResponseI
     }
 
 
-    /* (non-Javadoc)
-     * @see org.apache.directory.api.ldap.extras.extended.GracefulDisconnectResponse#setTimeOffline(int)
+    /**
+     * {@inheritDoc}
      */
     public void setTimeOffline( int timeOffline )
     {
@@ -144,11 +143,18 @@ public class GracefulDisconnectResponseI
     }
 
 
-    /* (non-Javadoc)
-     * @see org.apache.directory.api.ldap.extras.extended.GracefulDisconnectResponse#getReplicatedContexts()
-     */
     public Referral getReplicatedContexts()
     {
         return replicatedContexts;
     }
+    
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void addReplicatedContexts( String replicatedContext )
+    {
+        replicatedContexts.addLdapUrl( replicatedContext );
+    }
 }

Modified: directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/certGeneration/CertGenerationContainer.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/certGeneration/CertGenerationContainer.java?rev=1579091&r1=1579090&r2=1579091&view=diff
==============================================================================
--- directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/certGeneration/CertGenerationContainer.java (original)
+++ directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/certGeneration/CertGenerationContainer.java Tue Mar 18 23:43:55 2014
@@ -31,7 +31,7 @@ import org.apache.directory.api.asn1.ber
 public class CertGenerationContainer extends AbstractContainer
 {
     /** CertGenerationObject */
-    private CertGenerationRequestDecorator certGenObj;
+    private CertGenerationRequestDecorator certGenerationRequest;
 
 
     /**
@@ -47,23 +47,23 @@ public class CertGenerationContainer ext
 
 
     /**
-     * @return Returns the CertGenerationObject instance.
+     * @return Returns the CertGenerationRequest instance.
      */
-    public CertGenerationRequestDecorator getCertGenerationObject()
+    public CertGenerationRequestDecorator getCertGenerationRequest()
     {
-        return certGenObj;
+        return certGenerationRequest;
     }
 
 
     /**
-     * Set a CertGenerationObject Object into the container. It will be completed by
+     * Set a CertGenerationRequest instance into the container. It will be completed by
      * the ldapDecoder.
      * 
-     * @param certGenObj the CertGenerationObject to set.
+     * @param certGenerationRequest the CertGenerationRequest to set.
      */
-    public void setCertGenerationObject( CertGenerationRequestDecorator certGenObj )
+    public void setCertGenerationRequest( CertGenerationRequestDecorator certGenerationRequest )
     {
-        this.certGenObj = certGenObj;
+        this.certGenerationRequest = certGenerationRequest;
     }
 
 
@@ -73,6 +73,6 @@ public class CertGenerationContainer ext
     public void clean()
     {
         super.clean();
-        certGenObj = null;
+        certGenerationRequest = null;
     }
 }

Modified: directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/certGeneration/CertGenerationDecoder.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/certGeneration/CertGenerationDecoder.java?rev=1579091&r1=1579090&r2=1579091&view=diff
==============================================================================
--- directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/certGeneration/CertGenerationDecoder.java (original)
+++ directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/certGeneration/CertGenerationDecoder.java Tue Mar 18 23:43:55 2014
@@ -52,7 +52,7 @@ public class CertGenerationDecoder exten
         ByteBuffer bb = ByteBuffer.wrap( stream );
         CertGenerationContainer container = new CertGenerationContainer();
         decoder.decode( bb, container );
-        CertGenerationRequestDecorator certGenerationRequestDecorator = container.getCertGenerationObject();
+        CertGenerationRequestDecorator certGenerationRequestDecorator = container.getCertGenerationRequest();
 
         // Clean the container for the next decoding
         container.clean();

Modified: directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/certGeneration/CertGenerationGrammar.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/certGeneration/CertGenerationGrammar.java?rev=1579091&r1=1579090&r2=1579091&view=diff
==============================================================================
--- directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/certGeneration/CertGenerationGrammar.java (original)
+++ directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/certGeneration/CertGenerationGrammar.java Tue Mar 18 23:43:55 2014
@@ -91,9 +91,9 @@ public class CertGenerationGrammar exten
                 {
                     public void action( CertGenerationContainer container )
                     {
-                        CertGenerationRequestDecorator certGenerationObject = new CertGenerationRequestDecorator(
+                        CertGenerationRequestDecorator certGenerationRequest = new CertGenerationRequestDecorator(
                             LdapApiServiceFactory.getSingleton(), new CertGenerationRequestImpl() );
-                        container.setCertGenerationObject( certGenerationObject );
+                        container.setCertGenerationRequest( certGenerationRequest );
                     }
                 } );
 
@@ -133,7 +133,7 @@ public class CertGenerationGrammar exten
                                 throw new DecoderException( msg );
                             }
 
-                            container.getCertGenerationObject().setTargetDN( targetDN );
+                            container.getCertGenerationRequest().setTargetDN( targetDN );
                         }
                         else
                         {
@@ -179,7 +179,7 @@ public class CertGenerationGrammar exten
                                 throw new DecoderException( msg );
                             }
 
-                            container.getCertGenerationObject().setIssuerDN( issuerDN );
+                            container.getCertGenerationRequest().setIssuerDN( issuerDN );
                         }
                     }
                 } );
@@ -219,7 +219,7 @@ public class CertGenerationGrammar exten
                                 throw new DecoderException( msg );
                             }
 
-                            container.getCertGenerationObject().setSubjectDN( subjectDN );
+                            container.getCertGenerationRequest().setSubjectDN( subjectDN );
                         }
                         else
                         {
@@ -258,7 +258,7 @@ public class CertGenerationGrammar exten
 
                         if ( keyAlgorithm != null && ( keyAlgorithm.trim().length() > 0 ) )
                         {
-                            container.getCertGenerationObject().setKeyAlgorithm( keyAlgorithm );
+                            container.getCertGenerationRequest().setKeyAlgorithm( keyAlgorithm );
                         }
 
                         container.setGrammarEndAllowed( true );

Modified: directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulDisconnect/GracefulDisconnectContainer.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulDisconnect/GracefulDisconnectContainer.java?rev=1579091&r1=1579090&r2=1579091&view=diff
==============================================================================
--- directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulDisconnect/GracefulDisconnectContainer.java (original)
+++ directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulDisconnect/GracefulDisconnectContainer.java Tue Mar 18 23:43:55 2014
@@ -31,7 +31,7 @@ import org.apache.directory.api.asn1.ber
 public class GracefulDisconnectContainer extends AbstractContainer
 {
     /** GracefulShutdown */
-    private GracefulDisconnect gracefulDisconnect;
+    private GracefulDisconnectResponseDecorator gracefulDisconnectResponse;
 
 
     /**
@@ -47,23 +47,23 @@ public class GracefulDisconnectContainer
 
 
     /**
-     * @return Returns the Graceful Shutdown object.
+     * @return Returns the GracefulDisconnectResponse object.
      */
-    public GracefulDisconnect getGracefulDisconnect()
+    public GracefulDisconnectResponseDecorator getGracefulDisconnectResponse()
     {
-        return gracefulDisconnect;
+        return gracefulDisconnectResponse;
     }
 
 
     /**
-     * Set a GracefulDisconnect Object into the container. It will be completed
+     * Set a GracefulDisconnectResponse Object into the container. It will be completed
      * by the ldapDecoder.
      * 
-     * @param gracefulDisconnect the GracefulShutdown to set.
+     * @param gracefulDisconnectResponse the GracefulShutdown to set.
      */
-    public void setGracefulDisconnect( GracefulDisconnect gracefulDisconnect )
+    public void setGracefulDisconnectResponse( GracefulDisconnectResponseDecorator gracefulDisconnectResponse )
     {
-        this.gracefulDisconnect = gracefulDisconnect;
+        this.gracefulDisconnectResponse = gracefulDisconnectResponse;
     }
 
 
@@ -73,6 +73,6 @@ public class GracefulDisconnectContainer
     public void clean()
     {
         super.clean();
-        gracefulDisconnect = null;
+        gracefulDisconnectResponse = null;
     }
 }

Modified: directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulDisconnect/GracefulDisconnectDecoder.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulDisconnect/GracefulDisconnectDecoder.java?rev=1579091&r1=1579090&r2=1579091&view=diff
==============================================================================
--- directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulDisconnect/GracefulDisconnectDecoder.java (original)
+++ directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulDisconnect/GracefulDisconnectDecoder.java Tue Mar 18 23:43:55 2014
@@ -22,9 +22,9 @@ package org.apache.directory.api.ldap.ex
 
 import java.nio.ByteBuffer;
 
-import org.apache.directory.api.asn1.Asn1Object;
 import org.apache.directory.api.asn1.DecoderException;
 import org.apache.directory.api.asn1.ber.Asn1Decoder;
+import org.apache.directory.api.ldap.extras.extended.gracefulDisconnect.GracefulDisconnectResponse;
 
 
 /**
@@ -46,12 +46,12 @@ public class GracefulDisconnectDecoder e
      * @return An GracefulDisconnect object
      * @throws DecoderException If the decoding failed
      */
-    public Asn1Object decode( byte[] stream ) throws DecoderException
+    public GracefulDisconnectResponse decode( byte[] stream ) throws DecoderException
     {
         ByteBuffer bb = ByteBuffer.wrap( stream );
         GracefulDisconnectContainer container = new GracefulDisconnectContainer();
         decoder.decode( bb, container );
-        GracefulDisconnect gracefulDisconnect = container.getGracefulDisconnect();
+        GracefulDisconnectResponseDecorator gracefulDisconnect = container.getGracefulDisconnectResponse();
 
         // Clean the container for the next decoding
         container.clean();

Modified: directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulDisconnect/GracefulDisconnectFactory.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulDisconnect/GracefulDisconnectFactory.java?rev=1579091&r1=1579090&r2=1579091&view=diff
==============================================================================
--- directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulDisconnect/GracefulDisconnectFactory.java (original)
+++ directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulDisconnect/GracefulDisconnectFactory.java Tue Mar 18 23:43:55 2014
@@ -25,6 +25,7 @@ import org.apache.directory.api.ldap.cod
 import org.apache.directory.api.ldap.codec.api.ExtendedRequestDecorator;
 import org.apache.directory.api.ldap.codec.api.LdapApiService;
 import org.apache.directory.api.ldap.extras.extended.gracefulDisconnect.GracefulDisconnectResponse;
+import org.apache.directory.api.ldap.extras.extended.gracefulDisconnect.GracefulDisconnectResponseImpl;
 import org.apache.directory.api.ldap.model.message.ExtendedRequest;
 import org.apache.directory.api.ldap.model.message.ExtendedResponse;
 
@@ -95,6 +96,10 @@ public class GracefulDisconnectFactory i
      */
     public GracefulDisconnectResponse newResponse( byte[] encodedValue ) throws DecoderException
     {
-        return new GracefulDisconnectResponseDecorator( codec, encodedValue );
+        GracefulDisconnectResponseDecorator req = new GracefulDisconnectResponseDecorator( codec,
+            new GracefulDisconnectResponseImpl() );
+        req.setResponseValue( encodedValue );
+        
+        return req;
     }
 }

Modified: directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulDisconnect/GracefulDisconnectGrammar.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulDisconnect/GracefulDisconnectGrammar.java?rev=1579091&r1=1579090&r2=1579091&view=diff
==============================================================================
--- directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulDisconnect/GracefulDisconnectGrammar.java (original)
+++ directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulDisconnect/GracefulDisconnectGrammar.java Tue Mar 18 23:43:55 2014
@@ -29,6 +29,8 @@ import org.apache.directory.api.asn1.ber
 import org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException;
 import org.apache.directory.api.asn1.ber.tlv.UniversalTag;
 import org.apache.directory.api.i18n.I18n;
+import org.apache.directory.api.ldap.codec.api.LdapApiServiceFactory;
+import org.apache.directory.api.ldap.extras.extended.gracefulDisconnect.GracefulDisconnectResponseImpl;
 import org.apache.directory.api.ldap.model.exception.LdapURLEncodingException;
 import org.apache.directory.api.ldap.model.url.LdapUrl;
 import org.apache.directory.api.util.Strings;
@@ -87,7 +89,7 @@ public final class GracefulDisconnectGra
                         LOG.debug( "Delay = " + delay );
                     }
 
-                    container.getGracefulDisconnect().setDelay( delay );
+                    container.getGracefulDisconnectResponse().setDelay( delay );
                     container.setGrammarEndAllowed( true );
                 }
                 catch ( IntegerDecoderException e )
@@ -121,7 +123,7 @@ public final class GracefulDisconnectGra
                     String url = Strings.utf8ToString( value.getData() );
 
                     LdapUrl ldapUrl = new LdapUrl( url );
-                    container.getGracefulDisconnect().addReplicatedContexts( ldapUrl );
+                    container.getGracefulDisconnectResponse().addReplicatedContexts( url );
                     container.setGrammarEndAllowed( true );
 
                     if ( IS_DEBUG )
@@ -157,7 +159,7 @@ public final class GracefulDisconnectGra
                         LOG.debug( "Time Offline = " + timeOffline );
                     }
 
-                    container.getGracefulDisconnect().setTimeOffline( timeOffline );
+                    container.getGracefulDisconnectResponse().setTimeOffline( timeOffline );
                     container.setGrammarEndAllowed( true );
                 }
                 catch ( IntegerDecoderException e )
@@ -196,8 +198,12 @@ public final class GracefulDisconnectGra
                 {
                     public void action( GracefulDisconnectContainer container )
                     {
-                        GracefulDisconnect gracefulDisconnect = new GracefulDisconnect();
-                        container.setGracefulDisconnect( gracefulDisconnect );
+                        GracefulDisconnectResponseDecorator gracefulDisconnectResponse = 
+                            new GracefulDisconnectResponseDecorator(
+                                LdapApiServiceFactory.getSingleton(),
+                                new GracefulDisconnectResponseImpl()
+                                );
+                        container.setGracefulDisconnectResponse( gracefulDisconnectResponse );
                         container.setGrammarEndAllowed( true );
                     }
                 } );

Modified: directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulDisconnect/GracefulDisconnectResponseDecorator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulDisconnect/GracefulDisconnectResponseDecorator.java?rev=1579091&r1=1579090&r2=1579091&view=diff
==============================================================================
--- directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulDisconnect/GracefulDisconnectResponseDecorator.java (original)
+++ directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulDisconnect/GracefulDisconnectResponseDecorator.java Tue Mar 18 23:43:55 2014
@@ -21,21 +21,20 @@ package org.apache.directory.api.ldap.ex
 
 
 import java.nio.ByteBuffer;
+import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.directory.api.asn1.DecoderException;
 import org.apache.directory.api.asn1.EncoderException;
-import org.apache.directory.api.asn1.ber.Asn1Decoder;
+import org.apache.directory.api.asn1.ber.tlv.BerValue;
+import org.apache.directory.api.asn1.ber.tlv.TLV;
+import org.apache.directory.api.asn1.ber.tlv.UniversalTag;
 import org.apache.directory.api.i18n.I18n;
 import org.apache.directory.api.ldap.codec.api.ExtendedResponseDecorator;
 import org.apache.directory.api.ldap.codec.api.LdapApiService;
 import org.apache.directory.api.ldap.extras.extended.gracefulDisconnect.GracefulDisconnectResponse;
-import org.apache.directory.api.ldap.extras.extended.gracefulDisconnect.GracefulDisconnectResponseImpl;
-import org.apache.directory.api.ldap.model.exception.LdapURLEncodingException;
 import org.apache.directory.api.ldap.model.message.Referral;
-import org.apache.directory.api.ldap.model.message.ReferralImpl;
-import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
-import org.apache.directory.api.ldap.model.url.LdapUrl;
+import org.apache.directory.api.util.Strings;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -51,6 +50,16 @@ public class GracefulDisconnectResponseD
     /** The logger. */
     private static final Logger LOG = LoggerFactory.getLogger( GracefulDisconnectResponseDecorator.class );
 
+    /** Length of the sequence */
+    private int gracefulDisconnectSequenceLength;
+
+    /** Length of the replicated contexts */
+    private int replicatedContextsLength;
+    
+    /** The encoded LDAP URL list */
+    private List<byte[]> ldapUrlBytes;
+
+    private GracefulDisconnectResponse gracefulDisconnectResponse;
 
     /**
      * Creates a new instance of CancelResponseDecorator.
@@ -61,92 +70,13 @@ public class GracefulDisconnectResponseD
     public GracefulDisconnectResponseDecorator( LdapApiService codec, GracefulDisconnectResponse decoratedMessage )
     {
         super( codec, decoratedMessage );
-        responseValue = null;
-        encodeResponse();
-    }
-
-
-    /**
-     * Creates a new instance of CancelResponseDecorator.
-     *
-     * @param codec
-     * @param responseValue
-     */
-    public GracefulDisconnectResponseDecorator( LdapApiService codec, byte[] responseValue ) throws DecoderException
-    {
-        super( codec, new GracefulDisconnectResponseImpl() );
-        this.responseValue = responseValue;
-        decodeValue();
-    }
-
-
-    private void decodeValue() throws DecoderException
-    {
-        GracefulDisconnectDecoder decoder = new GracefulDisconnectDecoder();
-        org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulDisconnect.GracefulDisconnect codec = null;
-
-        try
-        {
-            codec = ( org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulDisconnect.GracefulDisconnect ) decoder
-                .decode( responseValue );
-            getDecorated().setTimeOffline( codec.getTimeOffline() );
-            getDecorated().setDelay( codec.getDelay() );
-            getDecorated().getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
-            List<LdapUrl> contexts = codec.getReplicatedContexts();
-
-            for ( LdapUrl ldapUrl : contexts )
-            {
-                getDecorated().getLdapResult().getReferral().addLdapUrl( ldapUrl.toString() );
-            }
-        }
-        catch ( DecoderException e )
-        {
-            LOG.error( I18n.err( I18n.ERR_04169 ), e );
-            throw e;
-        }
-    }
-
-
-    private void encodeResponse()
-    {
-        org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulDisconnect.GracefulDisconnect codec =
-            new org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulDisconnect.GracefulDisconnect();
-        codec.setTimeOffline( getDecorated().getTimeOffline() );
-        codec.setDelay( getDecorated().getDelay() );
-
-        for ( String ldapUrlStr : getDecorated().getLdapResult().getReferral().getLdapUrls() )
-        {
-            LdapUrl ldapUrl = null;
-
-            try
-            {
-                ldapUrl = new LdapUrl( ldapUrlStr );
-            }
-            catch ( LdapURLEncodingException e )
-            {
-                LOG.error( I18n.err( I18n.ERR_04170, ldapUrlStr ), e );
-                continue;
-            }
-
-            codec.addReplicatedContexts( ldapUrl );
-        }
-
-        try
-        {
-            super.responseValue = codec.encode().array();
-        }
-        catch ( EncoderException e )
-        {
-            LOG.error( I18n.err( I18n.ERR_04171 ), e );
-            throw new RuntimeException( e );
-        }
+        gracefulDisconnectResponse = decoratedMessage;
     }
 
-
+    
     // ------------------------------------------------------------------------
     // ExtendedResponse Interface Method Implementations
     // ------------------------------------------------------------------------
-
     /**
      * Gets the response OID specific encoded response values.
      * 
@@ -156,12 +86,18 @@ public class GracefulDisconnectResponseD
     {
         if ( responseValue == null )
         {
-            encodeResponse();
+            try
+            {
+                responseValue = encode().array();
+            }
+            catch ( EncoderException e )
+            {
+                LOG.error( I18n.err( I18n.ERR_04164 ), e );
+                throw new RuntimeException( e );
+            }
         }
 
-        final byte[] copy = new byte[responseValue.length];
-        System.arraycopy( responseValue, 0, copy, 0, responseValue.length );
-        return copy;
+        return responseValue;
     }
 
 
@@ -172,41 +108,25 @@ public class GracefulDisconnectResponseD
      */
     public void setResponseValue( byte[] responseValue )
     {
-        if ( responseValue == null )
-        {
-            this.responseValue = null;
-            getDecorated().setDelay( 0 );
-            getDecorated().setTimeOffline( 0 );
-            getDecorated().getLdapResult().setReferral( new ReferralImpl() );
-            return;
-        }
-
-        ByteBuffer bb = ByteBuffer.wrap( responseValue );
-        GracefulDisconnectContainer container = new GracefulDisconnectContainer();
-        Asn1Decoder decoder = new Asn1Decoder();
+        GracefulDisconnectDecoder decoder = new GracefulDisconnectDecoder();
 
         try
         {
-            decoder.decode( bb, container );
+            if ( responseValue != null )
+            {
+                decoder.decode( responseValue );
+                this.responseValue = new byte[responseValue.length];
+                System.arraycopy( responseValue, 0, this.responseValue, 0, responseValue.length );
+            }
+            else
+            {
+                this.responseValue = null;
+            }
         }
         catch ( DecoderException e )
         {
             LOG.error( I18n.err( I18n.ERR_04172 ), e );
         }
-
-        org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulDisconnect.GracefulDisconnect codec = container
-            .getGracefulDisconnect();
-
-        getDecorated().setDelay( codec.getDelay() );
-        getDecorated().setTimeOffline( codec.getTimeOffline() );
-
-        for ( LdapUrl ldapUrl : codec.getReplicatedContexts() )
-        {
-            getDecorated().getLdapResult().getReferral().addLdapUrl( ldapUrl.toString() );
-        }
-
-        this.responseValue = new byte[responseValue.length];
-        System.arraycopy( responseValue, 0, this.responseValue, 0, responseValue.length );
     }
 
 
@@ -215,7 +135,7 @@ public class GracefulDisconnectResponseD
      */
     public int getDelay()
     {
-        return getDecorated().getDelay();
+        return gracefulDisconnectResponse.getDelay();
     }
 
 
@@ -224,7 +144,7 @@ public class GracefulDisconnectResponseD
      */
     public void setDelay( int delay )
     {
-        getDecorated().setDelay( delay );
+        gracefulDisconnectResponse.setDelay( delay );
     }
 
 
@@ -233,7 +153,7 @@ public class GracefulDisconnectResponseD
      */
     public int getTimeOffline()
     {
-        return getDecorated().getTimeOffline();
+        return gracefulDisconnectResponse.getTimeOffline();
     }
 
 
@@ -242,7 +162,7 @@ public class GracefulDisconnectResponseD
      */
     public void setTimeOffline( int timeOffline )
     {
-        getDecorated().setTimeOffline( timeOffline );
+        gracefulDisconnectResponse.setTimeOffline( timeOffline );
     }
 
 
@@ -251,6 +171,147 @@ public class GracefulDisconnectResponseD
      */
     public Referral getReplicatedContexts()
     {
-        return getDecorated().getReplicatedContexts();
+        return gracefulDisconnectResponse.getReplicatedContexts();
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public void addReplicatedContexts( String replicatedContext )
+    {
+        gracefulDisconnectResponse.getReplicatedContexts().addLdapUrl( replicatedContext );
+    }
+
+
+    /**
+     * Compute the GracefulDisconnect length 
+     * 
+     * 0x30 L1 
+     *   | 
+     *   +--> [ 0x02 0x0(1-4) [0..720] ] 
+     *   +--> [ 0x80 0x0(1-3) [0..86400] ] 
+     *   +--> [ 0x30 L2 
+     *           | 
+     *           +--> (0x04 L3 value) + ]
+     */
+    public int computeLength()
+    {
+        gracefulDisconnectSequenceLength = 0;
+
+        if ( gracefulDisconnectResponse.getTimeOffline() != 0 )
+        {
+            gracefulDisconnectSequenceLength += 1 + 1 + BerValue.getNbBytes( gracefulDisconnectResponse.getTimeOffline() );
+        }
+
+        if ( gracefulDisconnectResponse.getDelay() != 0 )
+        {
+            gracefulDisconnectSequenceLength += 1 + 1 + BerValue.getNbBytes( gracefulDisconnectResponse.getDelay() );
+        }
+
+        if ( ( gracefulDisconnectResponse.getReplicatedContexts() != null ) &&
+            ( gracefulDisconnectResponse.getReplicatedContexts().getLdapUrls().size() != 0 ) )
+        {
+            replicatedContextsLength = 0;
+            
+            ldapUrlBytes = new ArrayList<byte[]>( gracefulDisconnectResponse.getReplicatedContexts().getLdapUrls().size() );
+
+            // We may have more than one reference.
+            for ( String replicatedContext : gracefulDisconnectResponse.getReplicatedContexts().getLdapUrls() )
+            {
+                byte[] bytes = Strings.getBytesUtf8( replicatedContext );
+                ldapUrlBytes.add( bytes );
+                int ldapUrlLength = bytes.length;
+                replicatedContextsLength += 1 + TLV.getNbBytes( ldapUrlLength ) + ldapUrlLength;
+            }
+
+            gracefulDisconnectSequenceLength += 1 + TLV.getNbBytes( replicatedContextsLength )
+                + replicatedContextsLength;
+        }
+
+        return 1 + TLV.getNbBytes( gracefulDisconnectSequenceLength ) + gracefulDisconnectSequenceLength;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public ByteBuffer encode() throws EncoderException
+    {
+        // Allocate the bytes buffer.
+        ByteBuffer bb = ByteBuffer.allocate( computeLength() );
+
+        return encode( bb );
+    }
+
+
+    /**
+     * Encodes the gracefulDisconnect extended operation.
+     * 
+     * @return A ByteBuffer that contains the encoded PDU
+     * @throws org.apache.directory.api.asn1.EncoderException If anything goes wrong.
+     */
+    public ByteBuffer encode( ByteBuffer bb ) throws EncoderException
+    {
+        if ( bb == null )
+        {
+            throw new EncoderException( "Null ByteBuffer, cannot encode " + this );
+        }
+
+        bb.put( UniversalTag.SEQUENCE.getValue() );
+        bb.put( TLV.getBytes( gracefulDisconnectSequenceLength ) );
+
+        if ( gracefulDisconnectResponse.getTimeOffline() != 0 )
+        {
+            BerValue.encode( bb, gracefulDisconnectResponse.getTimeOffline() );
+        }
+
+        if ( gracefulDisconnectResponse.getDelay() != 0 )
+        {
+            bb.put( ( byte ) GracefulActionConstants.GRACEFUL_ACTION_DELAY_TAG );
+            bb.put( ( byte ) TLV.getNbBytes( gracefulDisconnectResponse.getDelay() ) );
+            bb.put( BerValue.getBytes( gracefulDisconnectResponse.getDelay() ) );
+        }
+
+        if ( ( gracefulDisconnectResponse.getReplicatedContexts() != null ) &&
+             ( gracefulDisconnectResponse.getReplicatedContexts().getLdapUrls().size() != 0 ) )
+        {
+            bb.put( UniversalTag.SEQUENCE.getValue() );
+            bb.put( TLV.getBytes( replicatedContextsLength ) );
+
+            // We may have more than one reference.
+            for ( byte[] replicatedContext : ldapUrlBytes )
+            {
+                BerValue.encode( bb, replicatedContext );
+            }
+        }
+
+        return bb;
+    }
+
+
+    /**
+     * Return a string representation of the graceful disconnect
+     */
+    public String toString()
+    {
+        StringBuffer sb = new StringBuffer();
+
+        sb.append( "Graceful Disconnect extended operation" );
+        sb.append( "    TimeOffline : " ).append( gracefulDisconnectResponse.getTimeOffline() ).append( '\n' );
+        sb.append( "    Delay : " ).append( gracefulDisconnectResponse.getDelay() ).append( '\n' );
+
+        if ( ( gracefulDisconnectResponse.getReplicatedContexts() != null ) && ( gracefulDisconnectResponse.getReplicatedContexts().getLdapUrls().size() != 0 ) )
+        {
+            sb.append( "    Replicated contexts :" );
+
+            // We may have more than one reference.
+            for ( String url : gracefulDisconnectResponse.getReplicatedContexts().getLdapUrls() )
+            {
+                sb.append( "\n        " ).append( url );
+            }
+        }
+
+        return sb.toString();
     }
 }

Modified: directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulShutdown/GracefulShutdownContainer.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulShutdown/GracefulShutdownContainer.java?rev=1579091&r1=1579090&r2=1579091&view=diff
==============================================================================
--- directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulShutdown/GracefulShutdownContainer.java (original)
+++ directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulShutdown/GracefulShutdownContainer.java Tue Mar 18 23:43:55 2014
@@ -21,6 +21,7 @@ package org.apache.directory.api.ldap.ex
 
 
 import org.apache.directory.api.asn1.ber.AbstractContainer;
+import org.apache.directory.api.ldap.extras.extended.gracefulShutdown.GracefulShutdownRequest;
 
 
 /**
@@ -31,7 +32,7 @@ import org.apache.directory.api.asn1.ber
 public class GracefulShutdownContainer extends AbstractContainer
 {
     /** GracefulShutdown */
-    private GracefulShutdown gracefulShutdown;
+    private GracefulShutdownRequestDecorator gracefulShutdownRequest;
 
 
     /**
@@ -49,9 +50,9 @@ public class GracefulShutdownContainer e
     /**
      * @return Returns the Graceful Shutdown object.
      */
-    public GracefulShutdown getGracefulShutdown()
+    public GracefulShutdownRequestDecorator getGracefulShutdownRequest()
     {
-        return gracefulShutdown;
+        return gracefulShutdownRequest;
     }
 
 
@@ -61,9 +62,9 @@ public class GracefulShutdownContainer e
      * 
      * @param gracefulShutdown the GracefulShutdown to set.
      */
-    public void setGracefulShutdown( GracefulShutdown gracefulShutdown )
+    public void setGracefulShutdownRequest( GracefulShutdownRequestDecorator gracefulShutdown )
     {
-        this.gracefulShutdown = gracefulShutdown;
+        this.gracefulShutdownRequest = gracefulShutdown;
     }
 
 
@@ -73,6 +74,6 @@ public class GracefulShutdownContainer e
     public void clean()
     {
         super.clean();
-        gracefulShutdown = null;
+        gracefulShutdownRequest = null;
     }
 }

Modified: directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulShutdown/GracefulShutdownDecoder.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulShutdown/GracefulShutdownDecoder.java?rev=1579091&r1=1579090&r2=1579091&view=diff
==============================================================================
--- directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulShutdown/GracefulShutdownDecoder.java (original)
+++ directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulShutdown/GracefulShutdownDecoder.java Tue Mar 18 23:43:55 2014
@@ -25,6 +25,7 @@ import java.nio.ByteBuffer;
 import org.apache.directory.api.asn1.Asn1Object;
 import org.apache.directory.api.asn1.DecoderException;
 import org.apache.directory.api.asn1.ber.Asn1Decoder;
+import org.apache.directory.api.ldap.extras.extended.gracefulShutdown.GracefulShutdownRequest;
 
 
 /**
@@ -46,12 +47,12 @@ public class GracefulShutdownDecoder ext
      * @return An GracefulShutdown object
      * @throws org.apache.directory.api.asn1.DecoderException If the decoding failed
      */
-    public Asn1Object decode( byte[] stream ) throws DecoderException
+    public GracefulShutdownRequest decode( byte[] stream ) throws DecoderException
     {
         ByteBuffer bb = ByteBuffer.wrap( stream );
         GracefulShutdownContainer container = new GracefulShutdownContainer();
         decoder.decode( bb, container );
-        GracefulShutdown gracefulShutdown = container.getGracefulShutdown();
+        GracefulShutdownRequestDecorator gracefulShutdown = container.getGracefulShutdownRequest();
 
         // Clean the container for the next decoding
         container.clean();

Modified: directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulShutdown/GracefulShutdownGrammar.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulShutdown/GracefulShutdownGrammar.java?rev=1579091&r1=1579090&r2=1579091&view=diff
==============================================================================
--- directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulShutdown/GracefulShutdownGrammar.java (original)
+++ directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulShutdown/GracefulShutdownGrammar.java Tue Mar 18 23:43:55 2014
@@ -29,7 +29,9 @@ import org.apache.directory.api.asn1.ber
 import org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException;
 import org.apache.directory.api.asn1.ber.tlv.UniversalTag;
 import org.apache.directory.api.i18n.I18n;
+import org.apache.directory.api.ldap.codec.api.LdapApiServiceFactory;
 import org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulDisconnect.GracefulActionConstants;
+import org.apache.directory.api.ldap.extras.extended.gracefulShutdown.GracefulShutdownRequestImpl;
 import org.apache.directory.api.util.Strings;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -88,8 +90,10 @@ public final class GracefulShutdownGramm
                 {
                     public void action( GracefulShutdownContainer container )
                     {
-                        GracefulShutdown gracefulShutdown = new GracefulShutdown();
-                        container.setGracefulShutdown( gracefulShutdown );
+                        GracefulShutdownRequestDecorator gracefulShutdownRequest = new GracefulShutdownRequestDecorator(
+                            LdapApiServiceFactory.getSingleton(),
+                            new GracefulShutdownRequestImpl() );
+                        container.setGracefulShutdownRequest( gracefulShutdownRequest );
                         container.setGrammarEndAllowed( true );
                     }
                 } );
@@ -125,7 +129,7 @@ public final class GracefulShutdownGramm
                                 LOG.debug( "Time Offline = " + timeOffline );
                             }
 
-                            container.getGracefulShutdown().setTimeOffline( timeOffline );
+                            container.getGracefulShutdownRequest().setTimeOffline( timeOffline );
                             container.setGrammarEndAllowed( true );
                         }
                         catch ( IntegerDecoderException e )
@@ -167,7 +171,7 @@ public final class GracefulShutdownGramm
                                 LOG.debug( "Delay = " + delay );
                             }
 
-                            container.getGracefulShutdown().setDelay( delay );
+                            container.getGracefulShutdownRequest().setDelay( delay );
                             container.setGrammarEndAllowed( true );
                         }
                         catch ( IntegerDecoderException e )
@@ -211,7 +215,7 @@ public final class GracefulShutdownGramm
                                 LOG.debug( "Delay = " + delay );
                             }
 
-                            gracefulShutdownContainer.getGracefulShutdown().setDelay( delay );
+                            gracefulShutdownContainer.getGracefulShutdownRequest().setDelay( delay );
                             gracefulShutdownContainer.setGrammarEndAllowed( true );
                         }
                         catch ( IntegerDecoderException e )

Modified: directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulShutdown/GracefulShutdownRequestDecorator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulShutdown/GracefulShutdownRequestDecorator.java?rev=1579091&r1=1579090&r2=1579091&view=diff
==============================================================================
--- directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulShutdown/GracefulShutdownRequestDecorator.java (original)
+++ directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/gracefulShutdown/GracefulShutdownRequestDecorator.java Tue Mar 18 23:43:55 2014
@@ -20,11 +20,18 @@
 package org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulShutdown;
 
 
+import java.nio.ByteBuffer;
+
 import org.apache.directory.api.asn1.DecoderException;
 import org.apache.directory.api.asn1.EncoderException;
+import org.apache.directory.api.asn1.ber.tlv.BerValue;
+import org.apache.directory.api.asn1.ber.tlv.TLV;
+import org.apache.directory.api.asn1.ber.tlv.UniversalTag;
 import org.apache.directory.api.i18n.I18n;
 import org.apache.directory.api.ldap.codec.api.ExtendedRequestDecorator;
 import org.apache.directory.api.ldap.codec.api.LdapApiService;
+import org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulDisconnect.GracefulActionConstants;
+import org.apache.directory.api.ldap.extras.extended.certGeneration.CertGenerationRequest;
 import org.apache.directory.api.ldap.extras.extended.gracefulShutdown.GracefulShutdownRequest;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -40,6 +47,10 @@ public class GracefulShutdownRequestDeco
 {
     private static final Logger LOG = LoggerFactory.getLogger( GracefulShutdownRequestDecorator.class );
 
+    /** Length of the sequence */
+    private int gracefulSequenceLength;
+
+    private GracefulShutdownRequest gracefulShutdownRequest;
 
     /**
      * Creates a new instance of GracefulShutdownRequestDecorator.
@@ -50,6 +61,7 @@ public class GracefulShutdownRequestDeco
     public GracefulShutdownRequestDecorator( LdapApiService codec, GracefulShutdownRequest decoratedMessage )
     {
         super( codec, decoratedMessage );
+        gracefulShutdownRequest = decoratedMessage;
     }
 
 
@@ -62,7 +74,7 @@ public class GracefulShutdownRequestDeco
 
         try
         {
-            GracefulShutdown gs = ( GracefulShutdown ) decoder.decode( requestValue );
+            gracefulShutdownRequest = decoder.decode( requestValue );
 
             if ( requestValue != null )
             {
@@ -73,9 +85,6 @@ public class GracefulShutdownRequestDeco
             {
                 this.requestValue = null;
             }
-
-            setTimeOffline( gs.getTimeOffline() );
-            setDelay( gs.getDelay() );
         }
         catch ( DecoderException e )
         {
@@ -94,10 +103,7 @@ public class GracefulShutdownRequestDeco
         {
             try
             {
-                GracefulShutdown gs = new GracefulShutdown();
-                gs.setDelay( getDecorated().getDelay() );
-                gs.setTimeOffline( getDecorated().getTimeOffline() );
-                requestValue = gs.encode().array();
+                requestValue = encode().array();
             }
             catch ( EncoderException e )
             {
@@ -144,4 +150,90 @@ public class GracefulShutdownRequestDeco
     {
         getDecorated().setTimeOffline( timeOffline );
     }
+
+
+    /**
+     * Compute the GracefulShutdown length 
+     * 0x30 L1 
+     *   | 
+     *   +--> [0x02 0x0(1-4) [0..720] ] 
+     *   +--> [0x80 0x0(1-3) [0..86400] ] 
+     *   
+     * L1 will always be &lt 11.
+     */
+    public int computeLength()
+    {
+        int gracefulLength = 1 + 1;
+        gracefulSequenceLength = 0;
+
+        if ( gracefulShutdownRequest.getTimeOffline() != 0 )
+        {
+            gracefulSequenceLength += 1 + 1 + BerValue.getNbBytes( gracefulShutdownRequest.getTimeOffline() );
+        }
+
+        if ( gracefulShutdownRequest.getDelay() != 0 )
+        {
+            gracefulSequenceLength += 1 + 1 + BerValue.getNbBytes( gracefulShutdownRequest.getDelay() );
+        }
+
+        return gracefulLength + gracefulSequenceLength;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public ByteBuffer encode() throws EncoderException
+    {
+        // Allocate the bytes buffer.
+        ByteBuffer bb = ByteBuffer.allocate( computeLength() );
+
+        return encode( bb );
+    }
+
+
+    /**
+     * Encodes the gracefulShutdown extended operation.
+     * 
+     * @return A ByteBuffer that contains the encoded PDU
+     * @throws org.apache.directory.api.asn1.EncoderException If anything goes wrong.
+     */
+    public ByteBuffer encode( ByteBuffer bb ) throws EncoderException
+    {
+        if ( bb == null )
+        {
+            throw new EncoderException( "Null ByteBuffer, cannot encode " + this );
+        }
+
+        bb.put( UniversalTag.SEQUENCE.getValue() );
+        bb.put( TLV.getBytes( gracefulSequenceLength ) );
+
+        if ( gracefulShutdownRequest.getTimeOffline() != 0 )
+        {
+            BerValue.encode( bb, gracefulShutdownRequest.getTimeOffline() );
+        }
+
+        if ( gracefulShutdownRequest.getDelay() != 0 )
+        {
+            bb.put( ( byte ) GracefulActionConstants.GRACEFUL_ACTION_DELAY_TAG );
+            bb.put( ( byte ) BerValue.getNbBytes( gracefulShutdownRequest.getDelay() ) );
+            bb.put( BerValue.getBytes( gracefulShutdownRequest.getDelay() ) );
+        }
+        return bb;
+    }
+
+
+    /**
+     * Return a string representation of the graceful shutdown
+     */
+    public String toString()
+    {
+        StringBuffer sb = new StringBuffer();
+
+        sb.append( "Graceful Shutdown extended operation" );
+        sb.append( "    TimeOffline : " ).append( gracefulShutdownRequest.getTimeOffline() ).append( '\n' );
+        sb.append( "    Delay : " ).append( gracefulShutdownRequest.getDelay() ).append( '\n' );
+
+        return sb.toString();
+    }
 }

Modified: directory/shared/trunk/ldap/extras/codec/src/test/java/org/apache/directory/api/ldap/extras/extended/ads_impl/CertGenerationRequestTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/extras/codec/src/test/java/org/apache/directory/api/ldap/extras/extended/ads_impl/CertGenerationRequestTest.java?rev=1579091&r1=1579090&r2=1579091&view=diff
==============================================================================
--- directory/shared/trunk/ldap/extras/codec/src/test/java/org/apache/directory/api/ldap/extras/extended/ads_impl/CertGenerationRequestTest.java (original)
+++ directory/shared/trunk/ldap/extras/codec/src/test/java/org/apache/directory/api/ldap/extras/extended/ads_impl/CertGenerationRequestTest.java Tue Mar 18 23:43:55 2014
@@ -29,10 +29,8 @@ import java.nio.ByteBuffer;
 import org.apache.directory.api.asn1.DecoderException;
 import org.apache.directory.api.asn1.EncoderException;
 import org.apache.directory.api.asn1.ber.Asn1Decoder;
-import org.apache.directory.api.ldap.codec.api.LdapApiServiceFactory;
 import org.apache.directory.api.ldap.extras.extended.ads_impl.certGeneration.CertGenerationContainer;
 import org.apache.directory.api.ldap.extras.extended.ads_impl.certGeneration.CertGenerationRequestDecorator;
-import org.apache.directory.api.ldap.extras.extended.certGeneration.CertGenerationRequestImpl;
 import org.apache.directory.api.util.Strings;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -107,9 +105,7 @@ public class CertGenerationRequestTest
             fail( e.getMessage() );
         }
 
-        CertGenerationRequestDecorator req = new CertGenerationRequestDecorator(
-            LdapApiServiceFactory.getSingleton(), new CertGenerationRequestImpl() );
-        req = container.getCertGenerationObject();
+        CertGenerationRequestDecorator req = container.getCertGenerationRequest();
         assertEquals( dn, req.getTargetDN() );
         assertEquals( dn, req.getIssuerDN() );
         assertEquals( dn, req.getSubjectDN() );

Modified: directory/shared/trunk/ldap/extras/codec/src/test/java/org/apache/directory/api/ldap/extras/extended/ads_impl/GracefulDisconnectTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/extras/codec/src/test/java/org/apache/directory/api/ldap/extras/extended/ads_impl/GracefulDisconnectTest.java?rev=1579091&r1=1579090&r2=1579091&view=diff
==============================================================================
--- directory/shared/trunk/ldap/extras/codec/src/test/java/org/apache/directory/api/ldap/extras/extended/ads_impl/GracefulDisconnectTest.java (original)
+++ directory/shared/trunk/ldap/extras/codec/src/test/java/org/apache/directory/api/ldap/extras/extended/ads_impl/GracefulDisconnectTest.java Tue Mar 18 23:43:55 2014
@@ -25,13 +25,15 @@ import static org.junit.Assert.assertTru
 import static org.junit.Assert.fail;
 
 import java.nio.ByteBuffer;
+import java.util.Iterator;
+import java.util.List;
 
 import org.apache.directory.api.asn1.DecoderException;
 import org.apache.directory.api.asn1.EncoderException;
 import org.apache.directory.api.asn1.ber.Asn1Decoder;
-import org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulDisconnect.GracefulDisconnect;
 import org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulDisconnect.GracefulDisconnectContainer;
 import org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulDisconnect.GracefulDisconnectDecoder;
+import org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulDisconnect.GracefulDisconnectResponseDecorator;
 import org.apache.directory.api.util.Strings;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -188,13 +190,14 @@ public class GracefulDisconnectTest
             fail( de.getMessage() );
         }
 
-        GracefulDisconnect gracefulDisconnect = container.getGracefulDisconnect();
+        GracefulDisconnectResponseDecorator gracefulDisconnect = container.getGracefulDisconnectResponse();
         assertEquals( 1, gracefulDisconnect.getTimeOffline() );
         assertEquals( 1, gracefulDisconnect.getDelay() );
-        assertEquals( 2, gracefulDisconnect.getReplicatedContexts().size() );
-        assertEquals( "ldap://directory.apache.org:80/", gracefulDisconnect.getReplicatedContexts().get( 0 ).toString() );
-        assertEquals( "ldap://ldap.netscape.com/o=Babsco,c=US???(int=%5C00%5C00%5C00%5C04)", gracefulDisconnect
-            .getReplicatedContexts().get( 1 ).toString() );
+        assertEquals( 2, gracefulDisconnect.getReplicatedContexts().getLdapUrls().size() );
+        
+        Iterator<String> ldapUrls = gracefulDisconnect.getReplicatedContexts().getLdapUrls().iterator();
+        assertEquals( "ldap://directory.apache.org:80/", ldapUrls.next() );
+        assertEquals( "ldap://ldap.netscape.com/o=Babsco,c=US???(int=%5c00%5c00%5c00%5c04)", ldapUrls.next() );
 
         // Check the length
         assertEquals( 0x70, gracefulDisconnect.computeLength() );
@@ -246,10 +249,10 @@ public class GracefulDisconnectTest
             fail( de.getMessage() );
         }
 
-        GracefulDisconnect gracefulDisconnect = container.getGracefulDisconnect();
+        GracefulDisconnectResponseDecorator gracefulDisconnect = container.getGracefulDisconnectResponse();
         assertEquals( 1, gracefulDisconnect.getTimeOffline() );
         assertEquals( 0, gracefulDisconnect.getDelay() );
-        assertEquals( 0, gracefulDisconnect.getReplicatedContexts().size() );
+        assertEquals( 0, gracefulDisconnect.getReplicatedContexts().getLdapUrls().size() );
 
         // Check the length
         assertEquals( 0x05, gracefulDisconnect.computeLength() );
@@ -302,10 +305,10 @@ public class GracefulDisconnectTest
             fail( de.getMessage() );
         }
 
-        GracefulDisconnect gracefulDisconnect = container.getGracefulDisconnect();
+        GracefulDisconnectResponseDecorator gracefulDisconnect = container.getGracefulDisconnectResponse();
         assertEquals( 0, gracefulDisconnect.getTimeOffline() );
         assertEquals( 1, gracefulDisconnect.getDelay() );
-        assertEquals( 0, gracefulDisconnect.getReplicatedContexts().size() );
+        assertEquals( 0, gracefulDisconnect.getReplicatedContexts().getLdapUrls().size() );
 
         // Check the length
         assertEquals( 0x05, gracefulDisconnect.computeLength() );
@@ -361,10 +364,10 @@ public class GracefulDisconnectTest
             fail( de.getMessage() );
         }
 
-        GracefulDisconnect gracefulDisconnect = container.getGracefulDisconnect();
+        GracefulDisconnectResponseDecorator gracefulDisconnect = container.getGracefulDisconnectResponse();
         assertEquals( 1, gracefulDisconnect.getTimeOffline() );
         assertEquals( 1, gracefulDisconnect.getDelay() );
-        assertEquals( 0, gracefulDisconnect.getReplicatedContexts().size() );
+        assertEquals( 0, gracefulDisconnect.getReplicatedContexts().getLdapUrls().size() );
 
         // Check the length
         assertEquals( 0x08, gracefulDisconnect.computeLength() );
@@ -518,13 +521,14 @@ public class GracefulDisconnectTest
             fail( de.getMessage() );
         }
 
-        GracefulDisconnect gracefulDisconnect = container.getGracefulDisconnect();
+        GracefulDisconnectResponseDecorator gracefulDisconnect = container.getGracefulDisconnectResponse();
         assertEquals( 0, gracefulDisconnect.getTimeOffline() );
         assertEquals( 0, gracefulDisconnect.getDelay() );
-        assertEquals( 2, gracefulDisconnect.getReplicatedContexts().size() );
-        assertEquals( "ldap://directory.apache.org:80/", gracefulDisconnect.getReplicatedContexts().get( 0 ).toString() );
-        assertEquals( "ldap://ldap.netscape.com/o=Babsco,c=US???(int=%5C00%5C00%5C00%5C04)", gracefulDisconnect
-            .getReplicatedContexts().get( 1 ).toString() );
+        assertEquals( 2, gracefulDisconnect.getReplicatedContexts().getLdapUrls().size() );
+        
+        Iterator<String> ldapUrls = gracefulDisconnect.getReplicatedContexts().getLdapUrls().iterator();
+        assertEquals( "ldap://directory.apache.org:80/", ldapUrls.next() );
+        assertEquals( "ldap://ldap.netscape.com/o=Babsco,c=US???(int=%5c00%5c00%5c00%5c04)", ldapUrls.next() );
 
         // Check the length
         assertEquals( 0x6A, gracefulDisconnect.computeLength() );
@@ -573,10 +577,10 @@ public class GracefulDisconnectTest
             fail( de.getMessage() );
         }
 
-        GracefulDisconnect gracefulDisconnect = container.getGracefulDisconnect();
+        GracefulDisconnectResponseDecorator gracefulDisconnect = container.getGracefulDisconnectResponse();
         assertEquals( 0, gracefulDisconnect.getTimeOffline() );
         assertEquals( 0, gracefulDisconnect.getDelay() );
-        assertEquals( 0, gracefulDisconnect.getReplicatedContexts().size() );
+        assertEquals( 0, gracefulDisconnect.getReplicatedContexts().getLdapUrls().size() );
 
         // Check the length
         assertEquals( 0x02, gracefulDisconnect.computeLength() );

Modified: directory/shared/trunk/ldap/extras/codec/src/test/java/org/apache/directory/api/ldap/extras/extended/ads_impl/GracefulShutdownTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/extras/codec/src/test/java/org/apache/directory/api/ldap/extras/extended/ads_impl/GracefulShutdownTest.java?rev=1579091&r1=1579090&r2=1579091&view=diff
==============================================================================
--- directory/shared/trunk/ldap/extras/codec/src/test/java/org/apache/directory/api/ldap/extras/extended/ads_impl/GracefulShutdownTest.java (original)
+++ directory/shared/trunk/ldap/extras/codec/src/test/java/org/apache/directory/api/ldap/extras/extended/ads_impl/GracefulShutdownTest.java Tue Mar 18 23:43:55 2014
@@ -29,8 +29,8 @@ import java.nio.ByteBuffer;
 import org.apache.directory.api.asn1.DecoderException;
 import org.apache.directory.api.asn1.EncoderException;
 import org.apache.directory.api.asn1.ber.Asn1Decoder;
-import org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulShutdown.GracefulShutdown;
 import org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulShutdown.GracefulShutdownContainer;
+import org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulShutdown.GracefulShutdownRequestDecorator;
 import org.apache.directory.api.util.Strings;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -83,17 +83,17 @@ public class GracefulShutdownTest
             fail( de.getMessage() );
         }
 
-        GracefulShutdown gracefulShutdown = container.getGracefulShutdown();
-        assertEquals( 1, gracefulShutdown.getTimeOffline() );
-        assertEquals( 1, gracefulShutdown.getDelay() );
+        GracefulShutdownRequestDecorator gracefulShutdownRequest = container.getGracefulShutdownRequest();
+        assertEquals( 1, gracefulShutdownRequest.getTimeOffline() );
+        assertEquals( 1, gracefulShutdownRequest.getDelay() );
 
         // Check the length
-        assertEquals( 0x08, gracefulShutdown.computeLength() );
+        assertEquals( 0x08, gracefulShutdownRequest.computeLength() );
 
         // Check the encoding
         try
         {
-            ByteBuffer bb1 = gracefulShutdown.encode();
+            ByteBuffer bb1 = gracefulShutdownRequest.encode();
 
             String encodedPdu = Strings.dumpBytes( bb1.array() );
 
@@ -137,17 +137,17 @@ public class GracefulShutdownTest
             fail( de.getMessage() );
         }
 
-        GracefulShutdown gracefulShutdown = container.getGracefulShutdown();
-        assertEquals( 1, gracefulShutdown.getTimeOffline() );
-        assertEquals( 0, gracefulShutdown.getDelay() );
+        GracefulShutdownRequestDecorator gracefulShutdownRequest = container.getGracefulShutdownRequest();
+        assertEquals( 1, gracefulShutdownRequest.getTimeOffline() );
+        assertEquals( 0, gracefulShutdownRequest.getDelay() );
 
         // Check the length
-        assertEquals( 0x05, gracefulShutdown.computeLength() );
+        assertEquals( 0x05, gracefulShutdownRequest.computeLength() );
 
         // Check the encoding
         try
         {
-            ByteBuffer bb1 = gracefulShutdown.encode();
+            ByteBuffer bb1 = gracefulShutdownRequest.encode();
 
             String encodedPdu = Strings.dumpBytes( bb1.array() );
 
@@ -192,17 +192,17 @@ public class GracefulShutdownTest
             fail( de.getMessage() );
         }
 
-        GracefulShutdown gracefulShutdown = container.getGracefulShutdown();
-        assertEquals( 0, gracefulShutdown.getTimeOffline() );
-        assertEquals( 1, gracefulShutdown.getDelay() );
+        GracefulShutdownRequestDecorator gracefulShutdownRequest = container.getGracefulShutdownRequest();
+        assertEquals( 0, gracefulShutdownRequest.getTimeOffline() );
+        assertEquals( 1, gracefulShutdownRequest.getDelay() );
 
         // Check the length
-        assertEquals( 0x05, gracefulShutdown.computeLength() );
+        assertEquals( 0x05, gracefulShutdownRequest.computeLength() );
 
         // Check the encoding
         try
         {
-            ByteBuffer bb1 = gracefulShutdown.encode();
+            ByteBuffer bb1 = gracefulShutdownRequest.encode();
 
             String encodedPdu = Strings.dumpBytes( bb1.array() );
 
@@ -243,17 +243,17 @@ public class GracefulShutdownTest
             fail( de.getMessage() );
         }
 
-        GracefulShutdown gracefulShutdown = container.getGracefulShutdown();
-        assertEquals( 0, gracefulShutdown.getTimeOffline() );
-        assertEquals( 0, gracefulShutdown.getDelay() );
+        GracefulShutdownRequestDecorator gracefulShutdownRequest = container.getGracefulShutdownRequest();
+        assertEquals( 0, gracefulShutdownRequest.getTimeOffline() );
+        assertEquals( 0, gracefulShutdownRequest.getDelay() );
 
         // Check the length
-        assertEquals( 0x02, gracefulShutdown.computeLength() );
+        assertEquals( 0x02, gracefulShutdownRequest.computeLength() );
 
         // Check the encoding
         try
         {
-            ByteBuffer bb1 = gracefulShutdown.encode();
+            ByteBuffer bb1 = gracefulShutdownRequest.encode();
 
             String encodedPdu = Strings.dumpBytes( bb1.array() );
 
@@ -300,17 +300,17 @@ public class GracefulShutdownTest
             fail( de.getMessage() );
         }
 
-        GracefulShutdown gracefulShutdown = container.getGracefulShutdown();
-        assertEquals( 0, gracefulShutdown.getTimeOffline() );
-        assertEquals( 500, gracefulShutdown.getDelay() );
+        GracefulShutdownRequestDecorator gracefulShutdownRequest = container.getGracefulShutdownRequest();
+        assertEquals( 0, gracefulShutdownRequest.getTimeOffline() );
+        assertEquals( 500, gracefulShutdownRequest.getDelay() );
 
         // Check the length
-        assertEquals( 0x06, gracefulShutdown.computeLength() );
+        assertEquals( 0x06, gracefulShutdownRequest.computeLength() );
 
         // Check the encoding
         try
         {
-            ByteBuffer bb1 = gracefulShutdown.encode();
+            ByteBuffer bb1 = gracefulShutdownRequest.encode();
 
             String encodedPdu = Strings.dumpBytes( bb1.array() );
 
@@ -357,17 +357,17 @@ public class GracefulShutdownTest
             fail( de.getMessage() );
         }
 
-        GracefulShutdown gracefulShutdown = container.getGracefulShutdown();
-        assertEquals( 0, gracefulShutdown.getTimeOffline() );
-        assertEquals( 32767, gracefulShutdown.getDelay() );
+        GracefulShutdownRequestDecorator gracefulShutdownRequest = container.getGracefulShutdownRequest();
+        assertEquals( 0, gracefulShutdownRequest.getTimeOffline() );
+        assertEquals( 32767, gracefulShutdownRequest.getDelay() );
 
         // Check the length
-        assertEquals( 0x06, gracefulShutdown.computeLength() );
+        assertEquals( 0x06, gracefulShutdownRequest.computeLength() );
 
         // Check the encoding
         try
         {
-            ByteBuffer bb1 = gracefulShutdown.encode();
+            ByteBuffer bb1 = gracefulShutdownRequest.encode();
 
             String encodedPdu = Strings.dumpBytes( bb1.array() );
 
@@ -417,17 +417,17 @@ public class GracefulShutdownTest
             fail( de.getMessage() );
         }
 
-        GracefulShutdown gracefulShutdown = container.getGracefulShutdown();
-        assertEquals( 0, gracefulShutdown.getTimeOffline() );
-        assertEquals( 32768, gracefulShutdown.getDelay() );
+        GracefulShutdownRequestDecorator gracefulShutdownRequest = container.getGracefulShutdownRequest();
+        assertEquals( 0, gracefulShutdownRequest.getTimeOffline() );
+        assertEquals( 32768, gracefulShutdownRequest.getDelay() );
 
         // Check the length
-        assertEquals( 0x07, gracefulShutdown.computeLength() );
+        assertEquals( 0x07, gracefulShutdownRequest.computeLength() );
 
         // Check the encoding
         try
         {
-            ByteBuffer bb1 = gracefulShutdown.encode();
+            ByteBuffer bb1 = gracefulShutdownRequest.encode();
 
             String encodedPdu = Strings.dumpBytes( bb1.array() );
 



Mime
View raw message