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 2007/01/05 05:12:52 UTC

svn commit: r492896 - in /directory/trunks/apacheds: bootstrap-plugin/src/main/java/org/apache/directory/server/core/bootstrap/plugin/ constants/src/main/java/org/apache/directory/server/constants/ core-unit/src/main/java/org/apache/directory/server/co...

Author: akarasulu
Date: Thu Jan  4 20:12:51 2007
New Revision: 492896

URL: http://svn.apache.org/viewvc?view=rev&rev=492896
Log:
Completed and tested meta schema updates to comparators and its associated 
handling code to effect registries:

 o removed this bogus and empty RegistriesModifier class instead I modified
   the comparator registry to allow for unregistering comparators by OID and
   will do the same for other registries making this class unnecessary
 o added some additional methods to the SchemaChangeHandler interface 
 o stubbed out some methods which are still not implemented in the 
   MetaSchemaHandler
 o modified registries to be able to access schemas that have already been 
   loaded instead of getting the entire cloned map of loaded schemas by name
 o added more utility methods to the SchemaPartitionDao
 o added complete test cases for comparator handling
 o modified the abstract test case to have a handle on the global registries 
   for convenience
 o modified the ComparatorRegistry interface and the default implemetnation to
   now have an unregister method
 o cleaned up some constants


Added:
    directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/schema/MetaComparatorHandlerITest.java
    directory/trunks/apacheds/core-unit/src/test/resources/org/apache/directory/server/core/schema/bytecode   (with props)
Removed:
    directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/RegistryModifier.java
Modified:
    directory/trunks/apacheds/bootstrap-plugin/src/main/java/org/apache/directory/server/core/bootstrap/plugin/AttributesFactory.java
    directory/trunks/apacheds/constants/src/main/java/org/apache/directory/server/constants/MetaSchemaConstants.java
    directory/trunks/apacheds/core-unit/src/main/java/org/apache/directory/server/core/unit/AbstractTestCase.java
    directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/schema/SchemaServiceITest.java
    directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/MetaComparatorHandler.java
    directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/MetaSchemaHandler.java
    directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaChangeHandler.java
    directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaEntityFactory.java
    directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaManager.java
    directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaPartitionDao.java
    directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java
    directory/trunks/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/ComparatorRegistry.java
    directory/trunks/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultComparatorRegistry.java

Modified: directory/trunks/apacheds/bootstrap-plugin/src/main/java/org/apache/directory/server/core/bootstrap/plugin/AttributesFactory.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/bootstrap-plugin/src/main/java/org/apache/directory/server/core/bootstrap/plugin/AttributesFactory.java?view=diff&rev=492896&r1=492895&r2=492896
==============================================================================
--- directory/trunks/apacheds/bootstrap-plugin/src/main/java/org/apache/directory/server/core/bootstrap/plugin/AttributesFactory.java (original)
+++ directory/trunks/apacheds/bootstrap-plugin/src/main/java/org/apache/directory/server/core/bootstrap/plugin/AttributesFactory.java Thu Jan  4 20:12:51 2007
@@ -338,7 +338,7 @@
         
         if ( object.getDescription() != null )
         {
-            entry.put( MetaSchemaConstants.M_DESC_AT, object.getDescription() );
+            entry.put( MetaSchemaConstants.M_DESCRIPTION_AT, object.getDescription() );
         }
     }
     

Modified: directory/trunks/apacheds/constants/src/main/java/org/apache/directory/server/constants/MetaSchemaConstants.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/constants/src/main/java/org/apache/directory/server/constants/MetaSchemaConstants.java?view=diff&rev=492896&r1=492895&r2=492896
==============================================================================
--- directory/trunks/apacheds/constants/src/main/java/org/apache/directory/server/constants/MetaSchemaConstants.java (original)
+++ directory/trunks/apacheds/constants/src/main/java/org/apache/directory/server/constants/MetaSchemaConstants.java Thu Jan  4 20:12:51 2007
@@ -28,7 +28,8 @@
  */
 public interface MetaSchemaConstants
 {
-    public static final Object META_SCHEMA_OC = "metaSchema";
+    public static final String META_TOP_OC = "metaTop";
+    public static final String META_SCHEMA_OC = "metaSchema";
     public static final String META_OBJECT_CLASS_OC = "metaObjectClass";
     public static final String META_ATTRIBUTE_TYPE_OC = "metaAttributeType";
     public static final String META_MATCHING_RULE_OC = "metaMatchingRule";
@@ -56,7 +57,6 @@
     public static final String M_ORDERING_AT = "m-ordering";
     public static final String M_EQUALITY_AT = "m-equality";
     public static final String M_SYNTAX_AT = "m-syntax";
-    public static final String M_DESC_AT = "m-description";
     public static final String M_MUST_AT = "m-must";
     public static final String M_MAY_AT = "m-may";
     public static final String M_TYPE_OBJECT_CLASS_AT = "m-typeObjectClass";

Modified: directory/trunks/apacheds/core-unit/src/main/java/org/apache/directory/server/core/unit/AbstractTestCase.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core-unit/src/main/java/org/apache/directory/server/core/unit/AbstractTestCase.java?view=diff&rev=492896&r1=492895&r2=492896
==============================================================================
--- directory/trunks/apacheds/core-unit/src/main/java/org/apache/directory/server/core/unit/AbstractTestCase.java (original)
+++ directory/trunks/apacheds/core-unit/src/main/java/org/apache/directory/server/core/unit/AbstractTestCase.java Thu Jan  4 20:12:51 2007
@@ -39,9 +39,11 @@
 import junit.framework.TestCase;
 
 import org.apache.commons.io.FileUtils;
+import org.apache.directory.server.core.DirectoryService;
 import org.apache.directory.server.core.configuration.Configuration;
 import org.apache.directory.server.core.configuration.MutableStartupConfiguration;
 import org.apache.directory.server.core.configuration.ShutdownConfiguration;
+import org.apache.directory.server.schema.registries.Registries;
 import org.apache.directory.shared.ldap.ldif.Entry;
 import org.apache.directory.shared.ldap.ldif.LdifReader;
 
@@ -89,7 +91,7 @@
     protected MutableStartupConfiguration configuration = new MutableStartupConfiguration();
 
     /** A testEntries of entries as Attributes to add to the DIT for testing */
-    protected List testEntries = new ArrayList();
+    protected List<Entry> testEntries = new ArrayList<Entry>();
 
     /** An optional LDIF file path if set and present is read to add more test entries */
     private String ldifPath;
@@ -97,8 +99,10 @@
     /** Load resources relative to this class */
     private Class loadClass;
 
-    private Hashtable overrides = new Hashtable();
+    private Hashtable<String,Object> overrides = new Hashtable<String,Object>();
 
+    protected Registries registries;
+    
 
     protected AbstractTestCase(String username, String password)
     {
@@ -207,6 +211,7 @@
         configuration.setShutdownHookEnabled( false );
         doDelete( configuration.getWorkingDirectory() );
         setContextRoots( username, password, configuration );
+        registries = DirectoryService.getInstance().getConfiguration().getRegistries();
     }
 
 
@@ -241,7 +246,7 @@
      */
     protected void setContextRoots( String user, String passwd, Configuration cfg ) throws NamingException
     {
-        Hashtable env = new Hashtable( cfg.toJndiEnvironment() );
+        Hashtable<String,Object> env = new Hashtable<String,Object>( cfg.toJndiEnvironment() );
         env.put( Context.SECURITY_PRINCIPAL, user );
         env.put( Context.SECURITY_CREDENTIALS, passwd );
         env.put( Context.SECURITY_AUTHENTICATION, "simple" );
@@ -258,9 +263,9 @@
      * @return the sysRoot context which is also set
      * @throws NamingException if there is a failure of any kind
      */
-    protected void setContextRoots( Hashtable env ) throws NamingException
+    protected void setContextRoots( Hashtable<String,Object> env ) throws NamingException
     {
-        Hashtable envFinal = new Hashtable( env );
+        Hashtable<String,Object> envFinal = new Hashtable<String,Object>( env );
         if ( !envFinal.containsKey( Context.PROVIDER_URL ) )
         {
             envFinal.put( Context.PROVIDER_URL, "ou=system" );
@@ -270,7 +275,7 @@
         envFinal.putAll( overrides );
 
         // We have to initiate the first run as an admin at least.
-        Hashtable adminEnv = new Hashtable( envFinal );
+        Hashtable<String,Object> adminEnv = new Hashtable<String,Object>( envFinal );
         adminEnv.put( Context.SECURITY_PRINCIPAL, "uid=admin,ou=system" );
         adminEnv.put( Context.SECURITY_CREDENTIALS, "secret" );
         adminEnv.put( Context.SECURITY_AUTHENTICATION, "simple" );

Added: directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/schema/MetaComparatorHandlerITest.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/schema/MetaComparatorHandlerITest.java?view=auto&rev=492896
==============================================================================
--- directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/schema/MetaComparatorHandlerITest.java (added)
+++ directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/schema/MetaComparatorHandlerITest.java Thu Jan  4 20:12:51 2007
@@ -0,0 +1,540 @@
+/*
+ *  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.server.core.schema;
+
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.util.Comparator;
+
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.ModificationItem;
+
+import jdbm.helper.IntegerComparator;
+import jdbm.helper.StringComparator;
+
+import org.apache.directory.server.constants.MetaSchemaConstants;
+import org.apache.directory.server.constants.SystemSchemaConstants;
+import org.apache.directory.server.core.unit.AbstractAdminTestCase;
+import org.apache.directory.shared.ldap.exception.LdapInvalidNameException;
+import org.apache.directory.shared.ldap.exception.LdapOperationNotSupportedException;
+import org.apache.directory.shared.ldap.message.LockableAttributeImpl;
+import org.apache.directory.shared.ldap.message.LockableAttributesImpl;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.schema.MatchingRule;
+import org.apache.directory.shared.ldap.schema.Normalizer;
+import org.apache.directory.shared.ldap.schema.Syntax;
+
+
+/**
+ * A test case which tests the addition of various schema elements
+ * to the ldap server.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class MetaComparatorHandlerITest extends AbstractAdminTestCase
+{
+    private static final String OID = "1.3.6.1.4.1.18060.0.4.0.1.100000";
+    private static final String NEW_OID = "1.3.6.1.4.1.18060.0.4.0.1.100001";
+
+    
+    /**
+     * Gets relative DN to ou=schema.
+     */
+    private final LdapDN getComparatorContainer( String schemaName ) throws NamingException
+    {
+        return new LdapDN( "ou=comparators,cn=" + schemaName );
+    }
+    
+    
+    // ----------------------------------------------------------------------
+    // Test all core methods with normal operational pathways
+    // ----------------------------------------------------------------------
+
+    
+    public void testAddComparator() throws NamingException
+    {
+        Attributes attrs = new LockableAttributesImpl();
+        Attribute oc = new LockableAttributeImpl( SystemSchemaConstants.OBJECT_CLASS_AT, "top" );
+        oc.add( MetaSchemaConstants.META_TOP_OC );
+        oc.add( MetaSchemaConstants.META_COMPARATOR_OC );
+        attrs.put( oc );
+        attrs.put( MetaSchemaConstants.M_FQCN_AT, StringComparator.class.getName() );
+        attrs.put( MetaSchemaConstants.M_OID_AT, OID );
+        attrs.put( MetaSchemaConstants.M_DESCRIPTION_AT, "A test comparator" );
+        
+        LdapDN dn = getComparatorContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        super.schemaRoot.createSubcontext( dn, attrs );
+        
+        assertTrue( registries.getComparatorRegistry().hasComparator( OID ) );
+        assertEquals( registries.getComparatorRegistry().getSchemaName( OID ), "apachemeta" );
+        Class clazz = registries.getComparatorRegistry().lookup( OID ).getClass();
+        assertEquals( clazz, StringComparator.class );
+    }
+    
+    
+    public void testAddComparatorWithByteCode() throws Exception
+    {
+        InputStream in = getClass().getResourceAsStream( "bytecode" );
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        while ( in.available() > 0 )
+        {
+            out.write( in.read() );
+        }
+        
+        Attributes attrs = new LockableAttributesImpl();
+        Attribute oc = new LockableAttributeImpl( SystemSchemaConstants.OBJECT_CLASS_AT, "top" );
+        oc.add( MetaSchemaConstants.META_TOP_OC );
+        oc.add( MetaSchemaConstants.META_COMPARATOR_OC );
+        attrs.put( oc );
+        attrs.put( MetaSchemaConstants.M_FQCN_AT, "DummyComparator" );
+        attrs.put( MetaSchemaConstants.M_BYTECODE_AT, out.toByteArray() );
+        attrs.put( MetaSchemaConstants.M_OID_AT, OID );
+        attrs.put( MetaSchemaConstants.M_DESCRIPTION_AT, "A test comparator" );
+        
+        LdapDN dn = getComparatorContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        super.schemaRoot.createSubcontext( dn, attrs );
+        
+        assertTrue( registries.getComparatorRegistry().hasComparator( OID ) );
+        assertEquals( registries.getComparatorRegistry().getSchemaName( OID ), "apachemeta" );
+        Class clazz = registries.getComparatorRegistry().lookup( OID ).getClass();
+        assertEquals( clazz.getName(), "DummyComparator" );
+    }
+    
+    
+    public void testDeleteComparator() throws NamingException
+    {
+        LdapDN dn = getComparatorContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        testAddComparator();
+        
+        super.schemaRoot.destroySubcontext( dn );
+
+        assertFalse( "comparator should be removed from the registry after being deleted", 
+            registries.getComparatorRegistry().hasComparator( OID ) );
+        
+        try
+        {
+            registries.getComparatorRegistry().lookup( OID );
+            fail( "comparator lookup should fail after deleting the comparator" );
+        }
+        catch( NamingException e )
+        {
+        }
+    }
+
+
+    public void testRenameComparator() throws NamingException
+    {
+        LdapDN dn = getComparatorContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        testAddComparator();
+        
+        LdapDN newdn = getComparatorContainer( "apachemeta" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + NEW_OID );
+        super.schemaRoot.rename( dn, newdn );
+
+        assertFalse( "old comparator OID should be removed from the registry after being renamed", 
+            registries.getComparatorRegistry().hasComparator( OID ) );
+        
+        try
+        {
+            registries.getComparatorRegistry().lookup( OID );
+            fail( "comparator lookup should fail after deleting the comparator" );
+        }
+        catch( NamingException e )
+        {
+        }
+
+        assertTrue( registries.getComparatorRegistry().hasComparator( NEW_OID ) );
+        Class clazz = registries.getComparatorRegistry().lookup( NEW_OID ).getClass();
+        assertEquals( clazz, StringComparator.class );
+    }
+
+
+    public void testMoveComparator() throws NamingException
+    {
+        testAddComparator();
+        
+        LdapDN dn = getComparatorContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+
+        LdapDN newdn = getComparatorContainer( "apache" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        
+        super.schemaRoot.rename( dn, newdn );
+
+        assertTrue( "comparator OID should still be present", 
+            registries.getComparatorRegistry().hasComparator( OID ) );
+        
+        assertEquals( "comparator schema should be set to apache not apachemeta", 
+            registries.getComparatorRegistry().getSchemaName( OID ), "apache" );
+
+        Class clazz = registries.getComparatorRegistry().lookup( OID ).getClass();
+        assertEquals( clazz, StringComparator.class );
+    }
+
+
+    public void testMoveComparatorAndChangeRdn() throws NamingException
+    {
+        testAddComparator();
+        
+        LdapDN dn = getComparatorContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+
+        LdapDN newdn = getComparatorContainer( "apache" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + NEW_OID );
+        
+        super.schemaRoot.rename( dn, newdn );
+
+        assertFalse( "old comparator OID should NOT be present", 
+            registries.getComparatorRegistry().hasComparator( OID ) );
+        
+        assertTrue( "new comparator OID should be present", 
+            registries.getComparatorRegistry().hasComparator( NEW_OID ) );
+        
+        assertEquals( "comparator with new oid should have schema set to apache NOT apachemeta", 
+            registries.getComparatorRegistry().getSchemaName( NEW_OID ), "apache" );
+
+        Class clazz = registries.getComparatorRegistry().lookup( NEW_OID ).getClass();
+        assertEquals( clazz, StringComparator.class );
+    }
+
+    
+    public void testModifyComparatorWithModificationItems() throws NamingException
+    {
+        testAddComparator();
+        
+        LdapDN dn = getComparatorContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        
+        ModificationItem[] mods = new ModificationItem[1];
+        Attribute attr = new LockableAttributeImpl( MetaSchemaConstants.M_FQCN_AT, IntegerComparator.class.getName() );
+        mods[0] = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
+        super.schemaRoot.modifyAttributes( dn, mods );
+
+        assertTrue( "comparator OID should still be present", 
+            registries.getComparatorRegistry().hasComparator( OID ) );
+        
+        assertEquals( "comparator schema should be set to apachemeta", 
+            registries.getComparatorRegistry().getSchemaName( OID ), "apachemeta" );
+
+        Class clazz = registries.getComparatorRegistry().lookup( OID ).getClass();
+        assertEquals( clazz, IntegerComparator.class );
+    }
+
+    
+    public void testModifyComparatorWithAttributes() throws NamingException
+    {
+        testAddComparator();
+        
+        LdapDN dn = getComparatorContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        
+        Attributes mods = new LockableAttributesImpl();
+        mods.put( MetaSchemaConstants.M_FQCN_AT, IntegerComparator.class.getName() );
+        super.schemaRoot.modifyAttributes( dn, DirContext.REPLACE_ATTRIBUTE, mods );
+
+        assertTrue( "comparator OID should still be present", 
+            registries.getComparatorRegistry().hasComparator( OID ) );
+        
+        assertEquals( "comparator schema should be set to apachemeta", 
+            registries.getComparatorRegistry().getSchemaName( OID ), "apachemeta" );
+
+        Class clazz = registries.getComparatorRegistry().lookup( OID ).getClass();
+        assertEquals( clazz, IntegerComparator.class );
+    }
+    
+
+    // ----------------------------------------------------------------------
+    // Test move, rename, and delete when a MR exists and uses the Comparator
+    // ----------------------------------------------------------------------
+
+    
+    public void testDeleteComparatorWhenInUse() throws NamingException
+    {
+        LdapDN dn = getComparatorContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        testAddComparator();
+        registries.getMatchingRuleRegistry().register( "apachemeta", new DummyMR() );
+        
+        try
+        {
+            super.schemaRoot.destroySubcontext( dn );
+            fail( "should not be able to delete a comparator in use" );
+        }
+        catch( LdapOperationNotSupportedException e ) 
+        {
+            assertEquals( e.getResultCode(), ResultCodeEnum.UNWILLING_TO_PERFORM );
+        }
+
+        assertTrue( "comparator should still be in the registry after delete failure", 
+            registries.getComparatorRegistry().hasComparator( OID ) );
+    }
+    
+    
+    public void testMoveComparatorWhenInUse() throws NamingException
+    {
+        testAddComparator();
+        registries.getMatchingRuleRegistry().register( "apachemeta", new DummyMR() );
+        
+        LdapDN dn = getComparatorContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+
+        LdapDN newdn = getComparatorContainer( "apache" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        
+        try
+        {
+            super.schemaRoot.rename( dn, newdn );
+            fail( "should not be able to move a comparator in use" );
+        }
+        catch( LdapOperationNotSupportedException e ) 
+        {
+            assertEquals( e.getResultCode(), ResultCodeEnum.UNWILLING_TO_PERFORM );
+        }
+
+        assertTrue( "comparator should still be in the registry after move failure", 
+            registries.getComparatorRegistry().hasComparator( OID ) );
+    }
+
+
+    public void testMoveComparatorAndChangeRdnWhenInUse() throws NamingException
+    {
+        testAddComparator();
+        registries.getMatchingRuleRegistry().register( "apachemeta", new DummyMR() );
+        
+        LdapDN dn = getComparatorContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+
+        LdapDN newdn = getComparatorContainer( "apache" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + NEW_OID );
+        
+        try
+        {
+            super.schemaRoot.rename( dn, newdn );
+            fail( "should not be able to move a comparator in use" );
+        }
+        catch( LdapOperationNotSupportedException e ) 
+        {
+            assertEquals( e.getResultCode(), ResultCodeEnum.UNWILLING_TO_PERFORM );
+        }
+
+        assertTrue( "comparator should still be in the registry after move failure", 
+            registries.getComparatorRegistry().hasComparator( OID ) );
+    }
+
+    
+    public void testRenameComparatorWhenInUse() throws NamingException
+    {
+        LdapDN dn = getComparatorContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        testAddComparator();
+        registries.getMatchingRuleRegistry().register( "apachemeta", new DummyMR() );
+        
+        LdapDN newdn = getComparatorContainer( "apachemeta" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + NEW_OID );
+        
+        try
+        {
+            super.schemaRoot.rename( dn, newdn );
+            fail( "should not be able to rename a comparator in use" );
+        }
+        catch( LdapOperationNotSupportedException e ) 
+        {
+            assertEquals( e.getResultCode(), ResultCodeEnum.UNWILLING_TO_PERFORM );
+        }
+
+        assertTrue( "comparator should still be in the registry after rename failure", 
+            registries.getComparatorRegistry().hasComparator( OID ) );
+    }
+
+
+    // ----------------------------------------------------------------------
+    // Let's try some freaky stuff
+    // ----------------------------------------------------------------------
+
+
+    public void testMoveComparatorToTop() throws NamingException
+    {
+        testAddComparator();
+        
+        LdapDN dn = getComparatorContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+
+        LdapDN top = new LdapDN();
+        top.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        
+        try
+        {
+            super.schemaRoot.rename( dn, top );
+            fail( "should not be able to move a comparator up to ou=schema" );
+        }
+        catch( LdapInvalidNameException e ) 
+        {
+            assertEquals( e.getResultCode(), ResultCodeEnum.NAMING_VIOLATION );
+        }
+
+        assertTrue( "comparator should still be in the registry after move failure", 
+            registries.getComparatorRegistry().hasComparator( OID ) );
+    }
+
+
+    public void testMoveComparatorToNormalizers() throws NamingException
+    {
+        testAddComparator();
+        
+        LdapDN dn = getComparatorContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+
+        LdapDN newdn = new LdapDN( "ou=normalizers,cn=apachemeta" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        
+        try
+        {
+            super.schemaRoot.rename( dn, newdn );
+            fail( "should not be able to move a comparator up to normalizers container" );
+        }
+        catch( LdapInvalidNameException e ) 
+        {
+            assertEquals( e.getResultCode(), ResultCodeEnum.NAMING_VIOLATION );
+        }
+
+        assertTrue( "comparator should still be in the registry after move failure", 
+            registries.getComparatorRegistry().hasComparator( OID ) );
+    }
+    
+    
+    public void testAddComparatorToDisabledSchema() throws NamingException
+    {
+        Attributes attrs = new LockableAttributesImpl();
+        Attribute oc = new LockableAttributeImpl( SystemSchemaConstants.OBJECT_CLASS_AT, "top" );
+        oc.add( MetaSchemaConstants.META_TOP_OC );
+        oc.add( MetaSchemaConstants.META_COMPARATOR_OC );
+        attrs.put( oc );
+        attrs.put( MetaSchemaConstants.M_FQCN_AT, StringComparator.class.getName() );
+        attrs.put( MetaSchemaConstants.M_OID_AT, OID );
+        attrs.put( MetaSchemaConstants.M_DESCRIPTION_AT, "A test comparator" );
+        
+        // nis is by default inactive
+        LdapDN dn = getComparatorContainer( "nis" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        super.schemaRoot.createSubcontext( dn, attrs );
+        
+        assertFalse( "adding new comparator to disabled schema should not register it into the registries", 
+            registries.getComparatorRegistry().hasComparator( OID ) );
+    }
+
+
+    public void testMoveComparatorToDisabledSchema() throws NamingException
+    {
+        testAddComparator();
+        
+        LdapDN dn = getComparatorContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+
+        // nis is inactive by default
+        LdapDN newdn = getComparatorContainer( "nis" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        
+        super.schemaRoot.rename( dn, newdn );
+
+        assertFalse( "comparator OID should no longer be present", 
+            registries.getComparatorRegistry().hasComparator( OID ) );
+    }
+
+
+    public void testMoveComparatorToEnabledSchema() throws NamingException
+    {
+        testAddComparatorToDisabledSchema();
+        
+        // nis is inactive by default
+        LdapDN dn = getComparatorContainer( "nis" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+
+        assertFalse( "comparator OID should NOT be present when added to disabled nis schema", 
+            registries.getComparatorRegistry().hasComparator( OID ) );
+
+        LdapDN newdn = getComparatorContainer( "apachemeta" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        
+        super.schemaRoot.rename( dn, newdn );
+
+        assertTrue( "comparator OID should be present when moved to enabled schema", 
+            registries.getComparatorRegistry().hasComparator( OID ) );
+        
+        assertEquals( "comparator should be in apachemeta schema after move", 
+            registries.getComparatorRegistry().getSchemaName( OID ), "apachemeta" );
+    }
+
+
+    class DummyMR implements MatchingRule
+    {
+        private static final long serialVersionUID = 1L;
+
+        public Comparator getComparator() throws NamingException
+        {
+            return null;
+        }
+
+        public Normalizer getNormalizer() throws NamingException
+        {
+            return null;
+        }
+
+        public Syntax getSyntax() throws NamingException
+        {
+            return null;
+        }
+
+        public String getDescription()
+        {
+            return null;
+        }
+
+        public String getName()
+        {
+            return "dummy";
+        }
+
+        public String[] getNames()
+        {
+            return new String[] { "dummy" };
+        }
+
+        public String getOid()
+        {
+            return OID;
+        }
+
+        public boolean isObsolete()
+        {
+            return false;
+        }
+        
+    }
+}

Modified: directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/schema/SchemaServiceITest.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/schema/SchemaServiceITest.java?view=diff&rev=492896&r1=492895&r2=492896
==============================================================================
--- directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/schema/SchemaServiceITest.java (original)
+++ directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/schema/SchemaServiceITest.java Thu Jan  4 20:12:51 2007
@@ -75,7 +75,7 @@
     {
         SearchControls controls = new SearchControls();
         controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
-        Map persons = new HashMap();
+        Map<String, Attributes> persons = new HashMap<String, Attributes>();
         NamingEnumeration results = sysRoot.search( "", "(objectClass=person)", controls );
         while ( results.hasMore() )
         {
@@ -89,14 +89,14 @@
         Attributes person = null;
         Attribute ocs = null;
 
-        person = ( Attributes ) persons.get( "cn=person0,ou=system" );
+        person = persons.get( "cn=person0,ou=system" );
         assertNotNull( person );
         ocs = person.get( "objectClass" );
         assertEquals( 2, ocs.size() );
         assertTrue( ocs.contains( "top" ) );
         assertTrue( ocs.contains( "person" ) );
 
-        person = ( Attributes ) persons.get( "cn=person1,ou=system" );
+        person = persons.get( "cn=person1,ou=system" );
         assertNotNull( person );
         ocs = person.get( "objectClass" );
         assertEquals( 3, ocs.size() );
@@ -104,7 +104,7 @@
         assertTrue( ocs.contains( "person" ) );
         assertTrue( ocs.contains( "organizationalPerson" ) );
 
-        person = ( Attributes ) persons.get( "cn=person2,ou=system" );
+        person = persons.get( "cn=person2,ou=system" );
         assertNotNull( person );
         ocs = person.get( "objectClass" );
         assertEquals( 4, ocs.size() );
@@ -119,7 +119,7 @@
     {
         SearchControls controls = new SearchControls();
         controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
-        Map orgPersons = new HashMap();
+        Map<String, Attributes> orgPersons = new HashMap<String, Attributes>();
         NamingEnumeration results = sysRoot.search( "", "(objectClass=organizationalPerson)", controls );
         while ( results.hasMore() )
         {
@@ -133,7 +133,7 @@
         Attributes orgPerson = null;
         Attribute ocs = null;
 
-        orgPerson = ( Attributes ) orgPersons.get( "cn=person1,ou=system" );
+        orgPerson = orgPersons.get( "cn=person1,ou=system" );
         assertNotNull( orgPerson );
         ocs = orgPerson.get( "objectClass" );
         assertEquals( 3, ocs.size() );
@@ -141,7 +141,7 @@
         assertTrue( ocs.contains( "person" ) );
         assertTrue( ocs.contains( "organizationalPerson" ) );
 
-        orgPerson = ( Attributes ) orgPersons.get( "cn=person2,ou=system" );
+        orgPerson = orgPersons.get( "cn=person2,ou=system" );
         assertNotNull( orgPerson );
         ocs = orgPerson.get( "objectClass" );
         assertEquals( 4, ocs.size() );
@@ -156,7 +156,7 @@
     {
         SearchControls controls = new SearchControls();
         controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
-        Map inetOrgPersons = new HashMap();
+        Map<String, Attributes> inetOrgPersons = new HashMap<String, Attributes>();
         NamingEnumeration results = sysRoot.search( "", "(objectClass=inetOrgPerson)", controls );
         while ( results.hasMore() )
         {
@@ -170,7 +170,7 @@
         Attributes inetOrgPerson = null;
         Attribute ocs = null;
 
-        inetOrgPerson = ( Attributes ) inetOrgPersons.get( "cn=person2,ou=system" );
+        inetOrgPerson = inetOrgPersons.get( "cn=person2,ou=system" );
         assertNotNull( inetOrgPerson );
         ocs = inetOrgPerson.get( "objectClass" );
         assertEquals( 4, ocs.size() );

Added: directory/trunks/apacheds/core-unit/src/test/resources/org/apache/directory/server/core/schema/bytecode
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core-unit/src/test/resources/org/apache/directory/server/core/schema/bytecode?view=auto&rev=492896
==============================================================================
Binary file - no diff available.

Propchange: directory/trunks/apacheds/core-unit/src/test/resources/org/apache/directory/server/core/schema/bytecode
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/MetaComparatorHandler.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/MetaComparatorHandler.java?view=diff&rev=492896&r1=492895&r2=492896
==============================================================================
--- directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/MetaComparatorHandler.java (original)
+++ directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/MetaComparatorHandler.java Thu Jan  4 20:12:51 2007
@@ -30,8 +30,14 @@
 import org.apache.directory.server.constants.MetaSchemaConstants;
 import org.apache.directory.server.core.ServerUtils;
 import org.apache.directory.server.schema.bootstrap.Schema;
+import org.apache.directory.server.schema.registries.ComparatorRegistry;
+import org.apache.directory.server.schema.registries.MatchingRuleRegistry;
 import org.apache.directory.server.schema.registries.Registries;
+import org.apache.directory.shared.ldap.exception.LdapInvalidNameException;
+import org.apache.directory.shared.ldap.exception.LdapOperationNotSupportedException;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.name.Rdn;
 import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.apache.directory.shared.ldap.util.NamespaceTools;
 
@@ -45,17 +51,24 @@
  */
 public class MetaComparatorHandler implements SchemaChangeHandler
 {
+    private static final String OU_OID = "2.5.4.11";
+
+    private final PartitionSchemaLoader loader;
     private final SchemaEntityFactory factory;
-    private final RegistryModifier registryModifier;
     private final Registries targetRegistries;
+    private final ComparatorRegistry comparatorRegistry;
+    private final MatchingRuleRegistry matchingRuleRegistry;
     private final AttributeType m_oidAT;
 
+    
 
-    public MetaComparatorHandler( Registries targetRegistries ) throws NamingException
+    public MetaComparatorHandler( Registries targetRegistries, PartitionSchemaLoader loader ) throws NamingException
     {
         this.targetRegistries = targetRegistries;
+        this.loader = loader;
+        this.comparatorRegistry = targetRegistries.getComparatorRegistry();
+        this.matchingRuleRegistry = targetRegistries.getMatchingRuleRegistry();
         this.factory = new SchemaEntityFactory( targetRegistries );
-        this.registryModifier = new RegistryModifier();
         this.m_oidAT = targetRegistries.getAttributeTypeRegistry().lookup( MetaSchemaConstants.M_OID_AT );
     }
 
@@ -71,12 +84,23 @@
     }
     
     
+    private Schema getSchema( LdapDN name ) throws NamingException
+    {
+        return loader.getSchema( MetaSchemaUtils.getSchemaName( name ) );
+    }
+    
+    
     private void modify( LdapDN name, Attributes entry, Attributes targetEntry ) throws NamingException
     {
-        String oid = getOid( entry );
-        Comparator replacement = factory.getComparator( entry, targetRegistries );
-        Schema targetSchema = targetRegistries.getSchema( MetaSchemaUtils.getSchemaName( name ) );
-        registryModifier.modify( oid, replacement, targetSchema );
+        String oldOid = getOid( entry );
+        Comparator comparator = factory.getComparator( targetEntry, targetRegistries );
+        Schema schema = getSchema( name );
+        
+        if ( ! schema.isDisabled() )
+        {
+            comparatorRegistry.unregister( oldOid );
+            comparatorRegistry.register( schema.getSchemaName(), getOid( targetEntry ), comparator );
+        }
     }
 
 
@@ -96,24 +120,150 @@
 
     public void add( LdapDN name, Attributes entry ) throws NamingException
     {
+        LdapDN parentDn = ( LdapDN ) name.clone();
+        parentDn.remove( parentDn.size() - 1 );
+        checkNewParent( parentDn );
+        
         Comparator comparator = factory.getComparator( entry, targetRegistries );
-        Schema schema = targetRegistries.getSchema( MetaSchemaUtils.getSchemaName( name ) );
-        registryModifier.add( getOid( entry ), comparator, schema );
+        String oid = getOid( entry );
+        Schema schema = getSchema( name );
+        
+        if ( ! schema.isDisabled() )
+        {
+            comparatorRegistry.register( schema.getSchemaName(), oid, comparator );
+        }
     }
 
 
     public void delete( LdapDN name, Attributes entry ) throws NamingException
     {
-        Comparator comparator = factory.getComparator( entry, targetRegistries );
-        Schema schema = targetRegistries.getSchema( MetaSchemaUtils.getSchemaName( name ) );
-        registryModifier.remove( getOid( entry ), comparator, schema );
+        String oid = getOid( entry );
+        if ( matchingRuleRegistry.hasMatchingRule( oid ) )
+        {
+            throw new LdapOperationNotSupportedException( "The comparator with OID " + oid 
+                + " cannot be deleted until all " 
+                + "matchingRules using that comparator have also been deleted.", 
+                ResultCodeEnum.UNWILLING_TO_PERFORM );
+        }
+        
+        Schema schema = getSchema( name );
+        
+        if ( ! schema.isDisabled() )
+        {
+            comparatorRegistry.unregister( getOid( entry ) );
+        }
     }
 
 
     public void rename( LdapDN name, Attributes entry, String newRdn ) throws NamingException
     {
-        Schema schema = targetRegistries.getSchema( MetaSchemaUtils.getSchemaName( name ) );
+        String oldOid = getOid( entry );
+
+        if ( matchingRuleRegistry.hasMatchingRule( oldOid ) )
+        {
+            throw new LdapOperationNotSupportedException( "The comparator with OID " + oldOid 
+                + " cannot have it's OID changed until all " 
+                + "matchingRules using that comparator have been deleted.", 
+                ResultCodeEnum.UNWILLING_TO_PERFORM );
+        }
+
         String oid = NamespaceTools.getRdnValue( newRdn );
-        registryModifier.renameComparator( getOid( entry ), oid, schema );
+        Schema schema = getSchema( name );
+        
+        if ( ! schema.isDisabled() )
+        {
+            Comparator comparator = factory.getComparator( entry, targetRegistries );
+            comparatorRegistry.unregister( oldOid );
+            comparatorRegistry.register( schema.getSchemaName(), oid, comparator );
+        }
+    }
+
+
+    public void move( LdapDN oriChildName, LdapDN newParentName, String newRn, boolean deleteOldRn, Attributes entry ) 
+        throws NamingException
+    {
+        checkNewParent( newParentName );
+        String oldOid = getOid( entry );
+
+        if ( matchingRuleRegistry.hasMatchingRule( oldOid ) )
+        {
+            throw new LdapOperationNotSupportedException( "The comparator with OID " + oldOid 
+                + " cannot have it's OID changed until all " 
+                + "matchingRules using that comparator have been deleted.", 
+                ResultCodeEnum.UNWILLING_TO_PERFORM );
+        }
+
+        String oid = NamespaceTools.getRdnValue( newRn );
+
+        Schema oldSchema = getSchema( oriChildName );
+        Schema newSchema = getSchema( newParentName );
+        
+        Comparator comparator = factory.getComparator( entry, targetRegistries );
+
+        if ( ! oldSchema.isDisabled() )
+        {
+            comparatorRegistry.unregister( oldOid );
+        }
+
+        if ( ! newSchema.isDisabled() )
+        {
+            comparatorRegistry.register( newSchema.getSchemaName(), oid, comparator );
+        }
+    }
+
+
+    public void move( LdapDN oriChildName, LdapDN newParentName, Attributes entry ) 
+        throws NamingException
+    {
+        checkNewParent( newParentName );
+        String oid = getOid( entry );
+
+        if ( matchingRuleRegistry.hasMatchingRule( oid ) )
+        {
+            throw new LdapOperationNotSupportedException( "The comparator with OID " + oid 
+                + " cannot be moved to another schema until all " 
+                + "matchingRules using that comparator have been deleted.", 
+                ResultCodeEnum.UNWILLING_TO_PERFORM );
+        }
+
+        Schema oldSchema = getSchema( oriChildName );
+        Schema newSchema = getSchema( newParentName );
+        
+        Comparator comparator = factory.getComparator( entry, targetRegistries );
+        
+        if ( ! oldSchema.isDisabled() )
+        {
+            comparatorRegistry.unregister( oid );
+        }
+        
+        if ( ! newSchema.isDisabled() )
+        {
+            comparatorRegistry.register( newSchema.getSchemaName(), oid, comparator );
+        }
+    }
+    
+    
+    private void checkNewParent( LdapDN newParent ) throws NamingException
+    {
+        if ( newParent.size() != 3 )
+        {
+            throw new LdapInvalidNameException( 
+                "The parent dn of a comparator should be at most 3 name components in length.", 
+                ResultCodeEnum.NAMING_VIOLATION );
+        }
+        
+        Rdn rdn = newParent.getRdn();
+        if ( ! targetRegistries.getOidRegistry().getOid( rdn.getType() ).equals( OU_OID ) )
+        {
+            throw new LdapInvalidNameException( "The parent entry of a comparator should be an organizationalUnit.", 
+                ResultCodeEnum.NAMING_VIOLATION );
+        }
+        
+        if ( ! ( ( String ) rdn.getValue() ).equalsIgnoreCase( "comparators" ) )
+        {
+            throw new LdapInvalidNameException( 
+                "The parent entry of a comparator should have a relative name of ou=comparators.", 
+                ResultCodeEnum.NAMING_VIOLATION );
+        }
     }
 }

Modified: directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/MetaSchemaHandler.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/MetaSchemaHandler.java?view=diff&rev=492896&r1=492895&r2=492896
==============================================================================
--- directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/MetaSchemaHandler.java (original)
+++ directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/MetaSchemaHandler.java Thu Jan  4 20:12:51 2007
@@ -189,4 +189,17 @@
     {
         throw new NotImplementedException();
     }
+
+
+    public void move( LdapDN oriChildName, LdapDN newParentName, String newRn, boolean deleteOldRn, Attributes entry ) 
+        throws NamingException
+    {
+        throw new NotImplementedException();
+    }
+
+
+    public void move( LdapDN oriChildName, LdapDN newParentName, Attributes entry ) throws NamingException
+    {
+        throw new NotImplementedException();
+    }
 }

Modified: directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaChangeHandler.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaChangeHandler.java?view=diff&rev=492896&r1=492895&r2=492896
==============================================================================
--- directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaChangeHandler.java (original)
+++ directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaChangeHandler.java Thu Jan  4 20:12:51 2007
@@ -19,6 +19,7 @@
  */
 package org.apache.directory.server.core.schema;
 
+
 import javax.naming.NamingException;
 import javax.naming.directory.Attributes;
 import javax.naming.directory.ModificationItem;
@@ -35,10 +36,11 @@
  */
 public interface SchemaChangeHandler
 {
-    public void add( LdapDN name, Attributes entry ) throws NamingException;
-    public void delete( LdapDN name, Attributes entry ) throws NamingException;
-    public void rename( LdapDN name, Attributes entry, String newRdn ) throws NamingException;
-    public void modify( LdapDN name, int modOp, Attributes mods, Attributes entry, Attributes targetEntry ) throws NamingException;
-    public void modify( LdapDN name, ModificationItem[] mods, Attributes entry, Attributes targetEntry ) throws NamingException;
-//    public void move( LdapDN oldName, Attributes entry, Ldap) throws NamingException;
+    void add( LdapDN name, Attributes entry ) throws NamingException;
+    void delete( LdapDN name, Attributes entry ) throws NamingException;
+    void rename( LdapDN name, Attributes entry, String newRdn ) throws NamingException;
+    void modify( LdapDN name, int modOp, Attributes mods, Attributes entry, Attributes targetEntry ) throws NamingException;
+    void modify( LdapDN name, ModificationItem[] mods, Attributes entry, Attributes targetEntry ) throws NamingException;
+    void move( LdapDN oriChildName, LdapDN newParentName, String newRn, boolean deleteOldRn, Attributes entry ) throws NamingException;
+    void move( LdapDN oriChildName, LdapDN newParentName, Attributes entry ) throws NamingException;
 }

Modified: directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaEntityFactory.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaEntityFactory.java?view=diff&rev=492896&r1=492895&r2=492896
==============================================================================
--- directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaEntityFactory.java (original)
+++ directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaEntityFactory.java Thu Jan  4 20:12:51 2007
@@ -38,6 +38,7 @@
 import org.apache.directory.server.schema.registries.Registries;
 import org.apache.directory.shared.ldap.schema.*;
 import org.apache.directory.shared.ldap.schema.syntax.SyntaxChecker;
+import org.apache.directory.shared.ldap.util.AttributeUtils;
 
 
 /**
@@ -59,7 +60,7 @@
     /** A special ClassLoader that loads a class from the bytecode attribute */
     private final AttributeClassLoader classLoader;
     private final AttributeType oidAT;
-    private AttributeType byteCodeAT;
+    private final AttributeType byteCodeAT;
     
     
     public SchemaEntityFactory( Registries bootstrapRegistries ) throws NamingException
@@ -251,6 +252,8 @@
         {
             try
             {
+                Attribute bytecode = AttributeUtils.getAttribute( entry, byteCodeAT );
+                classLoader.setAttribute( bytecode );
                 clazz = classLoader.loadClass( className );
             }
             catch ( ClassCastException e )

Modified: directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaManager.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaManager.java?view=diff&rev=492896&r1=492895&r2=492896
==============================================================================
--- directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaManager.java (original)
+++ directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaManager.java Thu Jan  4 20:12:51 2007
@@ -64,7 +64,7 @@
         this.objectClassAT = this.globalRegistries.getAttributeTypeRegistry()
             .lookup( SystemSchemaConstants.OBJECT_CLASS_AT );
         this.metaSchemaHandler = new MetaSchemaHandler( this.globalRegistries, this.loader );
-        this.metaComparatorHandler = new MetaComparatorHandler( globalRegistries );
+        this.metaComparatorHandler = new MetaComparatorHandler( globalRegistries, loader );
     }
     
     
@@ -79,9 +79,49 @@
         throw new NotImplementedException();
     }
 
+    
+    public void add( LdapDN name, Attributes entry ) throws NamingException
+    {
+        Attribute oc = ServerUtils.getAttribute( objectClassAT, entry );
+        
+        if ( AttributeUtils.containsValue( oc, MetaSchemaConstants.META_SCHEMA_OC, objectClassAT ) )
+        {
+            metaSchemaHandler.add( name, entry );
+            return;
+        }
+        
+        if ( AttributeUtils.containsValue( oc, MetaSchemaConstants.META_COMPARATOR_OC, objectClassAT ) )
+        {
+            metaComparatorHandler.add( name, entry );
+            return;
+        }
+
+        throw new NotImplementedException( "only changes to metaSchema objects are managed at this time" );
+    }
+    
+
+    public void delete( LdapDN name, Attributes entry ) throws NamingException
+    {
+        Attribute oc = ServerUtils.getAttribute( objectClassAT, entry );
+        
+        if ( AttributeUtils.containsValue( oc, MetaSchemaConstants.META_SCHEMA_OC, objectClassAT ) )
+        {
+            metaSchemaHandler.delete( name, entry );
+            return;
+        }
+        
+        if ( AttributeUtils.containsValue( oc, MetaSchemaConstants.META_COMPARATOR_OC, objectClassAT ) )
+        {
+            metaComparatorHandler.delete( name, entry );
+            return;
+        }
 
+        throw new NotImplementedException( "only changes to metaSchema objects are managed at this time" );
+    }
+    
 
-    public void modify( LdapDN name, int modOp, Attributes mods, Attributes entry, Attributes targetEntry ) throws NamingException
+    public void modify( LdapDN name, int modOp, Attributes mods, Attributes entry, Attributes targetEntry ) 
+        throws NamingException
     {
         Attribute oc = ServerUtils.getAttribute( objectClassAT, entry );
         
@@ -101,7 +141,8 @@
     }
 
 
-    public void modify( LdapDN name, ModificationItem[] mods, Attributes entry, Attributes targetEntry ) throws NamingException
+    public void modify( LdapDN name, ModificationItem[] mods, Attributes entry, Attributes targetEntry ) 
+        throws NamingException
     {
         Attribute oc = ServerUtils.getAttribute( objectClassAT, entry );
         
@@ -114,6 +155,67 @@
         if ( AttributeUtils.containsValue( oc, MetaSchemaConstants.META_COMPARATOR_OC, objectClassAT ) )
         {
             metaComparatorHandler.modify( name, mods, entry, targetEntry );
+            return;
+        }
+
+        throw new NotImplementedException( "only changes to metaSchema objects are managed at this time" );
+    }
+
+
+    public void modifyRn( LdapDN name, String newRdn, boolean deleteOldRn, Attributes entry ) throws NamingException
+    {
+        Attribute oc = ServerUtils.getAttribute( objectClassAT, entry );
+        
+        if ( AttributeUtils.containsValue( oc, MetaSchemaConstants.META_SCHEMA_OC, objectClassAT ) )
+        {
+            metaSchemaHandler.rename( name, entry, newRdn );
+            return;
+        }
+        
+        if ( AttributeUtils.containsValue( oc, MetaSchemaConstants.META_COMPARATOR_OC, objectClassAT ) )
+        {
+            metaComparatorHandler.rename( name, entry, newRdn );
+            return;
+        }
+
+        throw new NotImplementedException( "only changes to metaSchema objects are managed at this time" );
+    }
+
+
+    public void move( LdapDN oriChildName, LdapDN newParentName, Attributes entry ) throws NamingException
+    {
+        Attribute oc = ServerUtils.getAttribute( objectClassAT, entry );
+        
+        if ( AttributeUtils.containsValue( oc, MetaSchemaConstants.META_SCHEMA_OC, objectClassAT ) )
+        {
+            metaSchemaHandler.move( oriChildName, newParentName, entry );
+            return;
+        }
+        
+        if ( AttributeUtils.containsValue( oc, MetaSchemaConstants.META_COMPARATOR_OC, objectClassAT ) )
+        {
+            metaComparatorHandler.move( oriChildName, newParentName, entry );
+            return;
+        }
+
+        throw new NotImplementedException( "only changes to metaSchema objects are managed at this time" );
+    }
+
+
+    public void move( LdapDN oriChildName, LdapDN newParentName, String newRn, boolean deleteOldRn, Attributes entry )
+        throws NamingException
+    {
+        Attribute oc = ServerUtils.getAttribute( objectClassAT, entry );
+        
+        if ( AttributeUtils.containsValue( oc, MetaSchemaConstants.META_SCHEMA_OC, objectClassAT ) )
+        {
+            metaSchemaHandler.move( oriChildName, newParentName, newRn, deleteOldRn, entry );
+            return;
+        }
+        
+        if ( AttributeUtils.containsValue( oc, MetaSchemaConstants.META_COMPARATOR_OC, objectClassAT ) )
+        {
+            metaComparatorHandler.move( oriChildName, newParentName, newRn, deleteOldRn, entry );
             return;
         }
 

Modified: directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaPartitionDao.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaPartitionDao.java?view=diff&rev=492896&r1=492895&r2=492896
==============================================================================
--- directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaPartitionDao.java (original)
+++ directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaPartitionDao.java Thu Jan  4 20:12:51 2007
@@ -51,6 +51,7 @@
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.name.Rdn;
 import org.apache.directory.shared.ldap.schema.AttributeType;
+import org.apache.directory.shared.ldap.schema.syntax.NumericOidSyntaxChecker;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -67,6 +68,7 @@
 {
     /** static class logger */
     private final static Logger log = LoggerFactory.getLogger( SchemaPartitionDao.class );
+    private final static NumericOidSyntaxChecker NUMERIC_OID_CHECKER = new NumericOidSyntaxChecker();
 
 
     private final Partition partition;
@@ -78,9 +80,11 @@
     private final String M_NAME_OID;
     private final String CN_OID;
     private final String M_OID_OID;
+    private final String OBJECTCLASS_OID;
     
     private final AttributeType disabledAttributeType;
     
+    
     /**
      * Creates a schema dao object backing information within a schema partition.
      * 
@@ -99,6 +103,7 @@
         this.CN_OID = oidRegistry.getOid( SystemSchemaConstants.CN_AT );
         this.disabledAttributeType = attrRegistry.lookup( MetaSchemaConstants.M_DISABLED_AT );
         this.M_OID_OID = oidRegistry.getOid( MetaSchemaConstants.M_OID_AT );
+        this.OBJECTCLASS_OID = oidRegistry.getOid( SystemSchemaConstants.OBJECT_CLASS_AT );
     }
     
     
@@ -156,15 +161,57 @@
     }
     
     
+    public boolean hasMatchingRule( String oid ) throws NamingException
+    {
+        BranchNode filter = new BranchNode( AssertionEnum.AND );
+        filter.addNode( new SimpleNode( OBJECTCLASS_OID, 
+            MetaSchemaConstants.META_MATCHING_RULE_OC, AssertionEnum.EQUALITY ) );
+
+        if ( NUMERIC_OID_CHECKER.isValidSyntax( oid ) )
+        {
+            filter.addNode( new SimpleNode( M_OID_OID, oid, AssertionEnum.EQUALITY ) );
+        }
+        else
+        {
+            filter.addNode( new SimpleNode( M_NAME_OID, oid.toLowerCase(), AssertionEnum.EQUALITY ) );
+        }
+        
+        SearchControls searchControls = new SearchControls();
+        searchControls.setSearchScope( SearchControls.SUBTREE_SCOPE );
+        NamingEnumeration<SearchResult> ne = null;
+
+        try
+        {
+            ne = partition.search( partition.getSuffix(), new HashMap(), filter, searchControls );
+            
+            if ( ! ne.hasMore() )
+            {
+                return false;
+            }
+            
+            if ( ne.hasMore() )
+            {
+                throw new NamingException( "Got more than one matchingRule for oid of " + oid );
+            }
+
+            return true;
+        }
+        finally
+        {
+            ne.close();
+        }
+    }
+    
+    
     /**
-     * Given the non-normalized name (alias) for a schema entity.  This method 
-     * finds the schema under which that entity is located. 
+     * Given the non-normalized name (alias) or the OID for a schema entity.  This 
+     * method finds the schema under which that entity is located. 
      * 
      * NOTE: this method presumes that all alias names across schemas are unique.  
      * This should be the case for LDAP but this can potentially be violated so 
      * we should make sure this is a unique name.
      * 
-     * @param entityName one of the names of the entity 
+     * @param entityName one of the names of the entity or it's numeric id
      * @return the name of the schema that contains that entity or null if no entity with 
      * that alias name exists
      * @throws NamingException if more than one entity has the name, or if there 
@@ -172,6 +219,48 @@
      */
     public String findSchema( String entityName ) throws NamingException
     {
+        LdapDN dn = findDn( entityName );
+        if ( dn == null )
+        {
+            return null;
+        }
+        
+        Rdn rdn = dn.getRdn( 1 );
+        if ( ! rdn.getType().equalsIgnoreCase( CN_OID ) )
+        {
+            throw new NamingException( "Attribute of second rdn in dn '" + dn.toNormName() 
+                + "' expected to be CN oid of " + CN_OID + " but was " + rdn.getType() );
+        }
+        
+        return ( String ) rdn.getValue();
+    }
+
+    
+    public LdapDN findDn( String entityName ) throws NamingException
+    {
+        SearchResult sr = find( entityName );
+        LdapDN dn = new LdapDN( sr.getName() );
+        dn.normalize( attrRegistry.getNormalizerMapping() );
+        return dn;
+    }
+    
+
+    /**
+     * Given the non-normalized name (alias) or the OID for a schema entity.  This 
+     * method finds the entry of the schema entity. 
+     * 
+     * NOTE: this method presumes that all alias names across schemas are unique.  
+     * This should be the case for LDAP but this can potentially be violated so 
+     * we should make sure this is a unique name.
+     * 
+     * @param entityName one of the names of the entity or it's numeric id
+     * @return the search result for the entity or null if no such entity exists with 
+     * that alias or numeric oid
+     * @throws NamingException if more than one entity has the name, or if there 
+     * are underlying data access problems
+     */
+    public SearchResult find( String entityName ) throws NamingException
+    {
         BranchNode filter = new BranchNode( AssertionEnum.OR );
         SimpleNode nameAVA = new SimpleNode( M_NAME_OID, entityName.toLowerCase(), AssertionEnum.EQUALITY );
         SimpleNode oidAVA = new SimpleNode( M_OID_OID, entityName.toLowerCase(), AssertionEnum.EQUALITY );
@@ -196,16 +285,7 @@
                 throw new NamingException( "Got more than one result for the entity name: " + entityName );
             }
 
-            LdapDN dn = new LdapDN( sr.getName() );
-            dn.normalize( attrRegistry.getNormalizerMapping() );
-            Rdn rdn = dn.getRdn( 1 );
-            if ( ! rdn.getType().equalsIgnoreCase( CN_OID ) )
-            {
-                throw new NamingException( "Attribute of second rdn in dn '" + dn.toNormName() 
-                    + "' expected to be CN oid of " + CN_OID + " but was " + rdn.getType() );
-            }
-            
-            return ( String ) rdn.getValue();
+            return sr;
         }
         finally
         {

Modified: directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java?view=diff&rev=492896&r1=492895&r2=492896
==============================================================================
--- directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java (original)
+++ directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java Thu Jan  4 20:12:51 2007
@@ -797,6 +797,46 @@
         next.modify( name, modOp, mods );
     }
     
+    
+    public void move( NextInterceptor next, LdapDN oriChildName, LdapDN newParentName, String newRn, boolean deleteOldRn )
+        throws NamingException
+    {
+        Attributes entry = nexus.lookup( oriChildName );
+
+        if ( oriChildName.startsWith( schemaBaseDN ) )
+        {
+            schemaManager.move( oriChildName, newParentName, newRn, deleteOldRn, entry );
+        }
+        
+        next.move( oriChildName, newParentName, newRn, deleteOldRn );
+    }
+
+
+    public void move( NextInterceptor next, LdapDN oriChildName, LdapDN newParentName ) throws NamingException
+    {
+        Attributes entry = nexus.lookup( oriChildName );
+
+        if ( oriChildName.startsWith( schemaBaseDN ) )
+        {
+            schemaManager.move( oriChildName, newParentName, entry );
+        }
+        
+        next.move( oriChildName, newParentName );
+    }
+    
+
+    public void modifyRn( NextInterceptor next, LdapDN name, String newRn, boolean deleteOldRn ) throws NamingException
+    {
+        Attributes entry = nexus.lookup( name );
+
+        if ( name.startsWith( schemaBaseDN ) )
+        {
+            schemaManager.modifyRn( name, newRn, deleteOldRn, entry );
+        }
+        
+        next.modifyRn( name, newRn, deleteOldRn );
+    }
+
 
     public void modify( NextInterceptor next, LdapDN name, ModificationItem[] mods ) throws NamingException
     {
@@ -1168,10 +1208,27 @@
         alterObjectClasses( attrs.get( "objectClass" ), this.registries.getObjectClassRegistry() );
         assertRequiredAttributesPresent( attrs );
         assertNumberOfAttributeValuesValid( attrs );
+
+        if ( normName.startsWith( schemaBaseDN ) )
+        {
+            schemaManager.add( normName, attrs );
+        }
         next.add(normName, attrs );
     }
     
     
+    public void delete( NextInterceptor next, LdapDN normName ) throws NamingException
+    {
+        Attributes entry = nexus.lookup( normName );
+        
+        if ( normName.startsWith( schemaBaseDN ) )
+        {
+            schemaManager.delete( normName, entry );
+        }
+        next.delete( normName );
+    }
+
+
     /**
      * Checks to see number of values of an attribute conforms to the schema
      */

Modified: directory/trunks/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/ComparatorRegistry.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/ComparatorRegistry.java?view=diff&rev=492896&r1=492895&r2=492896
==============================================================================
--- directory/trunks/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/ComparatorRegistry.java (original)
+++ directory/trunks/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/ComparatorRegistry.java Thu Jan  4 20:12:51 2007
@@ -84,4 +84,11 @@
      * @return Iterator of numeric OID strings 
      */
     Iterator<String> oidIterator();
+
+    /**
+     * Removes a registered comparator from this registry.
+     * 
+     * @param oid the oid of the comparator to remove.
+     */
+    void unregister( String oid );
 }

Modified: directory/trunks/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultComparatorRegistry.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultComparatorRegistry.java?view=diff&rev=492896&r1=492895&r2=492896
==============================================================================
--- directory/trunks/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultComparatorRegistry.java (original)
+++ directory/trunks/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultComparatorRegistry.java Thu Jan  4 20:12:51 2007
@@ -127,4 +127,11 @@
     {
         return comparators.keySet().iterator();
     }
+
+
+    public void unregister( String oid )
+    {
+        this.comparators.remove( oid );
+        this.oidToSchema.remove( oid );
+    }
 }