directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 55940 - in incubator/directory/eve/trunk/backend/core/src: java/org/apache/eve/jndi test/org/apache/eve/jndi
Date Fri, 29 Oct 2004 04:15:59 GMT
Author: akarasulu
Date: Thu Oct 28 21:15:59 2004
New Revision: 55940

Modified:
   incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/jndi/EveContextFactory.java
   incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/AbstractJndiTest.java
   incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/EveContextFactoryTest.java
Log:
added code to use env properties to enable multiple app partitions

Modified: incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/jndi/EveContextFactory.java
==============================================================================
--- incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/jndi/EveContextFactory.java
(original)
+++ incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/jndi/EveContextFactory.java
Thu Oct 28 21:15:59 2004
@@ -3,17 +3,22 @@
 
 import java.util.Hashtable;
 import java.util.List;
+import java.util.ArrayList;
 import java.io.File;
 
 import javax.naming.Context;
 import javax.naming.NamingException;
+import javax.naming.Name;
+import javax.naming.directory.Attributes;
 import javax.naming.spi.InitialContextFactory;
 
 import org.apache.ldap.common.name.LdapName;
 import org.apache.ldap.common.schema.AttributeType;
+import org.apache.ldap.common.schema.Normalizer;
 
 import org.apache.eve.RootNexus;
 import org.apache.eve.SystemPartition;
+import org.apache.eve.ApplicationPartition;
 import org.apache.eve.jndi.ibs.*;
 import org.apache.eve.db.*;
 import org.apache.eve.db.jdbm.JdbmDatabase;
@@ -22,6 +27,7 @@
 import org.apache.eve.schema.AttributeTypeRegistry;
 import org.apache.eve.schema.OidRegistry;
 import org.apache.eve.schema.GlobalRegistries;
+import org.apache.eve.schema.MatchingRuleRegistry;
 
 
 /**
@@ -49,6 +55,11 @@
     public static final String DEFAULT_WKDIR = "eve";
     /** a comma separated list of schema class files to load */
     public static final String SCHEMAS_ENV = "eve.schemas";
+
+    // ------------------------------------------------------------------------
+    //
+    // ------------------------------------------------------------------------
+
     /** default schema classes for the SCHEMAS_ENV property if not set */
     private static final String[] DEFAULT_SCHEMAS = new String[]
     {
@@ -64,12 +75,34 @@
         "org.apache.eve.schema.bootstrap.SystemSchema"
     };
 
+    // ------------------------------------------------------------------------
+    // Custom JNDI properties for adding new application partitions
+    // ------------------------------------------------------------------------
+
+    /** a comma separated list of partition names */
+    public static final String PARTITIONS_ENV = "eve.db.partitions";
+    /** the envprop key base to the suffix of a partition */
+    public static final String SUFFIX_BASE_ENV = "eve.db.partition.suffix.";
+    /** the envprop key base to the space separated list of indices for a partition */
+    public static final String INDICES_BASE_ENV = "eve.db.partition.indices.";
+    /** the envprop key base to the Attributes for the context root entry */
+    public static final String ATTRIBUTES_BASE_ENV = "eve.db.partition.attributes.";
+
+    // ------------------------------------------------------------------------
+    // Members
+    // ------------------------------------------------------------------------
+
     /** The singleton EveJndiProvider instance */
     private EveJndiProvider provider = null;
     /** the initial context environment that fired up the backend subsystem */
     private Hashtable initialEnv;
 
 
+    private SystemPartition system;
+    private GlobalRegistries globalRegistries;
+    private RootNexus root;
+
+
     /**
      * Default constructor that sets the provider of this EveContextFactory.
      */
@@ -199,9 +232,9 @@
             attributeTypeRegistry.lookup( SystemPartition.UPDN_OID )
         };
 
-        SystemPartition system = new SystemPartition( db, eng, attributes );
-        GlobalRegistries globalRegistries = new GlobalRegistries( system, bootstrapRegistries
);
-        RootNexus root = new RootNexus( system );
+        system = new SystemPartition( db, eng, attributes );
+        globalRegistries = new GlobalRegistries( system, bootstrapRegistries );
+        root = new RootNexus( system );
         provider = new EveJndiProvider( root );
 
 
@@ -255,6 +288,99 @@
                 filterService );
         provider.addInterceptor( interceptor, state );
 
+        if ( initialEnv.get( PARTITIONS_ENV ) != null )
+        {
+            initAppPartitions( wkdir );
+        }
+    }
+
+
+    private void initAppPartitions( String eveWkdir ) throws NamingException
+    {
+        OidRegistry oidRegistry = globalRegistries.getOidRegistry();
+        AttributeTypeRegistry attributeTypeRegistry;
+        attributeTypeRegistry = globalRegistries.getAttributeTypeRegistry();
+        MatchingRuleRegistry reg = globalRegistries.getMatchingRuleRegistry();
+
+        // start getting all the parameters from the initial environment
+        String[] names = ( ( String ) initialEnv.get( PARTITIONS_ENV ) ).split( " " );
+
+        for ( int ii = 0; ii < names.length; ii++ )
+        {
+            // ----------------------------------------------------------------
+            // create working directory under eve directory for app partition
+            // ----------------------------------------------------------------
+
+            String suffix = ( String ) initialEnv.get( SUFFIX_BASE_ENV + names[ii] );
+            String wkdir = eveWkdir + File.separator + names[ii];
+            mkdirs( eveWkdir, names[ii] );
+
+
+            // ----------------------------------------------------------------
+            // create the database/store
+            // ----------------------------------------------------------------
+
+            Name upSuffix = new LdapName( suffix );
+            Normalizer dnNorm = reg.lookup( "distinguishedNameMatch" ).getNormalizer();
+            Name normSuffix = new LdapName( ( String ) dnNorm.normalize( suffix ) );
+            Database db = new JdbmDatabase( upSuffix, wkdir );
+
+            // ----------------------------------------------------------------
+            // create the search engine using db, enumerators and evaluators
+            // ----------------------------------------------------------------
+
+            ExpressionEvaluator evaluator;
+            evaluator = new ExpressionEvaluator( db, oidRegistry, attributeTypeRegistry );
+            ExpressionEnumerator enumerator;
+            enumerator = new ExpressionEnumerator( db, evaluator );
+            SearchEngine eng = new DefaultSearchEngine( db, evaluator, enumerator );
+
+            // ----------------------------------------------------------------
+            // fill up a list with the AttributeTypes for the system indices
+            // ----------------------------------------------------------------
+
+            ArrayList attributeTypeList = new ArrayList();
+            attributeTypeList.add( attributeTypeRegistry.lookup( SystemPartition.ALIAS_OID
) );
+            attributeTypeList.add( attributeTypeRegistry.lookup( SystemPartition.EXISTANCE_OID
) );
+            attributeTypeList.add( attributeTypeRegistry.lookup( SystemPartition.HIERARCHY_OID
) );
+            attributeTypeList.add( attributeTypeRegistry.lookup( SystemPartition.NDN_OID
) );
+            attributeTypeList.add( attributeTypeRegistry.lookup( SystemPartition.ONEALIAS_OID
) );
+            attributeTypeList.add( attributeTypeRegistry.lookup( SystemPartition.SUBALIAS_OID
) );
+            attributeTypeList.add( attributeTypeRegistry.lookup( SystemPartition.UPDN_OID
) );
+
+            // ----------------------------------------------------------------
+            // if user indices are specified add those attribute types as well
+            // ----------------------------------------------------------------
+
+            if ( initialEnv.containsKey( INDICES_BASE_ENV + names[ii] ) )
+            {
+                String[] indices = ( ( String ) initialEnv.get( INDICES_BASE_ENV
+                        + names[ii] ) ).split( " " );
+
+                for ( int jj = 0; jj < indices.length; jj++ )
+                {
+                    attributeTypeList.add( attributeTypeRegistry.lookup( indices[jj] ) );
+                }
+            }
+
+            // ----------------------------------------------------------------
+            // fire up the appPartition & register it with the next
+            // ----------------------------------------------------------------
+
+            AttributeType[] indexTypes = ( AttributeType[] ) attributeTypeList
+                    .toArray( new AttributeType[attributeTypeList.size()] );
+            ApplicationPartition partition = new ApplicationPartition( upSuffix,
+                    normSuffix, db, eng, indexTypes );
+            root.register( partition );
+
+            // ----------------------------------------------------------------
+            // add the root context entry
+            // ----------------------------------------------------------------
+
+            Attributes rootEntry = ( Attributes ) initialEnv.get(
+                    ATTRIBUTES_BASE_ENV + names[ii] );
+            partition.add( suffix, normSuffix, rootEntry );
+        }
     }
 
 

Modified: incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/AbstractJndiTest.java
==============================================================================
--- incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/AbstractJndiTest.java
(original)
+++ incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/AbstractJndiTest.java
Thu Oct 28 21:15:59 2004
@@ -41,6 +41,9 @@
     /** flag whether to delete database files for each test or not */
     protected boolean doDelete = true;
 
+    /** extra environment parameters that can be added before setUp */
+    protected Hashtable extras = new Hashtable();
+
 
     /**
      * Get's the initial context factory for the provider's ou=system context
@@ -63,6 +66,7 @@
         }
 
         Hashtable env = new Hashtable();
+        env.putAll( extras );
         env.put( Context.PROVIDER_URL, "ou=system" );
         env.put( Context.INITIAL_CONTEXT_FACTORY, "org.apache.eve.jndi.EveContextFactory"
);
         env.put( EveContextFactory.WKDIR_ENV, "target/eve" );

Modified: incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/EveContextFactoryTest.java
==============================================================================
--- incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/EveContextFactoryTest.java
(original)
+++ incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/EveContextFactoryTest.java
Thu Oct 28 21:15:59 2004
@@ -17,12 +17,12 @@
 package org.apache.eve.jndi;
 
 
-import java.util.HashMap;
+import java.util.Hashtable;
+
 import javax.naming.directory.*;
+import javax.naming.Context;
 import javax.naming.NamingException;
-import javax.naming.NamingEnumeration;
-
-import org.apache.ldap.common.message.DerefAliasesEnum;
+import javax.naming.InitialContext;
 
 
 /**
@@ -33,6 +33,39 @@
  */
 public class EveContextFactoryTest extends AbstractJndiTest
 {
+    public EveContextFactoryTest()
+    {
+        BasicAttributes attrs = new BasicAttributes( true );
+        BasicAttribute attr = new BasicAttribute( "objectClass" );
+        attr.add( "top" );
+        attr.add( "organizationalUnit" );
+        attr.add( "extensibleObject" );
+        attrs.put( attr );
+        attr = new BasicAttribute( "ou" );
+        attr.add( "testing" );
+        attrs.put( attr );
+
+        extras.put( EveContextFactory.PARTITIONS_ENV, "testing example" );
+        extras.put( EveContextFactory.SUFFIX_BASE_ENV + "testing", "ou=testing" );
+        extras.put( EveContextFactory.INDICES_BASE_ENV + "testing", "ou objectClass" );
+        extras.put( EveContextFactory.ATTRIBUTES_BASE_ENV + "testing", attrs );
+
+        attrs = new BasicAttributes( true );
+        attr = new BasicAttribute( "objectClass" );
+        attr.add( "top" );
+        attr.add( "domain" );
+        attr.add( "extensibleObject" );
+        attrs.put( attr );
+        attr = new BasicAttribute( "dc" );
+        attr.add( "example" );
+        attrs.put( attr );
+
+        extras.put( EveContextFactory.SUFFIX_BASE_ENV + "example", "dc=example" );
+        extras.put( EveContextFactory.INDICES_BASE_ENV + "example", "ou dc objectClass" );
+        extras.put( EveContextFactory.ATTRIBUTES_BASE_ENV + "example", attrs );
+    }
+
+
     /**
      * Makes sure the system context has the right attributes and values.
      *
@@ -52,6 +85,11 @@
     }
 
 
+    /**
+     * Tests to make sure tearDown is working correctly.
+     *
+     * @throws NamingException if there are failures
+     */
     public void testSetupTeardown() throws NamingException
     {
         assertNotNull( sysRoot );
@@ -59,6 +97,44 @@
         Attributes attributes = sysRoot.getAttributes( "" );
         assertNotNull( attributes );
         assertEquals( "system", attributes.get( "ou" ).get() );
+        Attribute attribute = attributes.get( "objectClass" );
+        assertNotNull( attribute );
+        assertTrue( attribute.contains( "top" ) );
+        assertTrue( attribute.contains( "organizationalUnit" ) );
+    }
+
+
+    public void testAppPartitionExample() throws NamingException
+    {
+        Hashtable env = new Hashtable();
+        env.put( Context.PROVIDER_URL, "dc=example" );
+        env.put( Context.INITIAL_CONTEXT_FACTORY, "org.apache.eve.jndi.EveContextFactory"
);
+        InitialContext initialContext = new InitialContext( env );
+        DirContext appRoot = ( DirContext ) initialContext.lookup( "" );
+        assertNotNull( appRoot );
+
+        Attributes attributes = appRoot.getAttributes( "" );
+        assertNotNull( attributes );
+        assertEquals( "example", attributes.get( "dc" ).get() );
+        Attribute attribute = attributes.get( "objectClass" );
+        assertNotNull( attribute );
+        assertTrue( attribute.contains( "top" ) );
+        assertTrue( attribute.contains( "domain" ) );
+    }
+
+
+    public void testAppPartitionTesting() throws NamingException
+    {
+        Hashtable env = new Hashtable();
+        env.put( Context.PROVIDER_URL, "ou=testing" );
+        env.put( Context.INITIAL_CONTEXT_FACTORY, "org.apache.eve.jndi.EveContextFactory"
);
+        InitialContext initialContext = new InitialContext( env );
+        DirContext appRoot = ( DirContext ) initialContext.lookup( "" );
+        assertNotNull( appRoot );
+
+        Attributes attributes = appRoot.getAttributes( "" );
+        assertNotNull( attributes );
+        assertEquals( "testing", attributes.get( "ou" ).get() );
         Attribute attribute = attributes.get( "objectClass" );
         assertNotNull( attribute );
         assertTrue( attribute.contains( "top" ) );

Mime
View raw message