directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ersi...@apache.org
Subject svn commit: r396002 - /directory/trunks/apacheds/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/extended/
Date Fri, 21 Apr 2006 20:52:55 GMT
Author: ersiner
Date: Fri Apr 21 13:52:53 2006
New Revision: 396002

URL: http://svn.apache.org/viewcvs?rev=396002&view=rev
Log:
Added some of my old Stored Procedure Extended Operation Handler implementations.
They need some rework.

Added:
    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

Added: directory/trunks/apacheds/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/extended/JavaStoredProcedureExtendedOperationHandler.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/extended/JavaStoredProcedureExtendedOperationHandler.java?rev=396002&view=auto
==============================================================================
--- directory/trunks/apacheds/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/extended/JavaStoredProcedureExtendedOperationHandler.java
(added)
+++ directory/trunks/apacheds/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/extended/JavaStoredProcedureExtendedOperationHandler.java
Fri Apr 21 13:52:53 2006
@@ -0,0 +1,165 @@
+/*
+ *   Copyright 2006 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.directory.server.ldap.support.extended;
+
+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.directory.server.core.jndi.ServerLdapContext;
+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.util.ClassUtils;
+import org.apache.directory.shared.ldap.util.SpringClassUtils;
+import org.apache.directory.shared.ldap.util.StringTools;
+
+
+/**
+ * @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, StoredProcedure
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() )
+        {
+            StoredProcedureParameter pPojo = ( StoredProcedureParameter ) it.next();
+            
+            // Get type from String even if it holds a primitive type name
+            Class type = SpringClassUtils.forName( StringTools.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 retrieve the String and initialize a wrapper of the primitive.
+             * 
+             * Note that this is just how we prefer Java Specific Stored Procedures
+             * to handle parameters. Of course we do not have to it this way.
+             */
+            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
+        /**
+         * BIG BANG!!!
+        ctx.executeProcedure( 
+                StringTools.utf8ToString( pojo.getProcedure() ), 
+                ( Class[] ) types.toArray(),
+                values.toArray()
+                );
+        */
+    }
+
+    private Object getInitializedPrimitiveWrapperInstance( Class type, byte[] value )
+    {
+        Object instance = null;
+        try
+        {
+            instance = ClassUtils
+                    .primitiveToWrapper( type )
+                    .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)
+        {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        return instance;
+    }
+}

Added: directory/trunks/apacheds/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/extended/LanguageSpecificStoredProceureExtendedOperationHandler.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/extended/LanguageSpecificStoredProceureExtendedOperationHandler.java?rev=396002&view=auto
==============================================================================
--- directory/trunks/apacheds/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/extended/LanguageSpecificStoredProceureExtendedOperationHandler.java
(added)
+++ directory/trunks/apacheds/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/extended/LanguageSpecificStoredProceureExtendedOperationHandler.java
Fri Apr 21 13:52:53 2006
@@ -0,0 +1,35 @@
+/*
+ *   Copyright 2006 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.directory.server.ldap.support.extended;
+
+import org.apache.directory.server.core.jndi.ServerLdapContext;
+import org.apache.directory.shared.ldap.codec.extended.operations.StoredProcedure;
+
+
+/**
+ * An extension (hook) point that enables an implementor to provide his or her
+ * own Language Specific Stored Procedure Extended Operation handler.  
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$ $Date$
+ */
+public interface LanguageSpecificStoredProceureExtendedOperationHandler
+{
+    void handleStoredProcedureExtendedOperation( ServerLdapContext ctx, StoredProcedure spBean
) throws Exception;
+}

Added: directory/trunks/apacheds/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/extended/StoredProcedureExtendedOperationHandler.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/extended/StoredProcedureExtendedOperationHandler.java?rev=396002&view=auto
==============================================================================
--- directory/trunks/apacheds/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/extended/StoredProcedureExtendedOperationHandler.java
(added)
+++ directory/trunks/apacheds/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/extended/StoredProcedureExtendedOperationHandler.java
Fri Apr 21 13:52:53 2006
@@ -0,0 +1,104 @@
+/*
+ *   Copyright 2006 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.directory.server.ldap.support.extended;
+
+
+import java.nio.ByteBuffer;
+import java.util.Set;
+
+import javax.naming.ldap.Control;
+
+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;
+import org.apache.directory.shared.asn1.ber.Asn1Decoder;
+import org.apache.directory.shared.asn1.ber.IAsn1Container;
+import org.apache.directory.shared.asn1.codec.DecoderException;
+import org.apache.directory.shared.ldap.codec.extended.operations.StoredProcedure;
+import org.apache.directory.shared.ldap.codec.extended.operations.StoredProcedureContainer;
+import org.apache.directory.shared.ldap.codec.extended.operations.StoredProcedureDecoder;
+import org.apache.directory.shared.ldap.message.ExtendedRequest;
+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()
+    {
+        /**
+         * TODO return the correct OID. 
+         */
+        return "1.2.3.4.55.666.7777";
+    }
+
+    public void handleExtendedOperation( IoSession session, SessionRegistry registry, ExtendedRequest
req ) throws Exception
+    {
+        Control[] connCtls = ( Control[] ) req.getControls().values().toArray( new Control[
req.getControls().size() ] );
+        ServerLdapContext serverLdapContext = ( ServerLdapContext ) registry.getLdapContext(
session, connCtls, false);
+        StoredProcedure spBean = decodeBean( req.getPayload() );
+        
+        LanguageSpecificStoredProceureExtendedOperationHandler handler = null;
+        
+        /**
+         * TODO This part may be replaced by a better handler determiner.
+         */
+        if ( spBean.getLanguage().equals( "Java" ) )
+        {
+            handler = new JavaStoredProcedureExtendedOperationHandler();
+            handler.handleStoredProcedureExtendedOperation( serverLdapContext, spBean );
+        }
+    }
+    
+    private StoredProcedure decodeBean( byte[] payload )
+    {
+        Asn1Decoder storedProcedureDecoder = new StoredProcedureDecoder();
+        ByteBuffer stream = ByteBuffer.wrap( payload );
+        IAsn1Container storedProcedureContainer = new StoredProcedureContainer();
+
+        try
+        {
+            storedProcedureDecoder.decode( stream, storedProcedureContainer );
+        }
+        catch (DecoderException de)
+        {
+            de.printStackTrace();
+        }
+
+        StoredProcedure spBean = ( ( StoredProcedureContainer ) storedProcedureContainer
).getStoredProcedure();
+        
+        return spBean;
+    }
+
+	public Set getExtensionOids() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	public void setLdapProvider(LdapProtocolProvider provider) {
+		// TODO Auto-generated method stub
+		
+	}
+
+}



Mime
View raw message