You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by he...@apache.org on 2004/09/29 11:26:00 UTC

svn commit: rev 47477 - in webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src: java/org/apache/axis java/org/apache/axis/context java/org/apache/axis/engine java/org/apache/axis/providers java/org/apache/axis/registry test/org/apache/axis/engine test/org/apache/axis/engine/registry

Author: hemapani
Date: Wed Sep 29 02:25:59 2004
New Revision: 47477

Added:
   webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/Constants.java
   webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/Provider.java
   webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/context/
   webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/context/GlobalContext.java
   webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/context/SessionContext.java
   webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/context/SimpleSessionContext.java
   webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/providers/
   webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/providers/AbstractProvider.java
   webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/providers/SimpleJavaProvider.java
   webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/registry/ConcreateParameter.java
   webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/test/org/apache/axis/engine/EchoService.java
Modified:
   webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/AxisFault.java
   webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/engine/AxisEngine.java
   webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/engine/HandlerInvoker.java
   webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/engine/MessageContext.java
   webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/engine/Operation.java
   webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/engine/Service.java
   webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/engine/SimpleOperation.java
   webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/engine/SimpleService.java
   webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/registry/Parameter.java
   webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/test/org/apache/axis/engine/EngineTest.java
   webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/test/org/apache/axis/engine/registry/SpeakingProvider.java
Log:
add the simple java provider implementation to the Engine

Modified: webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/AxisFault.java
==============================================================================
--- webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/AxisFault.java	(original)
+++ webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/AxisFault.java	Wed Sep 29 02:25:59 2004
@@ -16,6 +16,8 @@
 
 package org.apache.axis;
 
+import java.lang.reflect.InvocationTargetException;
+
 
 /**
  * An exception which maps cleanly to a SOAP fault.
@@ -57,5 +59,32 @@
         super(arg0, arg1);
         // TODO Auto-generated constructor stub
     }
+    
+    /**
+    * Make an AxisFault based on a passed Exception.  If the Exception is
+    * already an AxisFault, simply use that.  Otherwise, wrap it in an
+    * AxisFault.  If the Exception is an InvocationTargetException (which
+    * already wraps another Exception), get the wrapped Exception out from
+    * there and use that instead of the passed one.
+    *
+    * @param e the <code>Exception</code> to build a fault for
+    * @return  an <code>AxisFault</code> representing <code>e</code>
+    */
+   public static AxisFault makeFault(Exception e)
+   {
+       if (e instanceof InvocationTargetException) {
+           Throwable t = ((InvocationTargetException)e).getTargetException();
+           if (t instanceof Exception) {
+               e = (Exception)t;
+           }
+       }
+
+       if (e instanceof AxisFault) {
+           return (AxisFault)e;
+       }
+
+       return new AxisFault(e.getMessage(),e);
+   }
+
 
 }

Added: webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/Constants.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/Constants.java	Wed Sep 29 02:25:59 2004
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2003,2004 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.axis;
+
+/**
+ * @author Srinath Perera(hemapani@opensource.lk)
+ */
+public class Constants {
+    public static final String APPLICATION_SCOPE = "application";
+    public static final String SESSION_SCOPE = "session";
+    public static final String GLOBAL_SCOPE = "global";
+}

Added: webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/Provider.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/Provider.java	Wed Sep 29 02:25:59 2004
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2003,2004 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.axis;
+
+import javax.xml.namespace.QName;
+
+/**
+ * This Provider is the workhorse who locate the implementation of the Web Service and 
+ * invoke the Web Service. 
+ * @author Srinath Perera(hemapani@opensource.lk)
+ */
+public interface Provider extends Handler{
+    public QName getName();
+}    
\ No newline at end of file

Added: webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/context/GlobalContext.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/context/GlobalContext.java	Wed Sep 29 02:25:59 2004
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2003,2004 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.axis.context;
+
+import java.util.HashMap;
+
+import org.apache.axis.registry.EngineRegistry;
+
+/**
+ * @author Srinath Perera(hemapani@opensource.lk)
+ */
+public class GlobalContext {
+    
+    private EngineRegistry registry;
+    private HashMap map = new HashMap();
+    
+    public GlobalContext(EngineRegistry er){
+        this.registry = er;
+    }
+
+    public Object get(Object key) {
+        return map.get(key);
+    }
+
+    public void put(String key, Object obj) {
+        map.put(key,obj);
+
+    }
+
+    /**
+     * @return
+     */
+    public EngineRegistry getRegistry() {
+        return registry;
+    }
+
+    /**
+     * @param registry
+     */
+    public void setRegistry(EngineRegistry registry) {
+        this.registry = registry;
+    }
+
+}

Added: webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/context/SessionContext.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/context/SessionContext.java	Wed Sep 29 02:25:59 2004
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2003,2004 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.axis.context;
+
+/**
+ * @author Srinath Perera(hemapani@opensource.lk)
+ */
+public interface SessionContext {
+    public Object get(Object key);
+    public void put(Object key,Object obj);
+}

Added: webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/context/SimpleSessionContext.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/context/SimpleSessionContext.java	Wed Sep 29 02:25:59 2004
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2003,2004 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.axis.context;
+
+import java.util.HashMap;
+
+/**
+ * @author Srinath Perera(hemapani@opensource.lk)
+ */
+public class SimpleSessionContext implements SessionContext {
+    private HashMap map = new HashMap();
+    public Object get(Object key) {
+        return map.get(key);
+    }
+
+    public void put(Object key, Object obj) {
+        map.put(key,obj);
+
+    }
+}

Modified: webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/engine/AxisEngine.java
==============================================================================
--- webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/engine/AxisEngine.java	(original)
+++ webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/engine/AxisEngine.java	Wed Sep 29 02:25:59 2004
@@ -39,7 +39,7 @@
         log.info("Axis Engine Started");        
         this.registry = registry;
     }
-    
+
     public void send(MessageContext mc)throws AxisFault{
         Stack executionStack = new Stack();
         QName currentTansportName = null;
@@ -90,7 +90,7 @@
         log.info("end the send()");
     }
     
-    public  void recive(MessageContext mc)throws AxisFault{
+    public void recive(MessageContext mc)throws AxisFault{
         Stack executionStack = new Stack();
         QName currentTansportName = null;
         QName currentServiceName = null;
@@ -123,6 +123,7 @@
             service.recive(mc);
             executionStack.push(service);
         }catch(AxisFault e){
+            e.printStackTrace();
             while(!executionStack.isEmpty()){
                 CommonExecutor commonExecutor = (CommonExecutor)executionStack.pop();
                 commonExecutor.rollback(mc);

Modified: webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/engine/HandlerInvoker.java
==============================================================================
--- webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/engine/HandlerInvoker.java	(original)
+++ webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/engine/HandlerInvoker.java	Wed Sep 29 02:25:59 2004
@@ -69,9 +69,9 @@
     public void revoke(MessageContext msgcontext)throws AxisFault{
         int length = handlers.size();
         if(currentHandlerIndex == 0){
-            currentHandlerIndex = length;
+            currentHandlerIndex = length -1;
         }
-        for(;currentHandlerIndex > 0 ;currentHandlerIndex--){
+        for(;currentHandlerIndex >= 0 ;currentHandlerIndex--){
             Handler handler = (Handler)handlers.get(currentHandlerIndex);
             handler.revoke(msgcontext); 
         }

Modified: webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/engine/MessageContext.java
==============================================================================
--- webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/engine/MessageContext.java	(original)
+++ webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/engine/MessageContext.java	Wed Sep 29 02:25:59 2004
@@ -17,6 +17,11 @@
 package org.apache.axis.engine;
 
 import javax.xml.namespace.QName;
+
+import org.apache.axis.context.GlobalContext;
+import org.apache.axis.context.SessionContext;
+import org.apache.axis.context.SimpleSessionContext;
+import org.apache.axis.registry.EngineRegistry;
 /**
  *  The palce where all the service specific states are kept. 
  *  All the Global states kept in the <code>EngineRegistry</code> and all the 
@@ -24,11 +29,20 @@
  *  artifacts does not keep states foward from the execution.  
  */
 public class MessageContext {
+    public MessageContext(EngineRegistry er){
+        globalContext = new GlobalContext(er);
+        sessionContext = new SimpleSessionContext();
+    }
+    
+    
     private boolean processingFault = false;
     private QName currentTansport = null; 
     private QName currentService = null;
     private QName currentOperation = null;
     
+    private SessionContext sessionContext;
+    private GlobalContext globalContext;
+    
     
     public boolean isProcessingFault(){
         return processingFault;
@@ -78,6 +92,34 @@
      */
     public QName getCurrentService() {
         return currentService;
+    }
+
+    /**
+     * @return
+     */
+    public GlobalContext getGlobalContext() {
+        return globalContext;
+    }
+
+    /**
+     * @return
+     */
+    public SessionContext getSessionContext() {
+        return sessionContext;
+    }
+
+    /**
+     * @param context
+     */
+    public void setGlobalContext(GlobalContext context) {
+        globalContext = context;
+    }
+
+    /**
+     * @param context
+     */
+    public void setSessionContext(SessionContext context) {
+        sessionContext = context;
     }
 
 }

Modified: webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/engine/Operation.java
==============================================================================
--- webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/engine/Operation.java	(original)
+++ webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/engine/Operation.java	Wed Sep 29 02:25:59 2004
@@ -17,13 +17,10 @@
 package org.apache.axis.engine;
 
 import org.apache.axis.CommonExecutor;
-import org.apache.axis.Handler;
 import org.apache.axis.registry.FlowInclude;
 import org.apache.axis.registry.NamedEngineElement;
 /**
  * Runtime representation of the WSDL Operation
  */
 public interface Operation extends FlowInclude,NamedEngineElement,CommonExecutor{
-    public Handler getProvider();
-    public void setProvider(Handler handler);
 }

Modified: webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/engine/Service.java
==============================================================================
--- webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/engine/Service.java	(original)
+++ webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/engine/Service.java	Wed Sep 29 02:25:59 2004
@@ -19,6 +19,7 @@
 import javax.xml.namespace.QName;
 
 import org.apache.axis.CommonExecutor;
+import org.apache.axis.Handler;
 import org.apache.axis.registry.FlowInclude;
 import org.apache.axis.registry.ModuleInclude;
 import org.apache.axis.registry.NamedEngineElement;
@@ -32,6 +33,9 @@
     TypeMappingInclude,CommonExecutor,ModuleInclude{
     public Operation getOperation(QName index);
     public void addOperation(Operation op);
-    
+    public Handler getProvider();
+    public Handler getSender();
+    public void setProvider(Handler handler);    
     public ClassLoader getClassLoader();
+    public void setClassLoader(ClassLoader cl);    
 }

Modified: webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/engine/SimpleOperation.java
==============================================================================
--- webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/engine/SimpleOperation.java	(original)
+++ webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/engine/SimpleOperation.java	Wed Sep 29 02:25:59 2004
@@ -26,34 +26,35 @@
 public class SimpleOperation extends ConcreateCommonExecuter implements Operation{
     private Log log = LogFactory.getLog(getClass());   
     private QName name;
-    private Handler provider;
+    private Service service;
     
-    
-    public SimpleOperation(QName name){
+    /**
+     * Each Operatrion must have a associated Service. The  service need to be specified 
+     * at the initialization of the Operation.  
+     * @param name
+     * @param service
+     */
+    public SimpleOperation(QName name,Service service){
         this.name = name;
+        this.service = service;
     }
     public void recive(MessageContext mc) throws AxisFault {
         super.recive(mc);
-        Handler provider = getProvider();
+        Handler provider = service.getProvider();
         if(provider != null){
             log.info("invoking the Provider");
             provider.invoke(mc);            
+        }else{
+            throw new AxisFault("provider is null");
         }
     }
 
     public void send(MessageContext mc) throws AxisFault {
         super.send(mc);
+        Handler provider = service.getProvider();
+        //TODO invoke the sender here
     }
     public QName getName() {
         return name;
     }
-
-    public Handler getProvider() {
-        return provider;
-    }
-
-    public void setProvider(Handler handler) {
-        provider = handler;
-    }
-
 }

Modified: webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/engine/SimpleService.java
==============================================================================
--- webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/engine/SimpleService.java	(original)
+++ webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/engine/SimpleService.java	Wed Sep 29 02:25:59 2004
@@ -21,6 +21,7 @@
 import javax.xml.namespace.QName;
 
 import org.apache.axis.AxisFault;
+import org.apache.axis.Handler;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -28,6 +29,9 @@
     private Log log = LogFactory.getLog(getClass());     
     private HashMap operations = new HashMap();
     private QName name;
+    private Handler provider;
+    private Handler sender;    
+    private ClassLoader classLoader;
     
     public SimpleService(QName name){
         this.name = name;
@@ -66,6 +70,34 @@
 
     public void addOperation(Operation op) {
         operations.put(op.getName(),op);
+    }
+
+    public Handler getProvider() {
+        return provider;
+    }
+
+    public void setProvider(Handler provider) {
+        this.provider = provider;
+
+    }
+
+    public void setClassLoader(ClassLoader cl) {
+        this.classLoader = cl;
+
+    }
+
+    /**
+     * @return
+     */
+    public Handler getSender() {
+        return sender;
+    }
+
+    /**
+     * @param handler
+     */
+    public void setSender(Handler handler) {
+        sender = handler;
     }
 
 }

Added: webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/providers/AbstractProvider.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/providers/AbstractProvider.java	Wed Sep 29 02:25:59 2004
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2003,2004 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.axis.providers;
+
+import java.lang.reflect.Method;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axis.*;
+import org.apache.axis.AxisFault;
+import org.apache.axis.Handler;
+import org.apache.axis.engine.MessageContext;
+import org.apache.axis.registry.AbstractEngineElement;
+
+/**
+ * This is the Absract provider. It is just a another handler. the 
+ * protected abstract methods are only for the sake of braking down the logic
+ * @author Srinath Perera(hemapani@opensource.lk)
+ */
+public abstract class AbstractProvider extends AbstractEngineElement implements Handler, Provider{
+    private QName name;
+    private String scope;
+    
+    protected abstract Object makeNewServiceObject(MessageContext msgContext)throws AxisFault;
+
+    public abstract Object getTheImplementationObject(
+            MessageContext msgContext)throws AxisFault;
+    
+    public abstract Object[] deserializeParameters(MessageContext msgContext,Method method)throws AxisFault;
+
+
+    public QName getName() {
+        return name;
+    }
+
+    public void setName(QName name) {
+        this.name = name;
+    }
+}

Added: webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/providers/SimpleJavaProvider.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/providers/SimpleJavaProvider.java	Wed Sep 29 02:25:59 2004
@@ -0,0 +1,161 @@
+/*
+ * Copyright 2001-2004 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.axis.providers;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axis.AxisFault;
+import org.apache.axis.Constants;
+import org.apache.axis.Handler;
+import org.apache.axis.context.SessionContext;
+import org.apache.axis.engine.MessageContext;
+import org.apache.axis.engine.Service;
+import org.apache.axis.registry.Parameter;
+
+/**
+ * This is a Simple java Provider. 
+ * @author Srinath Perera(hemapani@opensource.lk)
+ */
+
+public class SimpleJavaProvider extends AbstractProvider implements Handler {
+    private String message;
+    private QName name;
+    private String scope;
+    private Method method;
+    private ClassLoader classLoader;
+    
+    public SimpleJavaProvider(){
+        scope = Constants.APPLICATION_SCOPE;
+
+    }
+    
+    protected Object makeNewServiceObject(MessageContext msgContext)
+        throws AxisFault
+    {
+        try {
+            QName serviceName = msgContext.getCurrentService();
+            Service service = msgContext.getGlobalContext().getRegistry().getService(serviceName);
+            classLoader = service.getClassLoader();
+            Parameter classParm = service.getParameter("className");
+            String className = (String)classParm.getValue();
+            if(className == null)
+                throw new AxisFault("className parameter is null");
+            if(classLoader == null){
+                classLoader = Thread.currentThread().getContextClassLoader();
+            }
+            Class implClass =Class.forName(className,true,classLoader);
+            return implClass.newInstance();
+        } catch (Exception e) {
+            throw AxisFault.makeFault(e);
+        }
+    }
+
+    public Object getTheImplementationObject(
+            MessageContext msgContext)throws AxisFault{
+        QName serviceName = msgContext.getCurrentService();                
+        if(Constants.APPLICATION_SCOPE.equals(scope)){
+            return makeNewServiceObject(msgContext);
+        }else if(Constants.SESSION_SCOPE.equals(scope)){
+            SessionContext sessionContext = msgContext.getSessionContext();
+            Object obj = sessionContext.get(serviceName);
+            if(obj == null){
+                obj = makeNewServiceObject(msgContext);
+                sessionContext.put(serviceName,obj);
+            }
+            return obj;            
+        }else if(Constants.GLOBAL_SCOPE.equals(scope)){
+            SessionContext globalContext = msgContext.getSessionContext();
+            Object obj = globalContext.get(serviceName);
+            if(obj == null){
+                obj = makeNewServiceObject(msgContext);
+                globalContext.put(serviceName,obj);
+            }
+            return obj;
+        }else{
+            throw new AxisFault("unknown scope "+ scope);
+        }
+            
+    } 
+    
+    public Object[] deserializeParameters(MessageContext msgContext,Method method){
+        //TODO deserialize the parameters here
+        return null;
+    }
+
+
+    public QName getName() {
+        return name;
+    }
+
+    public void invoke(MessageContext msgContext) throws AxisFault {
+        try {
+            //get the implementation class for the Web Service 
+            Object obj = getTheImplementationObject(msgContext);
+            
+            //find the WebService method  
+            Class ImplClass =obj.getClass();
+            String methodName = msgContext.getCurrentOperation().getLocalPart();
+            Method[] methods = ImplClass.getMethods();
+            for(int i = 0;i<methods.length;i++){
+                if(methods[i].getName().equals(methodName)){
+                    this.method = methods[i];
+                    break;
+                }
+            }
+            //deserialize (XML-> java)
+            Object[] parms = deserializeParameters(msgContext,method);
+            //invoke the WebService 
+            Object result = method.invoke(obj,parms);
+            //TODO create a OM and put this back to the MessgaeContext 
+            
+        }  catch (SecurityException e) {
+            throw AxisFault.makeFault(e);
+        } catch (IllegalArgumentException e) {
+            throw AxisFault.makeFault(e);
+        } catch (IllegalAccessException e) {
+            throw AxisFault.makeFault(e);
+        } catch (InvocationTargetException e) {
+            throw AxisFault.makeFault(e);
+        }
+    }
+
+    public void revoke(MessageContext msgContext) {
+        System.out.println("I am Speaking Provider revoking :)");
+    }
+
+    public void setName(QName name) {
+        this.name = name;
+    }
+
+    /**
+     * @return
+     */
+    public ClassLoader getClassLoader() {
+        return classLoader;
+    }
+
+    /**
+     * @param loader
+     */
+    public void setClassLoader(ClassLoader loader) {
+        classLoader = loader;
+    }
+
+}

Added: webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/registry/ConcreateParameter.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/registry/ConcreateParameter.java	Wed Sep 29 02:25:59 2004
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2003,2004 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.axis.registry;
+
+
+/**
+ * @author Srinath Perera(hemapani@opensource.lk)
+ */
+public class ConcreateParameter implements Parameter  {
+    private String name;
+    private String value;
+    private int type = TEXT_PARAMETER;
+    
+    public ConcreateParameter(String name,String value) {
+        this.name = name;
+        this.value = value;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public Object getValue() {
+        return value;
+    }
+    public int getParameterType() {
+        return type;
+    }
+
+}

Modified: webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/registry/Parameter.java
==============================================================================
--- webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/registry/Parameter.java	(original)
+++ webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/java/org/apache/axis/registry/Parameter.java	Wed Sep 29 02:25:59 2004
@@ -17,6 +17,10 @@
 package org.apache.axis.registry;
 
 public interface Parameter {
+    public static int TEXT_PARAMETER = 0;
+    public static int DOM_PARAMETER = 1; 
+    
     public String getName();
     public Object getValue();
+    public int getParameterType();
 }

Added: webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/test/org/apache/axis/engine/EchoService.java
==============================================================================
--- (empty file)
+++ webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/test/org/apache/axis/engine/EchoService.java	Wed Sep 29 02:25:59 2004
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2003,2004 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.axis.engine;
+
+/**
+ * @author Srinath Perera(hemapani@opensource.lk)
+ */
+public class EchoService {
+    public void echoVoid(){
+        System.out.println("echo Service Called");
+    }
+}

Modified: webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/test/org/apache/axis/engine/EngineTest.java
==============================================================================
--- webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/test/org/apache/axis/engine/EngineTest.java	(original)
+++ webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/test/org/apache/axis/engine/EngineTest.java	Wed Sep 29 02:25:59 2004
@@ -21,16 +21,18 @@
 import junit.framework.TestCase;
 
 import org.apache.axis.engine.registry.MockFlow;
-import org.apache.axis.engine.registry.SpeakingProvider;
+import org.apache.axis.providers.SimpleJavaProvider;
+import org.apache.axis.registry.ConcreateParameter;
 import org.apache.axis.registry.EngineRegistry;
 import org.apache.axis.registry.Module;
+import org.apache.axis.registry.Parameter;
 import org.apache.axis.registry.SimpleEngineRegistry;
 
 /**
  * @author hemapani@opensource.lk
  */
 public class EngineTest extends TestCase{
-    private QName serviceName = new QName("","EchoVoidService");
+    private QName serviceName = new QName("","EchoService");
     private QName operationName = new QName("","echoVoid");
     private QName transportName = new QName("","NullTransport");
     private EngineRegistry engineRegistry;
@@ -60,19 +62,25 @@
         service.setInFlow(new MockFlow("service inflow",4));
         service.setOutFlow(new MockFlow("service outflow",5));
         service.setFaultFlow(new MockFlow("service faultflow",1));
+        service.setClassLoader(Thread.currentThread().getContextClassLoader());
+        
+        Parameter classParam = new ConcreateParameter("className",EchoService.class.getName());
+        service.addParameter(classParam);
+         
+        service.setProvider(new SimpleJavaProvider());
         
         Module m1 = new SimpleModule(new QName("","A Mdoule 1"));
         m1.setInFlow(new MockFlow("service module inflow",4));
         m1.setFaultFlow(new MockFlow("service module faultflow",1));
         service.addModule(m1);
         
-        Operation operation = new SimpleOperation(operationName);
+        Operation operation = new SimpleOperation(operationName,service);
         operation.setInFlow(new MockFlow("inflow",4));
-        operation.setProvider(new SpeakingProvider());
+        
         service.addOperation(operation);
         engineRegistry.addService(service);
         
-        mc = new MessageContext();
+        mc = new MessageContext(engineRegistry);
         mc.setCurrentTansport(transportName);
         mc.setCurrentService(serviceName);
         mc.setCurrentOperation(operationName);

Modified: webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/test/org/apache/axis/engine/registry/SpeakingProvider.java
==============================================================================
--- webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/test/org/apache/axis/engine/registry/SpeakingProvider.java	(original)
+++ webservices/axis/trunk/java/dev/scratch/srinath_eran_jaliya/src/test/org/apache/axis/engine/registry/SpeakingProvider.java	Wed Sep 29 02:25:59 2004
@@ -16,22 +16,17 @@
 
 package org.apache.axis.engine.registry;
 
-import javax.xml.namespace.QName;
+import java.lang.reflect.Method;
 
 import org.apache.axis.AxisFault;
 import org.apache.axis.Handler;
 import org.apache.axis.engine.MessageContext;
-import org.apache.axis.registry.AbstractEngineElement;
+import org.apache.axis.providers.AbstractProvider;
 
-public class SpeakingProvider extends AbstractEngineElement implements Handler {
+public class SpeakingProvider extends AbstractProvider implements Handler {
     private String message;
-    private QName name;
-    
     public SpeakingProvider(){}
 
-    public QName getName() {
-        return name;
-    }
 
     public void invoke(MessageContext msgContext) throws AxisFault {
         System.out.println("I am Speaking Provider Running :)");
@@ -40,9 +35,26 @@
     public void revoke(MessageContext msgContext) {
         System.out.println("I am Speaking Provider revoking :)");
     }
+    /* (non-Javadoc)
+     * @see org.apache.axis.engine.AbstractProvider#deserializeParameters(org.apache.axis.engine.MessageContext, java.lang.reflect.Method)
+     */
+    public Object[] deserializeParameters(
+        MessageContext msgContext,
+        Method method)
+        throws AxisFault {
+        return null;
+    }
+
+    public Object getTheImplementationObject(MessageContext msgContext)
+        throws AxisFault {
+        return null;
+    }
 
-    public void setName(QName name) {
-        this.name = name;
+    protected Object makeNewServiceObject(
+        MessageContext msgContext)
+        throws AxisFault {
+        // TODO Auto-generated method stub
+        return null;
     }
 
 }