directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ersi...@apache.org
Subject svn commit: r349319 - in /directory/sandbox/ersiner/apacheds-with-storedprocs: core-unit/src/test/java/org/apache/ldap/server/storedprocs/ core/src/main/java/org/apache/ldap/server/storedprocs/
Date Sun, 27 Nov 2005 21:32:41 GMT
Author: ersiner
Date: Sun Nov 27 13:32:27 2005
New Revision: 349319

URL: http://svn.apache.org/viewcvs?rev=349319&view=rev
Log:
Modified the class loader to accept a RootDSE and to search all naming contexts.
Modified tests to use the new class loader.
Added a test to test SP execution over current ServerLdapContext.
Cleaned up code.

Modified:
    directory/sandbox/ersiner/apacheds-with-storedprocs/core-unit/src/test/java/org/apache/ldap/server/storedprocs/JavaStoredProcTest.java
    directory/sandbox/ersiner/apacheds-with-storedprocs/core-unit/src/test/java/org/apache/ldap/server/storedprocs/LdapClassLoaderTest.java
    directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/JavaStoredProcedure.java
    directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/LdapClassLoader.java

Modified: directory/sandbox/ersiner/apacheds-with-storedprocs/core-unit/src/test/java/org/apache/ldap/server/storedprocs/JavaStoredProcTest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/ersiner/apacheds-with-storedprocs/core-unit/src/test/java/org/apache/ldap/server/storedprocs/JavaStoredProcTest.java?rev=349319&r1=349318&r2=349319&view=diff
==============================================================================
--- directory/sandbox/ersiner/apacheds-with-storedprocs/core-unit/src/test/java/org/apache/ldap/server/storedprocs/JavaStoredProcTest.java
(original)
+++ directory/sandbox/ersiner/apacheds-with-storedprocs/core-unit/src/test/java/org/apache/ldap/server/storedprocs/JavaStoredProcTest.java
Sun Nov 27 13:32:27 2005
@@ -19,6 +19,8 @@
 package org.apache.ldap.server.storedprocs;
 
 
+import javax.naming.Context;
+import javax.naming.NamingException;
 import javax.naming.directory.Attributes;
 import javax.naming.directory.BasicAttributes;
 
@@ -46,24 +48,57 @@
         "JsgACEgO2AASxAAAAAQAKAAAACgACAAAABQAIAAYAAQANAAAAAgAO";
 	private static final byte[] HELLOWORLD_CLASS_BYTES = Base64.decode( HELLOWORLD_CLASS_BASE64.toCharArray()
);
 	
-    public void testLoadingClass() throws Exception
+    protected void setUp() throws Exception
     {
+        // bind to RootDSE
+        overrideEnvironment( Context.PROVIDER_URL, "" );
+        super.setUp();
+    }
+    
+    public void testBasicStoredProcedureExecution() throws Exception
+    {
+        ServerLdapContext defaultContext = ( ServerLdapContext ) sysRoot.lookup( "ou=system"
);
+        ServerLdapContext RootDSE = ( ServerLdapContext ) sysRoot.lookup( "" );
+        
         // set up
         Attributes attributes = new BasicAttributes( "objectClass", "top", true );
         attributes.get( "objectClass" ).add( "javaClass" );
         attributes.put( "fqcn", "HelloWorld" );
         attributes.put( "byteCode", HELLOWORLD_CLASS_BYTES );
-        sysRoot.createSubcontext( "fqcn=HelloWorld", attributes );
-        assertNotNull( sysRoot.lookup( "fqcn=HelloWorld" ) );
+        defaultContext.createSubcontext( "fqcn=HelloWorld", attributes );
+        // assert set up successfull
+        assertNotNull( defaultContext.lookup( "fqcn=HelloWorld" ) );
         
-        // create the sp instance
+        // create the SP instance
         StoredProcedure sp = new JavaStoredProcedure(
-                ( ServerLdapContext ) ( sysRoot.lookup( "" ) ), 
-                "HelloWorld.main",
-                new Class[] { String[].class }
+                RootDSE, // always RootDSE
+                "HelloWorld.main", // fully qualified Stored Procedure name
+                new Class[] { String[].class } // parameters' type
                 );
         
-        // invoke the sp
+        // invoke the SP
         sp.call( new Object[] { new String[] {} } );
+    }
+    
+    public void testStoredProcedureExecutionOverServerLdapContextEntryPoint() throws NamingException
+    {
+        ServerLdapContext defaultContext = ( ServerLdapContext ) sysRoot.lookup( "ou=system"
);
+        ServerLdapContext RootDSE = ( ServerLdapContext ) sysRoot.lookup( "" );
+        
+        // set up
+        Attributes attributes = new BasicAttributes( "objectClass", "top", true );
+        attributes.get( "objectClass" ).add( "javaClass" );
+        attributes.put( "fqcn", "HelloWorld" );
+        attributes.put( "byteCode", HELLOWORLD_CLASS_BYTES );
+        defaultContext.createSubcontext( "fqcn=HelloWorld", attributes );
+        // assert set up successfull
+        assertNotNull( defaultContext.lookup( "fqcn=HelloWorld" ) );
+        
+        // invoke the SP over current context
+        RootDSE.executeProcedure( 
+                "HelloWorld.main",
+                new Class[] { String[].class },
+                new Object[] { new String[] { } }
+                );
     }
 }

Modified: directory/sandbox/ersiner/apacheds-with-storedprocs/core-unit/src/test/java/org/apache/ldap/server/storedprocs/LdapClassLoaderTest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/ersiner/apacheds-with-storedprocs/core-unit/src/test/java/org/apache/ldap/server/storedprocs/LdapClassLoaderTest.java?rev=349319&r1=349318&r2=349319&view=diff
==============================================================================
--- directory/sandbox/ersiner/apacheds-with-storedprocs/core-unit/src/test/java/org/apache/ldap/server/storedprocs/LdapClassLoaderTest.java
(original)
+++ directory/sandbox/ersiner/apacheds-with-storedprocs/core-unit/src/test/java/org/apache/ldap/server/storedprocs/LdapClassLoaderTest.java
Sun Nov 27 13:32:27 2005
@@ -19,8 +19,7 @@
 package org.apache.ldap.server.storedprocs;
 
 
-import java.lang.reflect.Method;
-
+import javax.naming.Context;
 import javax.naming.directory.Attributes;
 import javax.naming.directory.BasicAttributes;
 
@@ -33,7 +32,7 @@
  * Test case for LdapClassLoader.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev$
+ * @version $Rev$ $Date$
  */
 public class LdapClassLoaderTest extends AbstractAdminTestCase
 {
@@ -47,24 +46,32 @@
         "AAkAAAAdAAEAAQAAAAUqtwABsQAAAAEACgAAAAYAAQAAAAEACQALAAwAAQAJAAAAJQACAAEAAAA" +
         "JsgACEgO2AASxAAAAAQAKAAAACgACAAAABQAIAAYAAQANAAAAAgAO";
 	private static final byte[] HELLOWORLD_CLASS_BYTES = Base64.decode( HELLOWORLD_CLASS_BASE64.toCharArray()
);
-	
+    
+    protected void setUp() throws Exception
+    {
+        // bind to RootDSE
+        overrideEnvironment( Context.PROVIDER_URL, "" );
+        super.setUp();
+    }
+    
     public void testLoadingClass() throws Exception
     {
+        // get default naming context to work on
+        ServerLdapContext defaultContext = ( ServerLdapContext ) sysRoot.lookup( "ou=system"
);
+        
         // set up
         Attributes attributes = new BasicAttributes( "objectClass", "top", true );
         attributes.get( "objectClass" ).add( "javaClass" );
         attributes.put( "fqcn", "HelloWorld" );
         attributes.put( "byteCode", HELLOWORLD_CLASS_BYTES );
-        sysRoot.createSubcontext( "fqcn=HelloWorld", attributes );
-        assertNotNull( sysRoot.lookup( "fqcn=HelloWorld" ) );
+        defaultContext.createSubcontext( "fqcn=HelloWorld", attributes );
+        // assert set up successfull
+        assertNotNull( defaultContext.lookup( "fqcn=HelloWorld" ) );
 
         // load the class
         LdapClassLoader loader = new LdapClassLoader( ( ServerLdapContext ) ( sysRoot.lookup(
"" ) ) );
         Class clazz = loader.loadClass( "HelloWorld" );
+        // assert class loaded successfully
         assertEquals( clazz.getName(), "HelloWorld" );
-               
-        // call a static method over loaded class via reflection
-        Method m = clazz.getMethod("main", new Class[] { String[].class });
-        m.invoke( null, new Object[] { new String[] {} } );
     }
 }

Modified: directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/JavaStoredProcedure.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/JavaStoredProcedure.java?rev=349319&r1=349318&r2=349319&view=diff
==============================================================================
--- directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/JavaStoredProcedure.java
(original)
+++ directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/JavaStoredProcedure.java
Sun Nov 27 13:32:27 2005
@@ -33,11 +33,11 @@
  */
 public class JavaStoredProcedure implements StoredProcedure
 {
-    ServerLdapContext ctx;
-    String fQSPName;
-    Class[] parameterTypes;
-    Method method;
-    Class methodClass;
+    private ServerLdapContext ctx;
+    private String fQSPName;
+    private Class[] parameterTypes;
+    private Method method;
+    private Class methodClass;
     
     public JavaStoredProcedure( 
             ServerLdapContext ctx, 

Modified: directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/LdapClassLoader.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/LdapClassLoader.java?rev=349319&r1=349318&r2=349319&view=diff
==============================================================================
--- directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/LdapClassLoader.java
(original)
+++ directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/LdapClassLoader.java
Sun Nov 27 13:32:27 2005
@@ -38,7 +38,7 @@
  * A class loader that loads classes from an LDAP DIT.
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev$
+ * @version $Rev$ $Date$
  */
 public class LdapClassLoader extends ClassLoader
 {
@@ -63,21 +63,41 @@
     	controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
 
     	NamingEnumeration list = null;
+        
     	try 
-    	{
-			list = ctx.search( new LdapName(), filter, controls );
-			if ( list.hasMore() )
-			{
-				SearchResult result = ( SearchResult ) list.next();
-				Attribute byteCode = result.getAttributes().get( "byteCode" );
-				classBytes = ( byte[] ) byteCode.get();
-			}
-			else
-			{
-				String msg = "Class " + name + " not found in DIT.";
-				log.warn( msg );
-				throw new ClassNotFoundException( msg );
-			}
+    	{   
+            ServerLdapContext RootDSE = ( ( ServerLdapContext ) ctx.lookup( "" ) );
+            
+            // get Naming Contexts over the RootDSE
+            NamingEnumeration namingContexts = RootDSE
+                .getAttributes( "", new String[] { "namingContexts" } )
+                .get( "namingContexts" ).getAll();
+            
+            String currentNamingContext = null;
+            boolean classFound = false;
+            
+            while( namingContexts.hasMore() )
+            {
+                currentNamingContext = ( String ) namingContexts.next();
+                
+                // search the class under the naming context considered 
+                list = ( ( ServerLdapContext ) RootDSE.lookup( currentNamingContext ) ).search(
new LdapName(), filter, controls );
+                if ( list.hasMore() )
+                {
+                    SearchResult result = ( SearchResult ) list.next();
+                    Attribute byteCode = result.getAttributes().get( "byteCode" );
+                    classBytes = ( byte[] ) byteCode.get();
+                    classFound = true;
+                    continue;
+                }
+            }
+            
+            if ( !classFound )
+            {
+                String msg = "Class " + name + " not found in DIT.";
+                log.warn( msg );
+                throw new ClassNotFoundException( msg );
+            }
 		} 
     	catch ( NamingException e ) 
     	{



Mime
View raw message