You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2005/01/31 19:26:40 UTC

svn commit: r149278 - in incubator/directory/apacheds/trunk: ./ core/src/main/java/org/apache/ldap/server/schema/ core/src/main/java/org/apache/ldap/server/schema/bootstrap/ plugin/src/main/java/org/apache/ldap/server/tools/schema/ shared/src/main/java/org/apache/ldap/server/schema/bootstrap/

Author: akarasulu
Date: Mon Jan 31 10:26:31 2005
New Revision: 149278

URL: http://svn.apache.org/viewcvs?view=rev&rev=149278
Log:
changes ...

 o added support for generating object and state factories from schemas in
   plugin
 o registries devised for finding object and state factories
 o using factory.hints to trim down object factory choices
 o we are now ready to start using modello to generate domain interface, classes
   and object/state factories from a schema and a modello model

   What does all this mean ... we're one step away from having state/object
   factories for any schema used within the server.  The directory plugin
   will make the server into a easy to use object LDAP store.

   Ops like bind/rebind will store Person and InetOrgPerson etc. generating
   the appropriate attributes rather than serializing an object.  So don't
   worry just persist and lookup objects.  The directory will do the rest.

todos ...

 o still need to add the code to use the object and state factories as a service


Added:
    incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/schema/ObjectFactoryRegistry.java
    incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/schema/StateFactoryRegistry.java
    incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/schema/bootstrap/BootstrapObjectFactoryRegistry.java
    incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/schema/bootstrap/BootstrapStateFactoryRegistry.java
Modified:
    incubator/directory/apacheds/trunk/CHANGES.txt
    incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/schema/bootstrap/BootstrapRegistries.java
    incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/schema/bootstrap/BootstrapSchemaLoader.java
    incubator/directory/apacheds/trunk/plugin/src/main/java/org/apache/ldap/server/tools/schema/DirectorySchemaTool.java
    incubator/directory/apacheds/trunk/shared/src/main/java/org/apache/ldap/server/schema/bootstrap/ProducerTypeEnum.java

Modified: incubator/directory/apacheds/trunk/CHANGES.txt
URL: http://svn.apache.org/viewcvs/incubator/directory/apacheds/trunk/CHANGES.txt?view=diff&r1=149277&r2=149278
==============================================================================
--- incubator/directory/apacheds/trunk/CHANGES.txt (original)
+++ incubator/directory/apacheds/trunk/CHANGES.txt Mon Jan 31 10:26:31 2005
@@ -1,6 +1,11 @@
-Changes 0.8
-===========
+Changes since 0.8
+=================
 
  o added Preferences implementation for system settings (user Prefs not done)
  o added support for JNDI state factories and object factories
+ o added schema support for object and state factories - plugin is prep'd for
+   generating these from schema definitions and domain models: code to do this
+   just needs to be added.
+ o added factory.hints property to help drive the selection of a object
+   factory when there are multiple alternatives
 

Added: incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/schema/ObjectFactoryRegistry.java
URL: http://svn.apache.org/viewcvs/incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/schema/ObjectFactoryRegistry.java?view=auto&rev=149278
==============================================================================
--- incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/schema/ObjectFactoryRegistry.java (added)
+++ incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/schema/ObjectFactoryRegistry.java Mon Jan 31 10:26:31 2005
@@ -0,0 +1,54 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.ldap.server.schema;
+
+
+import javax.naming.NamingException;
+import javax.naming.ldap.LdapContext;
+
+import org.apache.ldap.server.jndi.ServerDirObjectFactory;
+
+
+/**
+ * A registry used for looking up JNDI object factories based on meta data
+ * regarding the objectClass and Class associations with the object factory.
+ * Unlike other registries which often throw exceptions when they cannot find
+ * an object, this one does not.  It returns null if an 'optional' object
+ * factory cannot be found.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public interface ObjectFactoryRegistry
+{
+    /**
+     * Gets the list of ObjectFactories associated with an entry.  Several object
+     * factories could be associated with an entry due to the presence of
+     * auxiliary objectClasses.
+     *
+     * @param ctx the context of the entry
+     * @return the ObjectFactories that could be used for the entry
+     */
+    ServerDirObjectFactory getObjectFactories( LdapContext ctx ) throws NamingException;
+
+    /**
+     * Registers a server-side object factory with this registry.
+     *
+     * @param factory the factory to register.
+     */
+    void register( ServerDirObjectFactory factory ) throws NamingException;
+}

Added: incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/schema/StateFactoryRegistry.java
URL: http://svn.apache.org/viewcvs/incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/schema/StateFactoryRegistry.java?view=auto&rev=149278
==============================================================================
--- incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/schema/StateFactoryRegistry.java (added)
+++ incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/schema/StateFactoryRegistry.java Mon Jan 31 10:26:31 2005
@@ -0,0 +1,56 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.ldap.server.schema;
+
+
+import javax.naming.NamingException;
+
+import org.apache.ldap.server.jndi.ServerDirStateFactory;
+
+
+/**
+ * A registry used for looking up JNDI state factories based on meta data
+ * regarding the objectClass and Class associations with the factory. Unlike
+ * other registries which often throw exceptions when they cannot find an
+ * object, this one does not.  It returns null if an 'optional' state factory
+ * cannot be found.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public interface StateFactoryRegistry
+{
+    /**
+     * Gets the list of StateFactories associated with a class.  Several state
+     * factories may be associated with a class or interface depending on its
+     * ancestry.  Also more specific factories may be registered for subclasses
+     * of the class.  So a request for a general class may result in several
+     * factories which could persist the state of an object although more
+     * specifically.
+     *
+     * @param obj the object to be persisted by the factories
+     * @return the set of state factories which persist objects of the specified class
+     */
+    ServerDirStateFactory getStateFactories( Object obj ) throws NamingException;
+
+    /**
+     * Registers a server-side state factory with this registry.
+     *
+     * @param factory the factory to register.
+     */
+    void register( ServerDirStateFactory factory );
+}

Added: incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/schema/bootstrap/BootstrapObjectFactoryRegistry.java
URL: http://svn.apache.org/viewcvs/incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/schema/bootstrap/BootstrapObjectFactoryRegistry.java?view=auto&rev=149278
==============================================================================
--- incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/schema/bootstrap/BootstrapObjectFactoryRegistry.java (added)
+++ incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/schema/bootstrap/BootstrapObjectFactoryRegistry.java Mon Jan 31 10:26:31 2005
@@ -0,0 +1,101 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.ldap.server.schema.bootstrap;
+
+
+import java.util.HashMap;
+import javax.naming.directory.Attribute;
+import javax.naming.NamingException;
+import javax.naming.ldap.LdapContext;
+
+import org.apache.ldap.server.schema.OidRegistry;
+import org.apache.ldap.server.schema.ObjectFactoryRegistry;
+import org.apache.ldap.server.jndi.ServerDirObjectFactory;
+
+
+/**
+ * A boostrap service implementation for an ObjectFactoryRegistry.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class BootstrapObjectFactoryRegistry implements ObjectFactoryRegistry
+{
+    /** Used to lookup a state factory by objectClass id */
+    private final HashMap byOid = new HashMap();
+
+    /** The oid registry used to get numeric ids */
+    private final OidRegistry oidRegistry;
+
+
+    // ------------------------------------------------------------------------
+    // C O N S T R U C T O R S
+    // ------------------------------------------------------------------------
+
+
+    /**
+     * Creates an ObjectFactoryRegistry that looks up an object factory to use.
+     *
+     * @param oidRegistry an object identifier registry
+     */
+    public BootstrapObjectFactoryRegistry( OidRegistry oidRegistry )
+    {
+        this.oidRegistry = oidRegistry;
+    }
+
+
+    public ServerDirObjectFactory getObjectFactories( LdapContext ctx ) throws NamingException
+    {
+        Attribute objectClass = ctx.getAttributes( "" ).get( "objectClass" );
+
+        if ( objectClass == null )
+        {
+            return null;
+        }
+
+        if ( ctx.getEnvironment().containsKey( "factory.hint" ) )
+        {
+            String oid = ( String ) ctx.getEnvironment().get( "factory.hint" );
+
+            String noid = oidRegistry.getOid( oid );
+
+            if ( byOid.containsKey( noid ) )
+            {
+                return ( ServerDirObjectFactory ) byOid.get( noid );
+            }
+        }
+
+        // hint did not work or was not provided so we return what we find first
+
+        for ( int ii = 0; ii < objectClass.size(); ii++ )
+        {
+            String noid = oidRegistry.getOid( ( String ) objectClass.get( ii ) );
+            if ( byOid.containsKey( noid ) )
+            {
+                return ( ServerDirObjectFactory ) byOid.get( noid );
+            }
+        }
+
+        return null;
+    }
+
+
+    public void register( ServerDirObjectFactory factory ) throws NamingException
+    {
+        byOid.put( oidRegistry.getOid( factory.getObjectClassId() ), factory );
+    }
+}

Modified: incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/schema/bootstrap/BootstrapRegistries.java
URL: http://svn.apache.org/viewcvs/incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/schema/bootstrap/BootstrapRegistries.java?view=diff&r1=149277&r2=149278
==============================================================================
--- incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/schema/bootstrap/BootstrapRegistries.java (original)
+++ incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/schema/bootstrap/BootstrapRegistries.java Mon Jan 31 10:26:31 2005
@@ -30,7 +30,7 @@
 
 
 /**
- * Document me.
+ * A set of boostrap registries used to fire up the server.
  *
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  * @version $Rev$
@@ -49,6 +49,8 @@
     private BootstrapOidRegistry oidRegistry;
     private BootstrapSyntaxCheckerRegistry syntaxCheckerRegistry;
     private BootstrapSyntaxRegistry syntaxRegistry;
+    private BootstrapObjectFactoryRegistry objectFactoryRegistry;
+    private BootstrapStateFactoryRegistry stateFactoryRegistry;
 
 
     public BootstrapRegistries()
@@ -65,6 +67,8 @@
         ditStructureRuleRegistry = new BootstrapDitStructureRuleRegistry( getOidRegistry() );
         matchingRuleUseRegistry = new BootstrapMatchingRuleUseRegistry();
         nameFormRegistry = new BootstrapNameFormRegistry( getOidRegistry() );
+        objectFactoryRegistry = new BootstrapObjectFactoryRegistry( getOidRegistry() );
+        stateFactoryRegistry = new BootstrapStateFactoryRegistry();
     }
 
 
@@ -128,6 +132,16 @@
         return syntaxRegistry;
     }
 
+    public ObjectFactoryRegistry getObjectFactoryRegistry()
+    {
+        return objectFactoryRegistry;
+    }
+
+    public StateFactoryRegistry getStateFactoryRegistry()
+    {
+        return stateFactoryRegistry;
+    }
+
 
     // ------------------------------------------------------------------------
     // Code used to sanity check the resolution of entities in registries
@@ -273,6 +287,7 @@
     private boolean resolve( AttributeType at, List errors )
     {
         boolean isSuccess = true;
+
         boolean hasMatchingRule = false;
 
         if ( at == null )
@@ -287,6 +302,7 @@
         catch ( NamingException e )
         {
             errors.add( e );
+
             isSuccess = false;
         }
 
@@ -302,6 +318,7 @@
         catch ( NamingException e )
         {
             errors.add( e );
+
             isSuccess = false;
         }
 
@@ -317,6 +334,7 @@
         catch ( NamingException e )
         {
             errors.add( e );
+
             isSuccess = false;
         }
 
@@ -332,6 +350,7 @@
         catch ( NamingException e )
         {
             errors.add( e );
+
             isSuccess = false;
         }
 
@@ -342,15 +361,18 @@
             if ( at.getSyntax() == null )
             {
                 String schema = attributeTypeRegistry.getSchemaName( at.getOid() );
+
                 errors.add( new NullPointerException( "attributeType "
                         + at.getName() + " in schema " + schema + " with OID "
                         + at.getOid() + " has a null Syntax" ) );
+
                 isSuccess = false;
             }
         }
         catch ( NamingException e )
         {
             errors.add( e );
+
             isSuccess = false;
         }
 
@@ -386,6 +408,7 @@
         }
 
         ObjectClass[] superiors = new org.apache.ldap.common.schema.ObjectClass[0];
+
         try
         {
             superiors = oc.getSuperClasses();
@@ -403,6 +426,7 @@
         }
 
         AttributeType[] mayList = new org.apache.ldap.common.schema.AttributeType[0];
+
         try
         {
             mayList = oc.getMayList();
@@ -421,6 +445,7 @@
 
 
         AttributeType[] mustList = new org.apache.ldap.common.schema.AttributeType[0];
+
         try
         {
             mustList = oc.getMustList();

Modified: incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/schema/bootstrap/BootstrapSchemaLoader.java
URL: http://svn.apache.org/viewcvs/incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/schema/bootstrap/BootstrapSchemaLoader.java?view=diff&r1=149277&r2=149278
==============================================================================
--- incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/schema/bootstrap/BootstrapSchemaLoader.java (original)
+++ incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/schema/bootstrap/BootstrapSchemaLoader.java Mon Jan 31 10:26:31 2005
@@ -22,6 +22,8 @@
 
 import org.apache.ldap.common.schema.*;
 import org.apache.ldap.server.schema.*;
+import org.apache.ldap.server.jndi.ServerDirStateFactory;
+import org.apache.ldap.server.jndi.ServerDirObjectFactory;
 
 
 /**
@@ -279,6 +281,18 @@
                 DITStructureRuleRegistry ditStructureRuleRegistry;
                 ditStructureRuleRegistry = registries.getDitStructureRuleRegistry();
                 ditStructureRuleRegistry.register( schema.getSchemaName(), ditStructureRule );
+                break;
+            case( ProducerTypeEnum.STATE_FACTORY_PRODUCER_VAL ):
+                ServerDirStateFactory stateFactory = ( ServerDirStateFactory ) schemaObject;
+                StateFactoryRegistry stateFactoryRegistry;
+                stateFactoryRegistry = registries.getStateFactoryRegistry();
+                stateFactoryRegistry.register( stateFactory );
+                break;
+            case( ProducerTypeEnum.OBJECT_FACTORY_PRODUCER_VAL ):
+                ServerDirObjectFactory objectFactory = ( ServerDirObjectFactory ) schemaObject;
+                ObjectFactoryRegistry objectFactoryRegistry;
+                objectFactoryRegistry = registries.getObjectFactoryRegistry();
+                objectFactoryRegistry.register( objectFactory );
                 break;
             default:
                 throw new IllegalStateException( "ProducerTypeEnum is broke!" );

Added: incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/schema/bootstrap/BootstrapStateFactoryRegistry.java
URL: http://svn.apache.org/viewcvs/incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/schema/bootstrap/BootstrapStateFactoryRegistry.java?view=auto&rev=149278
==============================================================================
--- incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/schema/bootstrap/BootstrapStateFactoryRegistry.java (added)
+++ incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/schema/bootstrap/BootstrapStateFactoryRegistry.java Mon Jan 31 10:26:31 2005
@@ -0,0 +1,79 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.ldap.server.schema.bootstrap;
+
+
+import java.util.HashMap;
+
+import javax.naming.NamingException;
+
+import org.apache.ldap.server.schema.StateFactoryRegistry;
+import org.apache.ldap.server.jndi.ServerDirStateFactory;
+
+
+/**
+ * A bootstrap service implementation for a state factory registry.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class BootstrapStateFactoryRegistry implements StateFactoryRegistry
+{
+    /** Used to lookup a state factory by class */
+    private final HashMap byClass = new HashMap();
+
+
+    public ServerDirStateFactory getStateFactories( Object obj ) throws NamingException
+    {
+        Class c = obj.getClass();
+
+        // if the class is mapped to a factory then this is most specific
+
+        if ( byClass.containsKey( c ) )
+        {
+            return ( ServerDirStateFactory ) byClass.get( c );
+        }
+
+        while ( ( c = c.getSuperclass() ) != null )
+        {
+            if ( byClass.containsKey( c ) )
+            {
+                return ( ServerDirStateFactory ) byClass.get( c );
+            }
+        }
+
+        // if we get this far start searching interfaces for a factory
+
+        Class[] interfaces = c.getInterfaces();
+
+        for ( int ii = 0; ii < interfaces.length; ii++ )
+        {
+            if ( byClass.containsKey( interfaces[ii] ) )
+            {
+                return ( ServerDirStateFactory ) byClass.get( interfaces[ii] );
+            }
+        }
+
+        return null;
+    }
+
+
+    public void register( ServerDirStateFactory factory )
+    {
+        byClass.put( factory.getAssociatedClass(), factory );
+    }
+}

Modified: incubator/directory/apacheds/trunk/plugin/src/main/java/org/apache/ldap/server/tools/schema/DirectorySchemaTool.java
URL: http://svn.apache.org/viewcvs/incubator/directory/apacheds/trunk/plugin/src/main/java/org/apache/ldap/server/tools/schema/DirectorySchemaTool.java?view=diff&r1=149277&r2=149278
==============================================================================
--- incubator/directory/apacheds/trunk/plugin/src/main/java/org/apache/ldap/server/tools/schema/DirectorySchemaTool.java (original)
+++ incubator/directory/apacheds/trunk/plugin/src/main/java/org/apache/ldap/server/tools/schema/DirectorySchemaTool.java Mon Jan 31 10:26:31 2005
@@ -26,8 +26,6 @@
 
 import org.apache.ldap.server.schema.bootstrap.BootstrapSchema;
 import org.apache.ldap.server.schema.bootstrap.ProducerTypeEnum;
-import org.apache.ldap.server.schema.bootstrap.ProducerTypeEnum;
-import org.apache.ldap.server.tools.schema.AttributeTypeLiteral;
 
 
 /**
@@ -41,22 +39,24 @@
     private static String basedir = System.getProperty( "basedir", "." );
 
     /** property for dir where OpenLDAP schema files and deps file are stored */
-    public static final String SCHEMA_SRC_DIR_PROP =
-            "maven.ldap.server.schema.src.dir";
+    public static final String SCHEMA_SRC_DIR_PROP = "maven.ldap.server.schema.src.dir";
+
     /** property for dir where the generated class files are created */
-    public static final String SCHEMA_TARGET_DIR_PROP =
-            "maven.ldap.server.schema.target.dir";
+    public static final String SCHEMA_TARGET_DIR_PROP = "maven.ldap.server.schema.target.dir";
 
     /** default dir where OpenLDAP schema files and deps file are kept */
     public static final String SCHEMA_SRC_DIR_DEFAULT =
             basedir + File.separator + "src" + File.separator + "main" 
 		+ File.separator + "schema";
+
     /** default dir where java src files are kept */
     public static final String JAVA_SRC_DIR_DEFAULT =
             basedir + File.separator + "src" + File.separator + "main" 
 		+ File.separator + "java";
+
    /** property for the name of the schema dependency file */
     public static final String SCHEMA_DEP_FILE_DEFAULT = "schema.deps";
+
     /** default dir where the generated class files are created */
     public static final String SCHEMA_TARGET_DIR_DEFAULT =
             basedir + File.separator + "target" + File.separator + "schema";
@@ -64,12 +64,14 @@
 
     /** the source directory where the schema OpenLDAP source files are kept */
     private String schemaSrcDir = SCHEMA_SRC_DIR_DEFAULT;
+
     /** the directory where we generate schema class files */
     private String schemaTargetDir = SCHEMA_TARGET_DIR_DEFAULT;
-    private String javaSrcDir = JAVA_SRC_DIR_DEFAULT;
 
+    private String javaSrcDir = JAVA_SRC_DIR_DEFAULT;
 
     private BootstrapSchema schema;
+
     private OpenLdapSchemaParser parser;
 
 
@@ -77,6 +79,7 @@
     public DirectorySchemaTool() throws Exception
     {
         parser = new OpenLdapSchemaParser();
+
         Velocity.init();
     }
 
@@ -136,36 +139,50 @@
             throw new NullPointerException( "the schema property must be set" );
         }
 
+        String filePath = schemaSrcDir + File.separator + schema.getSchemaName() + ".schema";
+
+        InputStream in = new FileInputStream( filePath );
 
-        InputStream in = new FileInputStream( schemaSrcDir + File.separator
-                + schema.getSchemaName() + ".schema" );
         parser.parse( in );
 
         generateSchema();
+
         generateAttributeTypes();
+
         generateObjectClasses();
+
         generateRest();
     }
 
 
     protected void generateSchema() throws Exception
     {
-        String schemaCapped =
-            Character.toUpperCase( schema.getSchemaName().charAt( 0 ) )
-            + schema.getSchemaName().substring( 1, schema.getSchemaName().length() );
+        StringBuffer schemaCapped = new StringBuffer();
+
+        schemaCapped.append( Character.toUpperCase( schema.getSchemaName().charAt( 0 ) ) );
+
+        schemaCapped.append( schema.getSchemaName().substring( 1, schema.getSchemaName().length() ) );
 
         VelocityContext context = new VelocityContext();
 
         context.put( "package", schema.getPackageName() );
-        context.put( "classname", schemaCapped + "Schema" );
+
+        context.put( "classname", schemaCapped.toString() + "Schema" );
+
         context.put( "schema", schema.getSchemaName() );
+
         context.put( "owner", schema.getOwner() ) ;
+
         context.put( "deps", schema.getDependencies()  ) ;
 
         Reader fileIn = getResourceReader( "Schema.template" );
+
         Writer writer = getResourceWriter( schema.getUnqualifiedClassName() );
+
         Velocity.evaluate( context, writer, "LOG", fileIn );
+
         writer.flush();
+
         writer.close();
     }
 
@@ -173,9 +190,13 @@
     protected void generateRest() throws Exception
     {
         List types = new ArrayList();
+
         types.addAll( ProducerTypeEnum.list() );
+
         types.remove( ProducerTypeEnum.ATTRIBUTE_TYPE_PRODUCER );
+
         types.remove( ProducerTypeEnum.OBJECT_CLASS_PRODUCER );
+
         ProducerTypeEnum type = null;
 
         for ( int ii = 0; ii < types.size(); ii++ )
@@ -189,52 +210,97 @@
 
 
             VelocityContext context = new VelocityContext();
+
             context.put( "package", schema.getPackageName() );
+
             context.put( "classname", schema.getUnqualifiedClassName( type ) );
+
             context.put( "schema", schema.getSchemaName() );
+
             context.put( "owner", schema.getOwner() ) ;
-            context.put( "type", type.getName().substring( 0,
-                    type.getName().length() - 8 ) ) ;
+
+            context.put( "type", type.getName().substring( 0, type.getName().length() - 8 ) ) ;
 
             String typeName = null;
+
             switch( type.getValue() )
             {
                 case( ProducerTypeEnum.COMPARATOR_PRODUCER_VAL ):
+
                     typeName = "ProducerTypeEnum.COMPARATOR_PRODUCER";
+
                     break;
+
                 case( ProducerTypeEnum.DIT_CONTENT_RULE_PRODUCER_VAL ):
+
                     typeName = "ProducerTypeEnum.DIT_CONTENT_RULE_PRODUCER";
+
                     break;
+
                 case( ProducerTypeEnum.DIT_STRUCTURE_RULE_PRODUCER_VAL ):
+
                     typeName = "ProducerTypeEnum.DIT_STRUCTURE_RULE_PRODUCER";
+
                     break;
+
                 case( ProducerTypeEnum.MATCHING_RULE_PRODUCER_VAL ):
+
                     typeName = "ProducerTypeEnum.MATCHING_RULE_PRODUCER";
+
                     break;
+
                 case( ProducerTypeEnum.MATCHING_RULE_USE_PRODUCER_VAL ):
+
                     typeName = "ProducerTypeEnum.MATCHING_RULE_USE_PRODUCER";
+
                     break;
+
                 case( ProducerTypeEnum.NAME_FORM_PRODUCER_VAL ):
+
                     typeName = "ProducerTypeEnum.NAME_FORM_PRODUCER";
+
                     break;
+
                 case( ProducerTypeEnum.NORMALIZER_PRODUCER_VAL ):
+
                     typeName = "ProducerTypeEnum.NORMALIZER_PRODUCER";
+
                     break;
+
                 case( ProducerTypeEnum.SYNTAX_CHECKER_PRODUCER_VAL ):
+
                     typeName = "ProducerTypeEnum.SYNTAX_CHECKER_PRODUCER";
+
                     break;
+
                 case( ProducerTypeEnum.SYNTAX_PRODUCER_VAL ):
+
                     typeName = "ProducerTypeEnum.SYNTAX_PRODUCER";
+
+                    break;
+
+                case( ProducerTypeEnum.STATE_FACTORY_PRODUCER_VAL ):
+
+                    typeName = "ProducerTypeEnum.STATE_FACTORY_PRODUCER";
+
+                    break;
+
+                case( ProducerTypeEnum.OBJECT_FACTORY_PRODUCER_VAL ):
+
+                    typeName = "ProducerTypeEnum.OBJECT_FACTORY_PRODUCER";
+
                     break;
+
                 default:
-                    throw new IllegalStateException( "Unexpected producer: "
-                        + type.getName() );
+
+                    throw new IllegalStateException( "Unexpected producer: " + type.getName() );
+
             }
 
             context.put( "typeName", typeName ) ;
+
             runVelocity( context, "typeless.template", type );
         }
-
     }
 
 
@@ -249,18 +315,25 @@
         }
 
         int size = parser.getAttributeTypes().size();
+
         AttributeTypeLiteral[] attributeTypes = new AttributeTypeLiteral[size];
-        attributeTypes = ( AttributeTypeLiteral[] )
-            parser.getAttributeTypes().values().toArray( attributeTypes );
+
+        attributeTypes = ( AttributeTypeLiteral[] ) parser.getAttributeTypes().values().toArray( attributeTypes );
 
         VelocityContext context = new VelocityContext();
+
         context.put( "package", schema.getPackageName() );
-        context.put( "classname",
-            schema.getUnqualifiedClassName( type ) );
+
+        context.put( "classname", schema.getUnqualifiedClassName( type ) );
+
         context.put( "schema", schema.getSchemaName() );
+
         context.put( "owner", schema.getOwner() ) ;
+
         context.put( "schemaDepCount", new Integer( schema.getDependencies().length ) );
+
         context.put( "schemaDeps", new String[] { "dep1", "dep2" }  ) ;
+
         context.put( "attrTypes", attributeTypes );
 
         runVelocity( context, "AttributeTypes.template", type );
@@ -278,31 +351,43 @@
         }
 
         int size = parser.getObjectClassTypes().size();
+
         ObjectClassLiteral[] objectClasses = new ObjectClassLiteral[size];
-        objectClasses = ( ObjectClassLiteral[] )
-            parser.getObjectClassTypes().values().toArray( objectClasses );
+
+        objectClasses = ( ObjectClassLiteral[] ) parser.getObjectClassTypes().values().toArray( objectClasses );
 
         VelocityContext context = new VelocityContext();
+
         context.put( "package", schema.getPackageName() );
+
         context.put( "classname", schema.getUnqualifiedClassName( type ) );
+
         context.put( "schema", schema.getSchemaName() );
+
         context.put( "owner", schema.getOwner() ) ;
+
         context.put( "schemaDepCount", new Integer( schema.getDependencies().length ) );
+
         context.put( "schemaDeps", new String[] { "dep1", "dep2" }  ) ;
+
         context.put( "objectClasses", objectClasses );
 
         runVelocity( context, "ObjectClasses.template", type );
     }
 
 
-    protected void runVelocity( VelocityContext context, String template,
-                                ProducerTypeEnum type )
+
+    protected void runVelocity( VelocityContext context, String template, ProducerTypeEnum type )
             throws Exception
     {
         Reader fileIn = getResourceReader( template );
+
         Writer writer = getResourceWriter( schema.getUnqualifiedClassName( type ) );
+
         Velocity.evaluate( context, writer, "LOG", fileIn );
+
         writer.flush();
+
         writer.close();
     }
 
@@ -316,6 +401,7 @@
     protected boolean mkdirs( String base, String path )
     {
         String[] comps = path.split( "/" );
+
         File file = new File( base );
 
         if ( ! file.exists() )
@@ -326,6 +412,7 @@
         for ( int ii = 0; ii < comps.length; ii++ )
         {
             file = new File( file, comps[ii] );
+
             if ( ! file.exists() )
             {
                 file.mkdirs();
@@ -339,22 +426,27 @@
     protected FileWriter getResourceWriter( String classname ) throws IOException
     {
         String pkg = schema.getPackageName();
+
         mkdirs( schemaTargetDir, pkg.replace( '.', File.separatorChar ) );
+
         File base = new File( schemaTargetDir );
+
         String relativePath = pkg.replace( '.', File.separatorChar );
+
         File dir = new File( base, relativePath );
+
         return new FileWriter( new File( dir, classname + ".java" ) );
     }
 
 
+
     protected boolean exists( ProducerTypeEnum type )
     {
         String defaultClass = schema.getFullDefaultBaseClassName( type );
 
         // check to see if any of the classes are available in the java 
         // source directory, if so we return true
-        File defaultFile = new File( getJavaSrcDir()
-                + File.separator + getFilePath( defaultClass ) );
+        File defaultFile = new File( getJavaSrcDir() + File.separator + getFilePath( defaultClass ) );
           
         return defaultFile.exists();
     }
@@ -363,7 +455,9 @@
     private String getFilePath( String fqcn )
     {
         String path = fqcn.replace( '.', File.separatorChar );
+
         path += ".java";
+
         return path;
     }
 }

Modified: incubator/directory/apacheds/trunk/shared/src/main/java/org/apache/ldap/server/schema/bootstrap/ProducerTypeEnum.java
URL: http://svn.apache.org/viewcvs/incubator/directory/apacheds/trunk/shared/src/main/java/org/apache/ldap/server/schema/bootstrap/ProducerTypeEnum.java?view=diff&r1=149277&r2=149278
==============================================================================
--- incubator/directory/apacheds/trunk/shared/src/main/java/org/apache/ldap/server/schema/bootstrap/ProducerTypeEnum.java (original)
+++ incubator/directory/apacheds/trunk/shared/src/main/java/org/apache/ldap/server/schema/bootstrap/ProducerTypeEnum.java Mon Jan 31 10:26:31 2005
@@ -50,7 +50,8 @@
         "NormalizerProducer", "ComparatorProducer", "SyntaxCheckerProducer",
         "SyntaxProducer", "MatchingRuleProducer", "AttributeTypeProducer",
         "ObjectClassProducer", "MatchingRuleUseProducer", "DitContentRuleProducer",
-        "NameFormProducer", "DitStructureRuleProducer"
+        "NameFormProducer", "DitStructureRuleProducer",
+        "StateFactoryProducer", "ObjectFactoryProducer"
     };
 
     /** value for Normalizer BootstrapProducers */
@@ -75,6 +76,10 @@
     public static final int NAME_FORM_PRODUCER_VAL = 9;
     /** value for DitStructureRule BootstrapProducers */
     public static final int DIT_STRUCTURE_RULE_PRODUCER_VAL = 10;
+    /** value for StateFactory BootstrapProducers */
+    public static final int STATE_FACTORY_PRODUCER_VAL = 11;
+    /** value for ObjectFactory BootstrapProducers */
+    public static final int OBJECT_FACTORY_PRODUCER_VAL = 12;
 
 
     /** enum for BootstrapProducers of Normalizer schema objects */
@@ -110,6 +115,12 @@
     /** enum for BootstrapProducers of DitStructureRule schema objects */
     public static final ProducerTypeEnum DIT_STRUCTURE_RULE_PRODUCER =
         new ProducerTypeEnum( producers[10], DIT_STRUCTURE_RULE_PRODUCER_VAL );
+    /** enum for BootstrapProducers of StateFactory schema objects */
+    public static final ProducerTypeEnum STATE_FACTORY_PRODUCER =
+        new ProducerTypeEnum( producers[11], STATE_FACTORY_PRODUCER_VAL );
+    /** enum for BootstrapProducers of ObjectFactory schema objects */
+    public static final ProducerTypeEnum OBJECT_FACTORY_PRODUCER =
+        new ProducerTypeEnum( producers[12], OBJECT_FACTORY_PRODUCER_VAL );
 
 
     /**
@@ -177,6 +188,14 @@
         if ( producerType.equalsIgnoreCase( ProducerTypeEnum.DIT_STRUCTURE_RULE_PRODUCER.getName() ) )
         {
             return ProducerTypeEnum.DIT_STRUCTURE_RULE_PRODUCER;
+        }
+        if ( producerType.equalsIgnoreCase( ProducerTypeEnum.STATE_FACTORY_PRODUCER.getName() ) )
+        {
+            return ProducerTypeEnum.STATE_FACTORY_PRODUCER;
+        }
+        if ( producerType.equalsIgnoreCase( ProducerTypeEnum.OBJECT_FACTORY_PRODUCER.getName() ) )
+        {
+            return ProducerTypeEnum.OBJECT_FACTORY_PRODUCER;
         }
 
         throw new IllegalArgumentException( "Unknown ProducerTypeEnum string"