directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ersi...@apache.org
Subject svn commit: r349484 - in /directory/sandbox/ersiner/apacheds-with-storedprocs: core-unit/src/test/java/org/apache/ldap/server/storedprocs/JavaStoredProcTest.java core/src/main/java/org/apache/ldap/server/storedprocs/LdapClassLoader.java
Date Mon, 28 Nov 2005 19:52:52 GMT
Author: ersiner
Date: Mon Nov 28 11:52:39 2005
New Revision: 349484

URL: http://svn.apache.org/viewcvs?rev=349484&view=rev
Log:
LdapClassLoader now considers default search contexts.


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/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=349484&r1=349483&r2=349484&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
Mon Nov 28 11:52:39 2005
@@ -101,4 +101,38 @@
                 new Object[] { new String[] { } }
                 );
     }
+    
+    public void testStoredProcedureExecutionOverServerLdapContextEntryPointWithDefaultSearchContext()
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" ) );
+        
+        ServerLdapContext configurationContext = ( ServerLdapContext ) sysRoot.lookup( "ou=configuration,ou=system"
);
+        
+        // set up
+        Attributes attributes2 = new BasicAttributes( "objectClass", "top", true );
+        attributes2.get( "objectClass" ).add( "extensibleObject" );
+        attributes2.put( "classLoaderDefaultSearchContext", "ou=system" );
+        attributes2.put( "cn", "ClassLoaderDefaultSearchContexts" );
+        configurationContext.createSubcontext( "cn=ClassLoaderDefaultSearchContexts", attributes2
);
+        // assert set up successfull
+        assertNotNull( configurationContext.lookup( "cn=ClassLoaderDefaultSearchContexts"
) );
+        
+        
+        // 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/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=349484&r1=349483&r2=349484&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
Mon Nov 28 11:52:39 2005
@@ -43,62 +43,98 @@
 public class LdapClassLoader extends ClassLoader
 {
     private static final Logger log = LoggerFactory.getLogger( LdapClassLoader.class );
-    private ServerLdapContext ctx;
+    private static String defaultSearchContextsConfig="cn=ClassLoaderDefaultSearchContexts,ou=configuration,ou=system";
+    private ServerLdapContext RootDSE;
 
     
-    public LdapClassLoader( ServerLdapContext ctx )
+    public LdapClassLoader( ServerLdapContext RootDSE ) throws NamingException
     {
-        this.ctx = ctx;
+        this.RootDSE = ( ( ServerLdapContext ) RootDSE.lookup( "" ) );
     }
 
-    
-    public Class findClass( String name ) throws ClassNotFoundException
+    private byte[] findClassInDIT( NamingEnumeration searchContexts, String name ) throws
ClassNotFoundException
     {
+        String currentSearchContextName = null;
+        ServerLdapContext currentSearchContext = null;
+        NamingEnumeration javaClassEntries = null;
         byte[] classBytes = null;
-
+        
         BranchNode filter = new BranchNode( BranchNode.AND );
         filter.addNode( new SimpleNode( "fqcn", name, LeafNode.EQUALITY ) );
         filter.addNode( new SimpleNode( "objectClass", "javaClass", LeafNode.EQUALITY ) );
+        
         SearchControls controls = new SearchControls();
         controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
+        
+        try
+        {
+            while( searchContexts.hasMore() )
+            {
+                currentSearchContextName = ( String ) searchContexts.next();
+                currentSearchContext = ( ServerLdapContext ) RootDSE.lookup( currentSearchContextName
);
+                
+                javaClassEntries = currentSearchContext.search( new LdapName(), filter, controls
);
+                if ( javaClassEntries.hasMore() ) // there should be only one!
+                {
+                    SearchResult javaClassEntry = ( SearchResult ) javaClassEntries.next();
+                    Attribute byteCode = javaClassEntry.getAttributes().get( "byteCode" );
+                    classBytes = ( byte[] ) byteCode.get();
+                    continue;
+                }
+            }
+        }
+        catch ( NamingException e )
+        {
+            throw new ClassNotFoundException();
+        }
+        
+        return classBytes;
+    }
+    
+    public Class findClass( String name ) throws ClassNotFoundException
+    {
+        byte[] classBytes = null;
 
-        NamingEnumeration list = null;
+        NamingEnumeration defaultSearchContexts = null;
+        NamingEnumeration namingContexts = null;
+        
+        ServerLdapContext defaultSearchContextsConfigContext = null;
         
         try 
         {   
-            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;
+            try
+            {
+                defaultSearchContextsConfigContext = 
+                    ( ServerLdapContext ) RootDSE.lookup( defaultSearchContextsConfig );
+            }
+            catch ( NamingException e )
+            {
+                log.debug( "No configuration data found for class loader default search contexts."
);
+            };
             
-            while( namingContexts.hasMore() )
+            if ( defaultSearchContextsConfigContext != null )
             {
-                currentNamingContext = ( String ) namingContexts.next();
+                defaultSearchContexts = defaultSearchContextsConfigContext
+                    .getAttributes( "", new String[] { "classLoaderDefaultSearchContext"
} )
+                    .get( "classLoaderDefaultSearchContext" ).getAll();
                 
-                System.out.println( currentNamingContext );
-                
-                // search the class under the naming context considered 
-                list = ( ( ServerLdapContext ) RootDSE.lookup( currentNamingContext ) ).search(
new LdapName(), filter, controls );
-                if ( list.hasMore() )
+                try
                 {
-                    SearchResult result = ( SearchResult ) list.next();
-                    Attribute byteCode = result.getAttributes().get( "byteCode" );
-                    classBytes = ( byte[] ) byteCode.get();
-                    classFound = true;
-                    continue;
+                    classBytes = findClassInDIT( defaultSearchContexts, name );
+                }
+                catch ( ClassNotFoundException e )
+                {
+                    log.debug( "Class " + name + " could not be found under default search
contexts." );
                 }
             }
             
-            if ( !classFound )
+            if ( classBytes == null )
             {
-                String msg = "Class " + name + " not found in DIT.";
-                log.warn( msg );
-                throw new ClassNotFoundException( msg );
+                namingContexts = RootDSE
+                    .getAttributes( "", new String[] { "namingContexts" } )
+                    .get( "namingContexts" ).getAll();
+                
+                classBytes = findClassInDIT( namingContexts, name );
             }
         } 
         catch ( NamingException e ) 
@@ -107,9 +143,16 @@
             log.error( msg, e );
             throw new ClassNotFoundException( msg );
         }
+        catch ( ClassNotFoundException e )
+        {
+            String msg = "Class " + name + " not found in DIT.";
+            log.warn( msg );
+            throw new ClassNotFoundException( msg );
+        }
         finally
         {
-            if ( list != null ) { try { list.close(); } catch( Exception e ) {} };
+            if ( defaultSearchContexts != null ) { try { defaultSearchContexts.close(); }
catch( Exception e ) {} };
+            if ( namingContexts != null ) { try { namingContexts.close(); } catch( Exception
e ) {} };
         }
 
         return defineClass( name, classBytes, 0, classBytes.length );



Mime
View raw message