directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r505125 - in /directory/apacheds/trunk: bootstrap-plugin/src/main/java/org/apache/directory/server/core/bootstrap/plugin/ core-unit/src/test/java/org/apache/directory/server/core/schema/ core/src/main/java/org/apache/directory/server/core/e...
Date Fri, 09 Feb 2007 01:57:06 GMT
Author: akarasulu
Date: Thu Feb  8 17:57:05 2007
New Revision: 505125

URL: http://svn.apache.org/viewvc?view=rev&rev=505125
Log:
changes ...

 o removed bogus attempt to implement modify REPLACE operations on the schema
   subentry: this is bogus since ADD and REMOVE work well enough why be so
   inefficient to destroy and recreate so many entities
 o added some test cases for syntaxCheckers that are added, and removed from the
   schema subentry
 o fixed some awkward code that was passing around schema name unnecessarily in 
   the SchemaManager
 o fixed bootstrap plugin to generate all schema entity containers
 o bootstrap plugin also generates an empty setup for the by default enabled
   other schema
 o fixed bugs in a couple services where modify operations on the schema 
   subentry are handled


Modified:
    directory/apacheds/trunk/bootstrap-plugin/src/main/java/org/apache/directory/server/core/bootstrap/plugin/BootstrapPlugin.java
    directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/SubschemaSubentryITest.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/exception/ExceptionService.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeService.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaManager.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaSubentryModifier.java

Modified: directory/apacheds/trunk/bootstrap-plugin/src/main/java/org/apache/directory/server/core/bootstrap/plugin/BootstrapPlugin.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/bootstrap-plugin/src/main/java/org/apache/directory/server/core/bootstrap/plugin/BootstrapPlugin.java?view=diff&rev=505125&r1=505124&r2=505125
==============================================================================
--- directory/apacheds/trunk/bootstrap-plugin/src/main/java/org/apache/directory/server/core/bootstrap/plugin/BootstrapPlugin.java
(original)
+++ directory/apacheds/trunk/bootstrap-plugin/src/main/java/org/apache/directory/server/core/bootstrap/plugin/BootstrapPlugin.java
Thu Feb  8 17:57:05 2007
@@ -263,7 +263,8 @@
         }
     }
 
-    
+
+    private static final String[] OTHER_SCHEMA_DEPENDENCIES = new String[] { "system", "core",
"apache", "apachemeta" };
     private void createSchemasAndContainers() throws NamingException
     {
         Map schemaMap = this.registries.getLoadedSchemas();
@@ -271,48 +272,106 @@
         while ( schemas.hasNext() )
         {
             Schema schema = ( Schema ) schemas.next();
-            LdapDN dn = new LdapDN( SystemSchemaConstants.CN_AT + "=" 
-                + schema.getSchemaName() + "," + CoreSchemaConstants.OU_AT + "=schema" );
-            dn.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
+            createSchemaAndContainers( schema );
+        }
+        
+        Schema other = new Schema()
+        {
+            public String[] getDependencies()
+            {
+                return OTHER_SCHEMA_DEPENDENCIES;
+            }
 
-            if ( hasEntry( dn ) )
+            public String getOwner()
             {
-                continue;
+                return "uid=admin,ou=system";
             }
-            
-            Attributes entry = attributesFactory.getAttributes( schema );
-            store.add( dn, entry );
-            dn.add( CoreSchemaConstants.OU_AT + "=comparators" );
-            dn.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
-            checkCreateContainer( dn );
-            dn.remove( dn.size() - 1 );
-            dn.add( CoreSchemaConstants.OU_AT + "=normalizers" );
-            dn.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
-            checkCreateContainer( dn );
-            dn.remove( dn.size() - 1 );
-            dn.add( CoreSchemaConstants.OU_AT + "=syntaxCheckers" );
-            dn.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
-            checkCreateContainer( dn );
-            dn.remove( dn.size() - 1 );
-            dn.add( CoreSchemaConstants.OU_AT + "=syntaxes" );
-            dn.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
-            checkCreateContainer( dn );
-            dn.remove( dn.size() - 1 );
-            dn.add( CoreSchemaConstants.OU_AT + "=matchingRules" );
-            dn.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
-            checkCreateContainer( dn );
-            dn.remove( dn.size() - 1 );
-            dn.add( CoreSchemaConstants.OU_AT + "=attributeTypes" );
-            dn.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
-            checkCreateContainer( dn );
-            dn.remove( dn.size() - 1 );
-            dn.add( CoreSchemaConstants.OU_AT + "=objectClasses" );
-            dn.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
-            checkCreateContainer( dn );
-        }
+
+            public String getSchemaName()
+            {
+                return "other";
+            }
+
+            public boolean isDisabled()
+            {
+                return false;
+            }
+        };
+        
+        createSchemaAndContainers( other );
     }
 
 
+    private void createSchemaAndContainers( Schema schema ) throws NamingException
+    {
+        LdapDN dn = new LdapDN( SystemSchemaConstants.CN_AT + "=" 
+            + schema.getSchemaName() + "," + CoreSchemaConstants.OU_AT + "=schema" );
+        dn.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
+
+        if ( hasEntry( dn ) )
+        {
+            return;
+        }
+        
+        Attributes entry = attributesFactory.getAttributes( schema );
+        store.add( dn, entry );
+        
+        dn.add( CoreSchemaConstants.OU_AT + "=comparators" );
+        dn.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
+        checkCreateContainer( dn );
+        
+        dn.remove( dn.size() - 1 );
+        dn.add( CoreSchemaConstants.OU_AT + "=normalizers" );
+        dn.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
+        checkCreateContainer( dn );
+        
+        dn.remove( dn.size() - 1 );
+        dn.add( CoreSchemaConstants.OU_AT + "=syntaxCheckers" );
+        dn.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
+        checkCreateContainer( dn );
+        
+        dn.remove( dn.size() - 1 );
+        dn.add( CoreSchemaConstants.OU_AT + "=syntaxes" );
+        dn.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
+        checkCreateContainer( dn );
+        
+        dn.remove( dn.size() - 1 );
+        dn.add( CoreSchemaConstants.OU_AT + "=matchingRules" );
+        dn.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
+        checkCreateContainer( dn );
+        
+        dn.remove( dn.size() - 1 );
+        dn.add( CoreSchemaConstants.OU_AT + "=attributeTypes" );
+        dn.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
+        checkCreateContainer( dn );
+        
+        dn.remove( dn.size() - 1 );
+        dn.add( CoreSchemaConstants.OU_AT + "=objectClasses" );
+        dn.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
+        checkCreateContainer( dn );
+        
+        dn.remove( dn.size() - 1 );
+        dn.add( CoreSchemaConstants.OU_AT + "=nameForms" );
+        dn.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
+        checkCreateContainer( dn );
+        
+        dn.remove( dn.size() - 1 );
+        dn.add( CoreSchemaConstants.OU_AT + "=ditStructureRules" );
+        dn.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
+        checkCreateContainer( dn );
+        
+        dn.remove( dn.size() - 1 );
+        dn.add( CoreSchemaConstants.OU_AT + "=ditContentRules" );
+        dn.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
+        checkCreateContainer( dn );
+        
+        dn.remove( dn.size() - 1 );
+        dn.add( CoreSchemaConstants.OU_AT + "=matchingRuleUse" );
+        dn.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
+        checkCreateContainer( dn );
+    }
+
+    
     private void addAttributeTypes() throws NamingException
     {
         getLog().info( "------------------------------------------------------------------------"
);

Modified: directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/SubschemaSubentryITest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/SubschemaSubentryITest.java?view=diff&rev=505125&r1=505124&r2=505125
==============================================================================
--- directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/SubschemaSubentryITest.java
(original)
+++ directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/SubschemaSubentryITest.java
Thu Feb  8 17:57:05 2007
@@ -20,6 +20,12 @@
 package org.apache.directory.server.core.schema;
 
 
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
 import javax.naming.directory.Attribute;
@@ -32,12 +38,18 @@
 import org.apache.directory.shared.ldap.exception.LdapNameAlreadyBoundException;
 import org.apache.directory.shared.ldap.exception.LdapOperationNotSupportedException;
 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;
+import org.apache.directory.shared.ldap.schema.syntax.AcceptAllSyntaxChecker;
 import org.apache.directory.shared.ldap.schema.syntax.AttributeTypeDescription;
+import org.apache.directory.shared.ldap.schema.syntax.SyntaxChecker;
+import org.apache.directory.shared.ldap.schema.syntax.SyntaxCheckerDescription;
 import org.apache.directory.shared.ldap.schema.syntax.parser.AttributeTypeDescriptionSchemaParser;
+import org.apache.directory.shared.ldap.schema.syntax.parser.SyntaxCheckerDescriptionSchemaParser;
+import org.apache.directory.shared.ldap.util.Base64;
 
 
 /**
@@ -51,6 +63,9 @@
 {
     private static final String GLOBAL_SUBSCHEMA_DN = "cn=schema";
     private static final String SUBSCHEMA_SUBENTRY = "subschemaSubentry";
+    
+    private static final SyntaxCheckerDescriptionSchemaParser syntaxCheckerDescriptionSchemaParser
=
+        new SyntaxCheckerDescriptionSchemaParser();
     private static final AttributeTypeDescriptionSchemaParser attributeTypeDescriptionSchemaParser
= 
         new AttributeTypeDescriptionSchemaParser();
 
@@ -202,6 +217,228 @@
         mods[0] = new ModificationItemImpl( DirContext.REPLACE_ATTRIBUTE, attr );
         super.schemaRoot.modifyAttributes( "cn=" + schemaName, mods );
     }
+    
+    
+    // -----------------------------------------------------------------------
+    // SyntaxChecker Tests
+    // -----------------------------------------------------------------------
+
+    
+    private void checkSyntaxCheckerPresent( String oid, String schemaName ) throws Exception
+    {
+        // -------------------------------------------------------------------
+        // check first to see if it is present in the subschemaSubentry
+        // -------------------------------------------------------------------
+        
+        Attributes attrs = getSubschemaSubentryAttributes();
+        Attribute attrTypes = attrs.get( "syntaxCheckers" );
+        SyntaxCheckerDescription syntaxCheckerDescription = null; 
+        for ( int ii = 0; ii < attrTypes.size(); ii++ )
+        {
+            String desc = ( String ) attrTypes.get( ii );
+            if ( desc.indexOf( oid ) != -1 )
+            {
+                syntaxCheckerDescription = syntaxCheckerDescriptionSchemaParser.parseSyntaxCheckerDescription(
desc );
+                break;
+            }
+        }
+        
+        assertNotNull( syntaxCheckerDescription );
+        assertEquals( oid, syntaxCheckerDescription.getNumericOid() );
+
+        // -------------------------------------------------------------------
+        // check next to see if it is present in the schema partition
+        // -------------------------------------------------------------------
+        
+        attrs = null;
+        attrs = schemaRoot.getAttributes( "m-oid=" + oid + ",ou=syntaxCheckers,cn=" + schemaName
);
+        assertNotNull( attrs );
+        SchemaEntityFactory factory = new SchemaEntityFactory( registries );
+        SyntaxChecker syntaxChecker = factory.getSyntaxChecker( attrs, registries );
+        assertEquals( oid, syntaxChecker.getSyntaxOid() );
+        
+        // -------------------------------------------------------------------
+        // check to see if it is present in the syntaxCheckerRegistry
+        // -------------------------------------------------------------------
+        
+        assertTrue( registries.getSyntaxCheckerRegistry().hasSyntaxChecker( oid ) );
+    }
+    
+    
+    private void checkSyntaxCheckerNotPresent( String oid, String schemaName ) throws Exception
+    {
+        // -------------------------------------------------------------------
+        // check first to see if it is present in the subschemaSubentry
+        // -------------------------------------------------------------------
+        
+        Attributes attrs = getSubschemaSubentryAttributes();
+        Attribute attrTypes = attrs.get( "syntaxCheckers" );
+        SyntaxCheckerDescription syntaxCheckerDescription = null; 
+        for ( int ii = 0; ii < attrTypes.size(); ii++ )
+        {
+            String desc = ( String ) attrTypes.get( ii );
+            if ( desc.indexOf( oid ) != -1 )
+            {
+                syntaxCheckerDescription = syntaxCheckerDescriptionSchemaParser.parseSyntaxCheckerDescription(
desc );
+                break;
+            }
+        }
+        
+        assertNull( syntaxCheckerDescription );
+
+        // -------------------------------------------------------------------
+        // check next to see if it is present in the schema partition
+        // -------------------------------------------------------------------
+        
+        attrs = null;
+        
+        try
+        {
+            attrs = schemaRoot.getAttributes( "m-oid=" + oid + ",ou=syntaxCheckers,cn=" +
schemaName );
+            fail( "should never get here" );
+        }
+        catch( NamingException e )
+        {
+        }
+        
+        assertNull( attrs );
+        
+        // -------------------------------------------------------------------
+        // check to see if it is present in the syntaxCheckerRegistry
+        // -------------------------------------------------------------------
+        
+        assertFalse( registries.getSyntaxCheckerRegistry().hasSyntaxChecker( oid ) );
+    }
+    
+    
+    private void modifySyntaxCheckers( int op, List<String> descriptions ) throws Exception
+    {
+        LdapDN dn = new LdapDN( getSubschemaSubentryDN() );
+        Attribute attr = new AttributeImpl( "syntaxCheckers" );
+        for ( String description : descriptions )
+        {
+            attr.add( description );
+        }
+        
+        Attributes mods = new AttributesImpl();
+        mods.put( attr );
+        
+        rootDSE.modifyAttributes( dn, op, mods );
+    }
+    
+    
+    /**
+     * Tests a number of modify add, remove and replace operation combinations for
+     * a syntaxChecker on the schema subentry.
+     */
+    public void testAddRemoveReplaceSyntaxCheckers() throws Exception
+    {
+        enableSchema( "nis" );
+        List<String> descriptions = new ArrayList<String>();
+        
+        // ( 1.3.6.1.4.1.18060.0.4.0.2.10000 DESC 'bogus desc' FQCN org.foo.Bar BYTECODE
14561234 )
+        descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.0.10000 DESC 'bogus desc' FQCN " 
+            + AcceptAllSyntaxChecker.class.getName() + " X-SCHEMA 'nis' )" );
+        descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.0.10001 DESC 'bogus desc' FQCN " 
+            + AcceptAllSyntaxChecker.class.getName() + " X-SCHEMA 'nis' )" );
+
+        // -------------------------------------------------------------------
+        // add and check
+        // -------------------------------------------------------------------
+        
+        modifySyntaxCheckers( DirContext.ADD_ATTRIBUTE, descriptions );
+        checkSyntaxCheckerPresent( "1.3.6.1.4.1.18060.0.4.1.0.10000", "nis" );
+        checkSyntaxCheckerPresent( "1.3.6.1.4.1.18060.0.4.1.0.10001", "nis" );
+
+        // -------------------------------------------------------------------
+        // remove and check
+        // -------------------------------------------------------------------
+        
+        modifySyntaxCheckers( DirContext.REMOVE_ATTRIBUTE, descriptions );
+        checkSyntaxCheckerNotPresent( "1.3.6.1.4.1.18060.0.4.1.0.10000", "nis" );
+        checkSyntaxCheckerNotPresent( "1.3.6.1.4.1.18060.0.4.1.0.10001", "nis" );
+        
+        // -------------------------------------------------------------------
+        // test failure to replace
+        // -------------------------------------------------------------------
+        
+        try
+        {
+            modifySyntaxCheckers( DirContext.REPLACE_ATTRIBUTE, descriptions );
+            fail( "modify REPLACE operations should not be allowed" );
+        }
+        catch ( LdapOperationNotSupportedException e )
+        {
+            assertEquals( ResultCodeEnum.UNWILLING_TO_PERFORM, e.getResultCode() );
+        }
+
+        // -------------------------------------------------------------------
+        // check add with valid bytecode
+        // -------------------------------------------------------------------
+        
+        descriptions.clear();
+        descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.0.10002 DESC 'bogus desc' FQCN DummySyntaxChecker
BYTECODE " 
+            +  getByteCode( "DummySyntaxChecker.bytecode" ) + " X-SCHEMA 'nis' )" );
+
+        modifySyntaxCheckers( DirContext.ADD_ATTRIBUTE, descriptions );
+        checkSyntaxCheckerPresent( "1.3.6.1.4.1.18060.0.4.1.0.10002", "nis" );
+
+        // -------------------------------------------------------------------
+        // check remove with valid bytecode
+        // -------------------------------------------------------------------
+        
+        modifySyntaxCheckers( DirContext.REMOVE_ATTRIBUTE, descriptions );
+        checkSyntaxCheckerNotPresent( "1.3.6.1.4.1.18060.0.4.1.0.10002", "nis" );
+
+        // -------------------------------------------------------------------
+        // check add no schema info
+        // -------------------------------------------------------------------
+        
+        descriptions.clear();
+        descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.0.10002 DESC 'bogus desc' FQCN DummySyntaxChecker
BYTECODE " 
+            +  getByteCode( "DummySyntaxChecker.bytecode" ) + " )" );
+
+        modifySyntaxCheckers( DirContext.ADD_ATTRIBUTE, descriptions );
+        checkSyntaxCheckerPresent( "1.3.6.1.4.1.18060.0.4.1.0.10002", "other" );
+    }
+    
+    
+    private String getByteCode( String resource ) throws IOException
+    {
+        InputStream in = getClass().getResourceAsStream( resource );
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        while ( in.available() > 0 )
+        {
+            out.write( in.read() );
+        }
+        
+        return new String( Base64.encode( out.toByteArray() ) );
+    }
+    
+    
+    // -----------------------------------------------------------------------
+    // Comparator Tests
+    // -----------------------------------------------------------------------
+    
+    
+    // -----------------------------------------------------------------------
+    // Normalizer Tests
+    // -----------------------------------------------------------------------
+    
+    
+    // -----------------------------------------------------------------------
+    // Syntax Tests
+    // -----------------------------------------------------------------------
+    
+    
+    // -----------------------------------------------------------------------
+    // MatchingRule Tests
+    // -----------------------------------------------------------------------
+    
+    
+    // -----------------------------------------------------------------------
+    // AttributeType Tests
+    // -----------------------------------------------------------------------
     
     
     /**

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/exception/ExceptionService.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/exception/ExceptionService.java?view=diff&rev=505125&r1=505124&r2=505125
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/exception/ExceptionService.java
(original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/exception/ExceptionService.java
Thu Feb  8 17:57:05 2007
@@ -247,6 +247,15 @@
     {
         // check if entry to modify exists
         String msg = "Attempt to modify non-existant entry: ";
+
+        // handle operations against the schema subentry in the schema service
+        // and never try to look it up in the nexus below
+        if ( name.getNormName().equalsIgnoreCase( subschemSubentryDn.getNormName() ) )
+        {
+            nextInterceptor.modify( name, modOp, attrs );
+            return;
+        }
+        
         assertHasEntry( nextInterceptor, msg, name );
 
         Attributes entry = nexus.lookup( name );

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeService.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeService.java?view=diff&rev=505125&r1=505124&r2=505125
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeService.java
(original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeService.java
Thu Feb  8 17:57:05 2007
@@ -165,6 +165,11 @@
     {
         nextInterceptor.modify( name, modOp, attrs );
 
+        if ( name.getNormName().equals( subschemaSubentryDn.getNormName() ) ) 
+        {
+            return;
+        }
+        
         // add operational attributes after call in case the operation fails
         Attributes attributes = new AttributesImpl( true );
         Attribute attribute = new AttributeImpl( "modifiersName" );

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaManager.java?view=diff&rev=505125&r1=505124&r2=505125
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaManager.java
(original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaManager.java
Thu Feb  8 17:57:05 2007
@@ -501,10 +501,12 @@
                     modifyRemoveOperation( opAttrOid, mod.getAttribute() );
                     break; 
                 case( DirContext.REPLACE_ATTRIBUTE ):
-                    AttributeType opAttrType = globalRegistries.getAttributeTypeRegistry().lookup(
opAttrOid );
-                    Attribute original = AttributeUtils.getAttribute( subentry, opAttrType
);
-                    modifyReplaceOperation( opAttrOid, mod.getAttribute(), original );
-                    break;
+                    throw new LdapOperationNotSupportedException( 
+                        "Modify REPLACE operations on schema subentries are not allowed:
" +
+                        "it's just silly to destroy and recreate so many \nschema entities
" +
+                        "that reside in schema operational attributes.  Instead use \na "
+
+                        "targeted combination of modify ADD and REMOVE operations.", 
+                        ResultCodeEnum.UNWILLING_TO_PERFORM );
                 default:
                     throw new IllegalStateException( "Undefined modify operation: " + mod.getModificationOp()
);
             }
@@ -546,229 +548,17 @@
                 }
                 break;
             case( DirContext.REPLACE_ATTRIBUTE ):
-                while ( ids.hasMore() )
-                {
-                    String id = ids.next();
-                    AttributeType opAttrAT = globalRegistries.getAttributeTypeRegistry().lookup(
id );
-                    Attribute modified = AttributeUtils.getAttribute( mods, opAttrAT );
-                    Attribute original = AttributeUtils.getAttribute( subentry, opAttrAT
);
-                    modifyReplaceOperation( opAttrAT.getOid(), modified, original );
-                }
-                break;
+                throw new LdapOperationNotSupportedException( 
+                    "Modify REPLACE operations on schema subentries are not allowed: " +
+                    "it's just silly to destroy and recreate so many \nschema entities "
+
+                    "that reside in schema operational attributes.  Instead use \na " +
+                    "targeted combination of modify ADD and REMOVE operations.", 
+                    ResultCodeEnum.UNWILLING_TO_PERFORM );
             default:
                 throw new IllegalStateException( "Undefined modify operation: " + modOp );
         }
     }
 
-
-    /**
-     * Handles modify replace operations on the schema subentry.
-     * 
-     * @param opAttrOid the numeric id of the operational attribute being modified
-     * @param mods the attribute with the modifications
-     * @param original the original values for the operational attribute being modified
-     * @throws NamingException if there are problems updating the registries or the 
-     * schema partition
-     */
-    private void modifyReplaceOperation( String opAttrOid, Attribute mods, Attribute original
) 
-        throws NamingException
-    {
-        int index = opAttr2handlerIndex.get( opAttrOid ).intValue();
-        SchemaChangeHandler handler = opAttr2handlerMap.get( opAttrOid );
-        switch( index )
-        {
-            case( COMPARATOR_INDEX ):
-                MetaComparatorHandler comparatorHandler = ( MetaComparatorHandler ) handler;
-                ComparatorDescription[] removedComparators = parsers.parseComparators( original
);
-                ComparatorDescription[] addedComparators = parsers.parseComparators( mods
);
-                
-                for ( ComparatorDescription comparatorDescription : removedComparators )
-                {
-                    comparatorHandler.delete( comparatorDescription.getNumericOid() );
-                    subentryModifier.delete( getSchema( comparatorDescription ), comparatorDescription
);
-                }
-                
-                for ( ComparatorDescription comparatorDescription : addedComparators )
-                {
-                    comparatorHandler.add( comparatorDescription );
-                    subentryModifier.add( getSchema( comparatorDescription ), comparatorDescription
);
-                }
-                break;
-            case( NORMALIZER_INDEX ):
-                MetaNormalizerHandler normalizerHandler = ( MetaNormalizerHandler ) handler;
-                NormalizerDescription[] removedNormalizers = parsers.parseNormalizers( original
);
-                NormalizerDescription[] addedNormalizers = parsers.parseNormalizers( mods
);
-                
-                for ( NormalizerDescription normalizerDescription : removedNormalizers )
-                {
-                    normalizerHandler.delete( normalizerDescription.getNumericOid() );
-                    subentryModifier.delete( getSchema( normalizerDescription ), normalizerDescription
);
-                }
-                
-                for ( NormalizerDescription normalizerDescription : addedNormalizers )
-                {
-                    normalizerHandler.add( normalizerDescription );
-                    subentryModifier.add( getSchema( normalizerDescription ), normalizerDescription
);
-                }
-                break;
-            case( SYNTAX_CHECKER_INDEX ):
-                MetaSyntaxCheckerHandler syntaxCheckerHandler = ( MetaSyntaxCheckerHandler
) handler;
-                SyntaxCheckerDescription[] removedSyntaxCheckers = parsers.parseSyntaxCheckers(
original );
-                SyntaxCheckerDescription[] addedSyntaxCheckers = parsers.parseSyntaxCheckers(
mods );
-                
-                for ( SyntaxCheckerDescription syntaxCheckerDescription : removedSyntaxCheckers
)
-                {
-                    syntaxCheckerHandler.delete( syntaxCheckerDescription.getNumericOid()
);
-                    subentryModifier.delete( getSchema( syntaxCheckerDescription ), syntaxCheckerDescription
);
-                }
-                
-                for ( SyntaxCheckerDescription syntaxCheckerDescription : addedSyntaxCheckers
)
-                {
-                    syntaxCheckerHandler.add( syntaxCheckerDescription );
-                    subentryModifier.delete( getSchema( syntaxCheckerDescription ), syntaxCheckerDescription
);
-                }
-                break;
-            case( SYNTAX_INDEX ):
-                MetaSyntaxHandler syntaxHandler = ( MetaSyntaxHandler ) handler;
-                Syntax[] removedSyntaxes = parsers.parseSyntaxes( original );
-                Syntax[] addedSyntaxes = parsers.parseSyntaxes( mods );
-                
-                for ( Syntax syntax : removedSyntaxes )
-                {
-                    syntaxHandler.delete( syntax );
-                    subentryModifier.deleteSchemaObject( syntax );
-                }
-                
-                for ( Syntax syntax : addedSyntaxes )
-                {
-                    syntaxHandler.add( syntax );
-                    subentryModifier.addSchemaObject( syntax );
-                }
-                break;
-            case( MATCHING_RULE_INDEX ):
-                MetaMatchingRuleHandler matchingRuleHandler = ( MetaMatchingRuleHandler )
handler;
-                MatchingRule[] removedMrs = parsers.parseMatchingRules( original );
-                MatchingRule[] addedMrs = parsers.parseMatchingRules( mods );
-                
-                for ( MatchingRule mr : removedMrs )
-                {
-                    matchingRuleHandler.delete( mr );
-                    subentryModifier.deleteSchemaObject( mr );
-                }
-                
-                for ( MatchingRule mr : addedMrs )
-                {
-                    matchingRuleHandler.add( mr );
-                    subentryModifier.addSchemaObject( mr );
-                }
-                break;
-            case( ATTRIBUTE_TYPE_INDEX ):
-                MetaAttributeTypeHandler atHandler = ( MetaAttributeTypeHandler ) handler;
-                AttributeType[] removedAts = parsers.parseAttributeTypes( original );
-                AttributeType[] addedAts = parsers.parseAttributeTypes( mods );
-                
-                for ( AttributeType at : removedAts )
-                {
-                    atHandler.delete( at );
-                    subentryModifier.deleteSchemaObject( at );
-                }
-                
-                for ( AttributeType at : addedAts )
-                {
-                    atHandler.add( at );
-                    subentryModifier.addSchemaObject( at );
-                }
-                break;
-            case( OBJECT_CLASS_INDEX ):
-                MetaObjectClassHandler ocHandler = ( MetaObjectClassHandler ) handler;
-                ObjectClass[] removedOcs = parsers.parseObjectClasses( original );
-                ObjectClass[] addedOcs = parsers.parseObjectClasses( mods );
-
-                for ( ObjectClass oc : removedOcs )
-                {
-                    ocHandler.delete( oc );
-                    subentryModifier.deleteSchemaObject( oc );
-                }
-                
-                for ( ObjectClass oc : addedOcs )
-                {
-                    ocHandler.add( oc );
-                    subentryModifier.addSchemaObject( oc );
-                }
-                break;
-            case( MATCHING_RULE_USE_INDEX ):
-                MetaMatchingRuleUseHandler mruHandler = ( MetaMatchingRuleUseHandler ) handler;
-                MatchingRuleUse[] removedMrus = parsers.parseMatchingRuleUses( original );
-                MatchingRuleUse[] addedMrus = parsers.parseMatchingRuleUses( mods );
-                
-                for ( MatchingRuleUse mru : removedMrus )
-                {
-                    mruHandler.delete( mru );
-                    subentryModifier.deleteSchemaObject( mru );
-                }
-                
-                for ( MatchingRuleUse mru : addedMrus )
-                {
-                    mruHandler.add( mru );
-                    subentryModifier.addSchemaObject( mru );
-                }
-                break;
-            case( DIT_STRUCTURE_RULE_INDEX ):
-                MetaDitStructureRuleHandler dsrHandler = ( MetaDitStructureRuleHandler )
handler;
-                DITStructureRule[] removedDsrs = parsers.parseDitStructureRules( original
);
-                DITStructureRule[] addedDsrs = parsers.parseDitStructureRules( mods );
-                
-                for ( DITStructureRule dsr : removedDsrs )
-                {
-                    dsrHandler.delete( dsr );
-                    subentryModifier.deleteSchemaObject( dsr );
-                }
-                
-                for ( DITStructureRule dsr : addedDsrs )
-                {
-                    dsrHandler.add( dsr );
-                    subentryModifier.addSchemaObject( dsr );
-                }
-                break;
-            case( DIT_CONTENT_RULE_INDEX ):
-                MetaDitContentRuleHandler dcrHandler = ( MetaDitContentRuleHandler ) handler;
-                DITContentRule[] removedDcrs = parsers.parseDitContentRules( original );
-                DITContentRule[] addedDcrs = parsers.parseDitContentRules( mods );
-                
-                for ( DITContentRule dcr : removedDcrs )
-                {
-                    dcrHandler.delete( dcr );
-                    subentryModifier.deleteSchemaObject( dcr );
-                }
-                
-                for ( DITContentRule dcr : addedDcrs )
-                {
-                    dcrHandler.add( dcr );
-                    subentryModifier.addSchemaObject( dcr );
-                }
-                break;
-            case( NAME_FORM_INDEX ):
-                MetaNameFormHandler nfHandler = ( MetaNameFormHandler ) handler;
-                NameForm[] removedNfs = parsers.parseNameForms( original );
-                NameForm[] addedNfs = parsers.parseNameForms( mods );
-                
-                for ( NameForm nf : removedNfs )
-                {
-                    nfHandler.delete( nf );
-                    subentryModifier.deleteSchemaObject( nf );
-                }
-                
-                for ( NameForm nf : addedNfs )
-                {
-                    nfHandler.add( nf );
-                    subentryModifier.addSchemaObject( nf );
-                }
-                break;
-            default:
-                throw new IllegalStateException( "Unknown index into handler array: " + index
);
-        }
-    }
-
     
     public String getSchema( AbstractSchemaDescription desc ) 
     {
@@ -802,7 +592,7 @@
                 for ( ComparatorDescription comparatorDescription : comparatorDescriptions
)
                 {
                     comparatorHandler.delete( comparatorDescription.getNumericOid() );
-                    subentryModifier.delete( getSchema( comparatorDescription ), comparatorDescription
);
+                    subentryModifier.delete( comparatorDescription );
                 }
                 break;
             case( NORMALIZER_INDEX ):
@@ -812,7 +602,7 @@
                 for ( NormalizerDescription normalizerDescription : normalizerDescriptions
)
                 {
                     normalizerHandler.delete( normalizerDescription.getNumericOid() );
-                    subentryModifier.delete( getSchema( normalizerDescription ), normalizerDescription
);
+                    subentryModifier.delete( normalizerDescription );
                 }
                 break;
             case( SYNTAX_CHECKER_INDEX ):
@@ -822,7 +612,7 @@
                 for ( SyntaxCheckerDescription syntaxCheckerDescription : syntaxCheckerDescriptions
)
                 {
                     syntaxCheckerHandler.delete( syntaxCheckerDescription.getNumericOid()
);
-                    subentryModifier.delete( getSchema( syntaxCheckerDescription ), syntaxCheckerDescription
);
+                    subentryModifier.delete( syntaxCheckerDescription );
                 }
                 break;
             case( SYNTAX_INDEX ):
@@ -932,6 +722,7 @@
                 for ( ComparatorDescription comparatorDescription : comparatorDescriptions
)
                 {
                     comparatorHandler.add( comparatorDescription );
+                    subentryModifier.add( comparatorDescription );
                 }
                 break;
             case( NORMALIZER_INDEX ):
@@ -941,6 +732,7 @@
                 for ( NormalizerDescription normalizerDescription : normalizerDescriptions
)
                 {
                     normalizerHandler.add( normalizerDescription );
+                    subentryModifier.add( normalizerDescription );
                 }
                 break;
             case( SYNTAX_CHECKER_INDEX ):
@@ -950,6 +742,7 @@
                 for ( SyntaxCheckerDescription syntaxCheckerDescription : syntaxCheckerDescriptions
)
                 {
                     syntaxCheckerHandler.add( syntaxCheckerDescription );
+                    subentryModifier.add( syntaxCheckerDescription );
                 }
                 break;
             case( SYNTAX_INDEX ):

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaSubentryModifier.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaSubentryModifier.java?view=diff&rev=505125&r1=505124&r2=505125
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaSubentryModifier.java
(original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaSubentryModifier.java
Thu Feb  8 17:57:05 2007
@@ -44,6 +44,7 @@
 import org.apache.directory.shared.ldap.schema.ObjectClass;
 import org.apache.directory.shared.ldap.schema.SchemaObject;
 import org.apache.directory.shared.ldap.schema.Syntax;
+import org.apache.directory.shared.ldap.schema.syntax.AbstractSchemaDescription;
 import org.apache.directory.shared.ldap.schema.syntax.ComparatorDescription;
 import org.apache.directory.shared.ldap.schema.syntax.NormalizerDescription;
 import org.apache.directory.shared.ldap.schema.syntax.SyntaxCheckerDescription;
@@ -143,9 +144,10 @@
         proxy.delete( dn, BYPASS );
     }
 
-
-    public void delete( String schemaName, NormalizerDescription normalizerDescription )
throws NamingException
+    
+    public void delete( NormalizerDescription normalizerDescription ) throws NamingException
     {
+        String schemaName = getSchema( normalizerDescription );
         PartitionNexusProxy proxy = InvocationStack.getInstance().peek().getProxy();
         LdapDN dn = new LdapDN( "m-oid=" + normalizerDescription.getNumericOid() + ",ou=normalizers,cn="

             + schemaName + ",ou=schema" );
@@ -153,8 +155,9 @@
     }
 
 
-    public void delete( String schemaName, SyntaxCheckerDescription syntaxCheckerDescription
) throws NamingException
+    public void delete( SyntaxCheckerDescription syntaxCheckerDescription ) throws NamingException
     {
+        String schemaName = getSchema( syntaxCheckerDescription );
         PartitionNexusProxy proxy = InvocationStack.getInstance().peek().getProxy();
         LdapDN dn = new LdapDN( "m-oid=" + syntaxCheckerDescription.getNumericOid() + ",ou=syntaxCheckers,cn="

             + schemaName + ",ou=schema" );
@@ -162,8 +165,9 @@
     }
 
 
-    public void delete( String schemaName, ComparatorDescription comparatorDescription )
throws NamingException
+    public void delete( ComparatorDescription comparatorDescription ) throws NamingException
     {
+        String schemaName = getSchema( comparatorDescription );
         PartitionNexusProxy proxy = InvocationStack.getInstance().peek().getProxy();
         LdapDN dn = new LdapDN( "m-oid=" + comparatorDescription.getNumericOid() + ",ou=comparators,cn="

             + schemaName + ",ou=schema" );
@@ -171,17 +175,18 @@
     }
 
 
-    public void add( String schemaName, ComparatorDescription comparatorDescription ) throws
NamingException
+    public void add( ComparatorDescription comparatorDescription ) throws NamingException
     {
+        String schemaName = getSchema( comparatorDescription );   
         PartitionNexusProxy proxy = InvocationStack.getInstance().peek().getProxy();
         LdapDN dn = new LdapDN( "m-oid=" + comparatorDescription.getNumericOid() + ",ou=comparators,cn="

             + schemaName + ",ou=schema" );
-        Attributes attrs = getAttributes( schemaName, comparatorDescription );
+        Attributes attrs = getAttributes( comparatorDescription );
         proxy.add( dn, attrs, BYPASS );
     }
     
     
-    private Attributes getAttributes( String schemaName, ComparatorDescription comparatorDescription
)
+    private Attributes getAttributes( ComparatorDescription comparatorDescription )
     {
         AttributesImpl attributes = new AttributesImpl( SystemSchemaConstants.OBJECT_CLASS_AT,
"top", true );
         attributes.get( SystemSchemaConstants.OBJECT_CLASS_AT ).add( "metaTop" );
@@ -204,17 +209,18 @@
     }
 
 
-    public void add( String schemaName, NormalizerDescription normalizerDescription ) throws
NamingException
+    public void add( NormalizerDescription normalizerDescription ) throws NamingException
     {
+        String schemaName = getSchema( normalizerDescription );
         PartitionNexusProxy proxy = InvocationStack.getInstance().peek().getProxy();
         LdapDN dn = new LdapDN( "m-oid=" + normalizerDescription.getNumericOid() + ",ou=normalizers,cn="

             + schemaName + ",ou=schema" );
-        Attributes attrs = getAttributes( schemaName, normalizerDescription );
+        Attributes attrs = getAttributes( normalizerDescription );
         proxy.add( dn, attrs, BYPASS );
     }
     
     
-    private Attributes getAttributes( String schemaName, NormalizerDescription normalizerDescription
)
+    private Attributes getAttributes( NormalizerDescription normalizerDescription )
     {
         AttributesImpl attributes = new AttributesImpl( SystemSchemaConstants.OBJECT_CLASS_AT,
"top", true );
         attributes.get( SystemSchemaConstants.OBJECT_CLASS_AT ).add( "metaTop" );
@@ -237,17 +243,29 @@
     }
 
 
-    public void add( String schemaName, SyntaxCheckerDescription syntaxCheckerDescription
) throws NamingException
+    public void add( SyntaxCheckerDescription syntaxCheckerDescription ) throws NamingException
     {
+        String schemaName = getSchema( syntaxCheckerDescription );
         PartitionNexusProxy proxy = InvocationStack.getInstance().peek().getProxy();
         LdapDN dn = new LdapDN( "m-oid=" + syntaxCheckerDescription.getNumericOid() + ",ou=syntaxCheckers,cn="

             + schemaName + ",ou=schema" );
-        Attributes attrs = getAttributes( schemaName, syntaxCheckerDescription );
+        Attributes attrs = getAttributes( syntaxCheckerDescription );
         proxy.add( dn, attrs, BYPASS );
     }
     
     
-    private Attributes getAttributes( String schemaName, SyntaxCheckerDescription syntaxCheckerDescription
)
+    private String getSchema( AbstractSchemaDescription desc ) 
+    {
+        if ( desc.getExtensions().containsKey( MetaSchemaConstants.X_SCHEMA ) )
+        {
+            return desc.getExtensions().get( MetaSchemaConstants.X_SCHEMA ).get( 0 );
+        }
+        
+        return MetaSchemaConstants.SCHEMA_OTHER;
+    }
+    
+    
+    private Attributes getAttributes( SyntaxCheckerDescription syntaxCheckerDescription )
     {
         AttributesImpl attributes = new AttributesImpl( SystemSchemaConstants.OBJECT_CLASS_AT,
"top", true );
         attributes.get( SystemSchemaConstants.OBJECT_CLASS_AT ).add( "metaTop" );



Mime
View raw message