directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r983899 - in /directory/shared/branches/shared-codec-merge: asn1/src/main/java/org/apache/directory/shared/asn1/codec/stateful/ ldap/src/main/java/org/apache/directory/shared/ldap/codec/ ldap/src/main/java/org/apache/directory/shared/ldap/m...
Date Tue, 10 Aug 2010 09:05:00 GMT
Author: elecharny
Date: Tue Aug 10 09:04:59 2010
New Revision: 983899

URL: http://svn.apache.org/viewvc?rev=983899&view=rev
Log:
o Removed the useless setEncodeMonitor method
o Removed the useless OutputCallback inner class
o Used the ControlEnum enumeration instead of a static initialization of Control in LdapMessageCodec

Modified:
    directory/shared/branches/shared-codec-merge/asn1/src/main/java/org/apache/directory/shared/asn1/codec/stateful/StatefulEncoder.java
    directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapEncoder.java
    directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageCodec.java
    directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/MessageEncoder.java

Modified: directory/shared/branches/shared-codec-merge/asn1/src/main/java/org/apache/directory/shared/asn1/codec/stateful/StatefulEncoder.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/asn1/src/main/java/org/apache/directory/shared/asn1/codec/stateful/StatefulEncoder.java?rev=983899&r1=983898&r2=983899&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/asn1/src/main/java/org/apache/directory/shared/asn1/codec/stateful/StatefulEncoder.java
(original)
+++ directory/shared/branches/shared-codec-merge/asn1/src/main/java/org/apache/directory/shared/asn1/codec/stateful/StatefulEncoder.java
Tue Aug 10 09:04:59 2010
@@ -48,13 +48,4 @@ public interface StatefulEncoder
      * @param cb the callback to set on the underlying provider specific encoder
      */
     void setCallback( EncoderCallback cb );
-
-
-    /**
-     * Sets the monitor of the underlying implementation.
-     * 
-     * @param monitor the monitor to set on the underlying implementation
-     */
-    void setEncoderMonitor( EncoderMonitor monitor );
-
 }

Modified: directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapEncoder.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapEncoder.java?rev=983899&r1=983898&r2=983899&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapEncoder.java
(original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapEncoder.java
Tue Aug 10 09:04:59 2010
@@ -28,8 +28,6 @@ import java.nio.channels.WritableByteCha
 
 import org.apache.directory.shared.asn1.codec.EncoderException;
 import org.apache.directory.shared.asn1.codec.stateful.EncoderCallback;
-import org.apache.directory.shared.asn1.codec.stateful.EncoderMonitor;
-import org.apache.directory.shared.asn1.codec.stateful.StatefulEncoder;
 import org.apache.directory.shared.i18n.I18n;
 import org.apache.directory.shared.ldap.message.spi.Provider;
 import org.apache.directory.shared.ldap.message.spi.ProviderEncoder;
@@ -55,7 +53,7 @@ public class LdapEncoder implements Prov
 
     /** A speedup for logger */
     private static final boolean IS_DEBUG = log.isDebugEnabled();
-    
+
     /** The associated Provider */
     final Provider provider;
 
@@ -71,7 +69,6 @@ public class LdapEncoder implements Prov
     public LdapEncoder( Provider provider )
     {
         this.provider = provider;
-        encodeCallback = new OutputCallback();
     }
 
 
@@ -92,8 +89,21 @@ public class LdapEncoder implements Prov
                 log.debug( "Encoding this LdapMessage : " + obj );
             }
 
-            ( ( OutputCallback ) encodeCallback ).attach( out );
-            encodeCallback.encodeOccurred( null, ( ( LdapMessageCodec ) obj ).encode() );
+            ByteBuffer encoded = ( ( LdapMessageCodec ) obj ).encode();
+
+            try
+            {
+                ( ( ByteBuffer ) encoded ).flip();
+                WritableByteChannel channel = Channels.newChannel( out );
+                channel.write( ( ByteBuffer ) encoded );
+            }
+            catch ( IOException e )
+            {
+                ProviderException pe = new ProviderException( provider, I18n.err( I18n.ERR_04065,
"", e
+                    .getLocalizedMessage() ) );
+                throw pe;
+            }
+
         }
         catch ( EncoderException e )
         {
@@ -170,7 +180,7 @@ public class LdapEncoder implements Prov
         }
         catch ( EncoderException e )
         {
-            String msg = I18n.err( I18n.ERR_04065,  obj, e.getLocalizedMessage() );
+            String msg = I18n.err( I18n.ERR_04065, obj, e.getLocalizedMessage() );
             log.error( msg );
             ProviderException pe = new ProviderException( provider, msg );
             throw pe;
@@ -201,7 +211,7 @@ public class LdapEncoder implements Prov
         ByteBuffer encoded = encodeBlocking( obj );
         encodeCallback.encodeOccurred( null, encoded );
         //TM long t1 = System.nanoTime();
-        
+
         //TM synchronized (lock)
         //TM {
         //TM     cumul += (t1 - t0);
@@ -226,66 +236,4 @@ public class LdapEncoder implements Prov
     {
         encodeCallback = cb;
     }
-
-
-    /**
-     * Not used ...
-     * 
-     * @deprecated
-     */
-    public void setEncoderMonitor( EncoderMonitor monitor )
-    {
-    }
-
-    /**
-     * The inner class used to write the PDU to a channel.
-     */
-    class OutputCallback implements EncoderCallback
-    {
-        /** The channel in which the PDU will be written */
-        private WritableByteChannel channel = null;
-
-
-        /**
-         * Callback to deliver a fully encoded object.
-         * 
-         * @param encoder the stateful encoder driving the callback
-         * @param encoded the object that was encoded
-         */
-        public void encodeOccurred( StatefulEncoder encoder, Object encoded )
-        {
-            try
-            {
-                ( ( ByteBuffer ) encoded ).flip();
-                channel.write( ( ByteBuffer ) encoded );
-            }
-            catch ( IOException e )
-            {
-                ProviderException pe = new ProviderException( provider, I18n.err( I18n.ERR_04065,
"", e.getLocalizedMessage() ) );
-                throw pe;
-            }
-        }
-
-
-        /**
-         * Associate a channel to the callback
-         * 
-         * @param channel The channel to use to write a PDU
-         */
-        void attach( WritableByteChannel channel )
-        {
-            this.channel = channel;
-        }
-
-
-        /**
-         * Associate a OutputStream to the callback. A channel will be created.
-         * 
-         * @param out The OutputStream to use
-         */
-        void attach( OutputStream out )
-        {
-            this.channel = Channels.newChannel( out );
-        }
-    }
 }

Modified: directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageCodec.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageCodec.java?rev=983899&r1=983898&r2=983899&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageCodec.java
(original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageCodec.java
Tue Aug 10 09:04:59 2010
@@ -23,9 +23,7 @@ package org.apache.directory.shared.ldap
 import java.nio.BufferOverflowException;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
 import org.apache.directory.shared.asn1.AbstractAsn1Object;
 import org.apache.directory.shared.asn1.ber.tlv.TLV;
@@ -34,16 +32,8 @@ import org.apache.directory.shared.asn1.
 import org.apache.directory.shared.asn1.codec.EncoderException;
 import org.apache.directory.shared.i18n.I18n;
 import org.apache.directory.shared.ldap.codec.controls.CodecControl;
-import org.apache.directory.shared.ldap.codec.controls.ManageDsaITControl;
-import org.apache.directory.shared.ldap.codec.controls.replication.syncDoneValue.SyncDoneValueControl;
-import org.apache.directory.shared.ldap.codec.controls.replication.syncInfoValue.SyncInfoValueControl;
-import org.apache.directory.shared.ldap.codec.controls.replication.syncRequestValue.SyncRequestValueControl;
-import org.apache.directory.shared.ldap.codec.controls.replication.syncStateValue.SyncStateValueControl;
-import org.apache.directory.shared.ldap.codec.search.controls.pagedSearch.PagedResultsControl;
-import org.apache.directory.shared.ldap.codec.search.controls.persistentSearch.PersistentSearchControl;
-import org.apache.directory.shared.ldap.codec.search.controls.subentries.SubentriesControl;
+import org.apache.directory.shared.ldap.codec.controls.ControlEnum;
 import org.apache.directory.shared.ldap.message.control.Control;
-import org.apache.directory.shared.ldap.message.control.replication.SynchronizationInfoEnum;
 
 
 /**
@@ -75,45 +65,6 @@ public abstract class LdapMessageCodec e
     /** The controls sequence length */
     private int controlsSequenceLength;
 
-    private static Map<String, Control> codecControls = new HashMap<String, Control>();
-    
-    static
-    {
-        // Initialize the different known Controls
-        Control control = new PersistentSearchControl();
-        codecControls.put( control.getOid(), control );
-
-        control = new ManageDsaITControl();
-        codecControls.put( control.getOid(), control );
-
-        control = new SubentriesControl();
-        codecControls.put( control.getOid(), control );
-
-        control = new PagedResultsControl();
-        codecControls.put( control.getOid(), control );
-        
-        control = new SyncDoneValueControl();
-        codecControls.put( control.getOid(), control );
-        
-        control = new SyncInfoValueControl( SynchronizationInfoEnum.NEW_COOKIE );
-        codecControls.put( control.getOid(), control );
-        
-        control = new SyncInfoValueControl( SynchronizationInfoEnum.REFRESH_DELETE );
-        codecControls.put( control.getOid(), control );
-        
-        control = new SyncInfoValueControl( SynchronizationInfoEnum.REFRESH_PRESENT );
-        codecControls.put( control.getOid(), control );
-        
-        control = new SyncInfoValueControl( SynchronizationInfoEnum.SYNC_ID_SET );
-        codecControls.put( control.getOid(), control );
-        
-        control = new SyncRequestValueControl();
-        codecControls.put( control.getOid(), control );
-        
-        control = new SyncStateValueControl();
-        codecControls.put( control.getOid(), control );
-    }
-
 
     // ~ Constructors
     // -------------------------------------------------------------------------------
@@ -170,11 +121,11 @@ public abstract class LdapMessageCodec e
     {
         return currentControl;
     }
-    
-    
+
+
     public Control getCodecControl( String oid )
     {
-        return codecControls.get( oid );
+        return ControlEnum.getControl( oid );
     }
 
 
@@ -186,12 +137,12 @@ public abstract class LdapMessageCodec e
     public void addControl( Control control )
     {
         currentControl = control;
-        
+
         if ( controls == null )
         {
             controls = new ArrayList<Control>();
         }
-        
+
         controls.add( control );
     }
 
@@ -204,17 +155,17 @@ public abstract class LdapMessageCodec e
      */
     public void addControls( List<Control> controls )
     {
-        if( this.controls == null )
+        if ( this.controls == null )
         {
             this.controls = controls;
         }
-        else if( controls != null )
+        else if ( controls != null )
         {
             this.controls.addAll( controls );
         }
     }
-    
-    
+
+
     /**
      * Init the controls array
      */
@@ -261,10 +212,10 @@ public abstract class LdapMessageCodec e
      */
     public abstract String getMessageTypeName();
 
-    
+
     protected abstract int computeLengthProtocolOp();
 
-    
+
     /**
      * Compute the LdapMessage length LdapMessage : 
      * 0x30 L1 
@@ -316,15 +267,15 @@ public abstract class LdapMessageCodec e
             controlsSequenceLength = 0;
 
             // We may have more than one control. ControlsLength is L4.
-            for ( Control control:controls )
+            for ( Control control : controls )
             {
-                controlsSequenceLength += ((CodecControl)control).computeLength();
+                controlsSequenceLength += ( ( CodecControl ) control ).computeLength();
             }
 
             // Computes the controls length
             controlsLength = controlsSequenceLength; // 1 + Length.getNbBytes(
-                                                     // controlsSequenceLength
-                                                     // ) + controlsSequenceLength;
+            // controlsSequenceLength
+            // ) + controlsSequenceLength;
 
             // Now, add the tag and the length of the controls length
             ldapMessageLength += 1 + TLV.getNbBytes( controlsSequenceLength ) + controlsSequenceLength;
@@ -336,9 +287,10 @@ public abstract class LdapMessageCodec e
         return 1 + ldapMessageLength + TLV.getNbBytes( ldapMessageLength );
     }
 
-    
+
     protected abstract void encodeProtocolOp( ByteBuffer buffer ) throws EncoderException;
 
+
     /**
      * Generate the PDU which contains the encoded object. 
      * 
@@ -366,15 +318,15 @@ public abstract class LdapMessageCodec e
     public ByteBuffer encode() throws EncoderException
     {
         try
-        {     
+        {
             // Allocate the bytes buffer.
             ByteBuffer bb = ByteBuffer.allocate( computeLength() );
-    
+
             try
             {
                 // The LdapMessage Sequence
                 bb.put( UniversalTag.SEQUENCE_TAG );
-    
+
                 // The length has been calculated by the computeLength method
                 bb.put( TLV.getBytes( ldapMessageLength ) );
             }
@@ -382,33 +334,33 @@ public abstract class LdapMessageCodec e
             {
                 throw new EncoderException( I18n.err( I18n.ERR_04005 ) );
             }
-    
+
             // The message Id
             Value.encode( bb, messageId );
-    
+
             // Add the protocolOp part
             encodeProtocolOp( bb );
-    
+
             // Do the same thing for Controls, if any.
             if ( controls != null )
             {
                 // Encode the controls
                 bb.put( ( byte ) LdapConstants.CONTROLS_TAG );
                 bb.put( TLV.getBytes( controlsLength ) );
-    
+
                 // Encode each control
-                for ( Control control:controls )
+                for ( Control control : controls )
                 {
-                    ((CodecControl)control).encode( bb );
+                    ( ( CodecControl ) control ).encode( bb );
                 }
             }
-    
+
             return bb;
         }
         catch ( EncoderException ee )
         {
             MessageEncoderException exception = new MessageEncoderException( messageId, ee.getMessage()
);
-            
+
             throw exception;
         }
     }
@@ -425,12 +377,12 @@ public abstract class LdapMessageCodec e
 
         sb.append( "LdapMessage\n" );
         sb.append( "    message Id : " ).append( messageId ).append( '\n' );
-        
+
         sb.append( protocolOp ).append( '\n' );
 
         if ( controls != null )
         {
-            for ( Control control:controls )
+            for ( Control control : controls )
             {
                 sb.append( control );
             }

Modified: directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/MessageEncoder.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/MessageEncoder.java?rev=983899&r1=983898&r2=983899&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/MessageEncoder.java
(original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/MessageEncoder.java
Tue Aug 10 09:04:59 2010
@@ -25,7 +25,6 @@ import java.nio.ByteBuffer;
 
 import org.apache.directory.shared.asn1.codec.EncoderException;
 import org.apache.directory.shared.asn1.codec.stateful.EncoderCallback;
-import org.apache.directory.shared.asn1.codec.stateful.EncoderMonitor;
 import org.apache.directory.shared.ldap.codec.LdapTransformer;
 import org.apache.directory.shared.ldap.message.internal.InternalMessage;
 import org.apache.directory.shared.ldap.message.spi.Provider;
@@ -136,15 +135,4 @@ public final class MessageEncoder implem
     {
         this.encoder.setCallback( cb );
     }
-
-
-    /**
-     * Sets the monitor of the underlying implementation.
-     * 
-     * @param monitor the monitor to set on the underlying implementation
-     */
-    public void setEncoderMonitor( EncoderMonitor monitor )
-    {
-        this.encoder.setEncoderMonitor( monitor );
-    }
 }



Mime
View raw message