directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r486226 - in /directory/branches/trunks/schema/apacheds: bootstrap-partition/pom.xml bootstrap-plugin/src/main/java/org/apache/directory/server/core/bootstrap/plugin/BootstrapPlugin.java core/src/main/schema/apachemeta.schema
Date Tue, 12 Dec 2006 16:46:02 GMT
Author: akarasulu
Date: Tue Dec 12 08:46:02 2006
New Revision: 486226

URL: http://svn.apache.org/viewvc?view=rev&rev=486226
Log:
schemaCheckers are now being loaded into the schema partition properly

Modified:
    directory/branches/trunks/schema/apacheds/bootstrap-partition/pom.xml
    directory/branches/trunks/schema/apacheds/bootstrap-plugin/src/main/java/org/apache/directory/server/core/bootstrap/plugin/BootstrapPlugin.java
    directory/branches/trunks/schema/apacheds/core/src/main/schema/apachemeta.schema

Modified: directory/branches/trunks/schema/apacheds/bootstrap-partition/pom.xml
URL: http://svn.apache.org/viewvc/directory/branches/trunks/schema/apacheds/bootstrap-partition/pom.xml?view=diff&rev=486226&r1=486225&r2=486226
==============================================================================
--- directory/branches/trunks/schema/apacheds/bootstrap-partition/pom.xml (original)
+++ directory/branches/trunks/schema/apacheds/bootstrap-partition/pom.xml Tue Dec 12 08:46:02
2006
@@ -39,6 +39,7 @@
   	    <artifactId>apacheds-bootstrap-plugin</artifactId>
         <configuration>
           <indexedAttributes>
+            <indexedAttribute>objectClass</indexedAttribute>
             <indexedAttribute>ou</indexedAttribute>
             <indexedAttribute>cn</indexedAttribute>
             <indexedAttribute>m-oid</indexedAttribute>

Modified: directory/branches/trunks/schema/apacheds/bootstrap-plugin/src/main/java/org/apache/directory/server/core/bootstrap/plugin/BootstrapPlugin.java
URL: http://svn.apache.org/viewvc/directory/branches/trunks/schema/apacheds/bootstrap-plugin/src/main/java/org/apache/directory/server/core/bootstrap/plugin/BootstrapPlugin.java?view=diff&rev=486226&r1=486225&r2=486226
==============================================================================
--- directory/branches/trunks/schema/apacheds/bootstrap-plugin/src/main/java/org/apache/directory/server/core/bootstrap/plugin/BootstrapPlugin.java
(original)
+++ directory/branches/trunks/schema/apacheds/bootstrap-plugin/src/main/java/org/apache/directory/server/core/bootstrap/plugin/BootstrapPlugin.java
Tue Dec 12 08:46:02 2006
@@ -20,13 +20,17 @@
 package org.apache.directory.server.core.bootstrap.plugin;
 
 import java.io.File;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Set;
 
+import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
 import javax.naming.directory.Attributes;
 import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
 
 import org.apache.directory.server.core.configuration.MutablePartitionConfiguration;
 import org.apache.directory.server.core.configuration.MutableStartupConfiguration;
@@ -40,6 +44,8 @@
 import org.apache.directory.server.core.schema.bootstrap.BootstrapSchemaLoader;
 import org.apache.directory.server.core.schema.bootstrap.CoreSchema;
 import org.apache.directory.server.core.schema.bootstrap.SystemSchema;
+import org.apache.directory.shared.ldap.filter.ExprNode;
+import org.apache.directory.shared.ldap.filter.PresenceNode;
 import org.apache.directory.shared.ldap.message.LockableAttributesImpl;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.schema.syntax.SyntaxChecker;
@@ -47,8 +53,9 @@
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
 
+
 /**
- * Document me!
+ * A plugin used to pre-load meta schema entries into the schema partition.
  *
  * @goal generate
  * @description creates and pre-loads ApacheDS schema partition
@@ -74,14 +81,22 @@
     private String[] bootstrapSchemaClasses;
     
     /**
-     * Attributes to index.
+     * The names of Attributes to index.
      * 
      * @parameter 
      */
     private String[] indexedAttributes;
     
+    /** Facotry used to create attributes objects from schema entities. */ 
     private AttributesFactory attributesFactory = new AttributesFactory();
+    
+    /** Registries of objects used to load the schema partition. */
+    private Registries registries = new BootstrapRegistries();
 
+    /** The partition to load schema entities into. */
+    private JdbmPartition partition = new JdbmPartition();
+    
+    
     /**
      * Loads a bunch of bootstrap classes into memory then adds them to a new 
      * schema partition within the target area.  The db files for this partition
@@ -89,63 +104,52 @@
      */
     public void execute() throws MojoExecutionException, MojoFailureException
     {
-        // -------------------------------------------------------------------
-        // load the bootstrap schemas to pre-load into the partition
-        // -------------------------------------------------------------------
-
-        // always include these core bootstrap schemas
-        Registries registries = new BootstrapRegistries();
-        Set<BootstrapSchema> schemas = new HashSet<BootstrapSchema>();
-        schemas.add( new SystemSchema() );
-        schemas.add( new ApacheSchema() );
-        schemas.add( new ApachemetaSchema() );
-        schemas.add( new CoreSchema() );
+        initializeSchemas();
+        initializePartition();
         
-        getLog().info( "------------------------------------------------------" );
-        getLog().info( "Found bootstrap schemas: " );
-
-        // start loading other schemas from the plugin's configuration section
-        for ( String schemaClassName: bootstrapSchemaClasses )
+        try
         {
-            try
-            {
-                Class schemaClass = Class.forName( schemaClassName );
-                schemas.add( ( BootstrapSchema ) schemaClass.newInstance() );
-            }
-            catch ( ClassNotFoundException e )
-            {
-                e.printStackTrace();
-                throw new MojoFailureException( "Could not find BootstrapSchema class: "
+ schemaClassName );
-            }
-            catch ( InstantiationException e )
-            {
-                e.printStackTrace();
-                throw new MojoFailureException( "Could not instantiate BootstrapSchema class:
" + schemaClassName );
-            }
-            catch ( IllegalAccessException e )
+            LdapDN dn = new LdapDN( "ou=schema" );
+            dn.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
+            
+            if ( ! partition.hasEntry( dn ) )
             {
-                e.printStackTrace();
-                throw new MojoFailureException( "Could not instantiate BootstrapSchema class
due to security: "
-                    + schemaClassName );
+                Attributes entry = new LockableAttributesImpl();
+                entry.put( "objectClass", "top" );
+                entry.get( "objectClass" ).add( "organizationalUnit" );
+                entry.put( "ou", "schema" );
+                partition.add( dn, entry );
             }
-            
-            getLog().info( "\t" + schemaClassName );
+
+            addSyntaxCheckers();
+            verifySyntaxCheckers();
+        }
+        catch ( NamingException e )
+        {
+            e.printStackTrace();
+            throw new MojoFailureException( "Failed to add syntaxCheckers to partition: "
+ e.getMessage() );
         }
-        getLog().info( "------------------------------------------------------" );
         
-        BootstrapSchemaLoader loader = new BootstrapSchemaLoader();
         try
         {
-            loader.load( schemas, ( BootstrapRegistries ) registries );
+            partition.sync();
         }
         catch ( NamingException e )
         {
             e.printStackTrace();
-            throw new MojoFailureException( "Failed to load bootstrap registries with schemas:
" + e.getMessage() );
         }
-        
+    }
+
+    
+    /**
+     * Creates the configuration and initializes the partition so we can start
+     * adding entries into it.
+     * 
+     * @throws MojoFailureException
+     */
+    private void initializePartition() throws MojoFailureException
+    {
         // start up the schema partition
-        JdbmPartition partition = new JdbmPartition();
         MutableStartupConfiguration msConf = new MutableStartupConfiguration();
         msConf.setWorkingDirectory( outputDirectory );
         
@@ -164,7 +168,6 @@
         }
         
         mpConfig.setIndexedAttributes( indexSet );
-        
         try
         {
             mpConfig.setSuffix( "ou=schema" );
@@ -186,44 +189,112 @@
             e.printStackTrace();
             throw new MojoFailureException( "Failed to initialize parition: " + e.getMessage()
);
         }
+    }
+    
+    
+    /**
+     * Loads all the bootstrap schemas into the registries in preparation for
+     * loading them into the schema partition.
+     * 
+     * @throws MojoFailureException
+     */
+    private void initializeSchemas() throws MojoFailureException
+    {
+        // -------------------------------------------------------------------
+        // load the bootstrap schemas to pre-load into the partition
+        // -------------------------------------------------------------------
+
+        // always include these core bootstrap schemas
+        Set<BootstrapSchema> schemas = new HashSet<BootstrapSchema>();
+        schemas.add( new SystemSchema() );
+        schemas.add( new ApacheSchema() );
+        schemas.add( new ApachemetaSchema() );
+        schemas.add( new CoreSchema() );
         
+        getLog().info( "------------------------------------------------------" );
+        getLog().info( "Found bootstrap schemas: " );
+
+        // start loading other schemas from the plugin's configuration section
+        for ( String schemaClassName: bootstrapSchemaClasses )
+        {
+            try
+            {
+                Class schemaClass = Class.forName( schemaClassName );
+                schemas.add( ( BootstrapSchema ) schemaClass.newInstance() );
+            }
+            catch ( ClassNotFoundException e )
+            {
+                e.printStackTrace();
+                throw new MojoFailureException( "Could not find BootstrapSchema class: "
+ schemaClassName );
+            }
+            catch ( InstantiationException e )
+            {
+                e.printStackTrace();
+                throw new MojoFailureException( "Could not instantiate BootstrapSchema class:
" + schemaClassName );
+            }
+            catch ( IllegalAccessException e )
+            {
+                e.printStackTrace();
+                throw new MojoFailureException( "Could not instantiate BootstrapSchema class
due to security: "
+                    + schemaClassName );
+            }
+            
+            getLog().info( "\t" + schemaClassName );
+        }
+        getLog().info( "------------------------------------------------------" );
+        
+        BootstrapSchemaLoader loader = new BootstrapSchemaLoader();
         try
         {
-            Attributes entry = new LockableAttributesImpl();
-            entry.put( "objectClass", "top" );
-            entry.get( "objectClass" ).add( "organizationalUnit" );
-            entry.put( "ou", "schema" );
-            partition.add( new LdapDN( "ou=schema" ), entry );
-
-            addSyntaxCheckers( registries.getSyntaxCheckerRegistry(), partition );
+            loader.load( schemas, ( BootstrapRegistries ) registries );
         }
         catch ( NamingException e )
         {
             e.printStackTrace();
-            throw new MojoFailureException( "Failed to add syntaxCheckers to partition: "
+ e.getMessage() );
+            throw new MojoFailureException( "Failed to load bootstrap registries with schemas:
" + e.getMessage() );
+        }
+    }
+    
+
+    private void verifySyntaxCheckers() throws NamingException
+    {
+        LdapDN dn = new LdapDN( "ou=schema" );
+        dn.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
+        ExprNode filter = new PresenceNode( registries.getOidRegistry().getOid( "objectClass"
) );
+        SearchControls searchCtls = new SearchControls();
+        searchCtls.setSearchScope( SearchControls.SUBTREE_SCOPE );
+        
+        NamingEnumeration list = partition.search( dn, new HashMap<String, Object>(),
filter, searchCtls );
+        while ( list.hasMore() )
+        {
+            SearchResult sr = ( SearchResult ) list.next();
+            getLog().info( "Found entry " + sr.getName() );
         }
     }
 
 
-    private void addSyntaxCheckers( SyntaxCheckerRegistry syntaxCheckerRegistry, JdbmPartition
partition ) throws NamingException
+    private void addSyntaxCheckers() throws NamingException
     {
+        SyntaxCheckerRegistry syntaxCheckerRegistry = registries.getSyntaxCheckerRegistry();
         Iterator<SyntaxChecker> ii = syntaxCheckerRegistry.iterator();
         while ( ii.hasNext() )
         {
             SyntaxChecker syntaxChecker = ii.next();
             getLog().info( "Adding syntax checker with oid = " + syntaxChecker.getSyntaxOid()
);
             String schemaName = syntaxCheckerRegistry.getSchemaName( syntaxChecker.getSyntaxOid()
);
-            LdapDN dn = checkCreateSchema( schemaName, partition );
+            LdapDN dn = checkCreateSchema( schemaName );
             dn.add( "ou=syntaxCheckers" );
-            checkCreateContainer( dn, partition );
+            dn.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
+            checkCreateContainer( dn );
             Attributes entry = attributesFactory.getAttributes( syntaxChecker );
             dn.add( "m-oid=" + syntaxChecker.getSyntaxOid() );
+            dn.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
             partition.add( dn, entry );
         }
     }
     
     
-    private void checkCreateContainer( LdapDN dn, JdbmPartition partition ) throws NamingException
+    private void checkCreateContainer( LdapDN dn ) throws NamingException
     {
         if ( partition.hasEntry( dn ) )
         {
@@ -238,9 +309,11 @@
     }
     
     
-    private LdapDN checkCreateSchema( String schemaName, JdbmPartition partition ) throws
NamingException
+    private LdapDN checkCreateSchema( String schemaName ) throws NamingException
     {
         LdapDN dn = new LdapDN( "cn=" + schemaName + ",ou=schema" );
+        dn.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
+
         if ( partition.hasEntry( dn ) )
         {
             return dn;

Modified: directory/branches/trunks/schema/apacheds/core/src/main/schema/apachemeta.schema
URL: http://svn.apache.org/viewvc/directory/branches/trunks/schema/apacheds/core/src/main/schema/apachemeta.schema?view=diff&rev=486226&r1=486225&r2=486226
==============================================================================
--- directory/branches/trunks/schema/apacheds/core/src/main/schema/apachemeta.schema (original)
+++ directory/branches/trunks/schema/apacheds/core/src/main/schema/apachemeta.schema Tue Dec
12 08:46:02 2006
@@ -189,7 +189,7 @@
     MAY ( m-obsolete $ m-must $ m-may $ m-not $ m-extensionDITContentRule )
 )
 
-# --- MetaDITContentRule objectclass ------------------------------------------
+# --- metaSyntaxChecker objectclass ------------------------------------------
 objectclass ( 1.3.6.1.4.1.18060.0.4.0.3.10
     NAME 'metaSyntaxChecker'
     DESC 'Meta definition of the SyntaxChecker object'
@@ -199,7 +199,7 @@
     MAY m-bytecode
 )
 
-# --- MetaDITContentRule objectclass ------------------------------------------
+# --- metaSchema objectclass ------------------------------------------
 objectclass ( 1.3.6.1.4.1.18060.0.4.0.3.11
     NAME 'metaSchema'
     DESC 'A schema object under which meta schema definitions are found'



Mime
View raw message