You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2011/01/24 01:25:48 UTC

svn commit: r1062585 - in /directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message: AbstractMessageDecorator.java MessageDecorator.java

Author: akarasulu
Date: Mon Jan 24 00:25:48 2011
New Revision: 1062585

URL: http://svn.apache.org/viewvc?rev=1062585&view=rev
Log:
going to defer adding decorators until after some other steps are complete but for now committing some work towards this

Added:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/AbstractMessageDecorator.java
      - copied, changed from r1062578, directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/AbstractMessage.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/MessageDecorator.java

Copied: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/AbstractMessageDecorator.java (from r1062578, directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/AbstractMessage.java)
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/AbstractMessageDecorator.java?p2=directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/AbstractMessageDecorator.java&p1=directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/AbstractMessage.java&r1=1062578&r2=1062585&rev=1062585&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/AbstractMessage.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/AbstractMessageDecorator.java Mon Jan 24 00:25:48 2011
@@ -20,43 +20,31 @@
 package org.apache.directory.shared.ldap.message;
 
 
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
 import org.apache.directory.shared.ldap.model.exception.MessageException;
 import org.apache.directory.shared.ldap.model.message.Control;
 import org.apache.directory.shared.ldap.model.message.Message;
 import org.apache.directory.shared.ldap.model.message.MessageTypeEnum;
 
+import java.util.Iterator;
+import java.util.Map;
+
 
 /**
- * Abstract message base class.
+ * Abstract message decorator base class.
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public abstract class AbstractMessage implements Message
+public abstract class AbstractMessageDecorator implements Message
 {
     static final long serialVersionUID = 7601738291101182094L;
 
-    /** Map of message controls using OID Strings for keys and Control values */
-    protected final Map<String, Control> controls;
 
-    /** The encoded controls length */
-    private int controlsLength;
-
-    /** The session unique message sequence identifier */
-    private int id;
-
-    /** The message type enumeration */
-    private final MessageTypeEnum type;
+    /** The Message decorated by this decorator */
+    private final Message decoratedMessage;
 
-    /** Transient Message Parameter Hash */
-    private final Map<Object, Object> parameters;
 
-    /** The current control */
-    private Control currentControl;
+    /** The encoded controls length */
+    private int controlsLength;
 
     /** The encoded message length */
     private int messageLength;
@@ -64,16 +52,12 @@ public abstract class AbstractMessage im
 
     /**
      * Completes the instantiation of a Message.
-     * 
-     * @param id the seq id of the message
-     * @param type the type of the message
+     *
+     * @param decoratedMessage the message to be decorated.
      */
-    protected AbstractMessage( final int id, final MessageTypeEnum type )
+    protected AbstractMessageDecorator( Message decoratedMessage )
     {
-        this.id = id;
-        this.type = type;
-        controls = new HashMap<String, Control>();
-        parameters = new HashMap<Object, Object>();
+        this.decoratedMessage = decoratedMessage;
     }
 
 
@@ -82,18 +66,18 @@ public abstract class AbstractMessage im
      * and their responses if any have the same message id. Clients at the
      * initialization of a session start with the first message's id set to 1
      * and increment it with each transaction.
-     * 
+     *
      * @return the session unique message id.
      */
     public int getMessageId()
     {
-        return id;
+        return decoratedMessage.getMessageId();
     }
 
 
     public void setMessageId( int id )
     {
-        this.id = id;
+        decoratedMessage.setMessageId( id );
     }
 
 
@@ -102,7 +86,7 @@ public abstract class AbstractMessage im
      */
     public Map<String, Control> getControls()
     {
-        return Collections.unmodifiableMap( controls );
+        return decoratedMessage.getControls();
     }
 
 
@@ -111,18 +95,18 @@ public abstract class AbstractMessage im
      */
     public Control getControl( String oid )
     {
-        return controls.get( oid );
+        return decoratedMessage.getControl( oid );
     }
 
 
     /**
      * Get the current Control Object
-     * 
+     *
      * @return The current Control Object
      */
     public Control getCurrentControl()
     {
-        return currentControl;
+        return decoratedMessage.getCurrentControl();
     }
 
 
@@ -131,7 +115,7 @@ public abstract class AbstractMessage im
      */
     public boolean hasControl( String oid )
     {
-        return controls.containsKey( oid );
+        return decoratedMessage.hasControl( oid );
     }
 
 
@@ -140,21 +124,20 @@ public abstract class AbstractMessage im
      */
     public void addControl( Control control ) throws MessageException
     {
-        controls.put( control.getOid(), control );
-        currentControl = control;
+        decoratedMessage.addControl( control );
     }
 
 
     /**
      * Deletes a control removing it from this Message.
-     * 
+     *
      * @param control the control to remove.
-     * @throws MessageException if controls cannot be added to this Message or the control is
+     * @throws org.apache.directory.shared.ldap.model.exception.MessageException if controls cannot be added to this Message or the control is
      *             not known etc.
      */
     public void removeControl( Control control ) throws MessageException
     {
-        controls.remove( control.getOid() );
+        decoratedMessage.removeControl( control );
     }
 
 
@@ -167,7 +150,7 @@ public abstract class AbstractMessage im
      */
     public MessageTypeEnum getType()
     {
-        return type;
+        return decoratedMessage.getType();
     }
 
 
@@ -186,7 +169,7 @@ public abstract class AbstractMessage im
      */
     public Object get( Object key )
     {
-        return parameters.get( key );
+        return decoratedMessage.get( key );
     }
 
 
@@ -201,7 +184,7 @@ public abstract class AbstractMessage im
      */
     public Object put( Object key, Object value )
     {
-        return parameters.put( key, value );
+        return decoratedMessage.put( key, value );
     }
 
 
@@ -227,28 +210,28 @@ public abstract class AbstractMessage im
 
         Message msg = ( Message ) obj;
 
-        if ( msg.getMessageId() != id )
+        if ( msg.getMessageId() != decoratedMessage.getMessageId() )
         {
             return false;
         }
 
-        if ( msg.getType() != type )
+        if ( msg.getType() != decoratedMessage.getType() )
         {
             return false;
         }
 
         Map<String, Control> controls = msg.getControls();
 
-        if ( controls.size() != this.controls.size() )
+        if ( controls.size() != decoratedMessage.getControls().size() )
         {
             return false;
         }
 
-        Iterator<String> list = this.controls.keySet().iterator();
+        Iterator<String> list = decoratedMessage.getControls().keySet().iterator();
 
         while ( list.hasNext() )
         {
-            if ( !controls.containsKey( list.next() ) )
+            if ( ! controls.containsKey( list.next() ) )
             {
                 return false;
             }
@@ -265,10 +248,9 @@ public abstract class AbstractMessage im
     public int hashCode()
     {
         int hash = 37;
-        hash = hash * 17 + id;
-        hash = hash * 17 + ( type == null ? 0 : type.hashCode() );
-        hash = hash * 17 + ( parameters == null ? 0 : parameters.hashCode() );
-        hash = hash * 17 + ( controls == null ? 0 : controls.hashCode() );
+        hash = hash * 17 + decoratedMessage.getMessageId();
+        hash = hash * 17 + ( decoratedMessage.getType() == null ? 0 : decoratedMessage.getType().hashCode() );
+        hash = hash * 17 + ( decoratedMessage.getControls() == null ? 0 : decoratedMessage.getControls().hashCode() );
 
         return hash;
     }
@@ -279,17 +261,35 @@ public abstract class AbstractMessage im
      */
     public void addAllControls( Control[] controls ) throws MessageException
     {
-        for ( Control c : controls )
+        decoratedMessage.addAllControls( controls );
+    }
+
+
+    /**
+     * Get a String representation of a LdapMessage
+     * 
+     * @return A LdapMessage String
+     */
+    public String toString()
+    {
+        StringBuilder sb = new StringBuilder();
+
+        if ( decoratedMessage.getControls() != null )
         {
-            this.controls.put( c.getOid(), c );
+            for ( Control control : decoratedMessage.getControls().values() )
+            {
+                sb.append( control );
+            }
         }
+
+        return sb.toString();
     }
 
 
     /**
      * {@inheritDoc}
      */
-    /* No qualifier*/void setControlsLength( int controlsLength )
+    public void setControlsLength( int controlsLength )
     {
         this.controlsLength = controlsLength;
     }
@@ -298,7 +298,7 @@ public abstract class AbstractMessage im
     /**
      * {@inheritDoc}
      */
-    /* No qualifier*/int getControlsLength()
+    public int getControlsLength()
     {
         return controlsLength;
     }
@@ -307,7 +307,7 @@ public abstract class AbstractMessage im
     /**
      * {@inheritDoc}
      */
-    /* No qualifier*/void setMessageLength( int messageLength )
+    public void setMessageLength( int messageLength )
     {
         this.messageLength = messageLength;
     }
@@ -316,29 +316,8 @@ public abstract class AbstractMessage im
     /**
      * {@inheritDoc}
      */
-    /* No qualifier*/int getMessageLength()
+    public int getMessageLength()
     {
         return messageLength;
     }
-
-
-    /**
-     * Get a String representation of a LdapMessage
-     * 
-     * @return A LdapMessage String
-     */
-    public String toString()
-    {
-        StringBuilder sb = new StringBuilder();
-
-        if ( controls != null )
-        {
-            for ( Control control : controls.values() )
-            {
-                sb.append( control );
-            }
-        }
-
-        return sb.toString();
-    }
 }

Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/MessageDecorator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/MessageDecorator.java?rev=1062585&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/MessageDecorator.java (added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/MessageDecorator.java Mon Jan 24 00:25:48 2011
@@ -0,0 +1,58 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.ldap.message;
+
+
+import org.apache.directory.shared.ldap.model.message.Message;
+
+
+/**
+ * Message decorator interface.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public interface MessageDecorator extends Message
+{
+    static final long serialVersionUID = 7601738291101182094L;
+
+
+    /**
+     * @param controlsLength sets the encoded length of the controls
+     */
+    void setControlsLength( int controlsLength );
+
+
+    /**
+     * @return the length of the controls once encoded
+     */
+    int getControlsLength();
+
+
+    /**
+     * @param messageLength sets the encode length of the message
+     */
+    void setMessageLength( int messageLength );
+
+
+    /**
+     * @return the encoded length of the message
+     */
+    int getMessageLength();
+}