directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r493074 - in /directory/trunks/apacheds: core-unit/src/test/java/org/apache/directory/server/core/schema/ core-unit/src/test/resources/org/apache/directory/server/core/schema/ core/src/main/java/org/apache/directory/server/core/schema/ sche...
Date Fri, 05 Jan 2007 16:39:45 GMT
Author: akarasulu
Date: Fri Jan  5 08:39:44 2007
New Revision: 493074

URL: http://svn.apache.org/viewvc?view=rev&rev=493074
Log:
Added handler and test cases to make sure changes to normalizers under ou=schema
are handled with the proper updates to registries.

 o added test case
 o modified normalizer registry to now unregister
 o added handler for normalizer events 
 o added test DummyNormalizer bytecode not class so it does not get loaded to 
   test dynamic code additions to the server via LDAP 
 o changed comparator 'bytecode' file to DummyComparator.bytecode


Added:
    directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/schema/MetaNormalizerHandlerITest.java
    directory/trunks/apacheds/core-unit/src/test/resources/org/apache/directory/server/core/schema/DummyComparator.bytecode
      - copied unchanged from r492896, directory/trunks/apacheds/core-unit/src/test/resources/org/apache/directory/server/core/schema/bytecode
    directory/trunks/apacheds/core-unit/src/test/resources/org/apache/directory/server/core/schema/DummyNormalizer.bytecode
  (with props)
    directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/MetaNormalizerHandler.java
Removed:
    directory/trunks/apacheds/core-unit/src/test/resources/org/apache/directory/server/core/schema/bytecode
Modified:
    directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/schema/MetaComparatorHandlerITest.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/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
    directory/trunks/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultNormalizerRegistry.java
    directory/trunks/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/NormalizerRegistry.java

Modified: 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=diff&rev=493074&r1=493073&r2=493074
==============================================================================
--- directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/schema/MetaComparatorHandlerITest.java
(original)
+++ directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/schema/MetaComparatorHandlerITest.java
Fri Jan  5 08:39:44 2007
@@ -98,7 +98,7 @@
     
     public void testAddComparatorWithByteCode() throws Exception
     {
-        InputStream in = getClass().getResourceAsStream( "bytecode" );
+        InputStream in = getClass().getResourceAsStream( "DummyComparator.bytecode" );
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         while ( in.available() > 0 )
         {

Added: directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/schema/MetaNormalizerHandlerITest.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/schema/MetaNormalizerHandlerITest.java?view=auto&rev=493074
==============================================================================
--- directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/schema/MetaNormalizerHandlerITest.java
(added)
+++ directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/schema/MetaNormalizerHandlerITest.java
Fri Jan  5 08:39:44 2007
@@ -0,0 +1,539 @@
+/*
+ *  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 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.DeepTrimNormalizer;
+import org.apache.directory.shared.ldap.schema.MatchingRule;
+import org.apache.directory.shared.ldap.schema.NoOpNormalizer;
+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 MetaNormalizerHandlerITest 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 getNormalizerContainer( String schemaName ) throws NamingException
+    {
+        return new LdapDN( "ou=normalizers,cn=" + schemaName );
+    }
+    
+    
+    // ----------------------------------------------------------------------
+    // Test all core methods with normal operational pathways
+    // ----------------------------------------------------------------------
+
+    
+    public void testAddNormalizer() 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_NORMALIZER_OC );
+        attrs.put( oc );
+        attrs.put( MetaSchemaConstants.M_FQCN_AT, NoOpNormalizer.class.getName() );
+        attrs.put( MetaSchemaConstants.M_OID_AT, OID );
+        attrs.put( MetaSchemaConstants.M_DESCRIPTION_AT, "A test normalizer" );
+        
+        LdapDN dn = getNormalizerContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        super.schemaRoot.createSubcontext( dn, attrs );
+        
+        assertTrue( registries.getNormalizerRegistry().hasNormalizer( OID ) );
+        assertEquals( registries.getNormalizerRegistry().getSchemaName( OID ), "apachemeta"
);
+        Class clazz = registries.getNormalizerRegistry().lookup( OID ).getClass();
+        assertEquals( clazz, NoOpNormalizer.class );
+    }
+    
+    
+    public void testAddNormalizerWithByteCode() throws Exception
+    {
+        InputStream in = getClass().getResourceAsStream( "DummyNormalizer.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_NORMALIZER_OC );
+        attrs.put( oc );
+        attrs.put( MetaSchemaConstants.M_FQCN_AT, "DummyNormalizer" );
+        attrs.put( MetaSchemaConstants.M_BYTECODE_AT, out.toByteArray() );
+        attrs.put( MetaSchemaConstants.M_OID_AT, OID );
+        attrs.put( MetaSchemaConstants.M_DESCRIPTION_AT, "A test normalizer" );
+        
+        LdapDN dn = getNormalizerContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        super.schemaRoot.createSubcontext( dn, attrs );
+        
+        assertTrue( registries.getNormalizerRegistry().hasNormalizer( OID ) );
+        assertEquals( registries.getNormalizerRegistry().getSchemaName( OID ), "apachemeta"
);
+        Class clazz = registries.getNormalizerRegistry().lookup( OID ).getClass();
+        assertEquals( clazz.getName(), "DummyNormalizer" );
+    }
+    
+    
+    public void testDeleteNormalizer() throws NamingException
+    {
+        LdapDN dn = getNormalizerContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        testAddNormalizer();
+        
+        super.schemaRoot.destroySubcontext( dn );
+
+        assertFalse( "normalizer should be removed from the registry after being deleted",

+            registries.getNormalizerRegistry().hasNormalizer( OID ) );
+        
+        try
+        {
+            registries.getNormalizerRegistry().lookup( OID );
+            fail( "normalizer lookup should fail after deleting the normalizer" );
+        }
+        catch( NamingException e )
+        {
+        }
+    }
+
+
+    public void testRenameNormalizer() throws NamingException
+    {
+        LdapDN dn = getNormalizerContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        testAddNormalizer();
+        
+        LdapDN newdn = getNormalizerContainer( "apachemeta" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + NEW_OID );
+        super.schemaRoot.rename( dn, newdn );
+
+        assertFalse( "old normalizer OID should be removed from the registry after being
renamed", 
+            registries.getNormalizerRegistry().hasNormalizer( OID ) );
+        
+        try
+        {
+            registries.getNormalizerRegistry().lookup( OID );
+            fail( "normalizer lookup should fail after deleting the normalizer" );
+        }
+        catch( NamingException e )
+        {
+        }
+
+        assertTrue( registries.getNormalizerRegistry().hasNormalizer( NEW_OID ) );
+        Class clazz = registries.getNormalizerRegistry().lookup( NEW_OID ).getClass();
+        assertEquals( clazz, NoOpNormalizer.class );
+    }
+
+
+    public void testMoveNormalizer() throws NamingException
+    {
+        testAddNormalizer();
+        
+        LdapDN dn = getNormalizerContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+
+        LdapDN newdn = getNormalizerContainer( "apache" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        
+        super.schemaRoot.rename( dn, newdn );
+
+        assertTrue( "normalizer OID should still be present", 
+            registries.getNormalizerRegistry().hasNormalizer( OID ) );
+        
+        assertEquals( "normalizer schema should be set to apache not apachemeta", 
+            registries.getNormalizerRegistry().getSchemaName( OID ), "apache" );
+
+        Class clazz = registries.getNormalizerRegistry().lookup( OID ).getClass();
+        assertEquals( clazz, NoOpNormalizer.class );
+    }
+
+
+    public void testMoveNormalizerAndChangeRdn() throws NamingException
+    {
+        testAddNormalizer();
+        
+        LdapDN dn = getNormalizerContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+
+        LdapDN newdn = getNormalizerContainer( "apache" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + NEW_OID );
+        
+        super.schemaRoot.rename( dn, newdn );
+
+        assertFalse( "old normalizer OID should NOT be present", 
+            registries.getNormalizerRegistry().hasNormalizer( OID ) );
+        
+        assertTrue( "new normalizer OID should be present", 
+            registries.getNormalizerRegistry().hasNormalizer( NEW_OID ) );
+        
+        assertEquals( "normalizer with new oid should have schema set to apache NOT apachemeta",

+            registries.getNormalizerRegistry().getSchemaName( NEW_OID ), "apache" );
+
+        Class clazz = registries.getNormalizerRegistry().lookup( NEW_OID ).getClass();
+        assertEquals( clazz, NoOpNormalizer.class );
+    }
+
+    
+    public void testModifyNormalizerWithModificationItems() throws NamingException
+    {
+        testAddNormalizer();
+        
+        LdapDN dn = getNormalizerContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        
+        ModificationItem[] mods = new ModificationItem[1];
+        Attribute attr = new LockableAttributeImpl( MetaSchemaConstants.M_FQCN_AT, DeepTrimNormalizer.class.getName()
);
+        mods[0] = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
+        super.schemaRoot.modifyAttributes( dn, mods );
+
+        assertTrue( "normalizer OID should still be present", 
+            registries.getNormalizerRegistry().hasNormalizer( OID ) );
+        
+        assertEquals( "normalizer schema should be set to apachemeta", 
+            registries.getNormalizerRegistry().getSchemaName( OID ), "apachemeta" );
+
+        Class clazz = registries.getNormalizerRegistry().lookup( OID ).getClass();
+        assertEquals( clazz, DeepTrimNormalizer.class );
+    }
+
+    
+    public void testModifyNormalizerWithAttributes() throws NamingException
+    {
+        testAddNormalizer();
+        
+        LdapDN dn = getNormalizerContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        
+        Attributes mods = new LockableAttributesImpl();
+        mods.put( MetaSchemaConstants.M_FQCN_AT, DeepTrimNormalizer.class.getName() );
+        super.schemaRoot.modifyAttributes( dn, DirContext.REPLACE_ATTRIBUTE, mods );
+
+        assertTrue( "normalizer OID should still be present", 
+            registries.getNormalizerRegistry().hasNormalizer( OID ) );
+        
+        assertEquals( "normalizer schema should be set to apachemeta", 
+            registries.getNormalizerRegistry().getSchemaName( OID ), "apachemeta" );
+
+        Class clazz = registries.getNormalizerRegistry().lookup( OID ).getClass();
+        assertEquals( clazz, DeepTrimNormalizer.class );
+    }
+    
+
+    // ----------------------------------------------------------------------
+    // Test move, rename, and delete when a MR exists and uses the Normalizer
+    // ----------------------------------------------------------------------
+
+    
+    public void testDeleteNormalizerWhenInUse() throws NamingException
+    {
+        LdapDN dn = getNormalizerContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        testAddNormalizer();
+        registries.getMatchingRuleRegistry().register( "apachemeta", new DummyMR() );
+        
+        try
+        {
+            super.schemaRoot.destroySubcontext( dn );
+            fail( "should not be able to delete a normalizer in use" );
+        }
+        catch( LdapOperationNotSupportedException e ) 
+        {
+            assertEquals( e.getResultCode(), ResultCodeEnum.UNWILLING_TO_PERFORM );
+        }
+
+        assertTrue( "normalizer should still be in the registry after delete failure", 
+            registries.getNormalizerRegistry().hasNormalizer( OID ) );
+    }
+    
+    
+    public void testMoveNormalizerWhenInUse() throws NamingException
+    {
+        testAddNormalizer();
+        registries.getMatchingRuleRegistry().register( "apachemeta", new DummyMR() );
+        
+        LdapDN dn = getNormalizerContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+
+        LdapDN newdn = getNormalizerContainer( "apache" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        
+        try
+        {
+            super.schemaRoot.rename( dn, newdn );
+            fail( "should not be able to move a normalizer in use" );
+        }
+        catch( LdapOperationNotSupportedException e ) 
+        {
+            assertEquals( e.getResultCode(), ResultCodeEnum.UNWILLING_TO_PERFORM );
+        }
+
+        assertTrue( "normalizer should still be in the registry after move failure", 
+            registries.getNormalizerRegistry().hasNormalizer( OID ) );
+    }
+
+
+    public void testMoveNormalizerAndChangeRdnWhenInUse() throws NamingException
+    {
+        testAddNormalizer();
+        registries.getMatchingRuleRegistry().register( "apachemeta", new DummyMR() );
+        
+        LdapDN dn = getNormalizerContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+
+        LdapDN newdn = getNormalizerContainer( "apache" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + NEW_OID );
+        
+        try
+        {
+            super.schemaRoot.rename( dn, newdn );
+            fail( "should not be able to move a normalizer in use" );
+        }
+        catch( LdapOperationNotSupportedException e ) 
+        {
+            assertEquals( e.getResultCode(), ResultCodeEnum.UNWILLING_TO_PERFORM );
+        }
+
+        assertTrue( "normalizer should still be in the registry after move failure", 
+            registries.getNormalizerRegistry().hasNormalizer( OID ) );
+    }
+
+    
+    public void testRenameNormalizerWhenInUse() throws NamingException
+    {
+        LdapDN dn = getNormalizerContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        testAddNormalizer();
+        registries.getMatchingRuleRegistry().register( "apachemeta", new DummyMR() );
+        
+        LdapDN newdn = getNormalizerContainer( "apachemeta" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + NEW_OID );
+        
+        try
+        {
+            super.schemaRoot.rename( dn, newdn );
+            fail( "should not be able to rename a normalizer in use" );
+        }
+        catch( LdapOperationNotSupportedException e ) 
+        {
+            assertEquals( e.getResultCode(), ResultCodeEnum.UNWILLING_TO_PERFORM );
+        }
+
+        assertTrue( "normalizer should still be in the registry after rename failure", 
+            registries.getNormalizerRegistry().hasNormalizer( OID ) );
+    }
+
+
+    // ----------------------------------------------------------------------
+    // Let's try some freaky stuff
+    // ----------------------------------------------------------------------
+
+
+    public void testMoveNormalizerToTop() throws NamingException
+    {
+        testAddNormalizer();
+        
+        LdapDN dn = getNormalizerContainer( "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 normalizer up to ou=schema" );
+        }
+        catch( LdapInvalidNameException e ) 
+        {
+            assertEquals( e.getResultCode(), ResultCodeEnum.NAMING_VIOLATION );
+        }
+
+        assertTrue( "normalizer should still be in the registry after move failure", 
+            registries.getNormalizerRegistry().hasNormalizer( OID ) );
+    }
+
+
+    public void testMoveNormalizerToComparatorContainer() throws NamingException
+    {
+        testAddNormalizer();
+        
+        LdapDN dn = getNormalizerContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+
+        LdapDN newdn = new LdapDN( "ou=comparators,cn=apachemeta" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        
+        try
+        {
+            super.schemaRoot.rename( dn, newdn );
+            fail( "should not be able to move a normalizer into comparators container" );
+        }
+        catch( LdapInvalidNameException e ) 
+        {
+            assertEquals( e.getResultCode(), ResultCodeEnum.NAMING_VIOLATION );
+        }
+
+        assertTrue( "normalizer should still be in the registry after move failure", 
+            registries.getNormalizerRegistry().hasNormalizer( OID ) );
+    }
+    
+    
+    public void testAddNormalizerToDisabledSchema() 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_NORMALIZER_OC );
+        attrs.put( oc );
+        attrs.put( MetaSchemaConstants.M_FQCN_AT, NoOpNormalizer.class.getName() );
+        attrs.put( MetaSchemaConstants.M_OID_AT, OID );
+        attrs.put( MetaSchemaConstants.M_DESCRIPTION_AT, "A test normalizer" );
+        
+        // nis is by default inactive
+        LdapDN dn = getNormalizerContainer( "nis" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        super.schemaRoot.createSubcontext( dn, attrs );
+        
+        assertFalse( "adding new normalizer to disabled schema should not register it into
the registries", 
+            registries.getNormalizerRegistry().hasNormalizer( OID ) );
+    }
+
+
+    public void testMoveNormalizerToDisabledSchema() throws NamingException
+    {
+        testAddNormalizer();
+        
+        LdapDN dn = getNormalizerContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+
+        // nis is inactive by default
+        LdapDN newdn = getNormalizerContainer( "nis" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        
+        super.schemaRoot.rename( dn, newdn );
+
+        assertFalse( "normalizer OID should no longer be present", 
+            registries.getNormalizerRegistry().hasNormalizer( OID ) );
+    }
+
+
+    public void testMoveNormalizerToEnabledSchema() throws NamingException
+    {
+        testAddNormalizerToDisabledSchema();
+        
+        // nis is inactive by default
+        LdapDN dn = getNormalizerContainer( "nis" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+
+        assertFalse( "normalizer OID should NOT be present when added to disabled nis schema",

+            registries.getNormalizerRegistry().hasNormalizer( OID ) );
+
+        LdapDN newdn = getNormalizerContainer( "apachemeta" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        
+        super.schemaRoot.rename( dn, newdn );
+
+        assertTrue( "normalizer OID should be present when moved to enabled schema", 
+            registries.getNormalizerRegistry().hasNormalizer( OID ) );
+        
+        assertEquals( "normalizer should be in apachemeta schema after move", 
+            registries.getNormalizerRegistry().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;
+        }
+        
+    }
+}

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

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

Added: directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/MetaNormalizerHandler.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/MetaNormalizerHandler.java?view=auto&rev=493074
==============================================================================
--- directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/MetaNormalizerHandler.java
(added)
+++ directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/MetaNormalizerHandler.java
Fri Jan  5 08:39:44 2007
@@ -0,0 +1,268 @@
+/*
+ *   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 javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.ModificationItem;
+
+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.MatchingRuleRegistry;
+import org.apache.directory.server.schema.registries.NormalizerRegistry;
+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.schema.Normalizer;
+import org.apache.directory.shared.ldap.util.NamespaceTools;
+
+
+/**
+ * A handler for operations peformed to add, delete, modify, rename and 
+ * move schema normalizers.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class MetaNormalizerHandler implements SchemaChangeHandler
+{
+    private static final String OU_OID = "2.5.4.11";
+
+    private final PartitionSchemaLoader loader;
+    private final SchemaEntityFactory factory;
+    private final Registries targetRegistries;
+    private final NormalizerRegistry normalizerRegistry;
+    private final MatchingRuleRegistry matchingRuleRegistry;
+    private final AttributeType m_oidAT;
+
+    
+
+    public MetaNormalizerHandler( Registries targetRegistries, PartitionSchemaLoader loader
) throws NamingException
+    {
+        this.targetRegistries = targetRegistries;
+        this.loader = loader;
+        this.normalizerRegistry = targetRegistries.getNormalizerRegistry();
+        this.matchingRuleRegistry = targetRegistries.getMatchingRuleRegistry();
+        this.factory = new SchemaEntityFactory( targetRegistries );
+        this.m_oidAT = targetRegistries.getAttributeTypeRegistry().lookup( MetaSchemaConstants.M_OID_AT
);
+    }
+
+
+    private String getOid( Attributes entry ) throws NamingException
+    {
+        Attribute oid = ServerUtils.getAttribute( m_oidAT, entry );
+        if ( oid == null )
+        {
+            return null;
+        }
+        return ( String ) oid.get();
+    }
+    
+    
+    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 oldOid = getOid( entry );
+        Normalizer normalizer = factory.getNormalizer( targetEntry, targetRegistries );
+        Schema schema = getSchema( name );
+        
+        if ( ! schema.isDisabled() )
+        {
+            normalizerRegistry.unregister( oldOid );
+            normalizerRegistry.register( schema.getSchemaName(), getOid( targetEntry ), normalizer
);
+        }
+    }
+
+
+    public void modify( LdapDN name, int modOp, Attributes mods, Attributes entry, Attributes
targetEntry )
+        throws NamingException
+    {
+        modify( name, entry, targetEntry );
+    }
+
+
+    public void modify( LdapDN name, ModificationItem[] mods, Attributes entry, Attributes
targetEntry )
+        throws NamingException
+    {
+        modify( name, entry, targetEntry );
+    }
+
+
+    public void add( LdapDN name, Attributes entry ) throws NamingException
+    {
+        LdapDN parentDn = ( LdapDN ) name.clone();
+        parentDn.remove( parentDn.size() - 1 );
+        checkNewParent( parentDn );
+        
+        Normalizer normalizer = factory.getNormalizer( entry, targetRegistries );
+        String oid = getOid( entry );
+        Schema schema = getSchema( name );
+        
+        if ( ! schema.isDisabled() )
+        {
+            normalizerRegistry.register( schema.getSchemaName(), oid, normalizer );
+        }
+    }
+
+
+    public void delete( LdapDN name, Attributes entry ) throws NamingException
+    {
+        String oid = getOid( entry );
+        if ( matchingRuleRegistry.hasMatchingRule( oid ) )
+        {
+            throw new LdapOperationNotSupportedException( "The normalizer with OID " + oid

+                + " cannot be deleted until all " 
+                + "matchingRules using that normalizer have also been deleted.", 
+                ResultCodeEnum.UNWILLING_TO_PERFORM );
+        }
+        
+        Schema schema = getSchema( name );
+        
+        if ( ! schema.isDisabled() )
+        {
+            normalizerRegistry.unregister( getOid( entry ) );
+        }
+    }
+
+
+    public void rename( LdapDN name, Attributes entry, String newRdn ) throws NamingException
+    {
+        String oldOid = getOid( entry );
+
+        if ( matchingRuleRegistry.hasMatchingRule( oldOid ) )
+        {
+            throw new LdapOperationNotSupportedException( "The normalizer with OID " + oldOid

+                + " cannot have it's OID changed until all " 
+                + "matchingRules using that normalizer have been deleted.", 
+                ResultCodeEnum.UNWILLING_TO_PERFORM );
+        }
+
+        String oid = NamespaceTools.getRdnValue( newRdn );
+        Schema schema = getSchema( name );
+        
+        if ( ! schema.isDisabled() )
+        {
+            Normalizer normalizer = factory.getNormalizer( entry, targetRegistries );
+            normalizerRegistry.unregister( oldOid );
+            normalizerRegistry.register( schema.getSchemaName(), oid, normalizer );
+        }
+    }
+
+
+    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 normalizer with OID " + oldOid

+                + " cannot have it's OID changed until all " 
+                + "matchingRules using that normalizer have been deleted.", 
+                ResultCodeEnum.UNWILLING_TO_PERFORM );
+        }
+
+        String oid = NamespaceTools.getRdnValue( newRn );
+
+        Schema oldSchema = getSchema( oriChildName );
+        Schema newSchema = getSchema( newParentName );
+        
+        Normalizer normalizer = factory.getNormalizer( entry, targetRegistries );
+
+        if ( ! oldSchema.isDisabled() )
+        {
+            normalizerRegistry.unregister( oldOid );
+        }
+
+        if ( ! newSchema.isDisabled() )
+        {
+            normalizerRegistry.register( newSchema.getSchemaName(), oid, normalizer );
+        }
+    }
+
+
+    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 normalizer with OID " + oid

+                + " cannot be moved to another schema until all " 
+                + "matchingRules using that normalizer have been deleted.", 
+                ResultCodeEnum.UNWILLING_TO_PERFORM );
+        }
+
+        Schema oldSchema = getSchema( oriChildName );
+        Schema newSchema = getSchema( newParentName );
+        
+        Normalizer normalizer = factory.getNormalizer( entry, targetRegistries );
+        
+        if ( ! oldSchema.isDisabled() )
+        {
+            normalizerRegistry.unregister( oid );
+        }
+        
+        if ( ! newSchema.isDisabled() )
+        {
+            normalizerRegistry.register( newSchema.getSchemaName(), oid, normalizer );
+        }
+    }
+    
+    
+    private void checkNewParent( LdapDN newParent ) throws NamingException
+    {
+        if ( newParent.size() != 3 )
+        {
+            throw new LdapInvalidNameException( 
+                "The parent dn of a normalizer 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 normalizer should
be an organizationalUnit.", 
+                ResultCodeEnum.NAMING_VIOLATION );
+        }
+        
+        if ( ! ( ( String ) rdn.getValue() ).equalsIgnoreCase( "normalizers" ) )
+        {
+            throw new LdapInvalidNameException( 
+                "The parent entry of a normalizer should have a relative name of ou=normalizers.",

+                ResultCodeEnum.NAMING_VIOLATION );
+        }
+    }
+}

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=493074&r1=493073&r2=493074
==============================================================================
--- 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
Fri Jan  5 08:39:44 2007
@@ -343,6 +343,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=493074&r1=493073&r2=493074
==============================================================================
--- 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
Fri Jan  5 08:39:44 2007
@@ -55,6 +55,7 @@
     private final Registries globalRegistries;
     private final AttributeType objectClassAT;
     private final MetaComparatorHandler metaComparatorHandler;
+    private final MetaNormalizerHandler metaNormalizerHandler;
     
 
     public SchemaManager( Registries globalRegistries, PartitionSchemaLoader loader ) throws
NamingException
@@ -65,6 +66,7 @@
             .lookup( SystemSchemaConstants.OBJECT_CLASS_AT );
         this.metaSchemaHandler = new MetaSchemaHandler( this.globalRegistries, this.loader
);
         this.metaComparatorHandler = new MetaComparatorHandler( globalRegistries, loader
);
+        this.metaNormalizerHandler = new MetaNormalizerHandler( globalRegistries, loader
);
     }
     
     
@@ -96,6 +98,12 @@
             return;
         }
 
+        if ( AttributeUtils.containsValue( oc, MetaSchemaConstants.META_NORMALIZER_OC, objectClassAT
) )
+        {
+            metaNormalizerHandler.add( name, entry );
+            return;
+        }
+
         throw new NotImplementedException( "only changes to metaSchema objects are managed
at this time" );
     }
     
@@ -116,6 +124,12 @@
             return;
         }
 
+        if ( AttributeUtils.containsValue( oc, MetaSchemaConstants.META_NORMALIZER_OC, objectClassAT
) )
+        {
+            metaNormalizerHandler.delete( name, entry );
+            return;
+        }
+
         throw new NotImplementedException( "only changes to metaSchema objects are managed
at this time" );
     }
     
@@ -137,6 +151,12 @@
             return;
         }
 
+        if ( AttributeUtils.containsValue( oc, MetaSchemaConstants.META_NORMALIZER_OC, objectClassAT
) )
+        {
+            metaNormalizerHandler.modify( name, modOp, mods, entry, targetEntry );
+            return;
+        }
+
         throw new NotImplementedException( "only changes to metaSchema objects are managed
at this time" );
     }
 
@@ -158,6 +178,12 @@
             return;
         }
 
+        if ( AttributeUtils.containsValue( oc, MetaSchemaConstants.META_NORMALIZER_OC, objectClassAT
) )
+        {
+            metaNormalizerHandler.modify( name, mods, entry, targetEntry );
+            return;
+        }
+
         throw new NotImplementedException( "only changes to metaSchema objects are managed
at this time" );
     }
 
@@ -178,6 +204,12 @@
             return;
         }
 
+        if ( AttributeUtils.containsValue( oc, MetaSchemaConstants.META_NORMALIZER_OC, objectClassAT
) )
+        {
+            metaNormalizerHandler.rename( name, entry, newRdn );
+            return;
+        }
+
         throw new NotImplementedException( "only changes to metaSchema objects are managed
at this time" );
     }
 
@@ -198,6 +230,12 @@
             return;
         }
 
+        if ( AttributeUtils.containsValue( oc, MetaSchemaConstants.META_NORMALIZER_OC, objectClassAT
) )
+        {
+            metaNormalizerHandler.move( oriChildName, newParentName, entry );
+            return;
+        }
+
         throw new NotImplementedException( "only changes to metaSchema objects are managed
at this time" );
     }
 
@@ -216,6 +254,12 @@
         if ( AttributeUtils.containsValue( oc, MetaSchemaConstants.META_COMPARATOR_OC, objectClassAT
) )
         {
             metaComparatorHandler.move( oriChildName, newParentName, newRn, deleteOldRn,
entry );
+            return;
+        }
+
+        if ( AttributeUtils.containsValue( oc, MetaSchemaConstants.META_NORMALIZER_OC, objectClassAT
) )
+        {
+            metaNormalizerHandler.move( oriChildName, newParentName, newRn, deleteOldRn,
entry );
             return;
         }
 

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=493074&r1=493073&r2=493074
==============================================================================
--- 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
Fri Jan  5 08:39:44 2007
@@ -88,7 +88,8 @@
     /**
      * Removes a registered comparator from this registry.
      * 
-     * @param oid the oid of the comparator to remove.
+     * @param oid the numeric oid of the comparator to remove.
+     * @throws NamingException if the oid is not a numeric id
      */
-    void unregister( String oid );
+    void unregister( String oid ) throws NamingException;
 }

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=493074&r1=493073&r2=493074
==============================================================================
--- 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
Fri Jan  5 08:39:44 2007
@@ -129,8 +129,13 @@
     }
 
 
-    public void unregister( String oid )
+    public void unregister( String oid ) throws NamingException
     {
+        if ( ! Character.isDigit( oid.charAt( 0 ) ) )
+        {
+            throw new NamingException( "OID " + oid + " is not a numeric OID" );
+        }
+
         this.comparators.remove( oid );
         this.oidToSchema.remove( oid );
     }

Modified: directory/trunks/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultNormalizerRegistry.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultNormalizerRegistry.java?view=diff&rev=493074&r1=493073&r2=493074
==============================================================================
--- directory/trunks/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultNormalizerRegistry.java
(original)
+++ directory/trunks/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultNormalizerRegistry.java
Fri Jan  5 08:39:44 2007
@@ -126,4 +126,16 @@
     {
         return byOid.keySet().iterator();
     }
+
+
+    public void unregister( String oid ) throws NamingException
+    {
+        if ( ! Character.isDigit( oid.charAt( 0 ) ) )
+        {
+            throw new NamingException( "OID " + oid + " is not a numeric OID" );
+        }
+
+        this.byOid.remove( oid );
+        this.oidToSchema.remove( oid );
+    }
 }

Modified: directory/trunks/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/NormalizerRegistry.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/NormalizerRegistry.java?view=diff&rev=493074&r1=493073&r2=493074
==============================================================================
--- directory/trunks/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/NormalizerRegistry.java
(original)
+++ directory/trunks/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/NormalizerRegistry.java
Fri Jan  5 08:39:44 2007
@@ -85,4 +85,12 @@
      * @return an Iterator over the set of OID Strings in this registry
      */
     Iterator<String> oidIterator();
+
+    /**
+     * Unregisters a normalizer from this registry by OID.
+     * 
+     * @param oid the numeric OID of the matchingRule the normalizer is for
+     * @throws NamingException if the provided argument is not a numeric OID
+     */
+    void unregister( String oid ) throws NamingException;
 }



Mime
View raw message