directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r834716 - in /directory: apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/ apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/...
Date Tue, 10 Nov 2009 23:54:49 GMT
Author: elecharny
Date: Tue Nov 10 23:54:48 2009
New Revision: 834716

URL: http://svn.apache.org/viewvc?rev=834716&view=rev
Log:
Fixed the addition of AT in disabled schema. All additions of AT in enabled, disabled and
not loaded schema are now working.

Modified:
    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/RegistrySynchronizerAdaptor.java
    directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandlerIT.java
    directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/schema/SubschemaSubentryIT.java
    directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java
    directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/SchemaEntityFactory.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/EntityFactory.java

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=834716&r1=834715&r2=834716&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
Tue Nov 10 23:54:48 2009
@@ -86,45 +86,39 @@
         // Relax the cloned registries
         clonedRegistries.setRelaxed();
         
-        AttributeType at = factory.getAttributeType( entry, clonedRegistries, schemaName
);
+        AttributeType at = factory.getAttributeType( entry, clonedRegistries, schemaManager,
schemaName );
         
-        if ( at == null )
+        // if the AT is null, that means the schema is disabled
+        if ( at != null )
         {
-            // We couldn't create the AT : this is an error
-            return;
-        }
-        
-        List<Throwable> errors = clonedRegistries.checkRefInteg();
-        
-        if ( errors.size() == 0 )
-        {
-            clonedRegistries.setStrict();
-            schemaManager.setRegistries( clonedRegistries  );
-        }
-        else
-        {
-            // We have some error : reject the addition and get out
-            return;
-        }
-        
-        // At this point, the constructed AttributeType has not been checked against the

-        // existing Registries. It may be broken (missing SUP, or such), it will be checked
-        // there, if the schema and the AttributeType are both enabled.
-        Schema schema = schemaManager.getLoadedSchema( schemaName );
-        
-        if ( schema.isEnabled() && at.isEnabled() )
-        {
-            at.applyRegistries( schemaManager.getRegistries() );
-        }
+            List<Throwable> errors = clonedRegistries.checkRefInteg();
+            
+            if ( errors.size() == 0 )
+            {
+                clonedRegistries.setStrict();
+                schemaManager.setRegistries( clonedRegistries  );
+            }
+            else
+            {
+                // We have some error : reject the addition and get out
+                return;
+            }
         
-        // Associates this AttributeType with the schema
-        addToSchema( at, schemaName );
+            // At this point, the constructed AttributeType has not been checked against
the 
+            // existing Registries. It may be broken (missing SUP, or such), it will be checked
+            // there, if the schema and the AttributeType are both enabled.
+            Schema schema = schemaManager.getLoadedSchema( schemaName );
+            
+            if ( schema.isEnabled() && at.isEnabled() )
+            {
+                at.applyRegistries( schemaManager.getRegistries() );
+            }
         
-        // Don't inject the modified element if the schema is disabled
-        if ( isSchemaEnabled( schemaName ) )
-        {
+            // Associates this AttributeType with the schema
+            addToSchema( at, schemaName );
+            
             schemaManager.register( at );
-
+    
             LOG.debug( "Added {} into the enabled schema {}", dn.getUpName(), schemaName
);
         }
         else
@@ -145,7 +139,7 @@
         ServerEntry entry = opContext.getEntry();
         String schemaName = getSchemaName( name );
         String oid = getOid( entry );
-        AttributeType at = factory.getAttributeType( targetEntry, schemaManager.getRegistries(),
schemaName );
+        AttributeType at = factory.getAttributeType( targetEntry, schemaManager.getRegistries(),
schemaManager, schemaName );
         
         if ( isSchemaEnabled( schemaName ) )
         {
@@ -177,7 +171,7 @@
         
         // Get the AttributeType from the given entry ( it has been grabbed from the server
earlier)
         String schemaName = getSchemaName( entry.getDn() );
-        AttributeType attributeType = factory.getAttributeType( entry, schemaManager.getRegistries(),
schemaName );
+        AttributeType attributeType = factory.getAttributeType( entry, schemaManager.getRegistries(),
schemaManager, schemaName );
         
         // Applies the Registries to this AttributeType 
         Schema schema = schemaManager.getLoadedSchema( schemaName );
@@ -245,7 +239,7 @@
     public void rename( ServerEntry entry, Rdn newRdn, boolean cascade ) throws Exception
     {
         String schemaName = getSchemaName( entry.getDn() );
-        AttributeType oldAt = factory.getAttributeType( entry, schemaManager.getRegistries(),
schemaName );
+        AttributeType oldAt = factory.getAttributeType( entry, schemaManager.getRegistries(),
schemaManager, schemaName );
 
         // Inject the new OID
         ServerEntry targetEntry = ( ServerEntry ) entry.clone();
@@ -259,7 +253,7 @@
         newDn.add( newRdn );
         targetEntry.setDn( newDn );
         
-        AttributeType at = factory.getAttributeType( targetEntry, schemaManager.getRegistries(),
schemaName );
+        AttributeType at = factory.getAttributeType( targetEntry, schemaManager.getRegistries(),
schemaManager, schemaName );
 
         if ( isSchemaEnabled( schemaName ) )
         {
@@ -289,12 +283,12 @@
         checkParent( newParentName, schemaManager, SchemaConstants.ATTRIBUTE_TYPE );
         String oldSchemaName = getSchemaName( oriChildName );
         String newSchemaName = getSchemaName( newParentName );
-        AttributeType oldAt = factory.getAttributeType( entry, schemaManager.getRegistries(),
oldSchemaName );
+        AttributeType oldAt = factory.getAttributeType( entry, schemaManager.getRegistries(),
schemaManager, oldSchemaName );
         ServerEntry targetEntry = ( ServerEntry ) entry.clone();
         String newOid = ( String ) newRn.getValue();
         targetEntry.put( MetaSchemaConstants.M_OID_AT, newOid );
         checkOidIsUnique( newOid );
-        AttributeType newAt = factory.getAttributeType( targetEntry, schemaManager.getRegistries(),
newSchemaName );
+        AttributeType newAt = factory.getAttributeType( targetEntry, schemaManager.getRegistries(),
schemaManager, newSchemaName );
 
         
         if ( !isSchemaLoaded( oldSchemaName ) )
@@ -340,8 +334,8 @@
         checkParent( newParentName, schemaManager, SchemaConstants.ATTRIBUTE_TYPE );
         String oldSchemaName = getSchemaName( oriChildName );
         String newSchemaName = getSchemaName( newParentName );
-        AttributeType oldAt = factory.getAttributeType( entry, schemaManager.getRegistries(),
oldSchemaName );
-        AttributeType newAt = factory.getAttributeType( entry, schemaManager.getRegistries(),
newSchemaName );
+        AttributeType oldAt = factory.getAttributeType( entry, schemaManager.getRegistries(),
schemaManager, oldSchemaName );
+        AttributeType newAt = factory.getAttributeType( entry, schemaManager.getRegistries(),
schemaManager, newSchemaName );
         
         if ( !isSchemaLoaded( oldSchemaName ) )
         {

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=834716&r1=834715&r2=834716&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
Tue Nov 10 23:54:48 2009
@@ -185,6 +185,7 @@
             
             String ouValue = ( String ) opContext.getDn().getRdn().getValue();
             ouValue = ouValue.trim().toLowerCase();
+            
             if ( ! VALID_OU_VALUES.contains( ouValue ) )
             {
                 throw new LdapInvalidNameException( 

Modified: directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandlerIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandlerIT.java?rev=834716&r1=834715&r2=834716&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandlerIT.java
(original)
+++ directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandlerIT.java
Tue Nov 10 23:54:48 2009
@@ -26,6 +26,7 @@
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+import javax.naming.NameNotFoundException;
 import javax.naming.NamingException;
 import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
@@ -139,7 +140,42 @@
     
     
     @Test
-    public void testAddAttributeTypeToDisabledSchema() throws Exception
+    public void testAddAttributeTypeToUnLoadedSchema() throws Exception
+    {
+        Attributes attrs = AttributeUtils.createAttributes( 
+            "objectClass: top",
+            "objectClass: metaTop",
+            "objectClass: metaAttributeType",
+            "m-oid:" + OID,
+            "m-syntax:" + SchemaConstants.INTEGER_SYNTAX,
+            "m-description:" + DESCRIPTION0,
+            "m-equality: caseIgnoreMatch",
+            "m-singleValue: FALSE",
+            "m-usage: directoryOperation" );
+
+        LdapDN dn = getAttributeTypeContainer( "notloaded" );
+        dn.add( "m-oid=" + OID );
+        
+        try
+        {
+            getSchemaContext( service ).createSubcontext( dn, attrs );
+            fail( "Should not be there" );
+        }
+        catch( NameNotFoundException nnfe )
+        {
+            // Expected result.
+        }
+        
+        assertFalse( "adding new attributeType to disabled schema should not register it
into the registries", 
+            service.getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
+        
+        // The added entry must not be present on disk
+        assertFalse( isOnDisk( dn ) );
+    }
+    
+    
+    @Test
+    public void testAddAttributeTypeToLoadedDisabledSchema() throws Exception
     {
         Attributes attrs = AttributeUtils.createAttributes( 
             "objectClass: top",
@@ -154,13 +190,16 @@
 
         LdapDN dn = getAttributeTypeContainer( "nis" );
         dn.add( "m-oid=" + OID );
+        
         getSchemaContext( service ).createSubcontext( dn, attrs );
         
         assertFalse( "adding new attributeType to disabled schema should not register it
into the registries", 
             service.getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
+        
+        // The added entry must be present on disk
         assertTrue( isOnDisk( dn ) );
     }
-    
+
     
     @Test
     public void testDeleteAttributeTypeFromEnabledSchema() throws Exception
@@ -188,6 +227,7 @@
     }
     
     
+    /*
     @Test
     public void testDeleteAttributeTypeFromDisabledSchema() throws Exception
     {
@@ -201,9 +241,17 @@
             service.getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
 
         // Check on disk that the added SchemaObject exist
-        assertTrue( isOnDisk( dn ) );
+        assertFalse( isOnDisk( dn ) );
         
-        getSchemaContext( service ).destroySubcontext( dn );
+        try
+        {
+            getSchemaContext( service ).destroySubcontext( dn );
+            fail( "Should not be there" );
+        }
+        catch( NameNotFoundException nnfe )
+        {
+            // Expected result.
+        }
 
         // Check in Registries
         assertFalse( "attributeType should be removed from the registry after being deleted",

@@ -212,6 +260,7 @@
         // Check on disk that the deleted SchemaObject does not exist anymore
         assertFalse( isOnDisk( dn ) );
     }
+    */
 
 
     @Test
@@ -565,6 +614,7 @@
     }
 
 
+    /*
     @Test
     @Ignore
     public void testMoveMatchingRuleToEnabledSchema() throws Exception
@@ -589,4 +639,5 @@
         assertEquals( "attributeType should be in apachemeta schema after move", 
             service.getSchemaManager().getAttributeTypeRegistry().getSchemaName( OID ), "apachemeta"
);
     }
+    */
 }

Modified: directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/schema/SubschemaSubentryIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/schema/SubschemaSubentryIT.java?rev=834716&r1=834715&r2=834716&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/schema/SubschemaSubentryIT.java
(original)
+++ directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/schema/SubschemaSubentryIT.java
Tue Nov 10 23:54:48 2009
@@ -1429,7 +1429,7 @@
         
         ServerEntry serverEntry = ServerEntryUtils.toServerEntry( attrs, LdapDN.EMPTY_LDAPDN,
service.getSchemaManager() );
         
-        AttributeType at = factory.getAttributeType( serverEntry, service.getSchemaManager().getRegistries(),
"nis" );
+        AttributeType at = factory.getAttributeType( serverEntry, service.getSchemaManager().getRegistries(),
service.getSchemaManager(), "nis" );
         assertEquals( "1.3.6.1.4.1.18060.0.4.0.2.10000", at.getOid() );
         assertEquals( "name", at.getSuperior().getName() );
         assertEquals( "bogus description", at.getDescription() );
@@ -1492,7 +1492,7 @@
         
         ServerEntry serverEntry = ServerEntryUtils.toServerEntry( attrs, LdapDN.EMPTY_LDAPDN,
service.getSchemaManager() );
 
-        AttributeType at = factory.getAttributeType( serverEntry, service.getSchemaManager().getRegistries(),
"nis" );
+        AttributeType at = factory.getAttributeType( serverEntry, service.getSchemaManager().getRegistries(),
service.getSchemaManager(), "nis" );
         assertEquals( "1.3.6.1.4.1.18060.0.4.0.2.10000", at.getOid() );
         assertEquals( "name", at.getSuperior().getName() );
         assertEquals( "bogus description", at.getDescription() );

Modified: directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java?rev=834716&r1=834715&r2=834716&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java
(original)
+++ directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java
Tue Nov 10 23:54:48 2009
@@ -299,7 +299,10 @@
     }
     
 
-    public boolean isDisabledAccepter()
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isDisabledAccepted()
     {
         // TODO Auto-generated method stub
         return false;
@@ -542,7 +545,7 @@
     private AttributeType registerAttributeType( Registries registries, Entry entry, Schema
schema ) 
         throws Exception
     {
-        AttributeType attributeType = factory.getAttributeType( entry, registries, schema.getSchemaName()
);
+        AttributeType attributeType = factory.getAttributeType( entry, registries, this,
schema.getSchemaName() );
         
         if ( registries.isRelaxed() )
         {
@@ -1329,7 +1332,14 @@
      */
     public Schema getLoadedSchema( String schemaName )
     {
-        return registries.getLoadedSchema( schemaName );
+        try
+        {
+            return loader.getSchema( schemaName );
+        }
+        catch ( Exception e )
+        {
+            return null;
+        }
     }
 
 
@@ -1338,7 +1348,15 @@
      */
     public boolean isSchemaLoaded( String schemaName )
     {
-        return registries.isSchemaLoaded( schemaName );
+        try
+        {
+            Schema schema = loader.getSchema( schemaName );
+            return schema != null;
+        }
+        catch ( Exception e )
+        {
+            return false;
+        }
     }
     
 

Modified: directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/SchemaEntityFactory.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/SchemaEntityFactory.java?rev=834716&r1=834715&r2=834716&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/SchemaEntityFactory.java
(original)
+++ directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/SchemaEntityFactory.java
Tue Nov 10 23:54:48 2009
@@ -36,6 +36,7 @@
 import org.apache.directory.shared.ldap.entry.Value;
 import org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute;
 import org.apache.directory.shared.ldap.exception.LdapInvalidAttributeValueException;
+import org.apache.directory.shared.ldap.exception.LdapOperationNotSupportedException;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.apache.directory.shared.ldap.schema.EntityFactory;
@@ -310,6 +311,15 @@
         // Get the schema
         Schema schema = getSchema( schemaName, targetRegistries );
 
+        if ( schema == null )
+        {
+            // The schema is not loaded. We can't create the requested SyntaxChecker
+            String msg = "Cannot add the SyntaxChecker " + entry.getDn().getUpName() + ",
as the associated schema (" +
+                schemaName + " is not loaded";
+            LOG.warn( msg );
+            throw new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM
);
+        }
+        
         // The FQCN
         String className = getFqcn( entry, SchemaConstants.SYNTAX_CHECKER );
         
@@ -347,6 +357,15 @@
         // Get the schema
         Schema schema = getSchema( schemaName, targetRegistries );
 
+        if ( schema == null )
+        {
+            // The schema is not loaded. We can't create the requested SyntaxChecker
+            String msg = "Cannot add the SyntaxChecker " + syntaxCheckerDescription.getName()
+ ", as the associated schema (" +
+                schemaName + " is not loaded";
+            LOG.warn( msg );
+            throw new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM
);
+        }
+        
         // The FQCN
         String fqcn = getFqcn( syntaxCheckerDescription, SchemaConstants.SYNTAX_CHECKER );
         
@@ -424,6 +443,15 @@
         // Get the schema
         Schema schema = getSchema( schemaName, targetRegistries );
 
+        if ( schema == null )
+        {
+            // The schema is not loaded. We can't create the requested Comparator
+            String msg = "Cannot add the Comparator " + comparatorDescription.getName() +
", as the associated schema (" +
+                schemaName + " is not loaded";
+            LOG.warn( msg );
+            throw new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM
);
+        }
+
         // The FQCN
         String fqcn = getFqcn( comparatorDescription, SchemaConstants.COMPARATOR );
         
@@ -461,6 +489,15 @@
         // Get the schema
         Schema schema = getSchema( schemaName, targetRegistries );
 
+        if ( schema == null )
+        {
+            // The schema is not loaded. We can't create the requested Comparator
+            String msg = "Cannot add the Comparator " + entry.getDn().getUpName() + ", as
the associated schema (" +
+                schemaName + " is not loaded";
+            LOG.warn( msg );
+            throw new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM
);
+        }
+        
         // The FQCN
         String fqcn = getFqcn( entry, SchemaConstants.COMPARATOR );
         
@@ -537,6 +574,15 @@
         // Get the schema
         Schema schema = getSchema( schemaName, targetRegistries );
 
+        if ( schema == null )
+        {
+            // The schema is not loaded. We can't create the requested Normalizer
+            String msg = "Cannot add the Normalizer " + normalizerDescription.getName() +
", as the associated schema (" +
+                schemaName + " is not loaded";
+            LOG.warn( msg );
+            throw new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM
);
+        }
+        
         // The FQCN
         String fqcn = getFqcn( normalizerDescription, SchemaConstants.NORMALIZER );
         
@@ -571,6 +617,15 @@
         // Get the schema
         Schema schema = getSchema( schemaName, targetRegistries );
 
+        if ( schema == null )
+        {
+            // The schema is not loaded. We can't create the requested Normalizer
+            String msg = "Cannot add the Normalizer " + entry.getDn().getUpName() + ", as
the associated schema (" +
+                schemaName + " is not loaded";
+            LOG.warn( msg );
+            throw new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM
);
+        }
+        
         // The FQCN
         String className = getFqcn( entry, SchemaConstants.NORMALIZER );
         
@@ -633,6 +688,15 @@
         // Get the schema
         Schema schema = getSchema( schemaName, targetRegistries );
 
+        if ( schema == null )
+        {
+            // The schema is not loaded. We can't create the requested Syntax
+            String msg = "Cannot add the Syntax " + entry.getDn().getUpName() + ", as the
associated schema (" +
+                schemaName + " is not loaded";
+            LOG.warn( msg );
+            throw new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM
);
+        }
+        
         // Create the new LdapSyntax instance
         LdapSyntax syntax = new LdapSyntax( oid );
         
@@ -671,6 +735,15 @@
         // Get the schema
         Schema schema = getSchema( schemaName, targetRegistries );
 
+        if ( schema == null )
+        {
+            // The schema is not loaded. We can't create the requested MatchingRule
+            String msg = "Cannot add the MatchingRule " + entry.getDn().getUpName() + ",
as the associated schema (" +
+                schemaName + " is not loaded";
+            LOG.warn( msg );
+            throw new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM
);
+        }
+        
         MatchingRule matchingRule = new MatchingRule( oid );
 
         // The syntax field
@@ -722,6 +795,15 @@
         // Get the schema
         Schema schema = getSchema( schemaName, targetRegistries );
 
+        if ( schema == null )
+        {
+            // The schema is not loaded. We can't create the requested ObjectClass
+            String msg = "Cannot add the ObjectClass " + entry.getDn().getUpName() + ", as
the associated schema (" +
+                schemaName + " is not loaded";
+            LOG.warn( msg );
+            throw new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM
);
+        }
+        
         // Create the ObjectClass instance
         ObjectClass oc = new ObjectClass( oid );
         
@@ -770,11 +852,12 @@
      *
      * @param entry The entry containing all the informations to build an AttributeType
      * @param targetRegistries The registries containing all the enabled SchemaObjects
+     * @param schemaManager The schema Manager
      * @param schemaName The schema containing this AttributeType
      * @return An AttributeType SchemaObject
      * @throws NamingException If the AttributeType is invalid
      */
-    public AttributeType getAttributeType( Entry entry, Registries targetRegistries, String
schemaName ) throws NamingException
+    public AttributeType getAttributeType( Entry entry, Registries targetRegistries, SchemaManager
schemaManager, String schemaName ) throws NamingException
     {
         checkEntry( entry, SchemaConstants.ATTRIBUTE_TYPE );
         
@@ -782,12 +865,24 @@
         String oid = getOid( entry, SchemaConstants.ATTRIBUTE_TYPE );
 
         // Get the schema
+        if ( !schemaManager.isSchemaLoaded( schemaName ) )
+        {
+            // The schema is not loaded, this is an error
+            String msg = "Cannot add the AttributeType " + entry.getDn().getUpName() + ",
as the associated schema (" +
+                schemaName + " is not loaded";
+            LOG.warn( msg );
+            throw new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM
);
+        }
+        
         Schema schema = getSchema( schemaName, targetRegistries );
         
         if ( schema == null )
         {
-            // The schema is not loaded. We can't create the requested AttributeType
-            return null;
+            // The schema is disabled. We still have to update the backend
+            String msg = "Cannot add the AttributeType " + entry.getDn().getUpName() + "
into the registries, "+
+                "as the associated schema (" + schemaName + " is disabled";
+            LOG.info( msg );
+            schema = schemaManager.getLoadedSchema( schemaName );
         }
 
         // Create the new AttributeType
@@ -1013,7 +1108,7 @@
         }
         else
         {
-            schemaObject.setEnabled( schema.isEnabled() );
+            schemaObject.setEnabled( schema != null && schema.isEnabled() );
         }
         
         // The isReadOnly field

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/EntityFactory.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/EntityFactory.java?rev=834716&r1=834715&r2=834716&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/EntityFactory.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/EntityFactory.java
Tue Nov 10 23:54:48 2009
@@ -111,9 +111,10 @@
      *
      * @param entry The entry containing all the informations to build an AttributeType
      * @param targetRegistries The registries containing all the enabled SchemaObjects
+     * @param schemaManager The SchemaManager
      * @param schemaName The schema containing this AttributeType
      * @return An AttributeType SchemaObject
      * @throws NamingException If the AttributeType is invalid
      */
-    AttributeType getAttributeType( Entry entry, Registries targetRegistries, String schemaName
) throws NamingException;
+    AttributeType getAttributeType( Entry entry, Registries targetRegistries, SchemaManager
schemaManager, String schemaName ) throws NamingException;
 }



Mime
View raw message