You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by er...@apache.org on 2005/11/19 07:54:47 UTC
svn commit: r345641 - in
/directory/sandbox/ersiner/apacheds-with-storedprocs:
core-unit/src/test/java/org/apache/ldap/server/storedprocs/JNDIClassLoaderTest.java
core/src/main/java/org/apache/ldap/server/storedprocs/JNDIClassLoader.java
Author: ersiner
Date: Fri Nov 18 22:54:36 2005
New Revision: 345641
URL: http://svn.apache.org/viewcvs?rev=345641&view=rev
Log:
Added method call over loaded class via reflection.
Made some cleanup.
Modified:
directory/sandbox/ersiner/apacheds-with-storedprocs/core-unit/src/test/java/org/apache/ldap/server/storedprocs/JNDIClassLoaderTest.java
directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/JNDIClassLoader.java
Modified: directory/sandbox/ersiner/apacheds-with-storedprocs/core-unit/src/test/java/org/apache/ldap/server/storedprocs/JNDIClassLoaderTest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/ersiner/apacheds-with-storedprocs/core-unit/src/test/java/org/apache/ldap/server/storedprocs/JNDIClassLoaderTest.java?rev=345641&r1=345640&r2=345641&view=diff
==============================================================================
--- directory/sandbox/ersiner/apacheds-with-storedprocs/core-unit/src/test/java/org/apache/ldap/server/storedprocs/JNDIClassLoaderTest.java (original)
+++ directory/sandbox/ersiner/apacheds-with-storedprocs/core-unit/src/test/java/org/apache/ldap/server/storedprocs/JNDIClassLoaderTest.java Fri Nov 18 22:54:36 2005
@@ -1,5 +1,5 @@
/*
- * Copyright 2004 The Apache Software Foundation
+ * Copyright 2005 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.
@@ -14,9 +14,13 @@
* limitations under the License.
*
*/
+
+
package org.apache.ldap.server.storedprocs;
-import javax.naming.NamingException;
+
+import java.lang.reflect.Method;
+
import javax.naming.directory.Attributes;
import javax.naming.directory.BasicAttributes;
@@ -43,9 +47,9 @@
"JsgACEgO2AASxAAAAAQAKAAAACgACAAAABQAIAAYAAQANAAAAAgAO";
private static final byte[] HELLOWORLD_CLASS_BYTES = Base64.decode( HELLOWORLD_CLASS_BASE64.toCharArray() );
-
public void testLoadingClass() throws Exception
{
+ // set up
Attributes attributes = new BasicAttributes( "objectClass", "top", true );
attributes.get( "objectClass" ).add( "javaClass" );
attributes.put( "fqcn", "HelloWorld" );
@@ -53,8 +57,13 @@
sysRoot.createSubcontext( "fqcn=HelloWorld", attributes );
assertNotNull( sysRoot.lookup( "fqcn=HelloWorld" ) );
+ // load the class
JNDIClassLoader loader = new JNDIClassLoader( ( ServerLdapContext ) ( sysRoot.lookup( "" ) ) );
Class clazz = loader.findClass( "HelloWorld" );
assertEquals( clazz.getName(), "HelloWorld" );
+
+ // call a static method over loaded class via reflection
+ Method m = clazz.getMethod("main", new Class[] { (new String[] {}).getClass() });
+ m.invoke( null, new Object[] { new String[] {} } );
}
}
Modified: directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/JNDIClassLoader.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/JNDIClassLoader.java?rev=345641&r1=345640&r2=345641&view=diff
==============================================================================
--- directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/JNDIClassLoader.java (original)
+++ directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/JNDIClassLoader.java Fri Nov 18 22:54:36 2005
@@ -14,6 +14,8 @@
* limitations under the License.
*
*/
+
+
package org.apache.ldap.server.storedprocs;
@@ -25,7 +27,6 @@
import org.apache.ldap.common.filter.BranchNode;
import org.apache.ldap.common.filter.LeafNode;
-import org.apache.ldap.common.filter.PresenceNode;
import org.apache.ldap.common.filter.SimpleNode;
import org.apache.ldap.common.name.LdapName;
import org.apache.ldap.server.jndi.ServerLdapContext;
@@ -34,11 +35,11 @@
/**
- * A class loader that loads classes from any directory service accessed via
- * JNDI.
+ * A class loader that loads classes from an LDAP DIT entry
+ * with objectClass javaClass.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev: $
+ * @version $Rev$
*/
public class JNDIClassLoader extends ClassLoader
{
@@ -81,7 +82,7 @@
}
catch ( NamingException e )
{
- String msg = "encountered JNDI failure while searching directory for class: " + name;
+ String msg = "Encountered JNDI failure while searching directory for class: " + name;
log.error( msg, e );
throw new ClassNotFoundException( msg );
}