directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ersi...@apache.org
Subject svn commit: r349795 - in /directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs: ./ codec/
Date Tue, 29 Nov 2005 19:07:43 GMT
Author: ersiner
Date: Tue Nov 29 11:07:35 2005
New Revision: 349795

URL: http://svn.apache.org/viewcvs?rev=349795&view=rev
Log:
Change the type of 'language' field in StoredProcedurePojo to String. This is predefined for
all implementations.
Implemented ExtendedOperationHandler interface with class StoredProcedureExtendedOperationHandler.
This class calls appropriate language specific handler after pojo decoding.
Added class JavaStoredProcedureExtendedOperationHandler which is a Java language specific
implementation for handling StoredProcedure ExtendedRequests. There is much to do about handling
primite and other types here.

Important: Project layout needs to be updated because putting everything in the core causes
cyclic dependencies which blocks compiling. Now the protocol subproject cannot be added to
the build path because of cyclic dependencies.


Added:
    directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/JavaStoredProcedureExtendedOperationHandler.java
    directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/StoredProcedureExtendedOperationHandler.java
Modified:
    directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/StoredProcedurePojo.java
    directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/codec/StoredProcedureGrammar.java

Added: directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/JavaStoredProcedureExtendedOperationHandler.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/JavaStoredProcedureExtendedOperationHandler.java?rev=349795&view=auto
==============================================================================
--- directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/JavaStoredProcedureExtendedOperationHandler.java
(added)
+++ directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/JavaStoredProcedureExtendedOperationHandler.java
Tue Nov 29 11:07:35 2005
@@ -0,0 +1,65 @@
+/*
+ *   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.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.server.jndi.ServerLdapContext;
+
+
+
+/**
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$ $Date$
+ */
+public class JavaStoredProcedureExtendedOperationHandler
+{
+    public JavaStoredProcedureExtendedOperationHandler()
+    {
+        
+    }
+    
+    // TODO this method could be defined by an interface
+    public void handleStoredProcedureExtendedOperation( ServerLdapContext serverLdapContext,
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();
+            // TODO determine type and add to list
+            // TODO determine value and add to list            
+        }
+        
+        // TODO determine what to do with the exception
+        serverLdapContext.executeProcedure( 
+                StringUtils.toUtf8( pojo.getProcedure() ), 
+                ( Class[] ) types.toArray(),
+                values.toArray()
+                );
+    }
+}

Added: directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/StoredProcedureExtendedOperationHandler.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/StoredProcedureExtendedOperationHandler.java?rev=349795&view=auto
==============================================================================
--- directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/StoredProcedureExtendedOperationHandler.java
(added)
+++ directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/StoredProcedureExtendedOperationHandler.java
Tue Nov 29 11:07:35 2005
@@ -0,0 +1,88 @@
+/*
+ *   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.nio.ByteBuffer;
+
+import org.apache.asn1.codec.DecoderException;
+import org.apache.asn1new.ber.Asn1Decoder;
+import org.apache.asn1new.ber.containers.IAsn1Container;
+import org.apache.ldap.common.message.Control;
+import org.apache.ldap.common.message.ExtendedRequest;
+import org.apache.ldap.server.jndi.ServerLdapContext;
+import org.apache.ldap.server.protocol.ExtendedOperationHandler;
+import org.apache.ldap.server.protocol.SessionRegistry;
+import org.apache.ldap.server.storedprocs.codec.StoredProcedureContainer;
+import org.apache.ldap.server.storedprocs.codec.StoredProcedureDecoder;
+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;
+    }
+}

Modified: directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/StoredProcedurePojo.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/StoredProcedurePojo.java?rev=349795&r1=349794&r2=349795&view=diff
==============================================================================
--- directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/StoredProcedurePojo.java
(original)
+++ directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/StoredProcedurePojo.java
Tue Nov 29 11:07:35 2005
@@ -25,7 +25,7 @@
 
 public class StoredProcedurePojo
 {
-    private byte[] language;
+    private String language;
 
     private byte[] procedure;
 
@@ -33,12 +33,12 @@
 
     private transient ParameterPojo currentParameter;
 
-    public byte[] getLanguage()
+    public String getLanguage()
     {
         return language;
     }
 
-    public void setLanguage( byte[] language )
+    public void setLanguage( String language )
     {
         this.language = language;
     }

Modified: directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/codec/StoredProcedureGrammar.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/codec/StoredProcedureGrammar.java?rev=349795&r1=349794&r2=349795&view=diff
==============================================================================
--- directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/codec/StoredProcedureGrammar.java
(original)
+++ directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/codec/StoredProcedureGrammar.java
Tue Nov 29 11:07:35 2005
@@ -122,7 +122,8 @@
                         }
                         else
                         {
-                            byte[] language = tlv.getValue().getData();
+                            // Only this field's type is String by default
+                            String language = StringUtils.toUtf8( tlv.getValue().getData()
);
                             
                             storedProcedurePojo = new StoredProcedurePojo();
                             



Mime
View raw message