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/18 20:01:04 UTC
svn commit: r345540 - in
/directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs:
./ JNDIClassLoader.java
Author: ersiner
Date: Fri Nov 18 11:00:59 2005
New Revision: 345540
URL: http://svn.apache.org/viewcvs?rev=345540&view=rev
Log:
Added a very simple JNDI Class Loader implementation.
Added:
directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/
directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/JNDIClassLoader.java
Added: 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=345540&view=auto
==============================================================================
--- directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/JNDIClassLoader.java (added)
+++ directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/JNDIClassLoader.java Fri Nov 18 11:00:59 2005
@@ -0,0 +1,72 @@
+/*
+ * 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.
+ * 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.storedprocs;
+
+
+import java.io.IOException;
+
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.DirContext;
+
+
+/**
+ * A class loader that loads classes from any directory service accessed via JNDI.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: $
+ */
+public class JNDIClassLoader extends ClassLoader
+{
+ DirContext ctx;
+ String dn;
+
+ public JNDIClassLoader( DirContext 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();
+ }
+
+ 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();
+ }
+}