directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ersi...@apache.org
Subject svn commit: r352015 - in /directory/protocol-providers/ldap/trunk: ./ src/main/java/org/apache/ldap/server/protocol/extended/ src/main/java/org/apache/ldap/server/protocol/extended/sp/
Date Sat, 03 Dec 2005 21:08:03 GMT
Author: ersiner
Date: Sat Dec  3 13:07:50 2005
New Revision: 352015

URL: http://svn.apache.org/viewcvs?rev=352015&view=rev
Log:
Cleaning up.

We still have a build problem.
I could not import asn1new stuff from ldap-protocol. I'm not sure if this dependency makes
things fails. We'll figure it out.

Added:
    directory/protocol-providers/ldap/trunk/src/main/java/org/apache/ldap/server/protocol/extended/
    directory/protocol-providers/ldap/trunk/src/main/java/org/apache/ldap/server/protocol/extended/sp/
    directory/protocol-providers/ldap/trunk/src/main/java/org/apache/ldap/server/protocol/extended/sp/JavaStoredProcedureExtendedOperationHandler.java
    directory/protocol-providers/ldap/trunk/src/main/java/org/apache/ldap/server/protocol/extended/sp/LanguageSpecificStoredProceureExtendedOperationHandler.java
    directory/protocol-providers/ldap/trunk/src/main/java/org/apache/ldap/server/protocol/extended/sp/StoredProcedureExtendedOperationHandler.java
Modified:
    directory/protocol-providers/ldap/trunk/project.xml

Modified: directory/protocol-providers/ldap/trunk/project.xml
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/ldap/trunk/project.xml?rev=352015&r1=352014&r2=352015&view=diff
==============================================================================
--- directory/protocol-providers/ldap/trunk/project.xml (original)
+++ directory/protocol-providers/ldap/trunk/project.xml Sat Dec  3 13:07:50 2005
@@ -195,6 +195,12 @@
       <version>3.8.1</version>
       <url>http://junit.org</url>
     </dependency>
+    <dependency>
+      <groupId>commons-lang</groupId>
+      <artifactId>commons-lang</artifactId>
+      <version>2.1</version>
+      <type>jar</type>
+    </dependency>
   </dependencies>
   
   <reports>

Added: directory/protocol-providers/ldap/trunk/src/main/java/org/apache/ldap/server/protocol/extended/sp/JavaStoredProcedureExtendedOperationHandler.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/ldap/trunk/src/main/java/org/apache/ldap/server/protocol/extended/sp/JavaStoredProcedureExtendedOperationHandler.java?rev=352015&view=auto
==============================================================================
--- directory/protocol-providers/ldap/trunk/src/main/java/org/apache/ldap/server/protocol/extended/sp/JavaStoredProcedureExtendedOperationHandler.java
(added)
+++ directory/protocol-providers/ldap/trunk/src/main/java/org/apache/ldap/server/protocol/extended/sp/JavaStoredProcedureExtendedOperationHandler.java
Sat Dec  3 13:07:50 2005
@@ -0,0 +1,160 @@
+/*
+ *   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.protocol.extended.sp;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.naming.NamingException;
+
+import org.apache.asn1.codec.util.StringUtils;
+import org.apache.ldap.common.message.extended.ParameterPojo;
+import org.apache.ldap.common.message.extended.StoredProcedurePojo;
+import org.apache.ldap.server.jndi.ServerLdapContext;
+import org.apache.ldap.server.storedprocs.SpringClassUtils;
+
+
+
+/**
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$ $Date$
+ */
+public class JavaStoredProcedureExtendedOperationHandler implements LanguageSpecificStoredProceureExtendedOperationHandler
+{
+    public JavaStoredProcedureExtendedOperationHandler()
+    {
+        
+    }
+    
+    public void handleStoredProcedureExtendedOperation( ServerLdapContext ctx, StoredProcedurePojo
pojo ) throws ClassNotFoundException, NamingException
+    {
+        List types = new ArrayList( pojo.getParameters().size() );
+        List values = new ArrayList( pojo.getParameters().size() );
+        
+        Iterator it = pojo.getParameters().iterator();
+        while ( it.hasNext() )
+        {
+            ParameterPojo pPojo = ( ParameterPojo ) it.next();
+            
+            // get type from String even if it holds a primitive type name
+            Class type = SpringClassUtils.forName( StringUtils.utf8ToString( pPojo.getType()
) ); 
+            
+            types.add( type );
+            
+            byte[] value = pPojo.getValue();
+            
+            /**
+             * If the type name refers to a Java primitive then
+             * we know that the value is encoded as its String representation and
+             * we retrive the String and initialize a wrapper of the primitive.
+             */
+            if ( type.isPrimitive() )
+            {
+                values.add( getInitializedPrimitiveWrapperInstance( type, value ) );
+            }
+            /**
+             * If the type is a complex Java type then
+             * just deserialize the object.
+             */
+            else
+            {
+                try
+                {
+                    // TODO Irritating syntax! Just wanted to see how it looks like..
+                    values.add
+                    ( 
+                        (
+                            new ObjectInputStream
+                            ( 
+                                new ByteArrayInputStream( value )
+                            ) 
+                        ).readObject()
+                    );
+                }
+                catch (IOException e)
+                {
+                    // TODO Auto-generated catch block
+                    e.printStackTrace();
+                }
+                catch (ClassNotFoundException e)
+                {
+                    // TODO Auto-generated catch block
+                    e.printStackTrace();
+                }
+            }
+            
+        }
+        
+        // TODO determine what to do with the exception
+        ctx.executeProcedure( 
+                StringUtils.utf8ToString( pojo.getProcedure() ), 
+                ( Class[] ) types.toArray(),
+                values.toArray()
+                );
+    }
+
+    private Object getInitializedPrimitiveWrapperInstance( Class type, byte[] value )
+    {
+        Object instance = null;
+        try
+        {
+            instance = org.apache.commons.lang.ClassUtils
+                    .primitiveToWrapper( type )
+                    .getConstructor( new Class[] {String.class} )
+                    .newInstance( new Object[] { StringUtils.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)
+        {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        return instance;
+    }
+}

Added: directory/protocol-providers/ldap/trunk/src/main/java/org/apache/ldap/server/protocol/extended/sp/LanguageSpecificStoredProceureExtendedOperationHandler.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/ldap/trunk/src/main/java/org/apache/ldap/server/protocol/extended/sp/LanguageSpecificStoredProceureExtendedOperationHandler.java?rev=352015&view=auto
==============================================================================
--- directory/protocol-providers/ldap/trunk/src/main/java/org/apache/ldap/server/protocol/extended/sp/LanguageSpecificStoredProceureExtendedOperationHandler.java
(added)
+++ directory/protocol-providers/ldap/trunk/src/main/java/org/apache/ldap/server/protocol/extended/sp/LanguageSpecificStoredProceureExtendedOperationHandler.java
Sat Dec  3 13:07:50 2005
@@ -0,0 +1,44 @@
+/*
+ *   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.protocol.extended.sp;
+
+import org.apache.ldap.common.message.extended.StoredProcedurePojo;
+import org.apache.ldap.server.jndi.ServerLdapContext;
+
+
+/**
+ * An extension (hook) point that enables an implementor to provide his or her
+ * own Stored Procedure Extended Operation handler.  
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$ $Date$
+ *
+ */
+public interface LanguageSpecificStoredProceureExtendedOperationHandler
+{
+    /**
+     * Handles the specified extended operation.
+     * 
+     * @param session the MINA session object related with current connection
+     * @param req the LDAP Extended operation request
+     * 
+     * @throws Exception if failed to handle the operation
+     */
+    void handleStoredProcedureExtendedOperation( ServerLdapContext ctx, StoredProcedurePojo
pojo ) throws Exception;
+}

Added: directory/protocol-providers/ldap/trunk/src/main/java/org/apache/ldap/server/protocol/extended/sp/StoredProcedureExtendedOperationHandler.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/ldap/trunk/src/main/java/org/apache/ldap/server/protocol/extended/sp/StoredProcedureExtendedOperationHandler.java?rev=352015&view=auto
==============================================================================
--- directory/protocol-providers/ldap/trunk/src/main/java/org/apache/ldap/server/protocol/extended/sp/StoredProcedureExtendedOperationHandler.java
(added)
+++ directory/protocol-providers/ldap/trunk/src/main/java/org/apache/ldap/server/protocol/extended/sp/StoredProcedureExtendedOperationHandler.java
Sat Dec  3 13:07:50 2005
@@ -0,0 +1,85 @@
+/*
+ *   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.protocol.extended.sp;
+
+
+import java.nio.ByteBuffer;
+
+import org.apache.asn1.codec.DecoderException;
+import org.apache.ldap.common.message.Control;
+import org.apache.ldap.common.message.ExtendedRequest;
+import org.apache.ldap.common.message.extended.StoredProcedurePojo;
+import org.apache.ldap.server.jndi.ServerLdapContext;
+import org.apache.ldap.server.protocol.ExtendedOperationHandler;
+import org.apache.ldap.server.protocol.SessionRegistry;
+import org.apache.mina.common.IoSession;
+
+
+/**
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$ $Date$
+ */
+public class StoredProcedureExtendedOperationHandler implements ExtendedOperationHandler
+{
+
+    public String getOid()
+    {
+        return "1.2.3.4.55.666.7777";
+    }
+
+    public void handleExtendedOperation( IoSession session, SessionRegistry registry, ExtendedRequest
req ) throws Exception
+    {
+        Control[] connCtls = ( Control[] ) req.getControls().toArray( new Control[ req.getControls().size()
] );
+        ServerLdapContext serverLdapContext = ( ServerLdapContext ) registry.getLdapContext(
session, connCtls, false);
+        StoredProcedurePojo pojo = decodePojo( req.getPayload() );
+        
+        // TODO This block will be replaced by a handler initiator via a factory. Now just
trying to make things work.
+        if ( pojo.getLanguage().equals( "Java" ) )
+        {
+            JavaStoredProcedureExtendedOperationHandler handler = new JavaStoredProcedureExtendedOperationHandler();
+            handler.handleStoredProcedureExtendedOperation( serverLdapContext, pojo );
+        }
+    }
+    
+    private StoredProcedurePojo decodePojo( byte[] payload )
+    {
+        Asn1Decoder storedProcedureDecoder = new StoredProcedureDecoder();
+
+        ByteBuffer stream = ByteBuffer.wrap( payload );
+
+        // Allocate a StoredProcedure Container
+        IAsn1Container storedProcedureContainer = new StoredProcedureContainer();
+
+        // Decode a StoredProcedure message
+        try
+        {
+            storedProcedureDecoder.decode( stream, storedProcedureContainer );
+        }
+        catch (DecoderException de)
+        {
+            de.printStackTrace();
+        }
+
+        StoredProcedurePojo pojo = ( ( StoredProcedureContainer ) storedProcedureContainer
)
+                .getStoredProcedurePojo();
+        
+        return pojo;
+    }
+}



Mime
View raw message