directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r494671 - in /directory/trunks/apacheds: core-unit/src/test/java/org/apache/directory/server/core/schema/ core/src/main/java/org/apache/directory/server/core/schema/ core/src/test/java/org/apache/directory/server/core/authz/support/ schema-...
Date Wed, 10 Jan 2007 00:46:50 GMT
Author: akarasulu
Date: Tue Jan  9 16:46:50 2007
New Revision: 494671

URL: http://svn.apache.org/viewvc?view=rev&rev=494671
Log:
adding handler for dealing with meta schema write to ou=schema for attributeTypes

Added:
    directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandlerITest.java
    directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandler.java
Modified:
    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/test/java/org/apache/directory/server/core/authz/support/DummyAttributeTypeRegistry.java
    directory/trunks/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/AttributeTypeRegistry.java
    directory/trunks/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultAttributeTypeRegistry.java

Added: directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandlerITest.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandlerITest.java?view=auto&rev=494671
==============================================================================
--- directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandlerITest.java
(added)
+++ directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandlerITest.java
Tue Jan  9 16:46:50 2007
@@ -0,0 +1,476 @@
+/*
+ *  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.DirContext;
+
+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.message.AttributeImpl;
+import org.apache.directory.shared.ldap.message.AttributesImpl;
+import org.apache.directory.shared.ldap.message.ModificationItemImpl;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.schema.AttributeType;
+
+
+/**
+ * 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 MetaAttributeTypeHandlerITest extends AbstractAdminTestCase
+{
+    private static final String DESCRIPTION0 = "A test attributeType";
+    private static final String DESCRIPTION1 = "An alternate description";
+
+    private static final String INTEGER_SYNTAX_OID = "1.3.6.1.4.1.1466.115.121.1.27";
+    private static final String DIRSTR_SYNTAX_OID = "1.3.6.1.4.1.1466.115.121.1.15";
+    
+    private static final String OID = "1.3.6.1.4.1.18060.0.4.0.2.100000";
+    private static final String NEW_OID = "1.3.6.1.4.1.18060.0.4.0.2.100001";
+
+    
+    /**
+     * Gets relative DN to ou=schema.
+     */
+    private final LdapDN getAttributeTypeContainer( String schemaName ) throws NamingException
+    {
+        return new LdapDN( "ou=attributeTypes,cn=" + schemaName );
+    }
+    
+    
+    // ----------------------------------------------------------------------
+    // Test all core methods with normal operational pathways
+    // ----------------------------------------------------------------------
+
+    
+    public void testAddAttributeType() throws NamingException
+    {
+        Attributes attrs = new AttributesImpl();
+        Attribute oc = new AttributeImpl( SystemSchemaConstants.OBJECT_CLASS_AT, "top" );
+        oc.add( MetaSchemaConstants.META_TOP_OC );
+        oc.add( MetaSchemaConstants.META_ATTRIBUTE_TYPE_OC );
+        attrs.put( oc );
+        attrs.put( MetaSchemaConstants.M_OID_AT, OID );
+        attrs.put( MetaSchemaConstants.M_SYNTAX_AT, INTEGER_SYNTAX_OID );
+        attrs.put( MetaSchemaConstants.M_DESCRIPTION_AT, DESCRIPTION0 );
+        attrs.put( MetaSchemaConstants.M_EQUALITY_AT, "caseIgnoreMatch" );
+        attrs.put( MetaSchemaConstants.M_SINGLE_VALUE_AT, "FALSE" );
+        attrs.put( MetaSchemaConstants.M_USAGE_AT, "directoryOperation" );
+        
+        LdapDN dn = getAttributeTypeContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        super.schemaRoot.createSubcontext( dn, attrs );
+        
+        assertTrue( registries.getAttributeTypeRegistry().hasAttributeType( OID ) );
+        assertEquals( registries.getAttributeTypeRegistry().getSchemaName( OID ), "apachemeta"
);
+    }
+    
+    
+    public void testDeleteAttributeType() throws NamingException
+    {
+        LdapDN dn = getAttributeTypeContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        testAddAttributeType();
+        
+        super.schemaRoot.destroySubcontext( dn );
+
+        assertFalse( "attributeType should be removed from the registry after being deleted",

+            registries.getAttributeTypeRegistry().hasAttributeType( OID ) );
+        
+        try
+        {
+            registries.getAttributeTypeRegistry().lookup( OID );
+            fail( "attributeType lookup should fail after deleting it" );
+        }
+        catch( NamingException e )
+        {
+        }
+    }
+
+
+    public void testRenameAttributeType() throws NamingException
+    {
+        LdapDN dn = getAttributeTypeContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        testAddAttributeType();
+        
+        LdapDN newdn = getAttributeTypeContainer( "apachemeta" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + NEW_OID );
+        super.schemaRoot.rename( dn, newdn );
+
+        assertFalse( "old attributeType OID should be removed from the registry after being
renamed", 
+            registries.getAttributeTypeRegistry().hasAttributeType( OID ) );
+        
+        try
+        {
+            registries.getAttributeTypeRegistry().lookup( OID );
+            fail( "attributeType lookup should fail after renaming the attributeType" );
+        }
+        catch( NamingException e )
+        {
+        }
+
+        assertTrue( registries.getAttributeTypeRegistry().hasAttributeType( NEW_OID ) );
+    }
+
+
+    public void testMoveAttributeType() throws NamingException
+    {
+        testAddAttributeType();
+        
+        LdapDN dn = getAttributeTypeContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+
+        LdapDN newdn = getAttributeTypeContainer( "apache" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        
+        super.schemaRoot.rename( dn, newdn );
+
+        assertTrue( "attributeType OID should still be present", 
+            registries.getAttributeTypeRegistry().hasAttributeType( OID ) );
+        
+        assertEquals( "attributeType schema should be set to apache not apachemeta", 
+            registries.getAttributeTypeRegistry().getSchemaName( OID ), "apache" );
+    }
+
+
+    public void testMoveAttributeTypeAndChangeRdn() throws NamingException
+    {
+        testAddAttributeType();
+        
+        LdapDN dn = getAttributeTypeContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+
+        LdapDN newdn = getAttributeTypeContainer( "apache" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + NEW_OID );
+        
+        super.schemaRoot.rename( dn, newdn );
+
+        assertFalse( "old attributeType OID should NOT be present", 
+            registries.getAttributeTypeRegistry().hasAttributeType( OID ) );
+        
+        assertTrue( "new attributeType OID should be present", 
+            registries.getAttributeTypeRegistry().hasAttributeType( NEW_OID ) );
+        
+        assertEquals( "attributeType with new oid should have schema set to apache NOT apachemeta",

+            registries.getAttributeTypeRegistry().getSchemaName( NEW_OID ), "apache" );
+    }
+
+    
+    public void testModifyAttributeTypeWithModificationItems() throws NamingException
+    {
+        testAddAttributeType();
+        
+        AttributeType at = registries.getAttributeTypeRegistry().lookup( OID );
+        assertEquals( at.getDescription(), DESCRIPTION0 );
+        assertEquals( at.getSyntax().getOid(), INTEGER_SYNTAX_OID );
+
+        LdapDN dn = getAttributeTypeContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        
+        ModificationItemImpl[] mods = new ModificationItemImpl[2];
+        Attribute attr = new AttributeImpl( MetaSchemaConstants.M_DESCRIPTION_AT, DESCRIPTION1
);
+        mods[0] = new ModificationItemImpl( DirContext.REPLACE_ATTRIBUTE, attr );
+        attr = new AttributeImpl( MetaSchemaConstants.M_SYNTAX_AT, DIRSTR_SYNTAX_OID );
+        mods[1] = new ModificationItemImpl( DirContext.REPLACE_ATTRIBUTE, attr );
+        super.schemaRoot.modifyAttributes( dn, mods );
+
+        assertTrue( "attributeType OID should still be present", 
+            registries.getAttributeTypeRegistry().hasAttributeType( OID ) );
+        
+        assertEquals( "attributeType schema should be set to apachemeta", 
+            registries.getAttributeTypeRegistry().getSchemaName( OID ), "apachemeta" );
+        
+        at = registries.getAttributeTypeRegistry().lookup( OID );
+        assertEquals( at.getDescription(), DESCRIPTION1 );
+        assertEquals( at.getSyntax().getOid(), DIRSTR_SYNTAX_OID );
+    }
+
+    
+    public void testModifyAttributeTypeWithAttributes() throws NamingException
+    {
+        testAddAttributeType();
+        
+        AttributeType at = registries.getAttributeTypeRegistry().lookup( OID );
+        assertEquals( at.getDescription(), DESCRIPTION0 );
+        assertEquals( at.getSyntax().getOid(), INTEGER_SYNTAX_OID );
+
+        LdapDN dn = getAttributeTypeContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        
+        Attributes mods = new AttributesImpl();
+        mods.put( MetaSchemaConstants.M_DESCRIPTION_AT, DESCRIPTION1 );
+        mods.put( MetaSchemaConstants.M_SYNTAX_AT, DIRSTR_SYNTAX_OID );
+        super.schemaRoot.modifyAttributes( dn, DirContext.REPLACE_ATTRIBUTE, mods );
+
+        assertTrue( "attributeType OID should still be present", 
+            registries.getAttributeTypeRegistry().hasAttributeType( OID ) );
+        
+        assertEquals( "attributeType schema should be set to apachemeta", 
+            registries.getAttributeTypeRegistry().getSchemaName( OID ), "apachemeta" );
+
+        at = registries.getAttributeTypeRegistry().lookup( OID );
+        assertEquals( at.getDescription(), DESCRIPTION1 );
+        assertEquals( at.getSyntax().getOid(), DIRSTR_SYNTAX_OID );
+    }
+    
+
+    // ----------------------------------------------------------------------
+    // Test move, rename, and delete when a MR exists and uses the Normalizer
+    // ----------------------------------------------------------------------
+
+    
+//    public void testDeleteSyntaxWhenInUse() throws NamingException
+//    {
+//        LdapDN dn = getSyntaxContainer( "apachemeta" );
+//        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+//        testAddSyntax();
+//        addDependeeMatchingRule();
+//        
+//        try
+//        {
+//            super.schemaRoot.destroySubcontext( dn );
+//            fail( "should not be able to delete a syntax in use" );
+//        }
+//        catch( LdapOperationNotSupportedException e ) 
+//        {
+//            assertEquals( e.getResultCode(), ResultCodeEnum.UNWILLING_TO_PERFORM );
+//        }
+//
+//        assertTrue( "syntax should still be in the registry after delete failure", 
+//            registries.getSyntaxRegistry().hasSyntax( OID ) );
+//    }
+//    
+//    
+//    public void testMoveSyntaxWhenInUse() throws NamingException
+//    {
+//        testAddSyntax();
+//        addDependeeMatchingRule();
+//        
+//        LdapDN dn = getSyntaxContainer( "apachemeta" );
+//        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+//
+//        LdapDN newdn = getSyntaxContainer( "apache" );
+//        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+//        
+//        try
+//        {
+//            super.schemaRoot.rename( dn, newdn );
+//            fail( "should not be able to move a syntax in use" );
+//        }
+//        catch( LdapOperationNotSupportedException e ) 
+//        {
+//            assertEquals( e.getResultCode(), ResultCodeEnum.UNWILLING_TO_PERFORM );
+//        }
+//
+//        assertTrue( "syntax should still be in the registry after move failure", 
+//            registries.getSyntaxRegistry().hasSyntax( OID ) );
+//    }
+//
+//
+//    public void testMoveSyntaxAndChangeRdnWhenInUse() throws NamingException
+//    {
+//        testAddSyntax();
+//        addDependeeMatchingRule()
+//        
+//        LdapDN dn = getSyntaxContainer( "apachemeta" );
+//        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+//
+//        LdapDN newdn = getSyntaxContainer( "apache" );
+//        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + NEW_OID );
+//        
+//        try
+//        {
+//            super.schemaRoot.rename( dn, newdn );
+//            fail( "should not be able to move a syntax in use" );
+//        }
+//        catch( LdapOperationNotSupportedException e ) 
+//        {
+//            assertEquals( e.getResultCode(), ResultCodeEnum.UNWILLING_TO_PERFORM );
+//        }
+//
+//        assertTrue( "syntax should still be in the registry after move failure", 
+//            registries.getSyntaxRegistry().hasSyntax( OID ) );
+//    }
+//
+//    
+
+    // Need to add body to this method which creates a new matchingRule after 
+    // the matchingRule addition code has been added.
+    
+//    private void addDependeeMatchingRule()
+//    {
+//        throw new NotImplementedException();
+//    }
+//    
+//    public void testRenameNormalizerWhenInUse() throws NamingException
+//    {
+//        LdapDN dn = getSyntaxContainer( "apachemeta" );
+//        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+//        testAddSyntax();
+//        addDependeeMatchingRule();
+//        
+//        LdapDN newdn = getSyntaxContainer( "apachemeta" );
+//        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + NEW_OID );
+//        
+//        try
+//        {
+//            super.schemaRoot.rename( dn, newdn );
+//            fail( "should not be able to rename a syntax in use" );
+//        }
+//        catch( LdapOperationNotSupportedException e ) 
+//        {
+//            assertEquals( e.getResultCode(), ResultCodeEnum.UNWILLING_TO_PERFORM );
+//        }
+//
+//        assertTrue( "syntax should still be in the registry after rename failure", 
+//            registries.getSyntaxRegistry().hasSyntax( OID ) );
+//    }
+
+
+    // ----------------------------------------------------------------------
+    // Let's try some freaky stuff
+    // ----------------------------------------------------------------------
+
+
+    public void testMoveAttributeTypeToTop() throws NamingException
+    {
+        testAddAttributeType();
+        
+        LdapDN dn = getAttributeTypeContainer( "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 attributeType up to ou=schema" );
+        }
+        catch( LdapInvalidNameException e ) 
+        {
+            assertEquals( e.getResultCode(), ResultCodeEnum.NAMING_VIOLATION );
+        }
+
+        assertTrue( "attributeType should still be in the registry after move failure", 
+            registries.getAttributeTypeRegistry().hasAttributeType( OID ) );
+    }
+
+
+    public void testMoveAttributeTypeToComparatorContainer() throws NamingException
+    {
+        testAddAttributeType();
+        
+        LdapDN dn = getAttributeTypeContainer( "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 attributeType into comparators container"
);
+        }
+        catch( LdapInvalidNameException e ) 
+        {
+            assertEquals( e.getResultCode(), ResultCodeEnum.NAMING_VIOLATION );
+        }
+
+        assertTrue( "attributeType should still be in the registry after move failure", 
+            registries.getAttributeTypeRegistry().hasAttributeType( OID ) );
+    }
+    
+    
+    public void testAddAttributeTypeToDisabledSchema() throws NamingException
+    {
+        Attributes attrs = new AttributesImpl();
+        Attribute oc = new AttributeImpl( SystemSchemaConstants.OBJECT_CLASS_AT, "top" );
+        oc.add( MetaSchemaConstants.META_TOP_OC );
+        oc.add( MetaSchemaConstants.META_ATTRIBUTE_TYPE_OC );
+        attrs.put( oc );
+        attrs.put( MetaSchemaConstants.M_OID_AT, OID );
+        attrs.put( MetaSchemaConstants.M_SYNTAX_AT, INTEGER_SYNTAX_OID );
+        attrs.put( MetaSchemaConstants.M_DESCRIPTION_AT, DESCRIPTION0 );
+        attrs.put( MetaSchemaConstants.M_EQUALITY_AT, "caseIgnoreMatch" );
+        attrs.put( MetaSchemaConstants.M_SINGLE_VALUE_AT, "FALSE" );
+        attrs.put( MetaSchemaConstants.M_USAGE_AT, "directoryOperation" );
+        
+        LdapDN dn = getAttributeTypeContainer( "nis" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        super.schemaRoot.createSubcontext( dn, attrs );
+        
+        assertFalse( "adding new attributeType to disabled schema should not register it
into the registries", 
+            registries.getAttributeTypeRegistry().hasAttributeType( OID ) );
+    }
+
+
+    public void testMoveAttributeTypeToDisabledSchema() throws NamingException
+    {
+        testAddAttributeType();
+        
+        LdapDN dn = getAttributeTypeContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+
+        // nis is inactive by default
+        LdapDN newdn = getAttributeTypeContainer( "nis" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        
+        super.schemaRoot.rename( dn, newdn );
+
+        assertFalse( "attributeType OID should no longer be present", 
+            registries.getAttributeTypeRegistry().hasAttributeType( OID ) );
+    }
+
+
+    public void testMoveMatchingRuleToEnabledSchema() throws NamingException
+    {
+        testAddAttributeTypeToDisabledSchema();
+        
+        // nis is inactive by default
+        LdapDN dn = getAttributeTypeContainer( "nis" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+
+        assertFalse( "attributeType OID should NOT be present when added to disabled nis
schema", 
+            registries.getAttributeTypeRegistry().hasAttributeType( OID ) );
+
+        LdapDN newdn = getAttributeTypeContainer( "apachemeta" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        
+        super.schemaRoot.rename( dn, newdn );
+
+        assertTrue( "attributeType OID should be present when moved to enabled schema", 
+            registries.getAttributeTypeRegistry().hasAttributeType( OID ) );
+        
+        assertEquals( "attributeType should be in apachemeta schema after move", 
+            registries.getAttributeTypeRegistry().getSchemaName( OID ), "apachemeta" );
+    }
+}

Added: directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandler.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandler.java?view=auto&rev=494671
==============================================================================
--- directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandler.java
(added)
+++ directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandler.java
Tue Jan  9 16:46:50 2007
@@ -0,0 +1,292 @@
+/*
+ *   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.util.HashSet;
+import java.util.Set;
+
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.SearchResult;
+
+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.AttributeTypeRegistry;
+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.AttributeImpl;
+import org.apache.directory.shared.ldap.message.ModificationItemImpl;
+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;
+
+
+/**
+ * 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 MetaAttributeTypeHandler implements SchemaChangeHandler
+{
+    private static final String OU_OID = "2.5.4.11";
+
+    private final PartitionSchemaLoader loader;
+    private final SchemaPartitionDao dao;
+    private final SchemaEntityFactory factory;
+    private final Registries targetRegistries;
+    private final AttributeTypeRegistry attributeTypeRegistry;
+    private final AttributeType m_oidAT;
+
+    
+
+    public MetaAttributeTypeHandler( Registries targetRegistries, PartitionSchemaLoader loader,
SchemaPartitionDao dao ) 
+        throws NamingException
+    {
+        this.targetRegistries = targetRegistries;
+        this.dao = dao;
+        this.loader = loader;
+        this.attributeTypeRegistry = targetRegistries.getAttributeTypeRegistry();
+        this.factory = new SchemaEntityFactory( targetRegistries );
+        this.m_oidAT = attributeTypeRegistry.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 );
+        AttributeType at = factory.getAttributeType( targetEntry, targetRegistries );
+        Schema schema = getSchema( name );
+        
+        if ( ! schema.isDisabled() )
+        {
+            attributeTypeRegistry.unregister( oldOid );
+            attributeTypeRegistry.register( schema.getSchemaName(), at );
+        }
+    }
+
+
+    public void modify( LdapDN name, int modOp, Attributes mods, Attributes entry, Attributes
targetEntry )
+        throws NamingException
+    {
+        modify( name, entry, targetEntry );
+    }
+
+
+    public void modify( LdapDN name, ModificationItemImpl[] 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 );
+        
+        AttributeType at = factory.getAttributeType( entry, targetRegistries );
+        Schema schema = getSchema( name );
+        
+        if ( ! schema.isDisabled() )
+        {
+            attributeTypeRegistry.register( schema.getSchemaName(), at );
+        }
+    }
+
+
+    private Set<String> getOids( Set<SearchResult> results ) throws NamingException
+    {
+        Set<String> oids = new HashSet<String>( results.size() );
+        
+        for ( SearchResult result : results )
+        {
+            LdapDN dn = new LdapDN( result.getName() );
+            dn.normalize( this.targetRegistries.getAttributeTypeRegistry().getNormalizerMapping()
);
+            oids.add( ( String ) dn.getRdn().getValue() );
+        }
+        
+        return oids;
+    }
+    
+    
+    public void delete( LdapDN name, Attributes entry ) throws NamingException
+    {
+        AttributeType at = factory.getAttributeType( entry, targetRegistries );
+        Set<SearchResult> dependees = dao.listAttributeTypeDependees( at );
+        if ( dependees != null && dependees.size() > 0 )
+        {
+            throw new LdapOperationNotSupportedException( "The attributeType with OID " +
at.getOid() 
+                + " cannot be deleted until all entities" 
+                + " using this attributeType have also been deleted.  The following dependees
exist: " 
+                + getOids( dependees ), 
+                ResultCodeEnum.UNWILLING_TO_PERFORM );
+        }
+        
+        Schema schema = getSchema( name );
+        
+        if ( ! schema.isDisabled() )
+        {
+            attributeTypeRegistry.unregister( at.getOid() );
+        }
+    }
+
+
+    public void rename( LdapDN name, Attributes entry, String newRdn ) throws NamingException
+    {
+        AttributeType oldAt = factory.getAttributeType( entry, targetRegistries );
+        Set<SearchResult> dependees = dao.listAttributeTypeDependees( oldAt );
+        if ( dependees != null && dependees.size() > 0 )
+        {
+            throw new LdapOperationNotSupportedException( "The attributeType with OID " +
oldAt.getOid()
+                + " cannot be deleted until all entities" 
+                + " using this attributeType have also been deleted.  The following dependees
exist: " 
+                + getOids( dependees ), 
+                ResultCodeEnum.UNWILLING_TO_PERFORM );
+        }
+
+        Schema schema = getSchema( name );
+        Attributes targetEntry = ( Attributes ) entry.clone();
+        String newOid = NamespaceTools.getRdnValue( newRdn );
+        targetEntry.put( new AttributeImpl( MetaSchemaConstants.M_OID_AT, newOid ) );
+        if ( ! schema.isDisabled() )
+        {
+            AttributeType at = factory.getAttributeType( targetEntry, targetRegistries );
+            attributeTypeRegistry.unregister( oldAt.getOid() );
+            attributeTypeRegistry.register( schema.getSchemaName(), at );
+        }
+    }
+
+
+    public void move( LdapDN oriChildName, LdapDN newParentName, String newRn, boolean deleteOldRn,
Attributes entry ) 
+        throws NamingException
+    {
+        checkNewParent( newParentName );
+        AttributeType oldAt = factory.getAttributeType( entry, targetRegistries );
+        Set<SearchResult> dependees = dao.listAttributeTypeDependees( oldAt );
+        if ( dependees != null && dependees.size() > 0 )
+        {
+            throw new LdapOperationNotSupportedException( "The attributeType with OID " +
oldAt.getOid()
+                + " cannot be deleted until all entities" 
+                + " using this attributeType have also been deleted.  The following dependees
exist: " 
+                + getOids( dependees ), 
+                ResultCodeEnum.UNWILLING_TO_PERFORM );
+        }
+
+        Schema oldSchema = getSchema( oriChildName );
+        Schema newSchema = getSchema( newParentName );
+        Attributes targetEntry = ( Attributes ) entry.clone();
+        String newOid = NamespaceTools.getRdnValue( newRn );
+        targetEntry.put( new AttributeImpl( MetaSchemaConstants.M_OID_AT, newOid ) );
+        AttributeType at = factory.getAttributeType( targetEntry, targetRegistries );
+
+        if ( ! oldSchema.isDisabled() )
+        {
+            attributeTypeRegistry.unregister( oldAt.getOid() );
+        }
+
+        if ( ! newSchema.isDisabled() )
+        {
+            attributeTypeRegistry.register( newSchema.getSchemaName(), at );
+        }
+    }
+
+
+    public void move( LdapDN oriChildName, LdapDN newParentName, Attributes entry ) 
+        throws NamingException
+    {
+        checkNewParent( newParentName );
+        AttributeType oldAt = factory.getAttributeType( entry, targetRegistries );
+        Set<SearchResult> dependees = dao.listAttributeTypeDependees( oldAt );
+        if ( dependees != null && dependees.size() > 0 )
+        {
+            throw new LdapOperationNotSupportedException( "The attributeType with OID " +
oldAt.getOid() 
+                + " cannot be deleted until all entities" 
+                + " using this attributeType have also been deleted.  The following dependees
exist: " 
+                + getOids( dependees ), 
+                ResultCodeEnum.UNWILLING_TO_PERFORM );
+        }
+
+        Schema oldSchema = getSchema( oriChildName );
+        Schema newSchema = getSchema( newParentName );
+        
+        AttributeType at = factory.getAttributeType( entry, targetRegistries );
+        
+        if ( ! oldSchema.isDisabled() )
+        {
+            attributeTypeRegistry.unregister( oldAt.getOid() );
+        }
+        
+        if ( ! newSchema.isDisabled() )
+        {
+            attributeTypeRegistry.register( newSchema.getSchemaName(), at );
+        }
+    }
+    
+    
+    private void checkNewParent( LdapDN newParent ) throws NamingException
+    {
+        if ( newParent.size() != 3 )
+        {
+            throw new LdapInvalidNameException( 
+                "The parent dn of a attributeType 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 attributeType should
be an organizationalUnit.", 
+                ResultCodeEnum.NAMING_VIOLATION );
+        }
+        
+        if ( ! ( ( String ) rdn.getValue() ).equalsIgnoreCase( "attributeTypes" ) )
+        {
+            throw new LdapInvalidNameException( 
+                "The parent entry of a attributeType should have a relative name of ou=attributeTypes.",

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

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=494671&r1=494670&r2=494671
==============================================================================
--- 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
Tue Jan  9 16:46:50 2007
@@ -59,6 +59,7 @@
     private final MetaSyntaxCheckerHandler metaSyntaxCheckerHandler;
     private final MetaSyntaxHandler metaSyntaxHandler;
     private final MetaMatchingRuleHandler metaMatchingRuleHandler;
+    private final MetaAttributeTypeHandler metaAttributeTypeHandler;
     
 
     public SchemaManager( Registries globalRegistries, PartitionSchemaLoader loader, SchemaPartitionDao
dao ) 
@@ -74,6 +75,7 @@
         this.metaSyntaxCheckerHandler = new MetaSyntaxCheckerHandler( globalRegistries, loader
);
         this.metaSyntaxHandler = new MetaSyntaxHandler( globalRegistries, loader, dao );
         this.metaMatchingRuleHandler = new MetaMatchingRuleHandler( globalRegistries, loader,
dao );
+        this.metaAttributeTypeHandler = new MetaAttributeTypeHandler( globalRegistries, loader,
dao );
     }
     
     
@@ -129,6 +131,12 @@
             return;
         }
 
+        if ( AttributeUtils.containsValue( oc, MetaSchemaConstants.META_ATTRIBUTE_TYPE_OC,
objectClassAT ) )
+        {
+            metaAttributeTypeHandler.add( name, entry );
+            return;
+        }
+
         throw new NotImplementedException( "only changes to metaSchema objects are managed
at this time" );
     }
     
@@ -173,6 +181,12 @@
             return;
         }
 
+        if ( AttributeUtils.containsValue( oc, MetaSchemaConstants.META_ATTRIBUTE_TYPE_OC,
objectClassAT ) )
+        {
+            metaAttributeTypeHandler.delete( name, entry );
+            return;
+        }
+
         throw new NotImplementedException( "only changes to metaSchema objects are managed
at this time" );
     }
     
@@ -218,6 +232,12 @@
             return;
         }
 
+        if ( AttributeUtils.containsValue( oc, MetaSchemaConstants.META_ATTRIBUTE_TYPE_OC,
objectClassAT ) )
+        {
+            metaAttributeTypeHandler.modify( name, modOp, mods, entry, targetEntry );
+            return;
+        }
+
         throw new NotImplementedException( "only changes to metaSchema objects are managed
at this time" );
     }
 
@@ -263,6 +283,12 @@
             return;
         }
 
+        if ( AttributeUtils.containsValue( oc, MetaSchemaConstants.META_ATTRIBUTE_TYPE_OC,
objectClassAT ) )
+        {
+            metaAttributeTypeHandler.modify( name, mods, entry, targetEntry );
+            return;
+        }
+
         throw new NotImplementedException( "only changes to metaSchema objects are managed
at this time" );
     }
 
@@ -307,6 +333,12 @@
             return;
         }
 
+        if ( AttributeUtils.containsValue( oc, MetaSchemaConstants.META_ATTRIBUTE_TYPE_OC,
objectClassAT ) )
+        {
+            metaAttributeTypeHandler.rename( name, entry, newRdn );
+            return;
+        }
+
         throw new NotImplementedException( "only changes to metaSchema objects are managed
at this time" );
     }
 
@@ -351,6 +383,12 @@
             return;
         }
 
+        if ( AttributeUtils.containsValue( oc, MetaSchemaConstants.META_ATTRIBUTE_TYPE_OC,
objectClassAT ) )
+        {
+            metaAttributeTypeHandler.move( oriChildName, newParentName, entry );
+            return;
+        }
+
         throw new NotImplementedException( "only changes to metaSchema objects are managed
at this time" );
     }
 
@@ -393,6 +431,12 @@
         if ( AttributeUtils.containsValue( oc, MetaSchemaConstants.META_MATCHING_RULE_OC,
objectClassAT ) )
         {
             metaMatchingRuleHandler.move( oriChildName, newParentName, newRn, deleteOldRn,
entry );
+            return;
+        }
+
+        if ( AttributeUtils.containsValue( oc, MetaSchemaConstants.META_ATTRIBUTE_TYPE_OC,
objectClassAT ) )
+        {
+            metaAttributeTypeHandler.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=494671&r1=494670&r2=494671
==============================================================================
--- 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
Tue Jan  9 16:46:50 2007
@@ -87,7 +87,10 @@
     private final String M_ORDERING_OID;
     private final String M_SUBSTRING_OID;
     private final String M_EQUALITY_OID;
-   
+    private final String M_SUP_ATTRIBUTE_TYPE_OID;
+    private final String M_MUST_OID;
+    private final String M_MAY_OID;
+    
     private final AttributeType disabledAttributeType;
     
     
@@ -114,6 +117,9 @@
         this.M_ORDERING_OID = oidRegistry.getOid( MetaSchemaConstants.M_ORDERING_AT );
         this.M_EQUALITY_OID = oidRegistry.getOid( MetaSchemaConstants.M_EQUALITY_AT );
         this.M_SUBSTRING_OID = oidRegistry.getOid( MetaSchemaConstants.M_SUBSTR_AT );
+        this.M_SUP_ATTRIBUTE_TYPE_OID = oidRegistry.getOid( MetaSchemaConstants.M_SUP_ATTRIBUTE_TYPE_AT
);
+        this.M_MUST_OID = oidRegistry.getOid( MetaSchemaConstants.M_MUST_AT );
+        this.M_MAY_OID = oidRegistry.getOid( MetaSchemaConstants.M_MAY_AT );
     }
 
 
@@ -441,5 +447,49 @@
         filter.addNode( new PresenceNode( M_OID_OID ) );
         filter.addNode( new PresenceNode( M_NAME_OID ) );
         return partition.search( partition.getSuffix(), new HashMap(), filter, searchControls
);
+    }
+
+
+    public Set<SearchResult> listAttributeTypeDependees( AttributeType at ) throws
NamingException
+    {
+        Set<SearchResult> set = new HashSet<SearchResult>( );
+        BranchNode filter = new BranchNode( AssertionEnum.AND );
+        
+        // ( objectClass = metaAttributeType )
+        BranchNode or = new BranchNode( AssertionEnum.OR );
+        or.addNode( new SimpleNode( OBJECTCLASS_OID, 
+            MetaSchemaConstants.META_ATTRIBUTE_TYPE_OC.toLowerCase(), AssertionEnum.EQUALITY
) );
+        or.addNode( new SimpleNode( OBJECTCLASS_OID, 
+            MetaSchemaConstants.META_OBJECT_CLASS_OC.toLowerCase(), AssertionEnum.EQUALITY
) );
+        filter.addNode( or );
+
+        
+        or = new BranchNode( AssertionEnum.OR );
+        or.addNode( new SimpleNode( M_MAY_OID, at.getOid(), AssertionEnum.EQUALITY ) );
+        or.addNode( new SimpleNode( M_MUST_OID, at.getOid(), AssertionEnum.EQUALITY ) );
+        or.addNode( new SimpleNode( M_SUP_ATTRIBUTE_TYPE_OID, at.getOid(), AssertionEnum.EQUALITY
) );
+        filter.addNode( or );
+
+        SearchControls searchControls = new SearchControls();
+        searchControls.setSearchScope( SearchControls.SUBTREE_SCOPE );
+        NamingEnumeration<SearchResult> ne = null;
+        
+        try
+        {
+            ne = partition.search( partition.getSuffix(), new HashMap(), filter, searchControls
);
+            while( ne.hasMore() )
+            {
+                set.add( ne.next() );
+            }
+        }
+        finally
+        {
+            if ( ne != null )
+            {
+                ne.close();
+            }
+        }
+        
+        return set;
     }
 }

Modified: directory/trunks/apacheds/core/src/test/java/org/apache/directory/server/core/authz/support/DummyAttributeTypeRegistry.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core/src/test/java/org/apache/directory/server/core/authz/support/DummyAttributeTypeRegistry.java?view=diff&rev=494671&r1=494670&r2=494671
==============================================================================
--- directory/trunks/apacheds/core/src/test/java/org/apache/directory/server/core/authz/support/DummyAttributeTypeRegistry.java
(original)
+++ directory/trunks/apacheds/core/src/test/java/org/apache/directory/server/core/authz/support/DummyAttributeTypeRegistry.java
Tue Jan  9 16:46:50 2007
@@ -67,6 +67,9 @@
         {
             return new AttributeType()
             {
+                private static final long serialVersionUID = 1L;
+
+
                 public boolean isSingleValue()
                 {
                     return false;
@@ -113,6 +116,7 @@
                 {
                     return new MatchingRule()
                     {
+                        private static final long serialVersionUID = 1L;
 
                         public Syntax getSyntax() throws NamingException
                         {
@@ -128,6 +132,8 @@
                         {
                             return new Normalizer()
                             {
+                                private static final long serialVersionUID = 1L;
+
                                 public Object normalize( Object value ) throws NamingException
                                 {
                                     return StringTools.deepTrimToLower( value.toString()
);
@@ -211,6 +217,8 @@
         {
             return new AttributeType()
             {
+                private static final long serialVersionUID = 1L;
+
                 public boolean isSingleValue()
                 {
                     return false;
@@ -246,6 +254,8 @@
                     return new Syntax()
                     {
 
+                        private static final long serialVersionUID = 1L;
+
                         public boolean isHumanReadible()
                         {
                             return true;
@@ -295,11 +305,14 @@
                 {
                     return new MatchingRule()
                     {
+                        private static final long serialVersionUID = 1L;
 
                         public Syntax getSyntax() throws NamingException
                         {
                             return new Syntax()
                             {
+                                private static final long serialVersionUID = 1L;
+
 
                                 public boolean isHumanReadible()
                                 {
@@ -348,6 +361,8 @@
                         {
                             return new Normalizer()
                             {
+                                private static final long serialVersionUID = 1L;
+
                                 public Object normalize( Object value ) throws NamingException
                                 {
                                     return StringTools.deepTrimToLower( value.toString()
);
@@ -469,5 +484,10 @@
     public Iterator<AttributeType> iterator()
     {
         return null;
+    }
+
+
+    public void unregister( String numericOid ) throws NamingException
+    {
     }
 }

Modified: directory/trunks/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/AttributeTypeRegistry.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/AttributeTypeRegistry.java?view=diff&rev=494671&r1=494670&r2=494671
==============================================================================
--- directory/trunks/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/AttributeTypeRegistry.java
(original)
+++ directory/trunks/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/AttributeTypeRegistry.java
Tue Jan  9 16:46:50 2007
@@ -121,4 +121,13 @@
      * @return Iterator over attributeTypes
      */
     Iterator<AttributeType> iterator();
+
+
+    /**
+     * Removes the AttributeType registered with this registry.
+     * 
+     * @param numericOid the numeric identifier
+     * @throws NamingException if the numeric identifier is invalid
+     */
+    void unregister( String numericOid ) throws NamingException;
 }

Modified: directory/trunks/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultAttributeTypeRegistry.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultAttributeTypeRegistry.java?view=diff&rev=494671&r1=494670&r2=494671
==============================================================================
--- directory/trunks/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultAttributeTypeRegistry.java
(original)
+++ directory/trunks/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultAttributeTypeRegistry.java
Tue Jan  9 16:46:50 2007
@@ -96,6 +96,7 @@
         {
             oidRegistry.register( names[ii], attributeType.getOid() );
         }
+        oidRegistry.register( attributeType.getOid(), attributeType.getOid() );
 
         registerDescendants( attributeType );
         oidToSchema.put( attributeType.getOid(), schema );
@@ -261,5 +262,18 @@
     public Iterator<AttributeType> iterator()
     {
         return byOid.values().iterator();
+    }
+    
+    
+    public void unregister( String numericOid ) throws NamingException
+    {
+        if ( ! Character.isDigit( numericOid.charAt( 0 ) ) )
+        {
+            throw new NamingException( "Looks like the arg is not a numeric OID" );
+        }
+
+        byOid.remove( numericOid );
+        oidToSchema.remove( numericOid );
+        oidToDescendantSet.remove( numericOid );
     }
 }



Mime
View raw message