directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r819187 - /directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/
Date Sat, 26 Sep 2009 18:12:58 GMT
Author: elecharny
Date: Sat Sep 26 18:12:57 2009
New Revision: 819187

URL: http://svn.apache.org/viewvc?rev=819187&view=rev
Log:
Many fixes to take care of disabled schema

Modified:
    directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/AbstractRegistrySynchronizer.java
    directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/AttributeTypeSynchronizer.java
    directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/ComparatorSynchronizer.java
    directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/DitContentRuleSynchronizer.java
    directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/DitStructureRuleSynchronizer.java
    directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/MatchingRuleSynchronizer.java
    directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/MatchingRuleUseSynchronizer.java
    directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/NameFormSynchronizer.java
    directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/NormalizerSynchronizer.java
    directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/ObjectClassSynchronizer.java
    directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/RegistrySynchronizerAdaptor.java
    directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/SchemaSynchronizer.java
    directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/SyntaxCheckerSynchronizer.java
    directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/SyntaxSynchronizer.java

Modified: directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/AbstractRegistrySynchronizer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/AbstractRegistrySynchronizer.java?rev=819187&r1=819186&r2=819187&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/AbstractRegistrySynchronizer.java (original)
+++ directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/AbstractRegistrySynchronizer.java Sat Sep 26 18:12:57 2009
@@ -20,6 +20,12 @@
 package org.apache.directory.server.core.schema.registries.synchronizers;
 
 
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.naming.NamingException;
+
 import org.apache.directory.server.core.entry.ServerEntry;
 import org.apache.directory.shared.ldap.constants.MetaSchemaConstants;
 import org.apache.directory.shared.ldap.entry.EntryAttribute;
@@ -31,16 +37,11 @@
 import org.apache.directory.shared.ldap.name.Rdn;
 import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.apache.directory.shared.ldap.schema.SchemaObject;
+import org.apache.directory.shared.ldap.schema.registries.OidRegistry;
 import org.apache.directory.shared.ldap.schema.registries.Registries;
+import org.apache.directory.shared.ldap.schema.registries.Schema;
 import org.apache.directory.shared.schema.loader.ldif.SchemaEntityFactory;
 
-//import javax.naming.NamingException;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import javax.naming.NamingException;
-
 
 /**
  * An abstract registry synchronizer with some reused functionality.
@@ -50,16 +51,25 @@
  */
 public abstract class AbstractRegistrySynchronizer implements RegistrySynchronizer
 {
+    /** The global registries */
     protected final Registries registries;
+    
+    /** The OID registry */
+    protected final OidRegistry oidRegistry;
+    
+    /** The m-oid AttrributeType */
     protected final AttributeType m_oidAT;
+    
+    /** The Schema objetc factory */
     protected final SchemaEntityFactory factory;
 
     
     protected AbstractRegistrySynchronizer( Registries targetRegistries ) throws Exception
     {
-        this.registries = targetRegistries;
-        this.m_oidAT = targetRegistries.getAttributeTypeRegistry().lookup( MetaSchemaConstants.M_OID_AT );
-        this.factory = new SchemaEntityFactory();
+        registries = targetRegistries;
+        m_oidAT = targetRegistries.getAttributeTypeRegistry().lookup( MetaSchemaConstants.M_OID_AT );
+        factory = new SchemaEntityFactory();
+        oidRegistry = registries.getOidRegistry();
     }
     
     
@@ -69,6 +79,32 @@
     }
     
     
+    /**
+     * Tells if a schema is loaded and enabled 
+     *
+     * @param schemaName The schema we want to check
+     * @return true if the schema is loaded and enabled, false otherwise
+     */
+    protected boolean isSchemaEnabled( String schemaName )
+    {
+        Schema schema = registries.getLoadedSchema( schemaName );
+        
+        return ( ( schema != null ) && schema.isEnabled() );
+    }
+    
+    
+    /**
+     * Exctract the schema name from the DN. It is supposed to be the 
+     * second RDN in the dn :
+     * <pre>
+     * ou=schema, cn=MySchema, ...
+     * </pre>
+     * Here, the schemaName is MySchema
+     *
+     * @param dn The DN we want to get the schema name from
+     * @return The schema name
+     * @throws NamingException If we got an error
+     */
     protected String getSchemaName( LdapDN dn ) throws NamingException
     {
         if ( dn.size() < 2 )
@@ -85,7 +121,7 @@
     {
         String oid = getOid( entry );
 
-        if ( registries.getOidRegistry().hasOid( oid ) )
+        if ( oidRegistry.hasOid( oid ) )
         {
             throw new LdapNamingException( "Oid " + oid + " for new schema entity is not unique.",
                 ResultCodeEnum.OTHER );
@@ -97,7 +133,7 @@
     {
         String oid = schemaObject.getOid();
 
-        if ( registries.getOidRegistry().hasOid( oid ) )
+        if ( oidRegistry.hasOid( oid ) )
         {
             throw new LdapNamingException( "Oid " + oid + " for new schema entity is not unique.",
                 ResultCodeEnum.OTHER );
@@ -107,7 +143,7 @@
 
     protected void checkOidIsUnique( String oid ) throws Exception
     {
-        if ( registries.getOidRegistry().hasOid( oid ) )
+        if ( oidRegistry.hasOid( oid ) )
         {
             throw new LdapNamingException( "Oid " + oid + " for new schema entity is not unique.",
                 ResultCodeEnum.OTHER );
@@ -161,14 +197,14 @@
     }
     
     
-    protected void unregisterOids( String oid ) throws Exception
+    protected void unregisterOids( SchemaObject obj ) throws Exception
     {
-        registries.getOidRegistry().unregister( oid );
+        oidRegistry.unregister( obj.getOid() );
     }
     
     
     protected void registerOids( SchemaObject obj ) throws Exception
     {
-        registries.getOidRegistry().register( obj );
+        oidRegistry.register( obj );
     }
 }

Modified: directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/AttributeTypeSynchronizer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/AttributeTypeSynchronizer.java?rev=819187&r1=819186&r2=819187&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/AttributeTypeSynchronizer.java (original)
+++ directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/AttributeTypeSynchronizer.java Sat Sep 26 18:12:57 2009
@@ -33,7 +33,6 @@
 import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.apache.directory.shared.ldap.schema.registries.AttributeTypeRegistry;
 import org.apache.directory.shared.ldap.schema.registries.Registries;
-import org.apache.directory.shared.ldap.schema.registries.Schema;
 
 
 /**
@@ -55,16 +54,14 @@
     }
 
 
-    protected boolean modify( LdapDN name, ServerEntry entry, ServerEntry targetEntry, boolean cascade ) 
+    public boolean modify( LdapDN name, ServerEntry entry, ServerEntry targetEntry, boolean cascade ) 
         throws Exception
     {
         String schemaName = getSchemaName( name );
         String oid = getOid( entry );
         AttributeType at = factory.getAttributeType( targetEntry, registries, schemaName );
         
-        Schema schema = registries.getLoadedSchema( schemaName );
-        
-        if ( ( schema != null ) && schema.isEnabled() )
+        if ( isSchemaEnabled( schemaName ) )
         {
             if ( atRegistry.contains( oid ) )
             {
@@ -90,9 +87,7 @@
         String schemaName = getSchemaName( name );
         AttributeType at = factory.getAttributeType( entry, registries, schemaName );
         
-        Schema schema = registries.getLoadedSchema( schemaName );
-        
-        if ( ( schema != null ) && schema.isEnabled() )
+        if ( isSchemaEnabled( schemaName ) )
         {
             // Don't inject the modified element if the schema is disabled
             atRegistry.register( at );
@@ -116,9 +111,7 @@
         String schemaName = getSchemaName( entry.getDn() );
         AttributeType at = factory.getAttributeType( entry, registries, schemaName );
         
-        Schema schema = registries.getLoadedSchema( schemaName );
-        
-        if ( ( schema != null ) && schema.isEnabled() )
+        if ( isSchemaEnabled( schemaName ) )
         {
             // Check that the entry has no descendant
             if ( atRegistry.hasDescendants( at.getOid() ) )
@@ -132,8 +125,10 @@
             // Don't inject the modified element if the schema is disabled
             atRegistry.unregister( at.getOid() );
         }
-        
-        unregisterOids( at.getOid() );
+        else
+        {
+            unregisterOids( at );
+        }
     }
 
 
@@ -159,9 +154,7 @@
         
         AttributeType at = factory.getAttributeType( targetEntry, registries, schemaName );
 
-        Schema schema = registries.getLoadedSchema( schemaName );
-        
-        if ( ( schema != null ) && schema.isEnabled() )
+        if ( isSchemaEnabled( schemaName ) )
         {
             // Check that the entry has no descendant
             if ( atRegistry.hasDescendants( oldAt.getOid() ) )
@@ -175,9 +168,11 @@
             atRegistry.unregister( oldAt.getOid() );
             atRegistry.register( at );
         }
-        
-        unregisterOids( oldAt.getOid() );
-        registerOids( at );
+        else
+        {
+            unregisterOids( oldAt );
+            registerOids( at );
+        }
     }
 
 
@@ -194,18 +189,16 @@
         checkOidIsUnique( newOid );
         AttributeType at = factory.getAttributeType( targetEntry, registries, newSchemaName );
 
-        Schema oldSchema = registries.getLoadedSchema( oldSchemaName );
-        
-        if ( ( oldSchema != null ) && oldSchema.isEnabled() )
+        if ( isSchemaEnabled( oldSchemaName ) )
         {
             atRegistry.unregister( oldAt.getOid() );
         }
+        else
+        {
+            unregisterOids( oldAt );
+        }
 
-        unregisterOids( oldAt.getOid() );
-
-        Schema newSchema = registries.getLoadedSchema( newSchemaName );
-        
-        if ( ( newSchema != null ) && newSchema.isEnabled() )
+        if ( isSchemaEnabled( newSchemaName ) )
         {
             atRegistry.register( at );
         }
@@ -225,19 +218,23 @@
         AttributeType oldAt = factory.getAttributeType( entry, registries, oldSchemaName );
         AttributeType at = factory.getAttributeType( entry, registries, newSchemaName );
         
-        Schema oldSchema = registries.getLoadedSchema( oldSchemaName );
-        
-        if ( ( oldSchema != null ) && oldSchema.isEnabled() )
+        if ( isSchemaEnabled( oldSchemaName ) )
         {
             atRegistry.unregister( oldAt.getOid() );
         }
+        else
+        {
+            unregisterOids( oldAt );
+        }
         
-        Schema newSchema = registries.getLoadedSchema( newSchemaName );
-        
-        if ( ( newSchema != null ) && newSchema.isEnabled() )
+        if ( isSchemaEnabled( newSchemaName ) )
         {
             atRegistry.register( at );
         }
+        else
+        {
+            registerOids( at );
+        }
     }
     
     

Modified: directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/ComparatorSynchronizer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/ComparatorSynchronizer.java?rev=819187&r1=819186&r2=819187&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/ComparatorSynchronizer.java (original)
+++ directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/ComparatorSynchronizer.java Sat Sep 26 18:12:57 2009
@@ -35,7 +35,6 @@
 import org.apache.directory.shared.ldap.schema.registries.ComparatorRegistry;
 import org.apache.directory.shared.ldap.schema.registries.MatchingRuleRegistry;
 import org.apache.directory.shared.ldap.schema.registries.Registries;
-import org.apache.directory.shared.ldap.schema.registries.Schema;
 
 
 /**
@@ -59,13 +58,13 @@
     }
 
     
-    protected boolean modify( LdapDN name, ServerEntry entry, ServerEntry targetEntry, boolean cascade ) throws Exception
+    public boolean modify( LdapDN name, ServerEntry entry, ServerEntry targetEntry, boolean cascade ) throws Exception
     {
         String schemaName = getSchemaName( name );
         String oid = getOid( entry );
         LdapComparator<?> comparator = factory.getLdapComparator( targetEntry, registries );
         
-        if ( ( schemaName != null ) && isSchemaLoaded( name ) )
+        if ( isSchemaEnabled( schemaName ) )
         {
             comparator.setSchemaName( schemaName );
 
@@ -90,9 +89,7 @@
         String schemaName = getSchemaName( name );
         comparator.setSchemaName( schemaName );
         
-        Schema schema = registries.getLoadedSchema( schemaName );
-        
-        if ( ( schema != null ) && schema.isEnabled() )
+        if ( isSchemaEnabled( schemaName ) )
         {
             comparatorRegistry.register( comparator );
         }
@@ -141,9 +138,7 @@
         
         String schemaName = getSchemaName( entry.getDn() );
         
-        Schema schema = registries.getLoadedSchema( schemaName );
-        
-        if ( ( schema != null ) && schema.isEnabled() )
+        if ( isSchemaEnabled( schemaName ) )
         {
             // Inject the new OID in the entry
             ServerEntry targetEntry = ( ServerEntry ) entry.clone();
@@ -186,18 +181,14 @@
 
         String oldSchemaName = getSchemaName( oriChildName );
         
-        Schema oldSchema = registries.getLoadedSchema( oldSchemaName );
-        
-        if ( ( oldSchema != null ) && oldSchema.isEnabled() )
+        if ( isSchemaEnabled( oldSchemaName ) )
         {
             comparatorRegistry.unregister( oldOid );
         }
 
         String newSchemaName = getSchemaName( newParentName );
         
-        Schema newSchema = registries.getLoadedSchema( newSchemaName );
-        
-        if ( ( newSchema != null ) && newSchema.isEnabled() )
+        if ( isSchemaEnabled( newSchemaName ) )
         {
             comparatorRegistry.register( comparator );
         }
@@ -222,18 +213,14 @@
         
         String oldSchemaName = getSchemaName( oriChildName );
         
-        Schema oldSchema = registries.getLoadedSchema( oldSchemaName );
-        
-        if ( ( oldSchema != null ) && oldSchema.isEnabled() )
+        if ( isSchemaEnabled( oldSchemaName ) )
         {
             comparatorRegistry.unregister( oid );
         }
         
         String newSchemaName = getSchemaName( newParentName );
         
-        Schema newSchema = registries.getLoadedSchema( newSchemaName );
-        
-        if ( ( newSchema != null ) && newSchema.isEnabled() )
+        if ( isSchemaEnabled( newSchemaName ) )
         {
             comparatorRegistry.register( comparator );
         }

Modified: directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/DitContentRuleSynchronizer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/DitContentRuleSynchronizer.java?rev=819187&r1=819186&r2=819187&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/DitContentRuleSynchronizer.java (original)
+++ directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/DitContentRuleSynchronizer.java Sat Sep 26 18:12:57 2009
@@ -49,7 +49,7 @@
      * @see org.apache.directory.server.core.schema.AbstractSchemaChangeHandler#modify(org.apache.directory.shared.ldap.name.LdapDN, javax.naming.directory.Attributes, javax.naming.directory.Attributes)
      */
     @Override
-    protected boolean modify( LdapDN name, ServerEntry entry, ServerEntry targetEntry, boolean cascade ) 
+    public boolean modify( LdapDN name, ServerEntry entry, ServerEntry targetEntry, boolean cascade ) 
         throws NamingException
     {
         // TODO Auto-generated method stub

Modified: directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/DitStructureRuleSynchronizer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/DitStructureRuleSynchronizer.java?rev=819187&r1=819186&r2=819187&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/DitStructureRuleSynchronizer.java (original)
+++ directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/DitStructureRuleSynchronizer.java Sat Sep 26 18:12:57 2009
@@ -51,7 +51,7 @@
      * javax.naming.directory.Attributes)
      */
     @Override
-    protected boolean modify( LdapDN name, ServerEntry entry, ServerEntry targetEntry, 
+    public boolean modify( LdapDN name, ServerEntry entry, ServerEntry targetEntry, 
         boolean cascade ) throws NamingException
     {
         // TODO Auto-generated method stub

Modified: directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/MatchingRuleSynchronizer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/MatchingRuleSynchronizer.java?rev=819187&r1=819186&r2=819187&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/MatchingRuleSynchronizer.java (original)
+++ directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/MatchingRuleSynchronizer.java Sat Sep 26 18:12:57 2009
@@ -32,7 +32,6 @@
 import org.apache.directory.shared.ldap.schema.MatchingRule;
 import org.apache.directory.shared.ldap.schema.registries.MatchingRuleRegistry;
 import org.apache.directory.shared.ldap.schema.registries.Registries;
-import org.apache.directory.shared.ldap.schema.registries.Schema;
 
 
 /**
@@ -55,22 +54,25 @@
     }
 
 
-    protected boolean modify( LdapDN name, ServerEntry entry, ServerEntry targetEntry, 
+    public boolean modify( LdapDN name, ServerEntry entry, ServerEntry targetEntry, 
         boolean cascade ) throws Exception
     {
-        String oid = getOid( entry );
         String schemaName = getSchemaName( name );
         MatchingRule mr = factory.getMatchingRule( targetEntry, registries, schemaName );
         
-        if ( registries.isSchemaLoaded( schemaName ) )
+        String oldOid = getOid( entry );
+        
+        if ( isSchemaEnabled( schemaName ) )
         {
-            matchingRuleRegistry.unregister( oid );
+            matchingRuleRegistry.unregister( oldOid );
             matchingRuleRegistry.register( mr );
             
             return SCHEMA_MODIFIED;
         }
-        
-        return SCHEMA_UNCHANGED;
+        else
+        {
+            return SCHEMA_UNCHANGED;
+        }
     }
 
 
@@ -84,9 +86,7 @@
         String schemaName = getSchemaName( name );
         MatchingRule mr = factory.getMatchingRule( entry, registries, schemaName );
         
-        Schema schema = registries.getLoadedSchema( schemaName );
-        
-        if ( ( schema != null ) && schema.isEnabled() )
+        if ( isSchemaEnabled( schemaName ) )
         {
             matchingRuleRegistry.register( mr );
         }
@@ -105,14 +105,14 @@
         String schemaName = getSchemaName( entry.getDn() );
         MatchingRule mr = factory.getMatchingRule( entry, registries, schemaName );
         
-        Schema schema = registries.getLoadedSchema( schemaName );
-        
-        if ( ( schema != null ) && schema.isEnabled() )
+        if ( isSchemaEnabled( schemaName ) )
         {
             matchingRuleRegistry.unregister( mr.getOid() );
         }
-        
-        unregisterOids( mr.getOid() );
+        else
+        {
+            unregisterOids( mr );
+        }
     }
 
     
@@ -130,17 +130,16 @@
         targetEntry.put( MetaSchemaConstants.M_OID_AT, newOid );
         MatchingRule mr = factory.getMatchingRule( targetEntry, registries, schemaName );
 
-        if ( registries.isSchemaLoaded( schemaName ) )
+        if ( isSchemaEnabled( schemaName ) )
         {
             matchingRuleRegistry.unregister( oldMr.getOid() );
             matchingRuleRegistry.register( mr );
         }
         else
         {
+            unregisterOids( oldMr );
             registerOids( mr );
         }
-
-        unregisterOids( oldMr.getOid() );
     }
 
 
@@ -157,14 +156,17 @@
         
         targetEntry.put( MetaSchemaConstants.M_OID_AT, newOid );
         MatchingRule mr = factory.getMatchingRule( targetEntry, registries, newSchemaName );
-
-        if ( registries.isSchemaLoaded( oldSchemaName ) )
+        
+        if ( isSchemaEnabled( oldSchemaName ) )
         {
             matchingRuleRegistry.unregister( oldMr.getOid() );
         }
-        unregisterOids( oldMr.getOid() );
+        else
+        {
+            unregisterOids( oldMr );
+        }
 
-        if ( registries.isSchemaLoaded( newSchemaName ) )
+        if ( isSchemaEnabled( newSchemaName ) )
         {
             matchingRuleRegistry.register( mr );
         }
@@ -182,16 +184,24 @@
         String oldSchemaName = getSchemaName( oriChildName );
         String newSchemaName = getSchemaName( newParentName );
         MatchingRule oldMr = factory.getMatchingRule( entry, registries, oldSchemaName );
-        MatchingRule mr = factory.getMatchingRule( entry, registries, newSchemaName );
-        
-        if ( registries.isSchemaLoaded( oldSchemaName ) )
+        MatchingRule newMr = factory.getMatchingRule( entry, registries, newSchemaName );
+
+        if ( isSchemaEnabled( oldSchemaName ) )
         {
             matchingRuleRegistry.unregister( oldMr.getOid() );
         }
+        else
+        {
+            unregisterOids( oldMr );
+        }
         
-        if ( registries.isSchemaLoaded( newSchemaName ) )
+        if ( isSchemaEnabled( newSchemaName ) )
         {
-            matchingRuleRegistry.register( mr );
+            matchingRuleRegistry.register( newMr );
+        }
+        else
+        {
+            registerOids( newMr );
         }
     }
     

Modified: directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/MatchingRuleUseSynchronizer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/MatchingRuleUseSynchronizer.java?rev=819187&r1=819186&r2=819187&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/MatchingRuleUseSynchronizer.java (original)
+++ directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/MatchingRuleUseSynchronizer.java Sat Sep 26 18:12:57 2009
@@ -46,7 +46,7 @@
 
 
     @Override
-    protected boolean modify( LdapDN name, ServerEntry entry, ServerEntry targetEntry, 
+    public boolean modify( LdapDN name, ServerEntry entry, ServerEntry targetEntry, 
         boolean cascade ) throws NamingException
     {
         // TODO Auto-generated method stub

Modified: directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/NameFormSynchronizer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/NameFormSynchronizer.java?rev=819187&r1=819186&r2=819187&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/NameFormSynchronizer.java (original)
+++ directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/NameFormSynchronizer.java Sat Sep 26 18:12:57 2009
@@ -49,7 +49,7 @@
      * javax.naming.directory.Attributes)
      */
     @Override
-    protected boolean modify( LdapDN name, ServerEntry entry, ServerEntry targetEntry, 
+    public boolean modify( LdapDN name, ServerEntry entry, ServerEntry targetEntry, 
         boolean cascade ) throws NamingException
     {
         return SCHEMA_UNCHANGED;

Modified: directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/NormalizerSynchronizer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/NormalizerSynchronizer.java?rev=819187&r1=819186&r2=819187&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/NormalizerSynchronizer.java (original)
+++ directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/NormalizerSynchronizer.java Sat Sep 26 18:12:57 2009
@@ -35,7 +35,6 @@
 import org.apache.directory.shared.ldap.schema.registries.MatchingRuleRegistry;
 import org.apache.directory.shared.ldap.schema.registries.NormalizerRegistry;
 import org.apache.directory.shared.ldap.schema.registries.Registries;
-import org.apache.directory.shared.ldap.schema.registries.Schema;
 
 
 /**
@@ -58,13 +57,13 @@
     }
     
     
-    protected boolean modify( LdapDN name, ServerEntry entry, ServerEntry targetEntry, boolean cascade ) throws Exception
+    public boolean modify( LdapDN name, ServerEntry entry, ServerEntry targetEntry, boolean cascade ) throws Exception
     {
         String schemaName = getSchemaName( name );
         String oldOid = getOid( entry );
         Normalizer normalizer = factory.getNormalizer( targetEntry, registries );
         
-        if ( ( schemaName != null ) && isSchemaLoaded( name ) )
+        if ( isSchemaEnabled( schemaName ) )
         {
             normalizer.setSchemaName( schemaName );
 
@@ -90,9 +89,7 @@
         String schemaName = getSchemaName( name );
         normalizer.setSchemaName( schemaName );
         
-        Schema schema = registries.getLoadedSchema( schemaName );
-        
-        if ( ( schema != null ) && schema.isEnabled() )
+        if ( isSchemaEnabled( schemaName ) )
         {
             normalizerRegistry.register( normalizer );
         }
@@ -131,6 +128,7 @@
     public void rename( ServerEntry entry, Rdn newRdn, boolean cascade ) throws Exception
     {
         String oldOid = getOid( entry );
+        String schemaName = getSchemaName( entry.getDn() );
 
         if ( matchingRuleRegistry.contains( oldOid ) )
         {
@@ -143,7 +141,7 @@
         String newOid = ( String ) newRdn.getValue();
         checkOidIsUniqueForNormalizer( newOid );
         
-        if ( isSchemaLoaded( entry.getDn() ) )
+        if ( isSchemaEnabled( schemaName ) )
         {
             // Inject the new OID
             ServerEntry targetEntry = ( ServerEntry ) entry.clone();
@@ -167,6 +165,8 @@
     {
         checkNewParent( newParentName );
         String oldOid = getOid( entry );
+        String oldSchemaName = getSchemaName( oriChildName );
+        String newSchemaName = getSchemaName( newParentName );
 
         if ( matchingRuleRegistry.contains( oldOid ) )
         {
@@ -180,12 +180,12 @@
         checkOidIsUniqueForNormalizer( oid );
         Normalizer normalizer = factory.getNormalizer( entry, registries );
 
-        if ( isSchemaLoaded( oriChildName ) )
+        if ( isSchemaEnabled( oldSchemaName ) )
         {
             normalizerRegistry.unregister( oldOid );
         }
 
-        if ( isSchemaLoaded( newParentName ) )
+        if ( isSchemaEnabled( newSchemaName ) )
         {
             normalizerRegistry.register( normalizer );
         }
@@ -197,6 +197,8 @@
     {
         checkNewParent( newParentName );
         String oid = getOid( entry );
+        String oldSchemaName = getSchemaName( oriChildName );
+        String newSchemaName = getSchemaName( newParentName );
 
         if ( matchingRuleRegistry.contains( oid ) )
         {
@@ -208,12 +210,13 @@
 
         Normalizer normalizer = factory.getNormalizer( entry, registries );
         
-        if ( isSchemaLoaded( oriChildName ) )
+        if ( isSchemaEnabled( oldSchemaName ) )
         {
             normalizerRegistry.unregister( oid );
         }
         
-        if ( isSchemaLoaded( newParentName ) )
+        
+        if ( isSchemaEnabled( newSchemaName ) )
         {
             normalizerRegistry.register( normalizer );
         }

Modified: directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/ObjectClassSynchronizer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/ObjectClassSynchronizer.java?rev=819187&r1=819186&r2=819187&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/ObjectClassSynchronizer.java (original)
+++ directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/ObjectClassSynchronizer.java Sat Sep 26 18:12:57 2009
@@ -33,7 +33,6 @@
 import org.apache.directory.shared.ldap.schema.ObjectClass;
 import org.apache.directory.shared.ldap.schema.registries.ObjectClassRegistry;
 import org.apache.directory.shared.ldap.schema.registries.Registries;
-import org.apache.directory.shared.ldap.schema.registries.Schema;
 
 
 /**
@@ -54,12 +53,13 @@
     }
 
 
-    protected boolean modify( LdapDN name, ServerEntry entry, ServerEntry targetEntry, boolean cascade ) throws Exception
+    public boolean modify( LdapDN name, ServerEntry entry, ServerEntry targetEntry, boolean cascade ) throws Exception
     {
         String oid = getOid( entry );
         ObjectClass oc = factory.getObjectClass( targetEntry, registries, getSchemaName( name ) );
+        String schemaName = getSchemaName( entry.getDn() );
 
-        if ( isSchemaLoaded( name ) )
+        if ( isSchemaEnabled( schemaName ) )
         {
             objectClassRegistry.unregister( oid );
             objectClassRegistry.register( oc );
@@ -81,9 +81,7 @@
         String schemaName = getSchemaName( name );
         ObjectClass oc = factory.getObjectClass( entry, registries, schemaName );
 
-        Schema schema = registries.getLoadedSchema( schemaName );
-        
-        if ( ( schema != null ) && schema.isEnabled() )
+        if ( isSchemaEnabled( schemaName ) )
         {
             objectClassRegistry.register( oc );
         }
@@ -102,9 +100,7 @@
         String schemaName = getSchemaName( entry.getDn() );
         ObjectClass oc = factory.getObjectClass( entry, registries, schemaName );
 
-        Schema schema = registries.getLoadedSchema( schemaName );
-        
-        if ( ( schema != null ) && schema.isEnabled() )
+        if ( isSchemaEnabled( schemaName ) )
         {
             // Check that the entry has no descendant
             if ( objectClassRegistry.hasDescendants( oc.getOid() ) )
@@ -117,8 +113,10 @@
             
             objectClassRegistry.unregister( oc.getOid() );
         }
-        
-        unregisterOids( oc.getOid() );
+        else
+        {
+            unregisterOids( oc );
+        }
     }
 
 
@@ -154,9 +152,7 @@
         checkOidIsUnique( newOid );
         ObjectClass oc = factory.getObjectClass( targetEntry, registries, schemaName );
 
-        Schema schema = registries.getLoadedSchema( schemaName );
-        
-        if ( ( schema != null ) && schema.isEnabled() )
+        if ( isSchemaEnabled( schemaName ) )
         {
             // Check that the entry has no descendant
             if ( objectClassRegistry.hasDescendants( oldOc.getOid() ) )
@@ -172,10 +168,9 @@
         }
         else
         {
+            unregisterOids( oldOc );
             registerOids( oc );
         }
-        
-        unregisterOids( oldOc.getOid() );
     }
 
 
@@ -204,18 +199,16 @@
         targetEntry.put( MetaSchemaConstants.M_OID_AT, newOid );
         ObjectClass oc = factory.getObjectClass( targetEntry, registries, newSchemaName );
 
-        Schema oldSchema = registries.getLoadedSchema( oldSchemaName );
-        
-        if ( ( oldSchema != null ) && oldSchema.isEnabled() )
+        if ( isSchemaEnabled( oldSchemaName ) )
         {
             objectClassRegistry.unregister( oldOc.getOid() );
         }
+        else
+        {
+            unregisterOids( oldOc );
+        }
         
-        unregisterOids( oldOc.getOid() );
-        
-        Schema newSchema = registries.getLoadedSchema( newSchemaName );
-        
-        if ( ( newSchema != null ) && newSchema.isEnabled() )
+        if ( isSchemaEnabled( newSchemaName ) )
         {
             objectClassRegistry.register( oc );
         }
@@ -247,15 +240,23 @@
 
         ObjectClass oc = factory.getObjectClass( entry, registries, newSchemaName );
         
-        if ( isSchemaLoaded( oriChildName ) )
+        if ( isSchemaEnabled( oldSchemaName ) )
         {
             objectClassRegistry.unregister( oldAt.getOid() );
         }
+        else
+        {
+            unregisterOids( oldAt );
+        }
         
-        if ( isSchemaLoaded( newParentName ) )
+        if ( isSchemaEnabled( newSchemaName ) )
         {
             objectClassRegistry.register( oc );
         }
+        else
+        {
+            registerOids( oc );
+        }
     }
 
 

Modified: directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/RegistrySynchronizerAdaptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/RegistrySynchronizerAdaptor.java?rev=819187&r1=819186&r2=819187&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/RegistrySynchronizerAdaptor.java (original)
+++ directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/RegistrySynchronizerAdaptor.java Sat Sep 26 18:12:57 2009
@@ -173,7 +173,9 @@
         
         if ( oc.contains( MetaSchemaConstants.META_SCHEMA_OC ) )
         {
-            schemaSynchronizer.add( opContext.getDn(), opContext.getEntry() );
+            LdapDN dn = opContext.getDn();
+            ServerEntry entry = opContext.getEntry();
+            schemaSynchronizer.add( dn, entry );
             return;
         }
         

Modified: directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/SchemaSynchronizer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/SchemaSynchronizer.java?rev=819187&r1=819186&r2=819187&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/SchemaSynchronizer.java (original)
+++ directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/SchemaSynchronizer.java Sat Sep 26 18:12:57 2009
@@ -28,6 +28,7 @@
 import javax.naming.NamingException;
 
 import org.apache.commons.lang.NotImplementedException;
+import org.apache.directory.server.constants.ServerDNConstants;
 import org.apache.directory.server.core.entry.ServerAttribute;
 import org.apache.directory.server.core.entry.ServerEntry;
 import org.apache.directory.server.core.entry.ServerEntryUtils;
@@ -62,23 +63,42 @@
 {
     private final SchemaEntityFactory factory;
     private final PartitionSchemaLoader loader;
-    private final Registries globalRegistries;
+    
+    /** The global registries */
+    private final Registries registries;
+    
+    /** The m-disable AttributeType */
     private final AttributeType disabledAT;
-    private final String OU_OID;
+    
+    /** The CN attributeType */
     private final AttributeType cnAT;
+    
+    /** The m-dependencies AttributeType */
     private final AttributeType dependenciesAT;
+    
+    /** A static DN referencing ou=schema */
+    private final LdapDN ouSchemaDN;
 
 
-    public SchemaSynchronizer( Registries globalRegistries, PartitionSchemaLoader loader ) throws Exception
+    /**
+     * Creates and initializes a new instance of Schema synchronizer
+     *
+     * @param registries The Registries
+     * @param loader The schema loader
+     * @throws Exception If something went wrong
+     */
+    public SchemaSynchronizer( Registries registries, PartitionSchemaLoader loader ) throws Exception
     {
-        this.globalRegistries = globalRegistries;
-        this.disabledAT = globalRegistries.getAttributeTypeRegistry().lookup( MetaSchemaConstants.M_DISABLED_AT );
+        this.registries = registries;
+        disabledAT = registries.getAttributeTypeRegistry().lookup( MetaSchemaConstants.M_DISABLED_AT );
         this.loader = loader;
-        this.OU_OID = globalRegistries.getAttributeTypeRegistry().getOidByName( SchemaConstants.OU_AT );
-        this.factory = new SchemaEntityFactory();
-        this.cnAT = globalRegistries.getAttributeTypeRegistry().lookup( SchemaConstants.CN_AT );
-        this.dependenciesAT = globalRegistries.getAttributeTypeRegistry()
+        factory = new SchemaEntityFactory();
+        cnAT = registries.getAttributeTypeRegistry().lookup( SchemaConstants.CN_AT );
+        dependenciesAT = registries.getAttributeTypeRegistry()
             .lookup( MetaSchemaConstants.M_DEPENDENCIES_AT );
+        
+        ouSchemaDN = new LdapDN( ServerDNConstants.OU_SCHEMA_DN );
+        ouSchemaDN.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
     }
 
 
@@ -195,10 +215,11 @@
     {
         LdapDN parentDn = ( LdapDN ) name.clone();
         parentDn.remove( parentDn.size() - 1 );
-        parentDn.normalize( globalRegistries.getAttributeTypeRegistry().getNormalizerMapping() );
-        if ( !parentDn.toNormName().equals( OU_OID + "=schema" ) )
+        parentDn.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
+
+        if ( !parentDn.equals( ouSchemaDN ) )
         {
-            throw new LdapInvalidNameException( "The parent dn of a schema should be " + OU_OID + "=schema and not: "
+            throw new LdapInvalidNameException( "The parent dn of a schema should be " + ouSchemaDN.getUpName() + " and not: "
                 + parentDn.toNormName(), ResultCodeEnum.NAMING_VIOLATION );
         }
 
@@ -208,6 +229,7 @@
         
         if ( disabled == null )
         {
+            // If the attribute is absent, then the schema is enabled by default
             isEnabled = true;
         }
         else if ( ! disabled.contains( "TRUE" ) )
@@ -245,7 +267,7 @@
         if ( isEnabled )
         {
             Schema schema = factory.getSchema( entry );
-            globalRegistries.schemaLoaded( schema );
+            registries.schemaLoaded( schema );
         }
     }
 
@@ -275,7 +297,7 @@
         
         // no need to check if schema is enabled or disabled here
         // if not in the loaded set there will be no negative effect
-        globalRegistries.schemaUnloaded( loader.getSchema( schemaName ) );
+        registries.schemaUnloaded( loader.getSchema( schemaName ) );
     }
 
 
@@ -292,7 +314,7 @@
     public void rename( ServerEntry entry, Rdn newRdn, boolean cascade ) throws Exception
     {
         String rdnAttribute = newRdn.getUpType();
-        String rdnAttributeOid = globalRegistries.getAttributeTypeRegistry().getOidByName( rdnAttribute );
+        String rdnAttributeOid = registries.getAttributeTypeRegistry().getOidByName( rdnAttribute );
 
         if ( ! rdnAttributeOid.equals( cnAT.getOid() ) )
         {
@@ -351,19 +373,19 @@
         
         // step [2] 
         String newSchemaName = ( String ) newRdn.getUpValue();
-        globalRegistries.getComparatorRegistry().renameSchema( schemaName, newSchemaName );
-        globalRegistries.getNormalizerRegistry().renameSchema( schemaName, newSchemaName );
-        globalRegistries.getSyntaxCheckerRegistry().renameSchema( schemaName, newSchemaName );
+        registries.getComparatorRegistry().renameSchema( schemaName, newSchemaName );
+        registries.getNormalizerRegistry().renameSchema( schemaName, newSchemaName );
+        registries.getSyntaxCheckerRegistry().renameSchema( schemaName, newSchemaName );
         
         // step [3]
-        renameSchema( globalRegistries.getAttributeTypeRegistry(), schemaName, newSchemaName );
-        renameSchema( globalRegistries.getDitContentRuleRegistry(), schemaName, newSchemaName );
-        renameSchema( globalRegistries.getDitStructureRuleRegistry(), schemaName, newSchemaName );
-        renameSchema( globalRegistries.getMatchingRuleRegistry(), schemaName, newSchemaName );
-        renameSchema( globalRegistries.getMatchingRuleUseRegistry(), schemaName, newSchemaName );
-        renameSchema( globalRegistries.getNameFormRegistry(), schemaName, newSchemaName );
-        renameSchema( globalRegistries.getObjectClassRegistry(), schemaName, newSchemaName );
-        renameSchema( globalRegistries.getLdapSyntaxRegistry(), schemaName, newSchemaName );
+        renameSchema( registries.getAttributeTypeRegistry(), schemaName, newSchemaName );
+        renameSchema( registries.getDitContentRuleRegistry(), schemaName, newSchemaName );
+        renameSchema( registries.getDitStructureRuleRegistry(), schemaName, newSchemaName );
+        renameSchema( registries.getMatchingRuleRegistry(), schemaName, newSchemaName );
+        renameSchema( registries.getMatchingRuleUseRegistry(), schemaName, newSchemaName );
+        renameSchema( registries.getNameFormRegistry(), schemaName, newSchemaName );
+        renameSchema( registries.getObjectClassRegistry(), schemaName, newSchemaName );
+        renameSchema( registries.getLdapSyntaxRegistry(), schemaName, newSchemaName );
     }
     
 
@@ -478,7 +500,7 @@
     private boolean disableSchema( String schemaName ) throws Exception
     {
         // First check that the schema is not already disabled
-        Map<String, Schema> schemas = globalRegistries.getLoadedSchemas();
+        Map<String, Schema> schemas = registries.getLoadedSchemas();
         
         Schema schema = schemas.get( schemaName );
         
@@ -496,6 +518,7 @@
                 "Cannot disable schema with enabled dependents: " + dependents,
                 ResultCodeEnum.UNWILLING_TO_PERFORM );
         }
+        
         schema.disable();
         
         // @TODO elecharny
@@ -506,7 +529,7 @@
                     " and we have to implement the unload method below." );
         }
         
-        // globalRegistries.unload( schemaName );
+        // registries.unload( schemaName );
         
         return SCHEMA_MODIFIED;
     }
@@ -518,14 +541,18 @@
      */
     private boolean enableSchema( String schemaName ) throws Exception
     {
-        if ( globalRegistries.isSchemaLoaded( schemaName ) )
+        Schema schema = loader.getSchema( schemaName );
+
+        if ( schema != null )
         {
             // TODO log warning: schemaName + " was already loaded"
+            schema.enable();
+            registries.schemaLoaded( schema );
             return SCHEMA_UNCHANGED;
         }
 
-        Schema schema = loader.getSchema( schemaName );
-        loader.loadWithDependencies( schema, globalRegistries );
+        loader.loadWithDependencies( schema, registries );
+        schema = loader.getSchema( schemaName );
         schema.enable();
         
         return SCHEMA_MODIFIED;
@@ -553,7 +580,7 @@
         if ( isEnabled )
         {
             // check to make sure all the dependencies are also enabled
-            Map<String,Schema> loaded = globalRegistries.getLoadedSchemas();
+            Map<String,Schema> loaded = registries.getLoadedSchemas();
             
             for ( Value<?> value:dependencies )
             {

Modified: directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/SyntaxCheckerSynchronizer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/SyntaxCheckerSynchronizer.java?rev=819187&r1=819186&r2=819187&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/SyntaxCheckerSynchronizer.java (original)
+++ directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/SyntaxCheckerSynchronizer.java Sat Sep 26 18:12:57 2009
@@ -34,7 +34,6 @@
 import org.apache.directory.shared.ldap.schema.SyntaxChecker;
 import org.apache.directory.shared.ldap.schema.registries.LdapSyntaxRegistry;
 import org.apache.directory.shared.ldap.schema.registries.Registries;
-import org.apache.directory.shared.ldap.schema.registries.Schema;
 import org.apache.directory.shared.ldap.schema.registries.SyntaxCheckerRegistry;
 
 
@@ -59,18 +58,19 @@
     }
 
 
-    protected boolean modify( LdapDN name, ServerEntry entry, ServerEntry targetEntry, boolean cascade ) throws Exception
+    public boolean modify( LdapDN name, ServerEntry entry, ServerEntry targetEntry, boolean cascade ) throws Exception
     {
         String schemaName = getSchemaName( name );
         String oid = getOid( entry );
         SyntaxChecker syntaxChecker = factory.getSyntaxChecker( targetEntry, registries );
         
-        if ( ( schemaName != null ) && isSchemaLoaded( name ) )
+        if ( isSchemaEnabled( schemaName ) )
         {
             syntaxChecker.setSchemaName( schemaName );
 
             syntaxCheckerRegistry.unregister( oid );
             syntaxCheckerRegistry.register( syntaxChecker );
+            
             return SCHEMA_MODIFIED;
         }
         
@@ -96,9 +96,7 @@
         String schemaName = getSchemaName( name );
         syntaxChecker.setSchemaName( schemaName );
 
-        Schema schema = registries.getLoadedSchema( schemaName );
-        
-        if ( ( schema != null ) && schema.isEnabled() )
+        if ( isSchemaEnabled( schemaName ) )
         {
             syntaxCheckerRegistry.register( syntaxChecker );
         }
@@ -122,9 +120,7 @@
         
         String schemaName = getSchemaName( entry.getDn() );
 
-        Schema schema = registries.getLoadedSchema( schemaName );
-        
-        if ( ( schema != null ) && schema.isEnabled() )
+        if ( isSchemaEnabled( schemaName ) )
         {
             syntaxCheckerRegistry.unregister( oid );
         }
@@ -137,6 +133,7 @@
     public void rename( ServerEntry entry, Rdn newRdn, boolean cascade ) throws Exception
     {
         String oldOid = getOid( entry );
+        String schemaName = getSchemaName( entry.getDn() );
 
         if ( ldapSyntaxRegistry.contains( oldOid ) )
         {
@@ -157,7 +154,7 @@
 
         targetEntry.put( MetaSchemaConstants.M_OID_AT, newOid );
         
-        if ( isSchemaLoaded( entry.getDn() ) )
+        if ( isSchemaEnabled( schemaName ) )
         {
             SyntaxChecker syntaxChecker = factory.getSyntaxChecker( targetEntry, registries );
             syntaxCheckerRegistry.unregister( oldOid );
@@ -171,6 +168,8 @@
     {
         checkNewParent( newParentName );
         String oldOid = getOid( entry );
+        String oldSchemaName = getSchemaName( oriChildName );
+        String newSchemaName = getSchemaName( newParentName );
 
         if ( ldapSyntaxRegistry.contains( oldOid ) )
         {
@@ -192,12 +191,12 @@
         targetEntry.put( MetaSchemaConstants.M_OID_AT, newOid );
         SyntaxChecker syntaxChecker = factory.getSyntaxChecker( targetEntry, registries );
 
-        if ( isSchemaLoaded( oriChildName ) )
+        if ( isSchemaEnabled( oldSchemaName ) )
         {
             syntaxCheckerRegistry.unregister( oldOid );
         }
 
-        if ( isSchemaLoaded( newParentName ) )
+        if ( isSchemaEnabled( newSchemaName ) )
         {
             syntaxCheckerRegistry.register( syntaxChecker );
         }
@@ -209,6 +208,8 @@
     {
         checkNewParent( newParentName );
         String oid = getOid( entry );
+        String oldSchemaName = getSchemaName( oriChildName );
+        String newSchemaName = getSchemaName( newParentName );
 
         if ( ldapSyntaxRegistry.contains( oid ) )
         {
@@ -220,12 +221,12 @@
 
         SyntaxChecker syntaxChecker = factory.getSyntaxChecker( entry, registries );
         
-        if ( isSchemaLoaded( oriChildName ) )
+        if ( isSchemaEnabled( oldSchemaName ) )
         {
             syntaxCheckerRegistry.unregister( oid );
         }
         
-        if ( isSchemaLoaded( newParentName ) )
+        if ( isSchemaEnabled( newSchemaName ) )
         {
             syntaxCheckerRegistry.register( syntaxChecker );
         }

Modified: directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/SyntaxSynchronizer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/SyntaxSynchronizer.java?rev=819187&r1=819186&r2=819187&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/SyntaxSynchronizer.java (original)
+++ directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/SyntaxSynchronizer.java Sat Sep 26 18:12:57 2009
@@ -20,19 +20,27 @@
 package org.apache.directory.server.core.schema.registries.synchronizers;
 
 
+import java.util.ArrayList;
+import java.util.List;
+
 import javax.naming.NamingException;
 
 import org.apache.directory.server.core.entry.ServerEntry;
 import org.apache.directory.shared.ldap.constants.MetaSchemaConstants;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.exception.LdapInvalidNameException;
+import org.apache.directory.shared.ldap.exception.LdapOperationNotSupportedException;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.name.Rdn;
+import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.apache.directory.shared.ldap.schema.LdapSyntax;
+import org.apache.directory.shared.ldap.schema.MatchingRule;
+import org.apache.directory.shared.ldap.schema.SchemaObject;
+import org.apache.directory.shared.ldap.schema.registries.AttributeTypeRegistry;
 import org.apache.directory.shared.ldap.schema.registries.LdapSyntaxRegistry;
+import org.apache.directory.shared.ldap.schema.registries.MatchingRuleRegistry;
 import org.apache.directory.shared.ldap.schema.registries.Registries;
-import org.apache.directory.shared.ldap.schema.registries.Schema;
 
 
 /**
@@ -55,12 +63,13 @@
     }
 
     
-    protected boolean modify( LdapDN name, ServerEntry entry, ServerEntry targetEntry, boolean cascade ) throws Exception
+    public boolean modify( LdapDN name, ServerEntry entry, ServerEntry targetEntry, boolean cascade ) throws Exception
     {
         String oid = getOid( entry );
         LdapSyntax syntax = factory.getSyntax( targetEntry, registries, getSchemaName( name ) );
+        String schemaName = getSchemaName( entry.getDn() );
         
-        if ( isSchemaLoaded( name ) )
+        if ( isSchemaEnabled( schemaName ) )
         {
             syntaxRegistry.unregister( oid );
             syntaxRegistry.register( syntax );
@@ -82,35 +91,102 @@
         String schemaName = getSchemaName( name );
         LdapSyntax syntax = factory.getSyntax( entry, registries, schemaName );
 
-        Schema schema = registries.getLoadedSchema( schemaName );
-        
-        if ( ( schema != null ) && schema.isEnabled() )
+        if ( isSchemaEnabled( schemaName ) )
         {
             syntaxRegistry.register( syntax );
         }
         else
         {
-            // even for disabled schemas add OIDs
             registerOids( syntax );
         }
     }
 
+    
+    /**
+     * Check if a syntax is used by an AT or a MR
+     */
+    private List<SchemaObject> checkInUse( String oid )
+    {
+        AttributeTypeRegistry atRegistry = registries.getAttributeTypeRegistry();
+        List<SchemaObject> dependees = new ArrayList<SchemaObject>();
+        
+        for ( AttributeType attributeType : atRegistry )
+        {
+            if ( oid.equals( attributeType.getSyntax().getOid() ) )
+            {
+                dependees.add( attributeType );
+            }
+        }
+        
+        MatchingRuleRegistry mrRegistry = registries.getMatchingRuleRegistry();
+        
+        for ( MatchingRule matchingRule : mrRegistry )
+        {
+            if ( oid.equals( matchingRule.getSyntax().getOid() ) )
+            {
+                dependees.add( matchingRule );
+            }
+        }
+        
+        return dependees;
+    }
+    
+    
+    /**
+     * Get the list of SchemaObject's name using a given syntax
+     */
+    private String getNames( List<SchemaObject> schemaObjects )
+    {
+        StringBuilder sb = new StringBuilder();
+        boolean isFirst = true;
+        
+        for ( SchemaObject schemaObject : schemaObjects )
+        {
+            if ( isFirst )
+            {
+                isFirst = false;
+            }
+            else
+            {
+                sb.append( ", " );
+            }
+            
+            sb.append(  schemaObject.getName() );
+        }
+        
+        return sb.toString();
+    }
 
+    
     /**
      * {@inheritDoc}
      */
     public void delete( ServerEntry entry, boolean cascade ) throws Exception
     {
         String oid = getOid( entry );
-        
         String schemaName = getSchemaName( entry.getDn() );
-        Schema schema = registries.getLoadedSchema( schemaName );
+        LdapSyntax syntax = factory.getSyntax( entry, registries, schemaName );
         
-        if ( ( schema != null ) && schema.isEnabled() )
+        // Check that this syntax is not used by an AttributeType
+        List<SchemaObject> dependees = checkInUse( oid );
+        
+        if ( dependees.size() != 0 )
+        {
+            throw new LdapOperationNotSupportedException( "The syntax with OID " + oid 
+              + " cannot be deleted until all entities" 
+              + " using this syntax have also been deleted.  The following dependees exist: " 
+              + getNames( dependees ), 
+              ResultCodeEnum.UNWILLING_TO_PERFORM );
+        }
+        
+        if ( isSchemaEnabled( schemaName ) )
         {
             syntaxRegistry.unregister( oid );
         }
-        unregisterOids( oid );
+        else
+        {
+            unregisterOids( syntax );
+        }
     }
 
     
@@ -120,18 +196,19 @@
     public void rename( ServerEntry entry, Rdn newRdn, boolean cascade ) throws Exception
     {
         String oldOid = getOid( entry );
+        String schemaName = getSchemaName( entry.getDn() );
 
-        // Dependency checks are to be handled by the SystemPartition not here.
-//        Set<ServerEntry> dependees = dao.listSyntaxDependents( oldOid );
-//        
-//        if ( dependees != null && dependees.size() > 0 )
-//        {
-//            throw new LdapOperationNotSupportedException( "The syntax with OID " + oldOid
-//                + " cannot be deleted until all entities" 
-//                + " using this syntax have also been deleted.  The following dependees exist: " 
-//                + getOids( dependees ), 
-//                ResultCodeEnum.UNWILLING_TO_PERFORM );
-//        }
+        // Check that this syntax is not used by an AttributeType
+        List<SchemaObject> dependees = checkInUse( oldOid );
+        
+        if ( dependees.size() != 0 )
+        {
+            throw new LdapOperationNotSupportedException( "The syntax with OID " + oldOid 
+              + " cannot be deleted until all entities" 
+              + " using this syntax have also been deleted.  The following dependees exist: " 
+              + getNames( dependees ), 
+              ResultCodeEnum.UNWILLING_TO_PERFORM );
+        }
 
         ServerEntry targetEntry = ( ServerEntry ) entry.clone();
         String newOid = ( String ) newRdn.getValue();
@@ -140,19 +217,18 @@
         targetEntry.put( MetaSchemaConstants.M_OID_AT, newOid );
         LdapSyntax syntax = factory.getSyntax( targetEntry, registries, getSchemaName( entry.getDn() ) );
         
-        if ( isSchemaLoaded( entry.getDn() ) )
+        if ( isSchemaEnabled( schemaName ) )
         {
             syntaxRegistry.unregister( oldOid );
             syntaxRegistry.register( syntax );
         }
         else
         {
+            // always remove old OIDs that are not in schema anymore
+            unregisterOids( syntax );
             // even for disabled schemas add OIDs
             registerOids( syntax );
         }
-        
-        // always remove old OIDs that are not in schema anymore
-        unregisterOids( oldOid );
     }
 
 
@@ -161,19 +237,20 @@
     {
         checkNewParent( newParentName );
         String oldOid = getOid( entry );
+        String oldSchemaName = getSchemaName( oriChildName );
+        String newSchemaName = getSchemaName( newParentName );
 
-        // Dep test before deletion is to be done by the SchemaPartition
-//        
-//        Set<ServerEntry> dependees = dao.listSyntaxDependents( oldOid );
-//        
-//        if ( dependees != null && dependees.size() > 0 )
-//        {
-//            throw new LdapOperationNotSupportedException( "The syntax with OID " + oldOid 
-//                + " cannot be deleted until all entities" 
-//                + " using this syntax have also been deleted.  The following dependees exist: " 
-//                + getOids( dependees ), 
-//                ResultCodeEnum.UNWILLING_TO_PERFORM );
-//        }
+        // Check that this syntax is not used by an AttributeType
+        List<SchemaObject> dependees = checkInUse( oldOid );
+        
+        if ( dependees.size() != 0 )
+        {
+            throw new LdapOperationNotSupportedException( "The syntax with OID " + oldOid 
+              + " cannot be deleted until all entities" 
+              + " using this syntax have also been deleted.  The following dependees exist: " 
+              + getNames( dependees ), 
+              ResultCodeEnum.UNWILLING_TO_PERFORM );
+        }
 
         ServerEntry targetEntry = ( ServerEntry ) entry.clone();
         String newOid = ( String ) newRn.getValue();
@@ -182,14 +259,16 @@
         targetEntry.put( MetaSchemaConstants.M_OID_AT, newOid );
         LdapSyntax syntax = factory.getSyntax( targetEntry, registries, getSchemaName( newParentName ) );
 
-        if ( isSchemaLoaded( oriChildName ) )
+        if ( isSchemaEnabled( oldSchemaName ) )
         {
             syntaxRegistry.unregister( oldOid );
         }
-        // always remove old OIDs that are not in schema anymore
-        unregisterOids( oldOid );
+        else
+        {
+            unregisterOids( syntax );
+        }
 
-        if ( isSchemaLoaded( newParentName ) )
+        if ( isSchemaEnabled( newSchemaName ) )
         {
             syntaxRegistry.register( syntax );
         }
@@ -206,6 +285,8 @@
     {
         checkNewParent( newParentName );
         String oid = getOid( entry );
+        String oldSchemaName = getSchemaName( oriChildName );
+        String newSchemaName = getSchemaName( newParentName );
 
         // schema dep check before delete to be handled by the SchemaPartition
 //        
@@ -222,15 +303,23 @@
         
         LdapSyntax syntax = factory.getSyntax( entry, registries, getSchemaName( newParentName ) );
         
-        if ( isSchemaLoaded( oriChildName ) )
+        if ( isSchemaEnabled( oldSchemaName ) )
         {
             syntaxRegistry.unregister( oid );
         }
+        else
+        {
+            unregisterOids( syntax );
+        }
         
-        if ( isSchemaLoaded( newParentName ) )
+        if ( isSchemaEnabled( newSchemaName ) )
         {
             syntaxRegistry.register( syntax );
         }
+        else
+        {
+            registerOids( syntax );
+        }
     }
     
     



Mime
View raw message