directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r1063965 - /directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/
Date Thu, 27 Jan 2011 02:48:06 GMT
Author: akarasulu
Date: Thu Jan 27 02:48:06 2011
New Revision: 1063965

URL: http://svn.apache.org/viewvc?rev=1063965&view=rev
Log:
code cleanup after extracting interfacce

Modified:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/EntryChangeContainer.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/EntryChangeDecoder.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/EntryChangeDecorator.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/EntryChangeGrammar.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/EntryChangeStates.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/SimpleEntryChange.java

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/EntryChangeContainer.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/EntryChangeContainer.java?rev=1063965&r1=1063964&r2=1063965&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/EntryChangeContainer.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/EntryChangeContainer.java
Thu Jan 27 02:48:06 2011
@@ -46,6 +46,20 @@ public class EntryChangeContainer extend
 
 
     /**
+     * Creates a container with decorator, optionally decorating the supplied
+     * Control if it is not a decorator implementation.
+     *
+     * @param control The EntryChange ControlDecorator, or a Control to be
+     * wrapped by a new decorator.
+     */
+    public EntryChangeContainer( EntryChange control )
+    {
+        this();
+        decorate( control );
+    }
+
+
+    /**
      * @return Returns the EntryChangeControl.
      */
     public EntryChangeDecorator getEntryChangeDecorator()
@@ -55,6 +69,27 @@ public class EntryChangeContainer extend
 
 
     /**
+     * Checks to see if the supplied EntryChange implementation is a decorator
+     * and if so just sets the EntryChangeDecorator to it. Otherwise the supplied
+     * control is decorated by creating a new EntryChangeDecorator to wrap the
+     * object.
+     *
+     * @param control The EntryChange Control to wrap, if it is not a decorator.
+     */
+    public void decorate( EntryChange control )
+    {
+        if ( control instanceof EntryChangeDecorator )
+        {
+            this.control = ( EntryChangeDecorator ) control;
+        }
+        else
+        {
+            this.control = new EntryChangeDecorator( control );
+        }
+    }
+
+
+    /**
      * Set a EntryChangeControl Object into the container. It will be completed
      * by the ldapDecoder.
      * 
@@ -65,6 +100,7 @@ public class EntryChangeContainer extend
         this.control = control;
     }
 
+
     /**
      * Clean the container
      */

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/EntryChangeDecoder.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/EntryChangeDecoder.java?rev=1063965&r1=1063964&r2=1063965&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/EntryChangeDecoder.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/EntryChangeDecoder.java
Thu Jan 27 02:48:06 2011
@@ -39,6 +39,7 @@ public class EntryChangeDecoder extends 
     /** An instance of this decoder */
     private static final Asn1Decoder decoder = new Asn1Decoder();
 
+
     /**
      * Decode the entry change control
      * 
@@ -48,12 +49,10 @@ public class EntryChangeDecoder extends 
      * 
      * @throws DecoderException If the decoding found an error
      */
-    
     public Asn1Object decode( byte[] controlBytes, Control control ) throws DecoderException
     {
         ByteBuffer bb = ByteBuffer.wrap( controlBytes );
-        EntryChangeContainer container = new EntryChangeContainer();
-        container.setEntryChangeDecorator( ( EntryChangeDecorator ) control );
+        EntryChangeContainer container = new EntryChangeContainer( ( EntryChangeDecorator
) control );
         decoder.decode( bb, container );
         return container.getEntryChangeDecorator();
     }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/EntryChangeDecorator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/EntryChangeDecorator.java?rev=1063965&r1=1063964&r2=1063965&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/EntryChangeDecorator.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/EntryChangeDecorator.java
Thu Jan 27 02:48:06 2011
@@ -53,7 +53,8 @@ public class EntryChangeDecorator extend
 
 
     /**
-     * Creates a new instance of EntryChangeControl.
+     * Creates a new instance of EntryChangeDecoder wrapping a newly created
+     * EntryChange Control object.
      */
     public EntryChangeDecorator()
     {
@@ -61,6 +62,23 @@ public class EntryChangeDecorator extend
     }
 
 
+    /**
+     * Creates a new instance of EntryChangeDecorator wrapping the supplied
+     * EntryChange Control.
+     *
+     * @param control The EntryChange Control to be decorated.
+     */
+    public EntryChangeDecorator( EntryChange control )
+    {
+        super( control, new EntryChangeDecoder() );
+    }
+
+
+    /**
+     * Internally used to not have to cast the decorated Control.
+     *
+     * @return the decorated Control.
+     */
     private EntryChange getEntryChange()
     {
         return ( EntryChange ) getDecorated();
@@ -83,15 +101,15 @@ public class EntryChangeDecorator extend
         int previousDnLength = 0;
         int changeNumberLength = 0;
 
-        if ( getEntryChange().getPreviousDn() != null )
+        if ( getPreviousDn() != null )
         {
-            previousDnBytes = Strings.getBytesUtf8( getEntryChange().getPreviousDn().getName()
);
+            previousDnBytes = Strings.getBytesUtf8( getPreviousDn().getName() );
             previousDnLength = 1 + TLV.getNbBytes( previousDnBytes.length ) + previousDnBytes.length;
         }
 
-        if ( getEntryChange().getChangeNumber() != UNDEFINED_CHANGE_NUMBER )
+        if ( getChangeNumber() != UNDEFINED_CHANGE_NUMBER )
         {
-            changeNumberLength = 1 + 1 + Value.getNbBytes( getEntryChange().getChangeNumber()
);
+            changeNumberLength = 1 + 1 + Value.getNbBytes( getChangeNumber() );
         }
 
         eccSeqLength = changeTypesLength + previousDnLength + changeNumberLength;
@@ -128,16 +146,16 @@ public class EntryChangeDecorator extend
 
         buffer.put( UniversalTag.ENUMERATED.getValue() );
         buffer.put( ( byte ) 1 );
-        buffer.put( Value.getBytes( getEntryChange().getChangeType().getValue() ) );
+        buffer.put( Value.getBytes( getChangeType().getValue() ) );
 
-        if ( getEntryChange().getPreviousDn() != null )
+        if ( getPreviousDn() != null )
         {
             Value.encode( buffer, previousDnBytes );
         }
 
-        if ( getEntryChange().getChangeNumber() != UNDEFINED_CHANGE_NUMBER )
+        if ( getChangeNumber() != UNDEFINED_CHANGE_NUMBER )
         {
-            Value.encode( buffer, getEntryChange().getChangeNumber() );
+            Value.encode( buffer, getChangeNumber() );
         }
 
         return buffer;
@@ -161,16 +179,16 @@ public class EntryChangeDecorator extend
 
                 buffer.put( UniversalTag.ENUMERATED.getValue() );
                 buffer.put( ( byte ) 1 );
-                buffer.put( Value.getBytes( getEntryChange().getChangeType().getValue() )
);
+                buffer.put( Value.getBytes( getChangeType().getValue() ) );
 
-                if ( getEntryChange().getPreviousDn() != null )
+                if ( getPreviousDn() != null )
                 {
                     Value.encode( buffer, previousDnBytes );
                 }
 
-                if ( getEntryChange().getChangeNumber() != UNDEFINED_CHANGE_NUMBER )
+                if ( getChangeNumber() != UNDEFINED_CHANGE_NUMBER )
                 {
-                    Value.encode( buffer, getEntryChange().getChangeNumber() );
+                    Value.encode( buffer, getChangeNumber() );
                 }
 
                 getDecorated().setValue( buffer.array() );
@@ -185,38 +203,56 @@ public class EntryChangeDecorator extend
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public ChangeType getChangeType ()
     {
         return getEntryChange().getChangeType();
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public void setChangeType ( ChangeType changeType )
     {
         getEntryChange().setChangeType( changeType );
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public Dn getPreviousDn ()
     {
         return getEntryChange().getPreviousDn();
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public void setPreviousDn ( Dn previousDn )
     {
         getEntryChange().setPreviousDn( previousDn );
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public long getChangeNumber ()
     {
         return getEntryChange().getChangeNumber();
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public void setChangeNumber ( long changeNumber )
     {
-        setChangeNumber( changeNumber );
+        getEntryChange().setChangeNumber( changeNumber );
     }
 }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/EntryChangeGrammar.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/EntryChangeGrammar.java?rev=1063965&r1=1063964&r2=1063965&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/EntryChangeGrammar.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/EntryChangeGrammar.java
Thu Jan 27 02:48:06 2011
@@ -113,8 +113,7 @@ public final class EntryChangeGrammar ex
                                 LOG.debug( "changeType = " + changeType );
                             }
 
-                            ( (EntryChange) entryChangeContainer.getEntryChangeDecorator().getDecorated()
)
-                                    .setChangeType( changeType );
+                            entryChangeContainer.getEntryChangeDecorator().setChangeType(
changeType );
                             break;
 
                         default:
@@ -159,9 +158,7 @@ public final class EntryChangeGrammar ex
             {
                 EntryChangeContainer entryChangeContainer = ( EntryChangeContainer ) container;
 
-                EntryChange entryChange = (EntryChange) entryChangeContainer
-                        .getEntryChangeDecorator().getDecorated();
-                ChangeType changeType = entryChange.getChangeType();
+                ChangeType changeType = entryChangeContainer.getEntryChangeDecorator().getChangeType();
 
 
                 if ( changeType != ChangeType.MODDN )
@@ -189,7 +186,7 @@ public final class EntryChangeGrammar ex
                         LOG.debug( "previousDN = " + previousDn );
                     }
 
-                    entryChange.setPreviousDn( previousDn );
+                    entryChangeContainer.getEntryChangeDecorator().setPreviousDn( previousDn
);
 
                     // We can have an END transition
                     entryChangeContainer.setGrammarEndAllowed( true );
@@ -214,9 +211,7 @@ public final class EntryChangeGrammar ex
                         LOG.debug( "changeNumber = " + changeNumber );
                     }
 
-                    EntryChange entryChange = (EntryChange) entryChangeContainer
-                            .getEntryChangeDecorator().getDecorated();
-                    entryChange.setChangeNumber( changeNumber );
+                    entryChangeContainer.getEntryChangeDecorator().setChangeNumber( changeNumber
);
 
                     // We can have an END transition
                     entryChangeContainer.setGrammarEndAllowed( true );

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/EntryChangeStates.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/EntryChangeStates.java?rev=1063965&r1=1063964&r2=1063965&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/EntryChangeStates.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/EntryChangeStates.java
Thu Jan 27 02:48:06 2011
@@ -60,13 +60,13 @@ public enum EntryChangeStates implements
     /** terminal state */
     LAST_EC_STATE;
 
+
     /**
      * Get the grammar name
      * 
-     * @param grammar The grammar code
      * @return The grammar name
      */
-    public String getGrammarName( int grammar )
+    public String getGrammarName()
     {
         return "EC_GRAMMAR";
     }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/SimpleEntryChange.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/SimpleEntryChange.java?rev=1063965&r1=1063964&r2=1063965&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/SimpleEntryChange.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/SimpleEntryChange.java
Thu Jan 27 02:48:06 2011
@@ -70,7 +70,7 @@ public class SimpleEntryChange extends B
     }
 
 
-    public void setPreviousDn(Dn previousDn)
+    public void setPreviousDn( Dn previousDn )
     {
         this.previousDn = previousDn;
     }



Mime
View raw message