directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r835383 - in /directory/shared/branches/shared-schema: ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaManager.java
Date Thu, 12 Nov 2009 13:52:59 GMT
Author: elecharny
Date: Thu Nov 12 13:52:59 2009
New Revision: 835383

URL: http://svn.apache.org/viewvc?rev=835383&view=rev
Log:
o Added some missing javadoc
o Implemented the verify() methods
o Added the destroy() method

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/src/main/java/org/apache/directory/shared/ldap/schema/SchemaManager.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=835383&r1=835382&r2=835383&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 Nov 12 13:52:59 2009
@@ -97,8 +97,8 @@
     /** The list of errors produced when loading some schema elements */
     private List<Throwable> errors;
     
-    /** The Schema loader used by this SchemaManager */
-    private SchemaLoader loader;
+    /** The Schema schemaLoader used by this SchemaManager */
+    private SchemaLoader schemaLoader;
     
     /** the factory that generates respective SchemaObjects from LDIF entries */
     protected final EntityFactory factory;
@@ -107,19 +107,20 @@
     private LdapDN schemaModificationAttributesDN;
     
     /**
-     * Creates a new instance of DefaultSchemaManager with the default schema loader
+     * Creates a new instance of DefaultSchemaManager with the default schema schemaLoader
      *
-     * @param loader
+     * @param schemaLoader
      */
     public DefaultSchemaManager( SchemaLoader loader ) throws Exception
     {
         // Default to the the root (one schemaManager for all the entries
         namingContext = LdapDN.EMPTY_LDAPDN;
-        this.loader = loader;
+        this.schemaLoader = loader;
         errors = null;
         registries = new Registries();
         factory = new SchemaEntityFactory();
     }
+    
 
     /**
      * Creates a new instance of DefaultSchemaManager, for a specific
@@ -130,7 +131,7 @@
     public DefaultSchemaManager( SchemaLoader loader, LdapDN namingContext ) throws Exception
     {
         this.namingContext = namingContext;
-        this.loader = loader;
+        this.schemaLoader = loader;
         errors = null;
         registries = new Registries();
         factory = new SchemaEntityFactory();
@@ -163,6 +164,53 @@
     }
     
     
+    /**
+     * Transform a String[] array of schema to a Schema[]
+     */
+    private Schema[] toArray( String... schemas ) throws Exception
+    {
+        Schema[] schemaArray = new Schema[schemas.length];
+        int n = 0;
+        
+        for ( String schemaName:schemas )
+        {
+            schemaArray[n++] = schemaLoader.getSchema( schemaName );
+        }
+        
+        return schemaArray;
+    }
+    
+    
+    private void registerSchemaObjects( Schema schema, Registries registries ) throws Exception
+    {
+        registerComparators( schema, registries );
+        registerNormalizers( schema, registries );
+        registerSyntaxCheckers( schema, registries );
+        registerSyntaxes( schema, registries );
+        registerMatchingRules( schema, registries );
+        registerAttributeTypes( schema, registries );
+        registerObjectClasses( schema, registries );
+        registerMatchingRuleUses( schema, registries );
+        registerDitContentRules( schema, registries );
+        registerNameForms( schema, registries );
+        registerDitStructureRules( schema, registries );
+
+        //notifyListenerOrRegistries( schema, registries );
+    }
+    
+    
+    //-----------------------------------------------------------------------
+    // API methods
+    //-----------------------------------------------------------------------
+    /**
+     * {@inheritDoc}
+     */
+    public void destroy( Registries registries )
+    {
+        // TODO : Implement this method
+    }
+    
+    
     /***
      * {@inheritDoc}
      */
@@ -185,7 +233,7 @@
                 registries = targetRegistries;
 
                 // Delete the old registries to avoid memory leaks
-                //destroy( oldRegistries );
+                destroy( oldRegistries );
                 
                 return true;
             }
@@ -203,40 +251,38 @@
     
     
     /**
-     * Transform a String[] array of schema to a Schema[]
+     * {@inheritDoc}
      */
-    private Schema[] toArray( String... schemas ) throws Exception
-    {
-        Schema[] schemaArray = new Schema[schemas.length];
-        int n = 0;
-        
-        for ( String schemaName:schemas )
-        {
-            schemaArray[n++] = loader.getSchema( schemaName );
-        }
-        
-        return schemaArray;
-    }
-    
-    
     public boolean disable( Schema... schemas )
     {
         // TODO Auto-generated method stub
         return false;
     }
 
+
+    /**
+     * {@inheritDoc}
+     */
     public boolean disable( String... schemas )
     {
         // TODO Auto-generated method stub
         return false;
     }
 
+    
+    /**
+     * {@inheritDoc}
+     */
     public boolean disabledRelaxed( Schema... schemas )
     {
         // TODO Auto-generated method stub
         return false;
     }
 
+    
+    /**
+     * {@inheritDoc}
+     */
     public boolean disabledRelaxed( String... schemas )
     {
         // TODO Auto-generated method stub
@@ -271,12 +317,20 @@
         return enable( toArray( schemas ) );
     }
 
+    
+    /**
+     * {@inheritDoc}
+     */
     public boolean enableRelaxed( Schema... schemas )
     {
         // TODO Auto-generated method stub
         return false;
     }
 
+    
+    /**
+     * {@inheritDoc}
+     */
     public boolean enableRelaxed( String... schemas )
     {
         // TODO Auto-generated method stub
@@ -292,6 +346,10 @@
         return errors;
     }
 
+    
+    /**
+     * {@inheritDoc}
+     */
     public Registries getRegistries()
     {
         return registries;
@@ -336,25 +394,6 @@
     }
 
     
-    
-    
-    private void registerSchemaObjects( Schema schema, Registries registries ) throws Exception
-    {
-        registerComparators( schema, registries );
-        registerNormalizers( schema, registries );
-        registerSyntaxCheckers( schema, registries );
-        registerSyntaxes( schema, registries );
-        registerMatchingRules( schema, registries );
-        registerAttributeTypes( schema, registries );
-        registerObjectClasses( schema, registries );
-        registerMatchingRuleUses( schema, registries );
-        registerDitContentRules( schema, registries );
-        registerNameForms( schema, registries );
-        registerDitStructureRules( schema, registries );
-
-        //notifyListenerOrRegistries( schema, registries );
-    }
-    
     /**
      * Load the schema in the registries. We will load everything accordingly to the two
flags :
      * - isRelaxed
@@ -405,7 +444,7 @@
      */
     private void registerAttributeTypes( Schema schema, Registries registries ) throws Exception
     {
-        for ( Entry entry : loader.loadAttributeTypes( schema ) )
+        for ( Entry entry : schemaLoader.loadAttributeTypes( schema ) )
         {
             registerAttributeType( registries, entry, schema );
         }
@@ -417,7 +456,7 @@
      */
     private void registerComparators( Schema schema, Registries registries ) throws Exception
     {
-        for ( Entry entry : loader.loadComparators( schema ) )
+        for ( Entry entry : schemaLoader.loadComparators( schema ) )
         {
             registerComparator( registries, entry, schema );
         }
@@ -429,7 +468,7 @@
      */
     private void registerDitContentRules( Schema schema, Registries registries ) throws Exception
     {
-        for ( Entry entry : loader.loadDitContentRules( schema ) )
+        for ( Entry entry : schemaLoader.loadDitContentRules( schema ) )
         {
             registerDitContentRule( registries, entry, schema );
         }
@@ -441,7 +480,7 @@
      */
     private void registerDitStructureRules( Schema schema, Registries registries ) throws
Exception
     {
-        for ( Entry entry : loader.loadDitStructureRules( schema ) )
+        for ( Entry entry : schemaLoader.loadDitStructureRules( schema ) )
         {
             registerDitStructureRule( registries, entry, schema );
         }
@@ -453,7 +492,7 @@
      */
     private void registerMatchingRules( Schema schema, Registries registries ) throws Exception
     {
-        for ( Entry entry : loader.loadMatchingRules( schema ) )
+        for ( Entry entry : schemaLoader.loadMatchingRules( schema ) )
         {
             registerMatchingRule( registries, entry, schema );
         }
@@ -465,7 +504,7 @@
      */
     private void registerMatchingRuleUses( Schema schema, Registries registries ) throws
Exception
     {
-        for ( Entry entry : loader.loadMatchingRuleUses( schema ) )
+        for ( Entry entry : schemaLoader.loadMatchingRuleUses( schema ) )
         {
             registerMatchingRuleUse( registries, entry, schema );
         }
@@ -477,7 +516,7 @@
      */
     private void registerNameForms( Schema schema, Registries registries ) throws Exception
     {
-        for ( Entry entry : loader.loadNameForms( schema ) )
+        for ( Entry entry : schemaLoader.loadNameForms( schema ) )
         {
             registerNameForm( registries, entry, schema );
         }
@@ -489,7 +528,7 @@
      */
     private void registerNormalizers( Schema schema, Registries registries ) throws Exception
     {
-        for ( Entry entry : loader.loadNormalizers( schema ) )
+        for ( Entry entry : schemaLoader.loadNormalizers( schema ) )
         {
             registerNormalizer( registries, entry, schema );
         }
@@ -501,7 +540,7 @@
      */
     private void registerObjectClasses( Schema schema, Registries registries ) throws Exception
     {
-        for ( Entry entry : loader.loadObjectClasses( schema ) )
+        for ( Entry entry : schemaLoader.loadObjectClasses( schema ) )
         {
             registerObjectClass( registries, entry, schema );
         }
@@ -513,7 +552,7 @@
      */
     private void registerSyntaxes( Schema schema, Registries registries ) throws Exception
     {
-        for ( Entry entry : loader.loadSyntaxes( schema ) )
+        for ( Entry entry : schemaLoader.loadSyntaxes( schema ) )
         {
             registerSyntax( registries, entry, schema );
         }
@@ -525,7 +564,7 @@
      */
     private void registerSyntaxCheckers( Schema schema, Registries registries ) throws Exception
     {
-        for ( Entry entry : loader.loadSyntaxCheckers( schema ) )
+        for ( Entry entry : schemaLoader.loadSyntaxCheckers( schema ) )
         {
             registerSyntaxChecker( registries, entry, schema );
         }
@@ -941,11 +980,15 @@
      */
     public boolean loadAllEnabled() throws Exception
     {
-        Schema[] schemas = loader.getAllEnabled().toArray( new Schema[0] );
+        Schema[] schemas = schemaLoader.getAllEnabled().toArray( new Schema[0] );
         
         return loadWithDeps( schemas );
     }
 
+    
+    /**
+     * {@inheritDoc}
+     */
     public boolean loadAllEnabledRelaxed() throws Exception
     {
         // TODO Auto-generated method stub
@@ -985,12 +1028,20 @@
         return loadDisabled( toArray( schemas ) );
     }
 
+    
+    /**
+     * {@inheritDoc}
+     */
     public boolean loadRelaxed( Schema... schemas ) throws Exception
     {
         // TODO Auto-generated method stub
         return false;
     }
 
+    
+    /**
+     * {@inheritDoc}
+     */
     public boolean loadRelaxed( String... schemas ) throws Exception
     {
         // TODO Auto-generated method stub
@@ -1077,7 +1128,7 @@
             else
             {
                 // Call recursively this method
-                Schema schemaDep = loader.getSchema( depName );
+                Schema schemaDep = schemaLoader.getSchema( depName );
                 loadDepsFirst( schemaDep, registries );
             }
         }
@@ -1087,52 +1138,115 @@
     }
 
     
+    /**
+     * {@inheritDoc}
+     */
     public boolean loadWithDepsRelaxed( Schema... schemas ) throws Exception
     {
         // TODO Auto-generated method stub
         return false;
     }
 
+    
+    /**
+     * {@inheritDoc}
+     */
     public boolean loadWithDepsRelaxed( String... schemas ) throws Exception
     {
         // TODO Auto-generated method stub
         return false;
     }
 
+    
+    /**
+     * {@inheritDoc}
+     */
     public void setRegistries( Registries registries )
     {
         // TODO Auto-generated method stub
         
     }
 
+    
+    /**
+     * {@inheritDoc}
+     */
     public boolean unload( Schema... schemas )
     {
         // TODO Auto-generated method stub
         return false;
     }
 
+
+    /**
+     * {@inheritDoc}
+     */
     public boolean unload( String... schemas )
     {
         // TODO Auto-generated method stub
         return false;
     }
 
-    public boolean verify( Schema... schemas )
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean verify( Schema... schemas ) throws Exception
     {
-        // TODO Auto-generated method stub
-        return false;
+        Registries clonedRegistries = null;
+        
+        clonedRegistries = registries.clone();
+        clonedRegistries.setRelaxed();
+        
+        for ( Schema schema : schemas )
+        {
+            try
+            {
+                
+                // Inject the schema
+                boolean loaded = load( clonedRegistries, schema );
+                
+                if ( !loaded )
+                {
+                    destroy( clonedRegistries );
+                    return false;
+                }
+                
+                // Now, check the registries
+                List<Throwable> errors = clonedRegistries.checkRefInteg();
+                
+                if ( errors.size() != 0 )
+                {
+                    destroy( clonedRegistries );
+                    return false;
+                }
+            }
+            catch ( Exception e )
+            {
+                destroy( clonedRegistries );
+                return false;
+            }
+        }
+        
+        return true;
     }
 
-    public boolean verify( String... schemas )
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean verify( String... schemas ) throws Exception
     {
-        // TODO Auto-generated method stub
-        return false;
+        return verify( toArray( schemas ) );
     }
 
+    
+    /**
+     * {@inheritDoc}
+     */
     public void setSchemaLoader( SchemaLoader schemaLoader )
     {
-        // TODO Auto-generated method stub
-        
+        this.schemaLoader = schemaLoader;
     }
 
 
@@ -1170,7 +1284,7 @@
      */
     public SchemaLoader getLoader()
     {
-        return loader;
+        return schemaLoader;
     }
 
     
@@ -1308,6 +1422,7 @@
         return registries.unregister( schemaObject );
     }
 
+    
     /**
      * {@inheritDoc}
      */
@@ -1333,7 +1448,7 @@
     {
         try
         {
-            return loader.getSchema( schemaName );
+            return schemaLoader.getSchema( schemaName );
         }
         catch ( Exception e )
         {
@@ -1349,7 +1464,7 @@
     {
         try
         {
-            Schema schema = loader.getSchema( schemaName );
+            Schema schema = schemaLoader.getSchema( schemaName );
             return schema != null;
         }
         catch ( Exception e )

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=835383&r1=835382&r2=835383&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 Nov 12 13:52:59 2009
@@ -231,9 +231,25 @@
      */
     boolean loadAllEnabledRelaxed() throws Exception;
     
+    
+    /**
+     * Unload the given set of Schemas
+     *
+     * @param schemas The list of Schema to unload
+     * @return True if all the schemas have been unloaded
+     */
     boolean unload( Schema... schemas );
+    
+    
+    /**
+     * Unload the given set of Schemas
+     *
+     * @param schemas The list of Schema to unload
+     * @return True if all the schemas have been unloaded
+     */
     boolean unload( String... schemas );
     
+    
     //---------------------------------------------------------------------------------
     // Other Schema methods
     //---------------------------------------------------------------------------------
@@ -257,19 +273,83 @@
      * 
      * If the modification is ok, the Registries will be updated.
      *  
-     *  @param schemas The list of schemas to enable
+     *  @param schemas The list of schema name to enable
      *  @return true if the Registries is still consistent, false otherwise.
      */
     boolean enable( String... schemas ) throws Exception;
 
+    
+    /**
+     * Enables a set of Schemas, and returns true if all the schema have been
+     * enabled, with all the dependent schemas. No check is done, the Registries
+     * might become inconsistent after this operation.
+     * 
+     *  @param schemas The list of schemas to enable
+     *  @return true if all the schemas have been enabled
+     */
     boolean enableRelaxed( Schema... schemas );
+
+    
+    /**
+     * Enables a set of Schemas, and returns true if all the schema have been
+     * enabled, with all the dependent schemas. No check is done, the Registries
+     * might become inconsistent after this operation.
+     * 
+     *  @param schemas The list of schema names to enable
+     *  @return true if all the schemas have been enabled
+     */
     boolean enableRelaxed( String... schemas );
     
     
+    /**
+     * Disables a set of Schemas, and returns true if all the schema have been
+     * disabled, with all the dependent schemas, and if the registries is 
+     * still consistent.
+     * 
+     * If the modification is ok, the Registries will be updated. 
+     * 
+     *  @param schemas The list of schemas to disable
+     *  @return true if the Registries is still consistent, false otherwise.
+     */
     boolean disable( Schema... schemas );
+    
+    
+    /**
+     * Disables a set of Schemas, and returns true if all the schema have been
+     * disabled, with all the dependent schemas, and if the registries is 
+     * still consistent.
+     * 
+     * If the modification is ok, the Registries will be updated. 
+     * 
+     *  @param schemas The list of schema names to disable
+     *  @return true if the Registries is still consistent, false otherwise.
+     */
     boolean disable( String... schemas );
 
+    
+    /**
+     * Disables a set of Schemas, and returns true if all the schema have been
+     * disabled, with all the dependent schemas. The Registries is not checked
+     * and can be inconsistent after this operation
+     * 
+     * If the modification is ok, the Registries will be updated. 
+     * 
+     *  @param schemas The list of schemas to disable
+     *  @return true if all the schemas have been disabled
+     */
     boolean disabledRelaxed( Schema... schemas );
+
+    
+    /**
+     * Disables a set of Schemas, and returns true if all the schema have been
+     * disabled, with all the dependent schemas. The Registries is not checked
+     * and can be inconsistent after this operation
+     * 
+     * If the modification is ok, the Registries will be updated. 
+     * 
+     *  @param schemas The list of schema names to disable
+     *  @return true if all the schemas have been disabled
+     */
     boolean disabledRelaxed( String... schemas );
 
 
@@ -278,9 +358,19 @@
      * 
      * @param schemas The schemas to check
      * @return true if the schemas can be loaded in the registries
+     * @throws Exception if something went wrong
      */
-    boolean verify( Schema... schemas );
-    boolean verify( String... schemas );
+    boolean verify( Schema... schemas ) throws Exception;
+    
+    
+    /**
+     * Check that the Schemas are consistent regarding the current Registries.
+     * 
+     * @param schemas The schema names to check
+     * @return true if the schemas can be loaded in the registries
+     * @throws Exception if something went wrong
+     */
+    boolean verify( String... schemas ) throws Exception;
     
     
     /**
@@ -405,6 +495,11 @@
     Map<String, OidNormalizer> getNormalizerMapping();
 
     
+    /**
+     * Associate a new Registries to the SchemaManager
+     *
+     * @param registries The new Registries
+     */
     void setRegistries( Registries registries );
     
     
@@ -419,11 +514,25 @@
     
     
     /**
+     * Delete the given registries and all its content. This method is called
+     * to avoid memory leaks.
+     *
+     * @param registries The registries to be deleted
+     */
+    public void destroy( Registries registries );
+    
+    
+    /**
      * @return The errors obtained when checking the registries
      */
     List<Throwable> getErrors();
     
     
+    /**
+     * Associate a Schema loader to this SchemaManager
+     *
+     * @param schemaLoader The schema loader to use
+     */
     void setSchemaLoader( SchemaLoader schemaLoader );
 
 



Mime
View raw message