directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r345581 - /directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/JNDIClassLoader.java
Date Fri, 18 Nov 2005 21:44:14 GMT
Author: akarasulu
Date: Fri Nov 18 13:44:10 2005
New Revision: 345581

URL: http://svn.apache.org/viewcvs?rev=345581&view=rev
Log:
added some code to JNDIClassLoader to search the directory for classes

Modified:
    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/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=345581&r1=345580&r2=345581&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 13:44:10 2005
@@ -14,17 +14,22 @@
  *   limitations under the License.
  *
  */
-
-
 package org.apache.ldap.server.storedprocs;
 
 
-import java.io.IOException;
-
+import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
 import javax.naming.directory.Attribute;
-import javax.naming.directory.Attributes;
-import javax.naming.directory.DirContext;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+
+import org.apache.ldap.common.filter.BranchNode;
+import org.apache.ldap.common.filter.LeafNode;
+import org.apache.ldap.common.filter.SimpleNode;
+import org.apache.ldap.common.name.LdapName;
+import org.apache.ldap.server.jndi.ServerLdapContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 /**
@@ -36,38 +41,50 @@
  */
 public class JNDIClassLoader extends ClassLoader
 {
-    DirContext ctx;
-    String dn;
+	private static final Logger log = LoggerFactory.getLogger( JNDIClassLoader.class );
+    private ServerLdapContext ctx;
 
-    public JNDIClassLoader( DirContext ctx, String dn )
+    
+    public JNDIClassLoader( ServerLdapContext ctx, String dn )
     {
         this.ctx = ctx;
-        this.dn = dn;
     }
 
+    
     public Class findClass( String name )
     {
         byte[] b = null;
 
-        try
-        {
-            b = loadClassData( name );
-        } catch ( IOException e )
-        {
-            e.printStackTrace();
-        }
-        catch ( NamingException e )
-        {
-            e.printStackTrace();
-        }
+    	BranchNode filter = new BranchNode( BranchNode.AND );
+    	filter.addNode( new SimpleNode( "fqcn", "HelloWorld", LeafNode.EQUALITY ) );
+    	filter.addNode( new SimpleNode( "objectClass", "javaClass", LeafNode.EQUALITY ) );
+    	SearchControls controls = new SearchControls();
+    	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" );
+				b = ( byte[] ) byteCode.get();
+			}
+			else
+			{
+				log.warn( "Class " + name + " not found in DIT." );
+			}
+		} 
+    	catch ( NamingException e ) 
+    	{
+			log.error( "encountered JNDI failure while searching directory for class: " + name, e
);
+		}
+    	finally
+    	{
+    		if ( list != null ) { try { list.close(); } catch( Exception e ) {} };
+    	}
 
         return defineClass( name, b, 0, b.length );
-    }
-
-    private byte[] loadClassData( String name ) throws IOException, NamingException
-    {
-        Attributes javaClassEntry = ctx.getAttributes( "fqcn=" + name + "," + dn );
-        Attribute javaByteCode = javaClassEntry.get( "byteCode" );
-        return ( byte[] ) javaByteCode.get();
     }
 }



Mime
View raw message