directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r414811 - /directory/trunks/apacheds/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/extended/
Date Fri, 16 Jun 2006 12:24:00 GMT
Author: akarasulu
Date: Fri Jun 16 05:23:59 2006
New Revision: 414811

URL: http://svn.apache.org/viewvc?rev=414811&view=rev
Log:
added code to resolve and execute stored procedures

Modified:
    directory/trunks/apacheds/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/extended/JavaStoredProcedureExtendedOperationHandler.java
    directory/trunks/apacheds/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/extended/LanguageSpecificStoredProceureExtendedOperationHandler.java
    directory/trunks/apacheds/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/extended/StoredProcedureExtendedOperationHandler.java

Modified: directory/trunks/apacheds/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/extended/JavaStoredProcedureExtendedOperationHandler.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/extended/JavaStoredProcedureExtendedOperationHandler.java?rev=414811&r1=414810&r2=414811&view=diff
==============================================================================
--- directory/trunks/apacheds/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/extended/JavaStoredProcedureExtendedOperationHandler.java
(original)
+++ directory/trunks/apacheds/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/extended/JavaStoredProcedureExtendedOperationHandler.java
Fri Jun 16 05:23:59 2006
@@ -20,16 +20,19 @@
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.ObjectInputStream;
-import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 
 import javax.naming.NamingException;
-import javax.naming.ldap.LdapContext;
 
+import org.apache.directory.server.core.jndi.ServerLdapContext;
+import org.apache.directory.server.core.sp.LdapClassLoader;
 import org.apache.directory.shared.ldap.codec.extended.operations.StoredProcedure;
 import org.apache.directory.shared.ldap.codec.extended.operations.StoredProcedure.StoredProcedureParameter;
+import org.apache.directory.shared.ldap.exception.LdapNamingException;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.util.ClassUtils;
 import org.apache.directory.shared.ldap.util.SpringClassUtils;
 import org.apache.directory.shared.ldap.util.StringTools;
@@ -41,7 +44,8 @@
  */
 public class JavaStoredProcedureExtendedOperationHandler implements LanguageSpecificStoredProceureExtendedOperationHandler
 {
-    public void handleStoredProcedureExtendedOperation( LdapContext ctx, StoredProcedure
pojo ) throws ClassNotFoundException, NamingException
+    public void handleStoredProcedureExtendedOperation( ServerLdapContext ctx, StoredProcedure
pojo ) 
+        throws ClassNotFoundException, NamingException
     {
         List types = new ArrayList( pojo.getParameters().size() );
         List values = new ArrayList( pojo.getParameters().size() );
@@ -104,16 +108,34 @@
         }
         
         // TODO determine what to do with the exception
-        /**
-         * BIG BANG!!!
-        ctx.executeProcedure( 
-                StringTools.utf8ToString( pojo.getProcedure() ), 
-                ( Class[] ) types.toArray(),
-                values.toArray()
-                );
-        */
+        executeProcedure( ctx, StringTools.utf8ToString( pojo.getProcedure() ), 
+                ( Class[] ) types.toArray(), values.toArray() );
     }
 
+    
+    public Object executeProcedure( ServerLdapContext ctx, String procedure, Class[] types,
Object[] values ) 
+        throws NamingException
+    {
+        int lastDot = procedure.lastIndexOf( '.' );
+        String className = procedure.substring( 0, lastDot );
+        String methodName = procedure.substring( lastDot + 1 );
+        LdapClassLoader loader = new LdapClassLoader( ctx );
+        
+        try
+        {
+            Class clazz = loader.loadClass( className );
+            Method proc = clazz.getMethod( methodName, types );
+            return proc.invoke( null, values );
+        }
+        catch ( Exception e )
+        {
+            LdapNamingException lne = new LdapNamingException( ResultCodeEnum.OTHER );
+            lne.setRootCause( e );
+            throw lne;
+        }
+    }
+    
+    
     private Object getInitializedPrimitiveWrapperInstance( Class type, byte[] value )
     {
         Object instance = null;
@@ -124,34 +146,8 @@
                     .getConstructor( new Class[] {String.class} )
                     .newInstance( new Object[] { StringTools.utf8ToString( value ) } );
         }
-        catch (IllegalArgumentException e)
-        {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        }
-        catch (SecurityException e)
-        {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        }
-        catch (InstantiationException e)
-        {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        }
-        catch (IllegalAccessException e)
-        {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        }
-        catch (InvocationTargetException e)
-        {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        }
-        catch (NoSuchMethodException e)
+        catch ( Exception e )
         {
-            // TODO Auto-generated catch block
             e.printStackTrace();
         }
         return instance;

Modified: directory/trunks/apacheds/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/extended/LanguageSpecificStoredProceureExtendedOperationHandler.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/extended/LanguageSpecificStoredProceureExtendedOperationHandler.java?rev=414811&r1=414810&r2=414811&view=diff
==============================================================================
--- directory/trunks/apacheds/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/extended/LanguageSpecificStoredProceureExtendedOperationHandler.java
(original)
+++ directory/trunks/apacheds/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/extended/LanguageSpecificStoredProceureExtendedOperationHandler.java
Fri Jun 16 05:23:59 2006
@@ -17,8 +17,7 @@
 package org.apache.directory.server.ldap.support.extended;
 
 
-import javax.naming.ldap.LdapContext;
-
+import org.apache.directory.server.core.jndi.ServerLdapContext;
 import org.apache.directory.shared.ldap.codec.extended.operations.StoredProcedure;
 
 
@@ -31,5 +30,5 @@
  */
 public interface LanguageSpecificStoredProceureExtendedOperationHandler 
 {
-    void handleStoredProcedureExtendedOperation( LdapContext ctx, StoredProcedure spBean
) throws Exception;
+    void handleStoredProcedureExtendedOperation( ServerLdapContext ctx, StoredProcedure spBean
) throws Exception;
 }

Modified: directory/trunks/apacheds/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/extended/StoredProcedureExtendedOperationHandler.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/extended/StoredProcedureExtendedOperationHandler.java?rev=414811&r1=414810&r2=414811&view=diff
==============================================================================
--- directory/trunks/apacheds/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/extended/StoredProcedureExtendedOperationHandler.java
(original)
+++ directory/trunks/apacheds/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/extended/StoredProcedureExtendedOperationHandler.java
Fri Jun 16 05:23:59 2006
@@ -27,6 +27,7 @@
 import javax.naming.ldap.Control;
 import javax.naming.ldap.LdapContext;
 
+import org.apache.directory.server.core.jndi.ServerLdapContext;
 import org.apache.directory.server.ldap.ExtendedOperationHandler;
 import org.apache.directory.server.ldap.LdapProtocolProvider;
 import org.apache.directory.server.ldap.SessionRegistry;
@@ -50,7 +51,18 @@
     public void handleExtendedOperation( IoSession session, SessionRegistry registry, ExtendedRequest
req ) throws Exception
     {
         Control[] connCtls = ( Control[] ) req.getControls().values().toArray( new Control[
req.getControls().size() ] );
-        LdapContext serverLdapContext = ( LdapContext ) registry.getLdapContext( session,
connCtls, false);
+        LdapContext ldapContext = ( LdapContext ) registry.getLdapContext( session, connCtls,
false);
+        ServerLdapContext serverLdapContext;
+        
+        if ( ldapContext instanceof ServerLdapContext )
+        {
+            serverLdapContext = ( ServerLdapContext ) ldapContext;
+        }
+        else
+        {
+            serverLdapContext = ( ServerLdapContext ) ldapContext.lookup( "" );
+        }
+        
         StoredProcedure spBean = decodeBean( req.getPayload() );
         
         LanguageSpecificStoredProceureExtendedOperationHandler handler = null;



Mime
View raw message