You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by se...@apache.org on 2010/11/27 14:24:08 UTC

svn commit: r1039676 - in /directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec: LdapMessageGrammar.java controls/ControlEnum.java controls/ControlFactory.java controls/replication/syncInfoValue/SyncInfoValueControl.java

Author: seelmann
Date: Sat Nov 27 13:24:08 2010
New Revision: 1039676

URL: http://svn.apache.org/viewvc?rev=1039676&view=rev
Log:
Fix for DIRSERVER-1585:
- removed ControlEnum
- added ControlFactory which always creates a new Control instance
- added default constructor to SyncInfoValueControl to be able to create an instance from ControlFactory
- simplyfied LdapMessageGrammar as ControlFactory never returns null


Added:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ControlFactory.java
Removed:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ControlEnum.java
Modified:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageGrammar.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueControl.java

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageGrammar.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageGrammar.java?rev=1039676&r1=1039675&r2=1039676&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageGrammar.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageGrammar.java Sat Nov 27 13:24:08 2010
@@ -70,8 +70,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.codec.actions.StoreReferenceAction;
 import org.apache.directory.shared.ldap.codec.actions.StoreTypeMatchingRuleAction;
 import org.apache.directory.shared.ldap.codec.actions.ValueAction;
-import org.apache.directory.shared.ldap.codec.controls.ControlEnum;
-import org.apache.directory.shared.ldap.codec.controls.ControlImpl;
+import org.apache.directory.shared.ldap.codec.controls.ControlFactory;
 import org.apache.directory.shared.ldap.codec.search.ExtensibleMatchFilter;
 import org.apache.directory.shared.ldap.codec.search.SubstringFilter;
 import org.apache.directory.shared.ldap.exception.LdapException;
@@ -3450,13 +3449,7 @@ public final class LdapMessageGrammar ex
 
                     Message message = ldapMessageContainer.getMessage();
 
-                    Control control = ControlEnum.getControl( oidValue );
-
-                    if ( control == null )
-                    {
-                        // This control is unknown, we will create a neutral control
-                        control = new ControlImpl( oidValue );
-                    }
+                    Control control = ControlFactory.createControl( oidValue );
 
                     message.addControl( control );
 

Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ControlFactory.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ControlFactory.java?rev=1039676&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ControlFactory.java (added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ControlFactory.java Sat Nov 27 13:24:08 2010
@@ -0,0 +1,107 @@
+/*
+ *  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.codec.controls;
+
+
+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.message.control.Control;
+
+
+/**
+ * A factory for Controls.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ControlFactory
+{
+
+    /**
+     * Creates a new Control instance. If the OID of a known control is provided
+     * a concrete Control instance is returned, otherwise an instance of 
+     * ControlImpl is returned. The following Controls are known:
+     * <ul>
+     * <li>ManageDsaITControl</li>
+     * <li>PagedResultsControl</li>
+     * <li>PersistentSearchControl</li>
+     * <li>SubentriesControl</li>
+     * <li>SyncDoneValueControl</li>
+     * <li>SyncInfoValueControl</li>
+     * <li>SyncRequestValueControl</li>
+     * <li>SyncStateValueControl</li>
+     * </ul>
+     * 
+     * Note that the created Control is empty, criticality and value are not set.
+     * Some Controls also need additional initialization.
+     *
+     * @param oid the control OID
+     * @return the control instance
+     */
+    public static Control createControl( String oid )
+    {
+        if ( ManageDsaITControl.CONTROL_OID.equals( oid ) )
+        {
+            return new ManageDsaITControl();
+        }
+
+        if ( PagedResultsControl.CONTROL_OID.equals( oid ) )
+        {
+            return new PagedResultsControl();
+        }
+
+        if ( PersistentSearchControl.CONTROL_OID.equals( oid ) )
+        {
+            return new PersistentSearchControl();
+        }
+
+        if ( SubentriesControl.CONTROL_OID.equals( oid ) )
+        {
+            return new SubentriesControl();
+        }
+
+        if ( SyncDoneValueControl.CONTROL_OID.equals( oid ) )
+        {
+            return new SyncDoneValueControl();
+        }
+
+        if ( SyncInfoValueControl.CONTROL_OID.equals( oid ) )
+        {
+            return new SyncInfoValueControl();
+        }
+
+        if ( SyncRequestValueControl.CONTROL_OID.equals( oid ) )
+        {
+            return new SyncRequestValueControl();
+        }
+
+        if ( SyncStateValueControl.CONTROL_OID.equals( oid ) )
+        {
+            return new SyncStateValueControl();
+        }
+
+        // This control is unknown, we will create a neutral control
+        return new ControlImpl( oid );
+    }
+}

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueControl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueControl.java?rev=1039676&r1=1039675&r2=1039676&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueControl.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueControl.java Sat Nov 27 13:24:08 2010
@@ -63,22 +63,26 @@ public class SyncInfoValueControl extend
     
     
     /**
+     * The constructor for this codec. Dont't forget to set the type.
+     */
+    public SyncInfoValueControl()
+    {
+        super( CONTROL_OID );
+        
+        decoder = new SyncInfoValueControlDecoder();
+    }
+    
+    
+    /**
      * The constructor for this codec.
      * @param type The kind of syncInfo we will store. Can be newCookie, 
      * refreshPresent, refreshDelete or syncIdSet
      */
     public SyncInfoValueControl( SynchronizationInfoEnum type )
     {
-        super( CONTROL_OID );
+        this();
 
-        decoder = new SyncInfoValueControlDecoder();
-        this.type = type;
-        
-        // Initialize the arrayList if needed
-        if ( type == SynchronizationInfoEnum.SYNC_ID_SET )
-        {
-            syncUUIDs = new ArrayList<byte[]>();
-        }
+        setType( type);
     }
     
     
@@ -102,6 +106,12 @@ public class SyncInfoValueControl extend
     public void setType( SynchronizationInfoEnum type )
     {
         this.type = type;
+
+        // Initialize the arrayList if needed
+        if ( type == SynchronizationInfoEnum.SYNC_ID_SET && syncUUIDs == null )
+        {
+            syncUUIDs = new ArrayList<byte[]>();
+        }
     }