directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r826175 - in /directory/shared/branches/shared-schema/ldap/src: main/java/org/apache/directory/shared/ldap/schema/registries/ test/java/org/apache/directory/shared/ldap/schema/registries/
Date Sat, 17 Oct 2009 04:19:23 GMT
Author: elecharny
Date: Sat Oct 17 04:19:20 2009
New Revision: 826175

URL: http://svn.apache.org/viewvc?rev=826175&view=rev
Log:
Added some more clone methods

Added:
    directory/shared/branches/shared-schema/ldap/src/test/java/org/apache/directory/shared/ldap/schema/registries/
    directory/shared/branches/shared-schema/ldap/src/test/java/org/apache/directory/shared/ldap/schema/registries/AttributeTypeRegistryTest.java
    directory/shared/branches/shared-schema/ldap/src/test/java/org/apache/directory/shared/ldap/schema/registries/OidRegistryTest.java
Modified:
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/AttributeTypeRegistry.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/OidRegistry.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/SchemaObjectRegistry.java

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/AttributeTypeRegistry.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/AttributeTypeRegistry.java?rev=826175&r1=826174&r2=826175&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/AttributeTypeRegistry.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/AttributeTypeRegistry.java
Sat Oct 17 04:19:20 2009
@@ -21,11 +21,11 @@
 
 
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
 
 import javax.naming.NamingException;
 import javax.naming.directory.NoSuchAttributeException;
@@ -46,7 +46,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class AttributeTypeRegistry extends SchemaObjectRegistry<AttributeType>
+public class AttributeTypeRegistry extends SchemaObjectRegistry<AttributeType> implements
Cloneable
 {
     /** static class logger */
     private static final Logger LOG = LoggerFactory.getLogger( AttributeTypeRegistry.class
);
@@ -58,7 +58,7 @@
     private transient Map<String, OidNormalizer> oidNormalizerMap;
     
     /** maps OIDs to a Set of descendants for that OID */
-    private final Map<String,Set<AttributeType>> oidToDescendantSet;
+    private Map<String,Set<AttributeType>> oidToDescendantSet;
 
     
     /**
@@ -67,8 +67,8 @@
     public AttributeTypeRegistry( OidRegistry oidRegistry )
     {
         super( SchemaObjectType.ATTRIBUTE_TYPE, oidRegistry );
-        oidNormalizerMap = new ConcurrentHashMap<String, OidNormalizer>();
-        oidToDescendantSet= new ConcurrentHashMap<String,Set<AttributeType>>();
+        oidNormalizerMap = new HashMap<String, OidNormalizer>();
+        oidToDescendantSet = new HashMap<String,Set<AttributeType>>();
     }
     
     
@@ -344,8 +344,28 @@
         }
     }
     
+    /**
+     * @see Object#toString()
+     */
     public String toString()
     {
         return byName.toString();
     }
+    
+    
+    /**
+     * Clone the AttributeTypeRegistry
+     */
+    public AttributeTypeRegistry clone() throws CloneNotSupportedException
+    {
+        AttributeTypeRegistry clone = (AttributeTypeRegistry)super.clone();
+        
+        // Clone the oidNormalizerMap (will be empty)
+        clone.oidNormalizerMap = new HashMap<String, OidNormalizer>();
+        
+        // Clone the oidToDescendant map (will be empty)
+        clone.oidToDescendantSet = new HashMap<String,Set<AttributeType>>();
+
+        return clone;
+    }
 }

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/OidRegistry.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/OidRegistry.java?rev=826175&r1=826174&r2=826175&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/OidRegistry.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/OidRegistry.java
Sat Oct 17 04:19:20 2009
@@ -21,6 +21,7 @@
 
 
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -42,7 +43,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class OidRegistry
+public class OidRegistry implements Cloneable
 {
     /** static class logger */
     private static final Logger LOG = LoggerFactory.getLogger( OidRegistry.class );
@@ -233,4 +234,27 @@
             LOG.debug( "Unregisted SchemaObject '{}' with OID: {}", removed, oid );
         }
     }
+    
+    
+    /**
+     * Clone the OidRegistry, and all the contained values
+     * 
+     * @return A new OidRegistry instance
+     */
+    public OidRegistry clone() throws CloneNotSupportedException
+    {
+        OidRegistry clone = (OidRegistry)super.clone();
+        
+        clone.byOid = new HashMap<String,SchemaObject>();
+        
+        // Clone the byOid Map
+        for ( String key : byOid.keySet() )
+        {
+            // Clone each SchemaObject
+            SchemaObject value = byOid.get( key );
+            clone.byOid.put( key, value.clone() );
+        }
+        
+        return clone;
+    }
 }

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/SchemaObjectRegistry.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/SchemaObjectRegistry.java?rev=826175&r1=826174&r2=826175&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/SchemaObjectRegistry.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/SchemaObjectRegistry.java
Sat Oct 17 04:19:20 2009
@@ -20,9 +20,9 @@
 package org.apache.directory.shared.ldap.schema.registries;
 
 
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
 
 import javax.naming.NamingException;
 
@@ -40,7 +40,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class SchemaObjectRegistry<T extends SchemaObject> implements Iterable<T>
+public class SchemaObjectRegistry<T extends SchemaObject> implements Iterable<T>,
Cloneable
 {
     /** static class logger */
     private static final Logger LOG = LoggerFactory.getLogger( SchemaObjectRegistry.class
);
@@ -49,13 +49,13 @@
     private static final boolean DEBUG = LOG.isDebugEnabled();
     
     /** a map of SchemaObject looked up by name */
-    protected final Map<String, T> byName;
+    protected Map<String, T> byName;
     
     /** The SchemaObject type */
     protected SchemaObjectType type;
 
     /** the global OID Registry */
-    protected final OidRegistry oidRegistry;
+    protected OidRegistry oidRegistry;
     
 
     /**
@@ -63,7 +63,7 @@
      */
     protected SchemaObjectRegistry( SchemaObjectType schemaObjectType, OidRegistry oidRegistry
)
     {
-        byName = new ConcurrentHashMap<String, T>();
+        byName = new HashMap<String, T>();
         type = schemaObjectType;
         this.oidRegistry = oidRegistry;
     }
@@ -365,4 +365,29 @@
 
         return true;
     }
+    
+
+    /**
+     * Clone a SchemaObjectRegistry
+     */
+    protected SchemaObjectRegistry<T> clone() throws CloneNotSupportedException
+    {
+        // Clone the base object
+        SchemaObjectRegistry<T> clone = (SchemaObjectRegistry<T>)super.clone();
+        
+        // Clone the byName Map
+        clone.byName = new HashMap<String, T>();
+        
+        for ( String key : byName.keySet() )
+        {
+            // Clone each SchemaObject
+            SchemaObject value = byName.get( key );
+            clone.byName.put( key, (T)value.clone() );
+        }
+        
+        // Clone the oidRegistry
+        clone.oidRegistry = oidRegistry.clone();
+        
+        return clone;
+    }
 }

Added: directory/shared/branches/shared-schema/ldap/src/test/java/org/apache/directory/shared/ldap/schema/registries/AttributeTypeRegistryTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/test/java/org/apache/directory/shared/ldap/schema/registries/AttributeTypeRegistryTest.java?rev=826175&view=auto
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/test/java/org/apache/directory/shared/ldap/schema/registries/AttributeTypeRegistryTest.java
(added)
+++ directory/shared/branches/shared-schema/ldap/src/test/java/org/apache/directory/shared/ldap/schema/registries/AttributeTypeRegistryTest.java
Sat Oct 17 04:19:20 2009
@@ -0,0 +1,71 @@
+/*
+ *  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.schema.registries;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.directory.shared.ldap.schema.AttributeType;
+import org.junit.Test;
+
+/**
+ * Test the AttributeTypeRegistry class
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class AttributeTypeRegistryTest
+{
+    @Test
+    public void testClone() throws Exception
+    {
+        OidRegistry oidRegistry = new OidRegistry();
+        AttributeTypeRegistry atRegistry = new AttributeTypeRegistry( oidRegistry );
+        AttributeType at0 = new AttributeType( "1.1" );
+        at0.addName( "t", "test", "Test", "T" );
+        
+        atRegistry.register( at0 );
+        
+        AttributeType at1 = new AttributeType( "1.2" );
+        at1.addName( "u", "unit", "Unit", "U" );
+
+        atRegistry.register( at1 );
+        
+        // Clone the ATRegistry
+        AttributeTypeRegistry clone = atRegistry.clone();
+        
+        assertEquals( at0, clone.lookup( "1.1" ) );
+        assertEquals( at1, clone.lookup( "1.2" ) );
+        
+        atRegistry.unregister( "1.1" );
+        assertFalse( atRegistry.contains( "1.1" ) );
+        assertTrue( clone.contains( "1.1" ) );
+        
+        AttributeType at = atRegistry.lookup( "1.2" );
+        at.setOid( "2.2" );
+        
+        at = atRegistry.lookup( "1.2" );
+        assertEquals( "2.2", at.getOid() );
+
+        at = clone.lookup( "1.2" );
+        assertEquals( "1.2", at.getOid() );
+    }
+}

Added: directory/shared/branches/shared-schema/ldap/src/test/java/org/apache/directory/shared/ldap/schema/registries/OidRegistryTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/test/java/org/apache/directory/shared/ldap/schema/registries/OidRegistryTest.java?rev=826175&view=auto
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/test/java/org/apache/directory/shared/ldap/schema/registries/OidRegistryTest.java
(added)
+++ directory/shared/branches/shared-schema/ldap/src/test/java/org/apache/directory/shared/ldap/schema/registries/OidRegistryTest.java
Sat Oct 17 04:19:20 2009
@@ -0,0 +1,77 @@
+/*
+ *  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.schema.registries;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.directory.shared.ldap.schema.AttributeType;
+import org.junit.Test;
+
+
+/**
+ * Test the OidRegistry class
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class OidRegistryTest
+{
+
+    @Test
+    public void testClone() throws Exception
+    {
+        OidRegistry oidRegistry = new OidRegistry();
+        AttributeType at0 = new AttributeType( "1.1" );
+        at0.addName( "t", "test", "Test", "T" );
+
+        oidRegistry.register( at0 );
+
+        AttributeType at1 = new AttributeType( "1.2" );
+        at1.addName( "u", "unit", "Unit", "U" );
+
+        oidRegistry.register( at1 );
+        
+        // Clone the oidRegistry
+        OidRegistry clone = oidRegistry.clone();
+        
+        assertTrue( clone.hasOid( "1.1" ) );
+        assertTrue( clone.hasOid( "1.2" ) );
+        
+        at0.setOid( "2.1" );
+        assertFalse( oidRegistry.hasOid( "2.1" ) );
+        assertFalse( clone.hasOid( "2.1" ) );
+        
+        AttributeType at = (AttributeType)oidRegistry.getSchemaObject( "1.1" );
+        assertEquals( "2.1", at.getOid() );
+        
+        at = (AttributeType)clone.getSchemaObject( "1.1" );
+        assertEquals( "1.1", at.getOid() );
+
+        oidRegistry.unregister( "2.1" );
+        oidRegistry.unregister( "1.1" );
+        assertFalse( oidRegistry.hasOid( "1.1" ) );
+        assertTrue( oidRegistry.hasOid( "1.2" ) );
+        assertFalse( oidRegistry.hasOid( "2.1" ) );
+        assertTrue( clone.hasOid( "1.1" ) );
+        assertTrue( clone.hasOid( "1.2" ) );
+    }
+}



Mime
View raw message