directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r886837 - in /directory/shared/branches/shared-schema: ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/ ldap-schema-loader/src/test/java/org/apache/directory/server/schema/ ldap/src/main/java/org/apache/directory/shared/...
Date Thu, 03 Dec 2009 16:14:13 GMT
Author: elecharny
Date: Thu Dec  3 16:13:58 2009
New Revision: 886837

URL: http://svn.apache.org/viewvc?rev=886837&view=rev
Log:
o Fixed the errors propagation
o Fixed the tests accordingly
o Modified some method signature

Modified:
    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/test/java/org/apache/directory/server/schema/SchemaManagerTest.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaManager.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/AbstractSchemaLoader.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/OidRegistry.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/Registries.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/SchemaLoader.java

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=886837&r1=886836&r2=886837&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
Thu Dec  3 16:13:58 2009
@@ -30,7 +30,6 @@
 import org.apache.directory.shared.ldap.constants.MetaSchemaConstants;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.entry.Entry;
-import org.apache.directory.shared.ldap.exception.LdapOperationNotSupportedException;
 import org.apache.directory.shared.ldap.exception.LdapSchemaViolationException;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.name.LdapDN;
@@ -647,7 +646,7 @@
         {
             if ( registries.isDisabledAccepted() || ( schema.isEnabled() && schemaObject.isEnabled()
) )
             {
-                registries.add( schemaObject );
+                registries.add( errors, schemaObject );
 
             }
             else
@@ -659,7 +658,7 @@
         {
             if ( schema.isEnabled() && schemaObject.isEnabled() )
             {
-                registries.add( schemaObject );
+                registries.add( errors, schemaObject );
             }
             else
             {
@@ -763,7 +762,7 @@
         }
 
         // Build the cross references
-        List<Throwable> errors = clonedRegistries.buildReferences();
+        errors = clonedRegistries.buildReferences();
 
         if ( errors.isEmpty() )
         {
@@ -773,6 +772,7 @@
             if ( errors.isEmpty() )
             {
                 // We are golden : let's apply the schema in the real registries
+                registries.setRelaxed();
 
                 // Load the schemas
                 for ( Schema schema : schemas )
@@ -782,6 +782,7 @@
 
                 // Build the cross references
                 registries.buildReferences();
+                registries.setStrict();
 
                 loaded = true;
             }
@@ -1141,20 +1142,24 @@
     /**
      * Check that the given OID does not already exist in the globalOidRegistry.
      */
-    private void checkOidIsUnique( SchemaObject schemaObject ) throws NamingException
+    private boolean checkOidIsUnique( SchemaObject schemaObject )
     {
         if ( registries.getGlobalOidRegistry().hasOid( schemaObject.getOid() ) )
         {
-            throw new LdapSchemaViolationException( "Oid " + schemaObject.getOid()
+            Throwable error = new LdapSchemaViolationException( "Oid " + schemaObject.getOid()
                 + " for new schema entity is not unique.", ResultCodeEnum.OTHER );
+            errors.add( error );
+            return false;
         }
+
+        return true;
     }
 
 
     /**
      * Retrieve the schema name for a specific SchemaObject, or return "other" if none is
found.
      */
-    private String getSchemaName( SchemaObject schemaObject ) throws Exception
+    private String getSchemaName( SchemaObject schemaObject )
     {
         String schemaName = StringTools.toLowerCase( schemaObject.getSchemaName() );
 
@@ -1175,18 +1180,26 @@
     /**
      * {@inheritDoc}
      */
-    public void add( SchemaObject schemaObject ) throws Exception
+    public boolean add( SchemaObject schemaObject ) throws Exception
     {
+        // First, clear the errors
+        errors.clear();
+
         if ( registries.isRelaxed() )
         {
             // Apply the addition right away
-            registries.add( schemaObject );
+            registries.add( errors, schemaObject );
+
+            return errors.isEmpty();
         }
         else
         {
             // Clone, apply, check, then apply again if ok
             // The new schemaObject's OID must not already exist
-            checkOidIsUnique( schemaObject );
+            if ( !checkOidIsUnique( schemaObject ) )
+            {
+                return false;
+            }
 
             // Build the new AttributeType from the given entry
             String schemaName = getSchemaName( schemaObject );
@@ -1195,7 +1208,17 @@
             // 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 = getLoadedSchema( schemaName );
-            List<Throwable> errors = new ArrayList<Throwable>();
+
+            if ( schema == null )
+            {
+                // The SchemaObject must be associated with an existing schema
+                String msg = "Cannot inject the SchemaObject " + schemaObject.getOid()
+                    + " as it's not associated with a schema";
+                LOG.info( msg );
+                Throwable error = new LdapSchemaViolationException( msg, ResultCodeEnum.OTHER
);
+                errors.add( error );
+                return false;
+            }
 
             if ( schema.isEnabled() && schemaObject.isEnabled() )
             {
@@ -1215,6 +1238,8 @@
                     registries.add( errors, schemaObject );
 
                     LOG.debug( "Added {} into the enabled schema {}", schemaObject.getName(),
schemaName );
+
+                    return true;
                 }
                 else
                 {
@@ -1222,18 +1247,19 @@
                     String msg = "Cannot add the SchemaObject " + schemaObject.getOid() +
" into the registries, "
                         + "the resulting registries would be inconsistent :" + StringTools.listToString(
errors );
                     LOG.info( msg );
-                    throw new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM
);
+
+                    return false;
                 }
             }
             else
             {
                 // At least, we register the OID in the globalOidRegistry, and associates
it with the
                 // schema
-                registries.associateWithSchema( schemaObject );
+                registries.associateWithSchema( errors, schemaObject );
 
                 LOG.debug( "Added {} into the disabled schema {}", schemaObject.getName(),
schemaName );
+                return errors.isEmpty();
             }
-
         }
     }
 
@@ -1270,14 +1296,7 @@
      */
     public Schema getLoadedSchema( String schemaName )
     {
-        try
-        {
-            return schemaLoader.getSchema( schemaName );
-        }
-        catch ( Exception e )
-        {
-            return null;
-        }
+        return schemaLoader.getSchema( schemaName );
     }
 
 

Modified: directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerTest.java?rev=886837&r1=886836&r2=886837&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerTest.java
(original)
+++ directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerTest.java
Thu Dec  3 16:13:58 2009
@@ -20,27 +20,21 @@
 package org.apache.directory.server.schema;
 
 
-import static org.junit.Assert.fail;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 
 import java.io.File;
 import java.io.IOException;
-import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.commons.io.FileUtils;
 import org.apache.directory.server.schema.loader.ldif.LdifSchemaLoaderTest;
-import org.apache.directory.shared.ldap.entry.Entry;
-import org.apache.directory.shared.ldap.exception.LdapOperationNotSupportedException;
+import org.apache.directory.shared.ldap.exception.LdapSchemaViolationException;
 import org.apache.directory.shared.ldap.schema.AttributeType;
-import org.apache.directory.shared.ldap.schema.LdapComparator;
-import org.apache.directory.shared.ldap.schema.LdapSyntax;
-import org.apache.directory.shared.ldap.schema.MatchingRule;
-import org.apache.directory.shared.ldap.schema.Normalizer;
 import org.apache.directory.shared.ldap.schema.SchemaManager;
-import org.apache.directory.shared.ldap.schema.SyntaxChecker;
 import org.apache.directory.shared.ldap.schema.UsageEnum;
 import org.apache.directory.shared.ldap.schema.ldif.extractor.SchemaLdifExtractor;
-import org.apache.directory.shared.ldap.schema.registries.Registries;
 import org.apache.directory.shared.schema.DefaultSchemaManager;
 import org.apache.directory.shared.schema.loader.ldif.JarLdifSchemaLoader;
 import org.apache.directory.shared.schema.loader.ldif.LdifSchemaLoader;
@@ -99,110 +93,6 @@
     }
 
 
-    private void checkComparators( List<Entry> comparators, SchemaManager schemaManager,
Registries expectedRegistries )
-        throws Exception
-    {
-        for ( Entry entry : comparators )
-        {
-            LdapComparator<?> expectedComparator = factory.getLdapComparator( schemaManager,
entry, schemaManager
-                .getRegistries(), "system" );
-            LdapComparator<?> comparator = schemaManager.getComparatorRegistry().lookup(
expectedComparator.getOid() );
-
-            if ( !expectedComparator.equals( comparator ) )
-            {
-                fail();
-            }
-
-            expectedRegistries.add( expectedComparator );
-        }
-    }
-
-
-    private void checkNormalizers( List<Entry> normalizers, SchemaManager schemaManager,
Registries expectedRegistries )
-        throws Exception
-    {
-        for ( Entry entry : normalizers )
-        {
-            Normalizer expectedNormalizer = factory.getNormalizer( schemaManager, entry,
schemaManager.getRegistries(),
-                "system" );
-            Normalizer normalizer = schemaManager.getNormalizerRegistry().lookup( expectedNormalizer.getOid()
);
-
-            if ( !expectedNormalizer.equals( normalizer ) )
-            {
-                fail();
-            }
-
-            expectedRegistries.add( expectedNormalizer );
-        }
-    }
-
-
-    private void checkSyntaxCheckers( List<Entry> syntaxCheckers, SchemaManager schemaManager,
-        Registries expectedRegistries ) throws Exception
-    {
-        for ( Entry entry : syntaxCheckers )
-        {
-            SyntaxChecker expectedSyntaxChecker = factory.getSyntaxChecker( schemaManager,
entry, schemaManager
-                .getRegistries(), "system" );
-            SyntaxChecker syntaxChecker = schemaManager.getSyntaxCheckerRegistry().lookup(
-                expectedSyntaxChecker.getOid() );
-
-            if ( !expectedSyntaxChecker.equals( syntaxChecker ) )
-            {
-                fail();
-            }
-
-            expectedRegistries.add( expectedSyntaxChecker );
-        }
-    }
-
-
-    private void checkSyntaxes( List<Entry> syntaxes, SchemaManager schemaManager,
Registries expectedRegistries )
-        throws Exception
-    {
-        List<Throwable> errors = new ArrayList<Throwable>();
-
-        for ( Entry entry : syntaxes )
-        {
-            LdapSyntax expectedLdapSyntax = factory.getSyntax( schemaManager, entry, schemaManager.getRegistries(),
-                "system" );
-            LdapSyntax syntax = schemaManager.getLdapSyntaxRegistry().lookup( expectedLdapSyntax.getOid()
);
-
-            expectedLdapSyntax.applyRegistries( errors, expectedRegistries );
-
-            if ( !expectedLdapSyntax.equals( syntax ) )
-            {
-                fail();
-            }
-
-            expectedRegistries.add( expectedLdapSyntax );
-        }
-    }
-
-
-    private void checkMatchingRules( List<Entry> matchingRules, SchemaManager schemaManager,
-        Registries expectedRegistries ) throws Exception
-    {
-        List<Throwable> errors = new ArrayList<Throwable>();
-
-        for ( Entry entry : matchingRules )
-        {
-            MatchingRule expectedMatchingRule = factory.getMatchingRule( schemaManager, entry,
schemaManager
-                .getRegistries(), "system" );
-            MatchingRule matchingRule = schemaManager.getMatchingRuleRegistry().lookup( expectedMatchingRule.getOid()
);
-
-            expectedMatchingRule.applyRegistries( errors, expectedRegistries );
-
-            if ( !expectedMatchingRule.equals( matchingRule ) )
-            {
-                fail();
-            }
-
-            expectedRegistries.add( expectedMatchingRule );
-        }
-    }
-
-
     private SchemaManager loadSystem() throws Exception
     {
         JarLdifSchemaLoader loader = new JarLdifSchemaLoader();
@@ -216,47 +106,13 @@
     }
 
 
-    /**
-     * We will load the System schema, and test that the schemaManager is consistent
-     */
-    @Test
-    public void testLoadSystem() throws Exception
-    {
-        JarLdifSchemaLoader loader = new JarLdifSchemaLoader();
-        SchemaManager schemaManager = new DefaultSchemaManager( loader );
-
-        Registries expectedRegistries = new Registries( null );
-
-        String schemaName = "system";
-
-        schemaManager.loadWithDeps( schemaName );
-
-        // Test Comparators
-        checkComparators( ldifLoader.loadComparators( schemaName ), schemaManager, expectedRegistries
);
-
-        // Test Normalizers
-        checkNormalizers( ldifLoader.loadNormalizers( schemaName ), schemaManager, expectedRegistries
);
-
-        // Test SyntaxCheckers
-        checkSyntaxCheckers( ldifLoader.loadSyntaxCheckers( schemaName ), schemaManager,
expectedRegistries );
-
-        // Test LdapSyntax
-        checkSyntaxes( ldifLoader.loadSyntaxes( schemaName ), schemaManager, expectedRegistries
);
-
-        // Test MatchingRules
-        checkMatchingRules( ldifLoader.loadMatchingRules( schemaName ), schemaManager, expectedRegistries
);
-
-        // Test ATs
-    }
-
-
     //-------------------------------------------------------------------------
     // AttributeType addition tests
     //-------------------------------------------------------------------------
     /**
      * Try to inject an AttributeType without any superior nor Syntax : it's invalid
      */
-    @Test(expected = LdapOperationNotSupportedException.class)
+    @Test
     public void testAddAttributeTypeNoSyntaxNoSuperior() throws Exception
     {
         SchemaManager schemaManager = loadSystem();
@@ -268,7 +124,13 @@
         attributeType.setSuperior( ( String ) null );
 
         // It should fail
-        schemaManager.add( attributeType );
+        assertFalse( schemaManager.add( attributeType ) );
+
+        List<Throwable> errors = schemaManager.getErrors();
+        assertEquals( 1, errors.size() );
+        Throwable error = errors.get( 0 );
+
+        assertTrue( error instanceof LdapSchemaViolationException );
     }
 
 
@@ -296,7 +158,7 @@
     /**
      * Try to inject an AttributeType which is Collective, but an operational AT
      */
-    @Test(expected = LdapOperationNotSupportedException.class)
+    @Test
     public void testAddAttributeTypeCollectiveOperational() throws Exception
     {
         SchemaManager schemaManager = loadSystem();
@@ -310,6 +172,14 @@
         attributeType.setCollective( true );
 
         // It should fail
-        schemaManager.add( attributeType );
+        // It should fail
+        assertFalse( schemaManager.add( attributeType ) );
+
+        List<Throwable> errors = schemaManager.getErrors();
+        assertEquals( 1, errors.size() );
+        Throwable error = errors.get( 0 );
+
+        assertTrue( error instanceof LdapSchemaViolationException );
+
     }
 }

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaManager.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaManager.java?rev=886837&r1=886836&r2=886837&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaManager.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaManager.java
Thu Dec  3 16:13:58 2009
@@ -553,12 +553,15 @@
     /**
      * Registers a new SchemaObject. The registries will be updated only if it's
      * consistent after this addition, if the SchemaManager is in Strict mode.
+     * If something went wrong during this operation, the 
+     * SchemaManager.getErrors() will give the list of generated errors.
      *
      * @param schemaObject the SchemaObject to register
+     * @return true if the addition has been made, false if there were some errors
      * @throws Exception if the SchemaObject is already registered or
      * the registration operation is not supported
      */
-    void add( SchemaObject schemaObject ) throws Exception;
+    boolean add( SchemaObject schemaObject ) throws Exception;
 
 
     /**

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/AbstractSchemaLoader.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/AbstractSchemaLoader.java?rev=886837&r1=886836&r2=886837&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/AbstractSchemaLoader.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/AbstractSchemaLoader.java
Thu Dec  3 16:13:58 2009
@@ -93,105 +93,9 @@
 
 
     /**
-     * Recursive method which loads schema's with their dependent schemas first
-     * and tracks what schemas it has seen so the recursion does not go out of
-     * control with dependency cycle detection.
-     *
-     * @param rootAncestor the triggering schema load request: the root ancestor of dependency
chain
-     * @param beenthere stack of schema names we have visited and have yet to load
-     * @param notLoaded hash of schemas keyed by name which have yet to be loaded
-     * @param schema the current schema we are attempting to load
-     * @param registries the set of registries to use while loading
-     * @param props to use while trying to resolve other schemas
-     * @throws Exception if there is a cycle detected and/or another
-     * failure results while loading, producing and or registering schema objects
-     *
-    protected final void loadDepsFirst( Schema rootAncestor, Stack<String> beenthere,
Map<String, Schema> notLoaded,
-                                        Schema schema, Registries registries ) throws Exception
-    {
-        if ( registries.isSchemaLoaded( schema.getSchemaName() ) )
-        {
-            LOG.warn( "{} schema has already been loaded" + schema.getSchemaName() );
-            return;
-        }
-        
-        beenthere.push( schema.getSchemaName() );
-        String[] deps = schema.getDependencies();
-
-        // if no deps then load this guy and return
-        if ( deps == null || deps.length == 0 )
-        {
-            if ( rootAncestor == schema )
-            {
-                load( schema, registries, false );
-            }
-            else
-            {
-                load( schema, registries, true );
-            }
-            
-            notLoaded.remove( schema.getSchemaName() );
-            beenthere.pop();
-            return;
-        }
-
-        /*
-         * We got deps and need to load them before this schema.  We go through
-         * all deps loading them with their deps first if they have not been
-         * loaded.
-         *
-        for ( String depName : deps )
-        {
-            // @todo if a dependency is not loaded it's not in this list
-            // @todo why is it not in this list?  Without being in this list
-            // @todo this for loop is absolutely useless - we will not load
-            // @todo any disabled dependencies at all.  I'm shocked that the
-            // @todo samba schema is actually loading when the nis dependency
-            // @todo is not loaded.
-
-            if ( !notLoaded.containsKey( depName ) )
-            {
-                continue;
-            }
-
-            Schema dep = notLoaded.get( depName );
-
-            // dep is not in the set of schema objects we need to try to resolve it
-            if ( dep == null )
-            {
-                // try to load dependency with the provided properties default
-                dep = getSchema( depName );
-            }
-
-            if ( beenthere.contains( dep.getSchemaName() ) )
-            {
-                // push again so we show the cycle in output
-                beenthere.push( dep.getSchemaName() );
-                throw new NamingException( "schema dependency cycle detected: " + beenthere
);
-            }
-
-            loadDepsFirst( rootAncestor, beenthere, notLoaded, dep, registries );
-        }
-
-        // We have loaded all our deps so we can load this schema
-        if ( rootAncestor == schema )
-        {
-            load( schema, registries, false );
-        }
-        else
-        {
-            load( schema, registries, true );
-        }
-        
-        notLoaded.remove( schema.getSchemaName() );
-        beenthere.pop();
-    }
-
-
-    /**
      * {@inheritDoc}
      */
-    public Schema getSchema( String schemaName ) throws Exception
+    public Schema getSchema( String schemaName )
     {
         return this.schemaMap.get( schemaName );
     }

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/OidRegistry.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/OidRegistry.java?rev=886837&r1=886836&r2=886837&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/OidRegistry.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/OidRegistry.java
Thu Dec  3 16:13:58 2009
@@ -52,7 +52,8 @@
 
     /** Maps OID to a SchemaObject */
     private Map<String, SchemaObject> byOid = new HashMap<String, SchemaObject>();
-    
+
+
     /**
      * Tells if the given OID is present on this registry
      * 
@@ -76,7 +77,7 @@
     public String getPrimaryName( String oid ) throws NamingException
     {
         SchemaObject schemaObject = byOid.get( oid );
-        
+
         if ( schemaObject != null )
         {
             return schemaObject.getName();
@@ -100,7 +101,7 @@
     public SchemaObject getSchemaObject( String oid ) throws NamingException
     {
         SchemaObject schemaObject = byOid.get( oid );
-        
+
         if ( schemaObject != null )
         {
             return schemaObject;
@@ -138,12 +139,12 @@
         }
 
         List<String> names = schemaObject.getNames();
-        
+
         if ( IS_DEBUG )
         {
             LOG.debug( "looked up names '{}' for OID '{}'", ArrayUtils.toString( names ),
oid );
         }
-        
+
         return names;
     }
 
@@ -181,21 +182,21 @@
         if ( schemaObject == null )
         {
             String message = "Cannot register a Null SchemaObject !";
-        
+
             LOG.debug( message );
             throw new NamingException( message );
         }
-        
+
         String oid = schemaObject.getOid();
-        
+
         if ( !OID.isOID( oid ) )
         {
             String message = "The given SchemaObject does not have a valid OID";
-            
+
             LOG.debug( message );
             throw new NamingException( message );
         }
-        
+
         /*
          * Update OID Map if it does not already exist
          */
@@ -215,8 +216,8 @@
             }
         }
     }
-    
-    
+
+
     /**
      * Store the given SchemaObject into the OidRegistry. Available only to 
      * the current package. A weak form (no check is done) of the register 
@@ -224,7 +225,7 @@
      *
      * @param schemaObject The SchemaObject to inject into the OidRegistry
      */
-    /* No qualifier */ void put( SchemaObject schemaObject )
+    /* No qualifier */void put( SchemaObject schemaObject )
     {
         byOid.put( schemaObject.getOid(), schemaObject );
     }
@@ -240,14 +241,14 @@
     {
         // Removes the <OID, names> from the byOID map
         SchemaObject removed = byOid.remove( oid );
-        
+
         if ( IS_DEBUG )
         {
             LOG.debug( "Unregisted SchemaObject '{}' with OID: {}", removed, oid );
         }
     }
-    
-    
+
+
     /**
      * Copy the OidRegistry, without the contained values
      * 
@@ -256,41 +257,41 @@
     public OidRegistry copy()
     {
         OidRegistry copy = new OidRegistry();
-        
+
         // Clone the map
-        copy.byOid = new HashMap<String,SchemaObject>();
-        
+        copy.byOid = new HashMap<String, SchemaObject>();
+
         return copy;
     }
-    
-    
+
+
     /**
      * @return The number of stored OIDs
      */
-    protected int size() 
+    protected int size()
     {
         return byOid.size();
     }
-    
-    
+
+
     public void clear()
     {
         // remove all the OID
         byOid.clear();
     }
-    
-    
+
+
     /**
      * @see Object#toString()
      */
     public String toString()
     {
         StringBuilder sb = new StringBuilder();
-        
+
         if ( byOid != null )
         {
             boolean isFirst = true;
-            
+
             for ( String oid : byOid.keySet() )
             {
                 if ( isFirst )
@@ -301,11 +302,11 @@
                 {
                     sb.append( ", " );
                 }
-                
+
                 sb.append( "<" );
-                
+
                 SchemaObject schemaObject = byOid.get( oid );
-                
+
                 if ( schemaObject != null )
                 {
                     sb.append( schemaObject.getObjectType() );
@@ -314,11 +315,11 @@
                     sb.append( ", " );
                     sb.append( schemaObject.getName() );
                 }
-                
+
                 sb.append( ">" );
             }
         }
-        
+
         return sb.toString();
     }
 }

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/Registries.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/Registries.java?rev=886837&r1=886836&r2=886837&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/Registries.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/Registries.java
Thu Dec  3 16:13:58 2009
@@ -1273,15 +1273,21 @@
         setRelaxed();
 
         // Register the SchemaObject in the registries
-        add( schemaObject );
+        register( errors, schemaObject );
+
+        // Associate the SchemaObject with its schema
+        associateWithSchema( errors, schemaObject );
 
         // Build the SchemaObject references
         buildReference( errors, schemaObject );
 
-        // Check the registries now
-        List<Throwable> checkErrors = checkRefInteg();
+        if ( errors.isEmpty() )
+        {
+            // Check the registries now
+            List<Throwable> checkErrors = checkRefInteg();
 
-        errors.addAll( checkErrors );
+            errors.addAll( checkErrors );
+        }
 
         // return the errors
         return errors;
@@ -1390,23 +1396,9 @@
 
 
     /**
-     * Applies the added SchemaObject to the given register. This method is common
-     * to all the addition operations (LDAP injection or schema loading).
-     */
-    public void add( SchemaObject schemaObject ) throws NamingException
-    {
-        // Register the SchemaObject in the registries
-        register( schemaObject );
-
-        // Associate the SchemaObject with its schema
-        associateWithSchema( schemaObject );
-    }
-
-
-    /**
      * Register the given SchemaObject into the associated Registry
      */
-    private void register( SchemaObject schemaObject ) throws NamingException
+    private void register( List<Throwable> errors, SchemaObject schemaObject ) throws
NamingException
     {
         LOG.debug( "Registering {}:{}", schemaObject.getObjectType(), schemaObject.getOid()
);
 
@@ -1477,7 +1469,7 @@
      * @param schemaObject The schemaObject to register
      * @throws NamingException If there is a problem
      */
-    public void associateWithSchema( SchemaObject schemaObject ) throws NamingException
+    public void associateWithSchema( List<Throwable> errors, SchemaObject schemaObject
) //throws NamingException
     {
         LOG.debug( "Registering {}:{}", schemaObject.getObjectType(), schemaObject.getOid()
);
 
@@ -1488,7 +1480,9 @@
             String msg = "Registering of " + schemaObject.getObjectType() + ":" + schemaObject.getOid()
                 + "failed, it's already present in the Registries";
             LOG.error( msg );
-            throw new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM
);
+            Throwable error = new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM
);
+            errors.add( error );
+            return;
         }
 
         // Get a normalized form of schema name
@@ -1521,7 +1515,15 @@
             // an instance of LoadableSchemaObject
             if ( !( schemaObject instanceof LoadableSchemaObject ) )
             {
-                globalOidRegistry.register( schemaObject );
+                try
+                {
+                    globalOidRegistry.register( schemaObject );
+                }
+                catch ( NamingException ne )
+                {
+                    errors.add( ne );
+                    return;
+                }
             }
 
             LOG.debug( "registered {} for OID {}", schemaObject.getName(), schemaObject.getOid()
);

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/SchemaLoader.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/SchemaLoader.java?rev=886837&r1=886836&r2=886837&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/SchemaLoader.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/SchemaLoader.java
Thu Dec  3 16:13:58 2009
@@ -47,9 +47,8 @@
      * 
      * @param schemaName the name of the schema to load
      * @return the Schema object associated with the name
-     * @throws Exception if any problems while trying to find the associated Schema
      */
-    Schema getSchema( String schemaName ) throws Exception;
+    Schema getSchema( String schemaName );
 
 
     /**



Mime
View raw message