incubator-agila-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mr...@apache.org
Subject svn commit: r165042 [18/30] - in /incubator/agila/trunk: ./ config/ modules/ modules/bpel/ modules/bpel/client/ modules/bpel/client/api/ modules/bpel/client/api/src/ modules/bpel/client/api/src/conf/ modules/bpel/client/api/src/java/ modules/bpel/client/api/src/java/org/ modules/bpel/client/api/src/java/org/apache/ modules/bpel/client/api/src/java/org/apache/agila/ modules/bpel/client/api/src/java/org/apache/agila/bpel/ modules/bpel/client/api/src/java/org/apache/agila/bpel/client/ modules/bpel/client/api/src/test/ modules/bpel/client/api/src/test/junit/ modules/bpel/client/api/src/test/junit/org/ modules/bpel/client/api/src/test/junit/org/apache/ modules/bpel/client/api/src/test/junit/org/apache/agila/ modules/bpel/client/api/src/test/junit/org/apache/agila/bpel/ modules/bpel/client/api/src/test/junit/org/apache/agila/bpel/client/ modules/bpel/client/web/ modules/bpel/client/web/src/ modules/bpel/client/web/src/conf/ modules/bpel/client/web/src/java/ modules/bpel/client/web/src/java/org/ modules/bpel/client/web/src/java/org/apache/ modules/bpel/client/web/src/java/org/apache/agila/ modules/bpel/client/web/src/java/org/apache/agila/bpel/ modules/bpel/client/web/src/java/org/apache/agila/bpel/web/ modules/bpel/client/web/src/java/org/apache/agila/bpel/web/common/ modules/bpel/client/web/src/java/org/apache/agila/bpel/web/deployer/ modules/bpel/client/web/src/java/org/apache/agila/bpel/web/deployer/action/ modules/bpel/client/web/src/java/org/apache/agila/bpel/web/deployer/form/ modules/bpel/client/web/src/java/org/apache/agila/bpel/web/engine/ modules/bpel/client/web/src/java/org/apache/agila/bpel/web/engine/action/ modules/bpel/client/web/src/java/org/apache/agila/bpel/web/engine/form/ modules/bpel/client/web/src/java/org/apache/agila/bpel/web/global/ modules/bpel/client/web/src/java/org/apache/agila/bpel/web/global/action/ modules/bpel/client/web/src/java/org/apache/agila/bpel/web/security/ modules/bpel/client/web/src/java/org/apache/agila/bpel/web/security/action/ modules/bpel/client/web/src/java/org/apache/agila/bpel/web/security/form/ modules/bpel/client/web/src/java/org/apache/agila/bpel/web/user/ modules/bpel/client/web/src/java/org/apache/agila/bpel/web/user/action/ modules/bpel/client/web/src/java/org/apache/agila/bpel/web/user/form/ modules/bpel/client/web/src/java/org/apache/agila/bpel/web/util/ modules/bpel/client/web/src/java/org/apache/agila/bpel/web/worklist/ modules/bpel/client/web/src/java/org/apache/agila/bpel/web/worklist/action/ modules/bpel/client/web/src/webapp/ modules/bpel/client/web/src/webapp/META-INF/ modules/bpel/client/web/src/webapp/WEB-INF/ modules/bpel/client/web/src/webapp/WEB-INF/classes/ modules/bpel/client/web/src/webapp/images/ modules/bpel/client/web/src/webapp/images/audit/ modules/bpel/client/web/src/webapp/style/ modules/bpel/common/ modules/bpel/common/src/ modules/bpel/common/src/aspect/ modules/bpel/common/src/conf/ modules/bpel/common/src/java/ modules/bpel/common/src/java/org/ modules/bpel/common/src/java/org/apache/ modules/bpel/common/src/java/org/apache/agila/ modules/bpel/common/src/java/org/apache/agila/bpel/ modules/bpel/common/src/java/org/apache/agila/bpel/common/ modules/bpel/common/src/java/org/apache/agila/bpel/common/aspect/ modules/bpel/common/src/java/org/apache/agila/bpel/common/configuration/ modules/bpel/common/src/java/org/apache/agila/bpel/common/util/ modules/bpel/common/src/java/org/apache/agila/bpel/common/util/logger/ modules/bpel/common/src/test/ modules/bpel/common/src/test/junit/ modules/bpel/common/src/test/junit/org/ modules/bpel/common/src/test/junit/org/apache/ modules/bpel/common/src/test/junit/org/apache/agila/ modules/bpel/common/src/test/junit/org/apache/agila/bpel/ modules/bpel/common/src/test/junit/org/apache/agila/bpel/common/ modules/bpel/common/src/test/junit/org/apache/agila/bpel/common/util/ modules/bpel/dist/ modules/bpel/dist/src/ modules/bpel/dist/src/java/ modules/bpel/dist/src/java/org/ modules/bpel/dist/src/java/org/apache/ modules/bpel/dist/src/java/org/apache/agila/ modules/bpel/dist/src/java/org/apache/agila/bpel/ modules/bpel/dist/src/java/org/apache/agila/bpel/util/ modules/bpel/dist/src/script/ modules/bpel/engine/ modules/bpel/engine/common/ modules/bpel/engine/common/src/ modules/bpel/engine/common/src/aspect/ modules/bpel/engine/common/src/hibernate/ modules/bpel/engine/common/src/hibernate/org/ modules/bpel/engine/common/src/hibernate/org/apache/ modules/bpel/engine/common/src/hibernate/org/apache/agila/ modules/bpel/engine/common/src/hibernate/org/apache/agila/bpel/ modules/bpel/engine/common/src/hibernate/org/apache/agila/bpel/engine/ modules/bpel/engine/common/src/hibernate/org/apache/agila/bpel/engine/common/ modules/bpel/engine/common/src/java/ modules/bpel/engine/common/src/java/org/ modules/bpel/engine/common/src/java/org/apache/ modules/bpel/engine/common/src/java/org/apache/agila/ modules/bpel/engine/common/src/java/org/apache/agila/bpel/ modules/bpel/engine/common/src/java/org/apache/agila/bpel/engine/ modules/bpel/engine/common/src/java/org/apache/agila/bpel/engine/common/ modules/bpel/engine/common/src/java/org/apache/agila/bpel/engine/common/aspect/ modules/bpel/engine/common/src/java/org/apache/agila/bpel/engine/common/event/ modules/bpel/engine/common/src/java/org/apache/agila/bpel/engine/common/event/execution/ modules/bpel/engine/common/src/java/org/apache/agila/bpel/engine/common/event/execution/impl/ modules/bpel/engine/common/src/java/org/apache/agila/bpel/engine/common/event/lifecycle/ modules/bpel/engine/common/src/java/org/apache/agila/bpel/engine/common/event/lifecycle/dao/ modules/bpel/engine/common/src/java/org/apache/agila/bpel/engine/common/lifecycle/ modules/bpel/engine/common/src/java/org/apache/agila/bpel/engine/common/monitoring/ modules/bpel/engine/common/src/java/org/apache/agila/bpel/engine/common/persistence/ modules/bpel/engine/common/src/java/org/apache/agila/bpel/engine/common/transaction/ modules/bpel/engine/common/src/test/ modules/bpel/engine/common/src/test/junit/ modules/bpel/engine/common/src/test/junit/org/ modules/bpel/engine/common/src/test/junit/org/apache/ modules/bpel/engine/common/src/test/junit/org/apache/agila/ modules/bpel/engine/common/src/test/junit/org/apache/agila/bpel/ modules/bpel/engine/common/src/test/junit/org/apache/agila/bpel/engine/ modules/bpel/engine/common/src/test/junit/org/apache/agila/bpel/engine/common/ modules/bpel/engine/common/src/test/junit/org/apache/agila/bpel/engine/common/event/ modules/bpel/engine/common/src/test/resources/ modules/bpel/engine/core/ modules/bpel/engine/core/src/ modules/bpel/engine/core/src/aspect/ modules/bpel/engine/core/src/hibernate/ modules/bpel/engine/core/src/hibernate/org/ modules/bpel/engine/core/src/hibernate/org/apache/ modules/bpel/engine/core/src/hibernate/org/apache/agila/ modules/bpel/engine/core/src/hibernate/org/apache/agila/bpel/ modules/bpel/engine/core/src/hibernate/org/apache/agila/bpel/engine/ modules/bpel/engine/core/src/java/ modules/bpel/engine/core/src/java/org/ modules/bpel/engine/core/src/java/org/apache/ modules/bpel/engine/core/src/java/org/apache/agila/ modules/bpel/engine/core/src/java/org/apache/agila/bpel/ modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/ modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/exception/ modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/ modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/ modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/definition/ modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/definition/impl/ modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/definition/impl/dao/ modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/ modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/impl/ modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/impl/dao/ modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/impl/xao/ modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/expression/ modules/bpel/engine/core/s
Date Wed, 27 Apr 2005 20:28:07 GMT
Added: incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/messaging/impl/WSMessageBroker.java
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/messaging/impl/WSMessageBroker.java?rev=165042&view=auto
==============================================================================
--- incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/messaging/impl/WSMessageBroker.java (added)
+++ incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/messaging/impl/WSMessageBroker.java Wed Apr 27 13:27:43 2005
@@ -0,0 +1,430 @@
+/*
+ * Copyright 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.agila.bpel.engine.priv.messaging.impl;
+
+import EDU.oswego.cs.dl.util.concurrent.BoundedBuffer;
+import EDU.oswego.cs.dl.util.concurrent.PooledExecutor;
+import org.apache.axis.MessageContext;
+import org.apache.axis.client.Call;
+import org.apache.axis.message.SOAPBodyElement;
+import org.apache.axis.utils.XMLUtils;
+import org.apache.log4j.Logger;
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.DocumentHelper;
+import org.dom4j.io.DOMReader;
+import org.dom4j.io.DOMWriter;
+import org.dom4j.io.SAXReader;
+import org.apache.agila.bpel.engine.common.event.execution.ExecutionEvent;
+import org.apache.agila.bpel.engine.common.event.EventManager;
+import org.apache.agila.bpel.engine.common.event.execution.ExecutionEvent;
+import org.apache.agila.bpel.engine.common.persistence.FinderException;
+import org.apache.agila.bpel.engine.common.persistence.XMLDataAccess;
+import org.apache.agila.bpel.engine.common.persistence.XMLSessionException;
+import org.apache.agila.bpel.engine.priv.core.definition.Activity;
+import org.apache.agila.bpel.engine.priv.core.definition.AgilaProcess;
+import org.apache.agila.bpel.engine.priv.messaging.InvocationException;
+import org.apache.agila.bpel.engine.priv.messaging.MessageBroker;
+import org.apache.agila.bpel.engine.priv.messaging.MessageFilter;
+import org.apache.agila.bpel.engine.priv.messaging.FilterException;
+import org.apache.agila.bpel.engine.exception.EngineRuntimeException;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Node;
+import org.w3c.dom.Element;
+
+import javax.wsdl.*;
+import javax.wsdl.extensions.ExtensibilityElement;
+import javax.wsdl.extensions.soap.SOAPBody;
+import javax.wsdl.extensions.soap.SOAPOperation;
+import javax.wsdl.extensions.soap.SOAPBinding;
+import javax.wsdl.factory.WSDLFactory;
+import javax.wsdl.xml.WSDLReader;
+import javax.xml.namespace.QName;
+import javax.xml.rpc.ServiceException;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.rmi.RemoteException;
+import java.util.*;
+
+/**
+ * Invokes a web service from a WSDL definition.
+ * @author mriou
+ * @author norsch
+ * @author chudick
+ */
+public class WSMessageBroker extends MessageBroker {
+
+    private static Logger log = Logger.getLogger(WSMessageBroker.class);
+
+    /**
+     * @TODO parameterize this
+     */
+    private PooledExecutor threadPool = new PooledExecutor(new BoundedBuffer(10), 100);
+    private static HashMap wsdlCache = new HashMap();
+
+    private static final String DEFINITIONS = "definitions";
+    private static final String SOAP_NS = "http://schemas.xmlsoap.org/wsdl/soap/";
+
+    private static DOMReader domReader = null;
+    private static DOMWriter domWriter = null;
+    private static SAXReader saxReader = null;
+
+    protected void asyncSend(Activity sender, String partner, String portType, String operation, Document message) {
+        final Activity fsender = sender;
+        final String fpartner = partner;
+        final String fportType = portType;
+        final String foperation = operation;
+        final Document fmessage = message;
+        try {
+            threadPool.execute(new Runnable() {
+                public void run() {
+                    syncSend(fsender, fpartner, fportType, foperation, fmessage);
+                }
+            });
+        } catch (InterruptedException e) {
+            log.error("Could not send message to " + portType + " : " + message.asXML(), e);
+        }
+    }
+
+    protected void asyncSend(Activity sender, String partner, String namespace, String portType, String operation, Document message) {
+        asyncSend(sender, partner, portType, operation, message);
+
+    }
+
+    protected Document syncSend(Activity sender, String partner, String portType, String operation, Document message) {
+        AgilaProcess process = sender.fetchProcess();
+        org.w3c.dom.Document wsdlDoc = getWSDLDesc(process.getNamespace(), process.getName());
+        Definition def = readWSDL(wsdlDoc);
+
+        String wsdlStringDoc = getDOMReader().read(wsdlDoc).asXML();
+        String nameSpaceURI = def.getTargetNamespace();
+        QName serviceName = getService(def, portType);
+        String[] wsdlAdditionalInfo = getWSDLAdditionalInfo(def, portType, operation);
+        String soapAction = wsdlAdditionalInfo[0];
+        String msgNS = null;
+        if (wsdlAdditionalInfo[1] != null && wsdlAdditionalInfo[1].length() > 0) {
+            msgNS = wsdlAdditionalInfo[1];
+        } else {
+            msgNS = nameSpaceURI;
+        }
+        String encoding = wsdlAdditionalInfo[2];
+        String operationStyle = wsdlAdditionalInfo[3];
+        InputStream wsdlDesc = new ByteArrayInputStream(wsdlStringDoc.getBytes());
+        Document preparedMsg = prepareMessage(message, operation, msgNS, encoding);
+
+        Document result = null;
+        try {
+            result = sendMessage(nameSpaceURI, serviceName,
+                                    portType, operation, soapAction, wsdlDesc, preparedMsg, operationStyle);
+
+            MessageFilter.filterMessage(result);
+
+            result.getRootElement().setName("message");
+        } catch (ServiceException e) {
+            log.error("Could not send message to " + portType + " : " + preparedMsg.asXML(), e);
+            EventManager.fireError(new Exception("Could not send message to " + portType + ". Reason:\n" + (e.getMessage() == null ? "unknown" : e.getMessage()) + "\nMessage:\n" + preparedMsg.asXML()));
+            throw new EngineRuntimeException(e);
+        } catch (RemoteException e) {
+            log.error("Could not send message to " + portType + " : " + preparedMsg.asXML(), e);
+            EventManager.fireError(new Exception("Could not send message to " + portType + ". Reason:\n" + (e.getMessage() == null ? "unknown" : e.getMessage()) + "\nMessage:\n" + preparedMsg.asXML()));
+            throw new EngineRuntimeException(e);
+        } catch (FilterException e) {
+            log.error("Could not send message to " + portType + " : " + preparedMsg.asXML(), e);
+            EventManager.fireError(new Exception("Could not send message to " + portType + ". Reason:\n" + (e.getMessage() == null ? "unknown" : e.getMessage()) + "\nMessage:\n" + preparedMsg.asXML()));
+            throw new EngineRuntimeException(e);
+        }
+        log.debug("Received message : " + result.asXML());
+        return result;
+    }
+
+    protected Document syncSend(Activity sender, String partner, String namespace, String portType, String operation, Document message) {
+        return syncSend(sender, partner, portType, operation, message);
+    }
+
+    private static org.dom4j.Document prepareMessage(Document doc, String elmtName,
+                                                     String namespace, String encoding) {
+        org.dom4j.QName qName = null;
+        if ("literal".equals(encoding)) {
+            qName = org.dom4j.QName.get(elmtName, "", namespace);
+        } else {
+            qName = org.dom4j.QName.get(elmtName, "ns1", namespace);
+        }
+        Document resultDoc = DocumentHelper.createDocument();
+        org.dom4j.Element root = DocumentHelper.createElement(qName);
+        resultDoc.add(root);
+        List elmtList = doc.getRootElement().elements();
+        for (int m = 0; m < elmtList.size(); m++) {
+            org.dom4j.Element detachedElmt = (org.dom4j.Element) ((org.dom4j.Element) elmtList.get(m)).detach();
+            root.add(detachedElmt);
+        }
+        return resultDoc;
+    }
+
+    private static Definition readWSDL(org.w3c.dom.Document wsdlDesc) {
+        WSDLFactory factory = null;
+        try {
+            factory = WSDLFactory.newInstance();
+        } catch (WSDLException e) {
+            throw new InvocationException("Could not find WSDL factory.", e);
+        }
+        WSDLReader reader = factory.newWSDLReader();
+        reader.setFeature("javax.wsdl.verbose", true);
+        reader.setFeature("javax.wsdl.importDocuments", false);
+
+        Definition def = null;
+        try {
+            def = reader.readWSDL(null, wsdlDesc);
+        } catch (WSDLException e) {
+            throw new InvocationException("Could not read a WSDL document.", e);
+        }
+        return def;
+    }
+
+    private static org.w3c.dom.Document getWSDLDesc(String processNS, String processName) {
+        org.w3c.dom.Document document = null;
+        try {
+            document = XMLDataAccess.getDOMDocument("/process/def", "" + (processNS + processName).hashCode());
+        } catch (XMLSessionException e) {
+            throw new InvocationException(e);
+        } catch (FinderException e) {
+            throw new InvocationException(e);
+        }
+        return document;
+    }
+
+    private static String[] getWSDLAdditionalInfo(Definition def, String portTypeName, String operationName) {
+        Map bindings = def.getBindings();
+        Binding portBinding = null;
+        if (bindings != null) {
+            for (Iterator bindingsIter = bindings.keySet().iterator(); bindingsIter.hasNext();) {
+                QName bindingName = (QName) bindingsIter.next();
+                Binding binding = (Binding) bindings.get(bindingName);
+                if (binding == null) {
+                    throw new InvocationException("Service " + def.getTargetNamespace() + " with port " +
+                                                      portTypeName + " doesn't have any " + bindingName + " binding declared.");
+                }
+                if (binding.getPortType().getQName().getLocalPart().equals(portTypeName)) {
+                    if (binding.getBindingOperation(operationName, null, null) == null) {
+                        throw new InvocationException("Service " + def.getTargetNamespace() + " with port " +
+                                                          portTypeName + " doesn't have the operation " + operationName +
+                                                          " declared in the port binding.");
+                    }
+                    portBinding = binding;
+                    break;
+                }
+            }
+        }
+        if (portBinding == null) {
+            throw new InvocationException("Could not find a binding for port " + portTypeName +
+                                              " in service " + def.getTargetNamespace());
+        }
+
+        // Extracting operation style (message or rpc)
+        String operationStyle = null;
+        List portBindingExts = portBinding.getExtensibilityElements();
+        for (int m = 0; m < portBindingExts.size(); m++) {
+            ExtensibilityElement extElmt = (ExtensibilityElement) portBindingExts.get(m);
+            if (SOAP_NS.equals(extElmt.getElementType().getNamespaceURI())) {
+                operationStyle = ((SOAPBinding) extElmt).getStyle();
+            }
+        }
+        if (operationStyle == null || (!"rpc".equals(operationStyle) && !"document".equals(operationStyle))) {
+            throw new InvocationException("Could not get the operation style associated with the binding, please " +
+                                              "make sure that you have a soap:binding element in your binding " +
+                                              "declaration defining a style (rpc/document)");
+        }
+        
+        String soapAction = null;
+        BindingOperation bindingOperation = portBinding.getBindingOperation(operationName, null, null);
+        List extensibilityElmts = bindingOperation.getExtensibilityElements();
+        for (int m = 0; m < extensibilityElmts.size(); m++) {
+            ExtensibilityElement extensibilityElement = (ExtensibilityElement) extensibilityElmts.get(m);
+            if (SOAP_NS.equals(extensibilityElement.getElementType().getNamespaceURI())) {
+                soapAction = ((SOAPOperation) extensibilityElement).getSoapActionURI();
+                break;
+            }
+        }
+
+        String msgUrl = null;
+        String encoding = null;
+        List bindingInputExt = bindingOperation.getBindingInput().getExtensibilityElements();
+        for (int m = 0; m < bindingInputExt.size(); m++) {
+            ExtensibilityElement extensibilityElement = (ExtensibilityElement) bindingInputExt.get(m);
+            extensibilityElement.getElementType().getNamespaceURI();
+            if (SOAP_NS.equals(extensibilityElement.getElementType().getNamespaceURI())) {
+                SOAPBody soapBodyExt = (SOAPBody) extensibilityElement;
+
+                msgUrl = soapBodyExt.getNamespaceURI();
+                encoding = soapBodyExt.getUse();
+            }
+
+        }
+
+        if (soapAction == null) {
+            log.info("No SOAPAction could be found for service " + def.getTargetNamespace() + " no SOAPAction element " +
+                         "will be included in the message.");
+        }
+
+        String[] result = new String[4];
+        result[0] = soapAction;
+        result[1] = msgUrl;
+        result[2] = encoding;
+        result[3] = operationStyle;
+
+        return result;
+    }
+
+    private static QName getService(Definition def, String port) {
+        Map services = def.getServices();
+        for (Iterator serviceIter = services.keySet().iterator(); serviceIter.hasNext();) {
+            QName serviceQName = (QName) serviceIter.next();
+            Service service = (Service) services.get(serviceQName);
+            if (service.getPort(port) != null) {
+                return service.getQName();
+            }
+        }
+        throw new InvocationException("No service have been defined for portType " + port);
+    }
+
+    private static Document sendMessage(String nameSpaceURI, QName serviceQName, String portType,
+                                                    String operation, String soapAction, InputStream wsdlDesc,
+                                                    Document sentDoc, String operationStyle)
+            throws ServiceException, RemoteException {
+
+        org.w3c.dom.Document domDoc = null;
+        try {
+            domDoc = getDOMWriter().write(sentDoc);
+        } catch (DocumentException e) {
+            throw new ServiceException(e);
+        }
+
+        org.apache.axis.client.Service service = new org.apache.axis.client.Service(wsdlDesc, serviceQName);
+        QName portQName = new QName(nameSpaceURI, portType);
+        Call call = (Call) service.createCall(portQName, operation);
+        call.setProperty(Call.SOAPACTION_USE_PROPERTY, new Boolean(true));
+        if (soapAction != null) {
+            call.setProperty(Call.SOAPACTION_URI_PROPERTY, soapAction);
+        }
+
+        SOAPBodyElement[] input;
+        if ("rpc".equals(operationStyle)) {
+            input = new SOAPBodyElement[1];
+            input[0] = new SOAPBodyElement(domDoc.getDocumentElement());
+        } else {
+            input = new SOAPBodyElement[sentDoc.getRootElement().elements().size()];
+            NodeList nodeList = domDoc.getDocumentElement().getChildNodes();
+            int elmtCount = 0;
+            for (int m = 0; m < nodeList.getLength(); m++) {
+                if (nodeList.item(m).getNodeType() == Node.ELEMENT_NODE) {
+                    input[elmtCount] = new SOAPBodyElement((Element) nodeList.item(m));
+                }
+            }
+        }
+        Vector results = (Vector) call.invoke(input);
+
+        // TODO (maybe protocol/log it)
+        MessageContext mc = call.getMessageContext();
+        log.info("============= Response ==============");
+        try {
+            XMLUtils.PrettyElementToStream(mc.getResponseMessage().getSOAPEnvelope().getAsDOM(), System.out);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        org.w3c.dom.Document result = null;
+        try {
+            result = ((SOAPBodyElement) results.get(0)).getAsDocument();
+        } catch (Exception e) {
+            throw new ServiceException(e);
+        }
+        return getDOMReader().read(result);
+    }
+
+    private static DOMReader getDOMReader() {
+        if (domReader == null) {
+            domReader = new DOMReader();
+        }
+        return domReader;
+    }
+
+    private static DOMWriter getDOMWriter() {
+        if (domWriter == null) {
+            domWriter = new DOMWriter();
+        }
+        return domWriter;
+    }
+
+    private static SAXReader getSAXReader() {
+        if (saxReader == null) {
+            saxReader = new SAXReader();
+        }
+        return saxReader;
+
+    }
+
+//    private org.w3c.dom.Document getWSDLDesc(String processNS, int processVersion) {
+//        org.w3c.dom.Document wsdlDoc = null;
+//        if (wsdlCache.get(processNS) != null) {
+//            // Easy way, get WSDL def in the cache
+//            return (org.w3c.dom.Document) wsdlCache.get(processNS);
+//        } else {
+//            // Hard way, get the BPEL doc and then the WSDL def
+//            String processFileName = DeployerConfiguration.getDeployDir()
+//                    + NSUtil.extractFileNameFromNS(processNS) + "~" + processVersion;
+//            Document bpelDoc = null;
+//            try {
+//                bpelDoc = getSAXReader().read(processFileName);
+//            } catch (DocumentException e) {
+//                throw new InvocationException("Could not read the process description: " + processFileName);
+//            }
+//            // Finding out the WSDL doc from namespaces declared in the BPEL description
+//            List namespaces = bpelDoc.getRootElement().declaredNamespaces();
+//            for (int m = 0; m < namespaces.size(); m++) {
+//                Namespace ns = (Namespace) namespaces.get(m);
+//                String referencedFilePath = NSUtil.extractFileNameFromNS(ns.getURI());
+//                File referencedFile = new File(DeployerConfiguration.getDeployDir() + referencedFilePath);
+//                if (referencedFile.exists()) {
+//                    Document referencedDoc = null;
+//                    try {
+//                        referencedDoc = getSAXReader().read(referencedFile);
+//                    } catch (DocumentException e) {
+//                        throw new InvocationException("Could not parse a the referenced WSDL document : "
+//                                + ns.getURI() + " / " + referencedFilePath);
+//                    } catch (MalformedURLException e) {
+//                        throw new InvocationException("Could not locate the referenced WSDL document : "
+//                                + ns.getURI() + " / " + referencedFilePath);
+//                    }
+//                    if (DEFINITIONS.equals(referencedDoc.getRootElement().getName())) {
+//                        try {
+//                            wsdlDoc = getDOMWriter().write(referencedDoc);
+//                        } catch (DocumentException e) {
+//                            throw new InvocationException("Could not create a DOM tree for  the referenced WSDL document : "
+//                                    + ns.getURI() + " / " + referencedFilePath);
+//                        }
+//                    }
+//                }
+//            }
+//
+//            if (wsdlDoc == null) {
+//                throw new InvocationException("Couldn't find the WSDL description for the process " + processNS
+//                        + ", please make sure it has been properly deployed.");
+//            } else {
+//                wsdlCache.put(processNS, wsdlDoc);
+//            }
+//        }
+//        return wsdlDoc;
+//    }
+}

Added: incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/package.html
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/package.html?rev=165042&view=auto
==============================================================================
--- incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/package.html (added)
+++ incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/package.html Wed Apr 27 13:27:43 2005
@@ -0,0 +1,4 @@
+<html>
+    <body>
+    </body>
+</html>
\ No newline at end of file

Added: incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/timer/EngineTimer.java
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/timer/EngineTimer.java?rev=165042&view=auto
==============================================================================
--- incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/timer/EngineTimer.java (added)
+++ incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/timer/EngineTimer.java Wed Apr 27 13:27:43 2005
@@ -0,0 +1,122 @@
+/*
+ * Copyright 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.agila.bpel.engine.priv.timer;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Timer;
+
+import org.apache.log4j.Logger;
+
+import org.apache.agila.bpel.engine.common.lifecycle.LifecycleAwareResource;
+import org.apache.agila.bpel.engine.common.lifecycle.LifecycleException;
+import org.apache.agila.bpel.engine.common.persistence.DBSessionException;
+import org.apache.agila.bpel.engine.common.persistence.PersistentDataAccess;
+import org.apache.agila.bpel.engine.common.transaction.TransactionException;
+import org.apache.agila.bpel.engine.common.transaction.TransactionManager;
+import org.apache.agila.bpel.engine.priv.timer.dao.ECTaskDAO;
+import org.apache.agila.bpel.engine.priv.timer.po.ECTaskPersister;
+
+/**
+ * A synchronized static timer that should be used by all instances of the Process
+ * Engine to schedule its tasks.
+ */
+public class EngineTimer implements LifecycleAwareResource {
+
+    private static Logger log = Logger.getLogger(EngineTimer.class);
+
+    private static Collection tasks;
+	public static Timer timer;
+
+	public static void schedule(ExecutionContextTask task, Date time) {
+        tasks.add(task);
+        persist(task, time);
+		timer.schedule(task, time);
+	}
+
+    public static void cancelTaskFor(Long ecId) {
+        ArrayList removeList = new ArrayList();
+        if (tasks != null) {
+	        for (Iterator tasksIter = tasks.iterator(); tasksIter.hasNext();) {
+	            ExecutionContextTask contextTask = (ExecutionContextTask) tasksIter.next();
+	            if (contextTask.getContextId().equals(ecId)) {
+	                contextTask.cancel();
+	                remove(contextTask);
+	                removeList.add(contextTask);
+	            }
+	        }
+	        tasks.removeAll(removeList);
+        }
+    }
+
+    private static void persist(ExecutionContextTask task, Date time) {
+        ECTaskPersister taskPersister = new ECTaskPersister();
+        taskPersister.setDueDate(time);
+        taskPersister.setEcId(task.getContextId());
+        taskPersister.setAdditionalInfo(task.getAdditionalInfo());
+        PersistentDataAccess.create(taskPersister);
+    }
+
+    private static void remove(ExecutionContextTask task) {
+        ECTaskPersister taskPersister = null;
+        try {
+            taskPersister = ECTaskDAO.findByECId(task.getContextId());
+        } catch (DBSessionException e) {
+            log.warn("Could not remove the task persister for a new task.", e);
+        }
+        PersistentDataAccess.remove(taskPersister);
+    }
+
+    public void create() throws LifecycleException {
+        tasks = new ArrayList();
+        timer = new Timer();
+    }
+
+    public void start() throws LifecycleException {
+        try {
+            TransactionManager.beginTransaction();
+        } catch (TransactionException e) {
+            throw new LifecycleException("Unable to start EngineTimer", e);
+        }
+        List ecTasks = PersistentDataAccess.findAll(ECTaskPersister.class);
+        for (int m = 0; m < ecTasks.size(); m++) {
+            ECTaskPersister taskPersister = (ECTaskPersister) ecTasks.get(m);
+            ExecutionContextTask ecTask = null;
+            if (taskPersister.getAdditionalInfo() == null || taskPersister.getAdditionalInfo().length() == 0) {
+                ecTask = new WaitECTask(taskPersister.getEcId());
+            } else {
+                ecTask = new PickECTask(taskPersister.getEcId(), new Integer(taskPersister.getAdditionalInfo()).intValue());
+            }
+            tasks.add(ecTask);
+            timer.schedule(ecTask, taskPersister.getDueDate());
+        }
+        try {
+            TransactionManager.commitTransaction();
+        } catch (TransactionException e) {
+            throw new LifecycleException("Unable to start EngineTimer", e);
+        }
+    }
+
+    public void stop() throws LifecycleException { }
+
+    public void destroy() throws LifecycleException {
+        tasks = null;
+        timer = null;
+    }
+}

Added: incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/timer/ExecutionContextTask.java
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/timer/ExecutionContextTask.java?rev=165042&view=auto
==============================================================================
--- incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/timer/ExecutionContextTask.java (added)
+++ incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/timer/ExecutionContextTask.java Wed Apr 27 13:27:43 2005
@@ -0,0 +1,25 @@
+/*
+ * Copyright 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.agila.bpel.engine.priv.timer;
+
+import java.util.TimerTask;
+
+public abstract class ExecutionContextTask extends TimerTask {
+
+    public abstract Long getContextId();
+
+    public abstract String getAdditionalInfo();
+}

Added: incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/timer/PickECTask.java
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/timer/PickECTask.java?rev=165042&view=auto
==============================================================================
--- incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/timer/PickECTask.java (added)
+++ incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/timer/PickECTask.java Wed Apr 27 13:27:43 2005
@@ -0,0 +1,75 @@
+/*
+ * Copyright 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.agila.bpel.engine.priv.timer;
+
+import org.apache.log4j.Logger;
+
+import org.apache.agila.bpel.engine.common.event.EventManager;
+import org.apache.agila.bpel.engine.common.persistence.DBSessionException;
+import org.apache.agila.bpel.engine.common.persistence.FinderException;
+import org.apache.agila.bpel.engine.common.transaction.TransactionException;
+import org.apache.agila.bpel.engine.common.transaction.TransactionManager;
+import org.apache.agila.bpel.engine.priv.core.dynamic.ExecutionContextFactory;
+import org.apache.agila.bpel.engine.priv.core.dynamic.PickEC;
+
+/**
+ * Callback for alarm events of pick execution contexts.
+ * @see EngineTimer
+ * @see org.apache.agila.bpel.engine.priv.core.dynamic.PickEC
+ */
+public class PickECTask extends ExecutionContextTask {
+
+    private Logger log = Logger.getLogger(PickECTask.class);
+
+    public Long pickECId;
+    private int activityPos;
+
+    public PickECTask(Long pickECId, int activityPos) {
+        this.pickECId = pickECId;
+        this.activityPos = activityPos;
+        if (log.isDebugEnabled()) {
+            log.debug("Registering a pick alarm for PickEC " + pickECId + " and activity pos " + activityPos);
+        }
+    }
+
+    public Long getContextId() {
+        return pickECId;
+    }
+
+    public void run() {
+        PickEC pickEC = null;
+        try {
+            TransactionManager.beginTransaction();
+            pickEC = (PickEC) ExecutionContextFactory.findECById(pickECId);
+            pickEC.notifyAlarm(activityPos);
+            TransactionManager.commitTransaction();
+        } catch (DBSessionException e) {
+            EventManager.fireError(e);
+            log.error("A database error occured when initializing a connection for querying an execution context.", e);
+        } catch (TransactionException e) {
+            EventManager.fireError(e);
+            log.error("A database error occured when executing a finder on execution context.", e);
+        } catch (FinderException e) {
+            EventManager.fireError(e);
+            log.error("The pickEC that should have been notified for a due date that has been reached could not be " +
+                    "found, please check for the Pick Execution Context with id " + pickECId, e);
+        }
+    }
+
+    public String getAdditionalInfo() {
+        return Integer.toString(activityPos);
+    }
+}

Added: incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/timer/WaitECTask.java
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/timer/WaitECTask.java?rev=165042&view=auto
==============================================================================
--- incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/timer/WaitECTask.java (added)
+++ incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/timer/WaitECTask.java Wed Apr 27 13:27:43 2005
@@ -0,0 +1,64 @@
+/*
+ * Copyright 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.agila.bpel.engine.priv.timer;
+
+import org.apache.agila.bpel.engine.common.persistence.DBSessionException;
+import org.apache.agila.bpel.engine.common.persistence.FinderException;
+import org.apache.agila.bpel.engine.common.transaction.TransactionException;
+import org.apache.agila.bpel.engine.common.transaction.TransactionManager;
+import org.apache.agila.bpel.engine.priv.core.dynamic.ExecutionContextFactory;
+import org.apache.agila.bpel.engine.priv.core.dynamic.WaitEC;
+
+import org.apache.log4j.Logger;
+
+/**
+ * Task that notifies a WaitEC that its due date has been reached.
+ */
+public class WaitECTask extends ExecutionContextTask {
+
+	private Logger log = Logger.getLogger(getClass());
+
+	private Long waitECId;
+
+	public WaitECTask(Long executionContextId) {
+		this.waitECId = executionContextId;
+	}
+
+    public Long getContextId() {
+        return waitECId;
+    }
+
+	public void run() {
+		WaitEC waitEC = null;
+		try {
+			TransactionManager.beginTransaction();
+			waitEC = (WaitEC) ExecutionContextFactory.findECById(waitECId);
+			waitEC.dueDateReached();
+			TransactionManager.commitTransaction();
+		} catch (DBSessionException e) {
+			log.error("A database error occured when initializing a connection for querying an execution context.", e);
+		} catch (TransactionException e) {
+			log.error("A database error occured when executing a finder on execution context.", e);
+		} catch (FinderException e) {
+			log.error("The waitEC that should have been notified for a due date that has been reached could not be " +
+					"found, please check for the Wait Execution Context with id " + waitECId, e);
+		}
+	}
+
+    public String getAdditionalInfo() {
+        return null;
+    }
+}

Added: incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/timer/dao/ECTaskDAO.java
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/timer/dao/ECTaskDAO.java?rev=165042&view=auto
==============================================================================
--- incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/timer/dao/ECTaskDAO.java (added)
+++ incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/timer/dao/ECTaskDAO.java Wed Apr 27 13:27:43 2005
@@ -0,0 +1,50 @@
+/*
+ * Copyright 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.agila.bpel.engine.priv.timer.dao;
+
+import java.util.List;
+
+import net.sf.hibernate.Hibernate;
+import net.sf.hibernate.HibernateException;
+import net.sf.hibernate.Session;
+
+import org.apache.agila.bpel.engine.common.persistence.DBSessionException;
+import org.apache.agila.bpel.engine.common.persistence.DBSessionManager;
+import org.apache.agila.bpel.engine.common.persistence.PersistentDataAccess;
+import org.apache.agila.bpel.engine.priv.timer.po.ECTaskPersister;
+
+/**
+ * DAO for execution context tasks.
+ */
+public class ECTaskDAO extends PersistentDataAccess {
+
+    private static String FINDBY_ECID =
+            "FROM org.apache.agila.bpel.engine.priv.timer.po.ECTaskPersister as ectask " +
+            "WHERE ectask.ecId = ?";
+
+    public static ECTaskPersister findByECId(Long ecId) throws DBSessionException {
+        Session session = DBSessionManager.getActiveSession();
+
+        List results = null;
+        try {
+            results = session.find(FINDBY_ECID, ecId, Hibernate.LONG);
+        } catch (HibernateException e) {
+            throw new DBSessionException(e);
+        }
+        return (ECTaskPersister) results.get(0);
+
+    }
+}

Added: incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/timer/po/ECTaskPersister.java
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/timer/po/ECTaskPersister.java?rev=165042&view=auto
==============================================================================
--- incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/timer/po/ECTaskPersister.java (added)
+++ incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/timer/po/ECTaskPersister.java Wed Apr 27 13:27:43 2005
@@ -0,0 +1,62 @@
+/*
+ * Copyright 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.agila.bpel.engine.priv.timer.po;
+
+import java.util.Date;
+
+/**
+ * A persistent class used by the EngineTimer to record created tasks
+ * so they can be restored after Agila is shutdown.
+ */
+public class ECTaskPersister {
+
+    private Long id;
+    private Date dueDate;
+    private Long ecId;
+    private String additionalInfo;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public Date getDueDate() {
+        return dueDate;
+    }
+
+    public void setDueDate(Date dueDate) {
+        this.dueDate = dueDate;
+    }
+
+    public Long getEcId() {
+        return ecId;
+    }
+
+    public void setEcId(Long ecId) {
+        this.ecId = ecId;
+    }
+
+    public String getAdditionalInfo() {
+        return additionalInfo;
+    }
+
+    public void setAdditionalInfo(String additionalInfo) {
+        this.additionalInfo = additionalInfo;
+    }
+}

Added: incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/util/CorrelationExtractor.java
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/util/CorrelationExtractor.java?rev=165042&view=auto
==============================================================================
--- incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/util/CorrelationExtractor.java (added)
+++ incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/util/CorrelationExtractor.java Wed Apr 27 13:27:43 2005
@@ -0,0 +1,182 @@
+/*
+ * Copyright 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.agila.bpel.engine.priv.util;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import org.dom4j.Document;
+import org.dom4j.DocumentHelper;
+import org.dom4j.Namespace;
+import org.dom4j.Node;
+import org.dom4j.XPath;
+import org.apache.agila.bpel.engine.exception.CorrelationViolationException;
+import org.apache.agila.bpel.engine.exception.ExecutionException;
+import org.apache.agila.bpel.engine.priv.core.definition.CorrelationRef;
+import org.apache.agila.bpel.engine.priv.core.definition.CorrelationSet;
+import org.apache.agila.bpel.engine.priv.core.definition.Property;
+import org.apache.agila.bpel.engine.priv.core.definition.PropertyAlias;
+import org.apache.agila.bpel.engine.priv.core.definition.AgilaProcess;
+import org.apache.log4j.Logger;
+
+/**
+ * Extracts correlation values from a Collection of correlation set references
+ * and an XML element.
+ */
+public class CorrelationExtractor {
+
+    private static final String PATH_SEP = "/";
+    private static final String NS_SEP = ":";
+    private static final String DEFAULT_NS = "defaultNS";
+
+    private static Logger log = Logger.getLogger(CorrelationExtractor.class);
+
+     public static Map extractCorrelationsValues(AgilaProcess process, String namespace, Collection corrRefs, Document message) throws CorrelationViolationException {
+        HashMap selectedCorrelRefs = new HashMap(corrRefs.size());
+        try {
+          for (Iterator correlRefIter = corrRefs.iterator(); correlRefIter.hasNext();) {
+              CorrelationRef ref = (CorrelationRef) correlRefIter.next();
+              selectedCorrelRefs.put(ref, extractCorrelationValues(process, ref, namespace, message));
+          }
+        } catch (CorrelationViolationException e) {
+          // TODO that's not a real solution
+          selectedCorrelRefs.clear();
+        }
+        return selectedCorrelRefs;
+    }
+
+    /**
+     *
+     * @param contextNode
+     * @param xpathExpression
+     * @param namespaces
+     * @return
+     */
+    public static Node selectSingleNode( Node contextNode, String xpathExpression, Map namespaces ) {
+      org.dom4j.XPath xpath = contextNode.createXPath( xpathExpression );
+      xpath.setNamespaceURIs( namespaces );
+      return xpath.selectSingleNode( contextNode );
+    }
+
+    /**
+     *
+     * @param messageType
+     * @return
+     */
+    public static String extractNamespace(String messageType) {
+      int index = messageType.indexOf(NS_SEP);
+      if (index != -1) {
+        return messageType.substring(0, index);
+      }
+      return null;
+    }
+
+    public static Node checkAlias(PropertyAlias alias, String namespace, Document message) {
+      // TODO namespace handling
+      String nsPrefix = extractNamespace(alias.getMessageType());
+      HashMap nsMap = new HashMap();
+      if (nsPrefix != null) {
+        nsMap.put(nsPrefix, namespace);
+      }
+      return selectSingleNode(message, "//message/" + alias.getPart() + (alias.getQuery().equals("/") ? "" : alias.getQuery()),  nsMap);
+    }
+
+    public static Map extractCorrelationValues(AgilaProcess process, CorrelationRef ref, String namespace, Document message) throws CorrelationViolationException {
+        CorrelationSet set = process.getCorrelationSet(ref.getSet());
+
+        if (set == null) throw new ExecutionException("No correlation set with name " + ref.getSet()
+                + " has been defined.");
+
+        HashMap propertyMap = new HashMap();
+        try {
+          for (Iterator propIter = set.getProperties().iterator(); propIter.hasNext();) {
+            String property = (String) propIter.next();
+            propertyMap.put(property, extractPropertyValue(process, namespace, property, message));
+          }
+        } catch (CorrelationViolationException e) {
+          // TODO that's not a real solution
+          propertyMap.clear();
+          throw e;
+        }
+        return propertyMap;
+    }
+
+    public static String extractPropertyValue(AgilaProcess process, String namespace, String property, Document message) throws CorrelationViolationException {
+        Property prop = process.getProperty(property);
+        if (prop == null) {
+            throw new ExecutionException("Property " + property + " could not be found in process " + process.getName());
+        }
+
+        PropertyAlias alias = null;
+        Node propertyValue = null;
+        for (Iterator it = prop.getAliases().iterator(); it.hasNext(); ) {
+          alias = (PropertyAlias)it.next();
+          propertyValue = checkAlias(alias, namespace, message);
+          if (propertyValue != null) {
+            break;
+          }
+        }
+
+        /* TODO namespaces
+        XPath xpathSelector = null;
+        Namespace defaultNS = message.getRootElement().getNamespace();
+        if (defaultNS != null) {
+            xpathSelector = DocumentHelper.createXPath("//defaultNS:message/defaultNS:" + alias.getPart() +
+                    namespacePath(alias.getQuery(), DEFAULT_NS));
+            HashMap nsMap = new HashMap(1);
+            nsMap.put(DEFAULT_NS, defaultNS.getURI());
+            xpathSelector.setNamespaceURIs(nsMap);
+        } else {
+            xpathSelector = DocumentHelper.createXPath("//message/" + alias.getPart() + alias.getQuery());
+        }
+
+//        Node propertyValue = message.selectSingleNode("/message/" + alias.getPart() + alias.getQuery());
+        Node propertyValue = xpathSelector.selectSingleNode(message);
+        */
+
+        // This shouldn't occur as the type of the message should be checked at reception
+        // and the type must be compatible with property aliases.
+        if (propertyValue == null) {
+            // TODO null is not really a fault. handle better.
+            log.error("Could not acknowledge a message " + message.asXML() + ". The property with alias " +
+                    "/message/" + alias.getPart() + alias.getQuery() + " could not be selected in message.");
+            throw new CorrelationViolationException("Could not acknowledge a message " + message.asXML() + ". The property " +
+                    "with alias /message/" + alias.getPart() + alias.getQuery() +
+                    " could not be selected in message.");
+        }
+        return propertyValue.getText();
+    }
+
+    /**
+     * Sets a namespace prefix for all elements of a path
+     * @param path
+     * @return prefixed path
+     */
+    private static String namespacePath(String path, String ns) {
+        StringBuffer result = new StringBuffer();
+        for (StringTokenizer pathTokenizer = new StringTokenizer(path, PATH_SEP); pathTokenizer.hasMoreTokens();) {
+            String pathElm = pathTokenizer.nextToken();
+            result.append(PATH_SEP);
+            result.append(ns);
+            result.append(NS_SEP);
+            result.append(pathElm);
+        }
+        return result.toString();
+    }
+}

Added: incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/util/Enum.java
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/util/Enum.java?rev=165042&view=auto
==============================================================================
--- incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/util/Enum.java (added)
+++ incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/util/Enum.java Wed Apr 27 13:27:43 2005
@@ -0,0 +1,56 @@
+/*
+ * Copyright 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.agila.bpel.engine.priv.util;
+
+/**
+ * <p>Simulates an enum like in C++.</p>
+ *
+ * @author <a href="mailto:norman.schoeneich@anybet.de">Norman Schöneich</a>
+ */
+public class Enum {
+
+  private int id;
+  private String text;
+
+  protected Enum(int id, String text) {
+    this.id = id;
+    this.text = text;
+  }
+
+  public int getId() {
+    return id;
+  }
+
+  public void setId(int id) {
+    this.id = id;
+  }
+
+  public String getText() {
+    return text;
+  }
+
+  public void setText(String text) {
+    this.text = text;
+  }
+
+  public String toString() {
+    StringBuffer buffer = new StringBuffer(this.getClass().getName() + "[");
+    buffer.append("id=" + this.getId());
+    buffer.append(" (" + this.getText() + ")");
+    buffer.append("]\n");
+    return buffer.toString();
+  }
+}

Added: incubator/agila/trunk/modules/bpel/engine/core/src/test/junit/org/apache/agila/bpel/engine/TestEngineAdmin.java
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpel/engine/core/src/test/junit/org/apache/agila/bpel/engine/TestEngineAdmin.java?rev=165042&view=auto
==============================================================================
--- incubator/agila/trunk/modules/bpel/engine/core/src/test/junit/org/apache/agila/bpel/engine/TestEngineAdmin.java (added)
+++ incubator/agila/trunk/modules/bpel/engine/core/src/test/junit/org/apache/agila/bpel/engine/TestEngineAdmin.java Wed Apr 27 13:27:43 2005
@@ -0,0 +1,55 @@
+/*
+ * Copyright 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.agila.bpel.engine;
+
+import junit.framework.TestCase;
+import net.sf.hibernate.cfg.Configuration;
+import net.sf.hibernate.tool.hbm2ddl.SchemaExport;
+
+import org.apache.agila.bpel.engine.common.lifecycle.LifecycleManager;
+import org.apache.agila.bpel.engine.exception.EngineException;
+
+public class TestEngineAdmin extends TestCase {
+
+    protected void setUp() throws Exception {
+        //SchemaExport schemaExport = new SchemaExport(new Configuration().configure());
+        //schemaExport.create(true, true);
+
+        LifecycleManager.getLifecycleManager().createResources();
+        LifecycleManager.getLifecycleManager().startResources();
+    }
+
+    protected void tearDown() throws Exception {
+        LifecycleManager.getLifecycleManager().stopResources();
+        LifecycleManager.getLifecycleManager().destroyResources();
+    }
+
+    public void testFindAllProcess() throws Exception {
+        try {
+            AgilaEngineAdminFactory.getEngineAdmin().findAllProcessNames();
+        } catch (EngineException e) {
+            System.out.println("No Process in DB");
+        }
+    }
+
+    public void findActiveInstances() throws Exception {
+        AgilaEngineAdminFactory.getEngineAdmin().findActiveInstances();
+    }
+
+    public void findTerminatedInstances() throws Exception {
+        AgilaEngineAdminFactory.getEngineAdmin().findTerminatedInstances();
+    }
+}

Added: incubator/agila/trunk/modules/bpel/engine/core/src/test/junit/org/apache/agila/bpel/engine/core/TestActivity.java
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpel/engine/core/src/test/junit/org/apache/agila/bpel/engine/core/TestActivity.java?rev=165042&view=auto
==============================================================================
--- incubator/agila/trunk/modules/bpel/engine/core/src/test/junit/org/apache/agila/bpel/engine/core/TestActivity.java (added)
+++ incubator/agila/trunk/modules/bpel/engine/core/src/test/junit/org/apache/agila/bpel/engine/core/TestActivity.java Wed Apr 27 13:27:43 2005
@@ -0,0 +1,258 @@
+/*
+ * Copyright 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.agila.bpel.engine.core;
+
+import java.util.HashSet;
+import java.util.Iterator;
+
+import junit.framework.TestCase;
+import net.sf.hibernate.cfg.Configuration;
+import net.sf.hibernate.tool.hbm2ddl.SchemaExport;
+
+import org.apache.agila.bpel.engine.common.lifecycle.LifecycleManager;
+import org.apache.agila.bpel.engine.common.transaction.TransactionManager;
+import org.apache.agila.bpel.engine.priv.core.definition.Activity;
+import org.apache.agila.bpel.engine.priv.core.definition.ActivityFactory;
+import org.apache.agila.bpel.engine.priv.core.definition.AlarmEvent;
+import org.apache.agila.bpel.engine.priv.core.definition.Assign;
+import org.apache.agila.bpel.engine.priv.core.definition.Assignment;
+import org.apache.agila.bpel.engine.priv.core.definition.CorrelationRef;
+import org.apache.agila.bpel.engine.priv.core.definition.Empty;
+import org.apache.agila.bpel.engine.priv.core.definition.Invoke;
+import org.apache.agila.bpel.engine.priv.core.definition.MessageEvent;
+import org.apache.agila.bpel.engine.priv.core.definition.Pick;
+import org.apache.agila.bpel.engine.priv.core.definition.ProcessFactory;
+import org.apache.agila.bpel.engine.priv.core.definition.Receive;
+import org.apache.agila.bpel.engine.priv.core.definition.Reply;
+import org.apache.agila.bpel.engine.priv.core.definition.Scope;
+import org.apache.agila.bpel.engine.priv.core.definition.Sequence;
+import org.apache.agila.bpel.engine.priv.core.definition.Switch;
+import org.apache.agila.bpel.engine.priv.core.definition.Terminate;
+import org.apache.agila.bpel.engine.priv.core.definition.AgilaProcess;
+import org.apache.agila.bpel.engine.priv.core.definition.Wait;
+import org.apache.agila.bpel.engine.priv.core.definition.While;
+
+/**
+ * Creates a small network of activities and checks everything
+ * around; like the links relationships and the container
+ * relationships.
+ */
+public class TestActivity extends TestCase {
+
+    protected void setUp() throws Exception {
+        LifecycleManager.getLifecycleManager().createResources();
+        LifecycleManager.getLifecycleManager().startResources();
+
+        SchemaExport schemaExport = new SchemaExport(new Configuration().configure());
+        schemaExport.create(true, true);
+
+        TransactionManager.beginTransaction();
+    }
+
+    protected void tearDown() throws Exception {
+        TransactionManager.commitTransaction();
+
+        LifecycleManager.getLifecycleManager().stopResources();
+        LifecycleManager.getLifecycleManager().destroyResources();
+    }
+
+    public void testCreate() throws Exception {
+        // Creating process
+        AgilaProcess testProcess = ProcessFactory.createProcess("TestProcess", "");
+
+        // Creating root sequence with its activities
+        Sequence testSequence = (Sequence) ActivityFactory.createActivity(Sequence.class, testProcess);
+        {
+            Receive activity1 = (Receive) ActivityFactory.createActivity(Receive.class, testSequence);
+            activity1.setName("act1");
+
+            Reply activity2 = (Reply) ActivityFactory.createActivity(Reply.class, testSequence);
+            activity2.setName("act2");
+
+            Empty activity3 = (Empty) ActivityFactory.createActivity(Empty.class, testSequence);
+            activity3.setName("act3");
+
+            While testWhile = (While) ActivityFactory.createActivity(While.class, testSequence);
+            testWhile.setCondition("false");
+            {
+                Scope testScope = (Scope) ActivityFactory.createActivity(Scope.class, testWhile);
+                {
+                    Wait activity4 = (Wait) ActivityFactory.createActivity(Wait.class, testScope);
+                    activity4.setName("act4");
+                }
+            }
+
+            Invoke activity5 = (Invoke) ActivityFactory.createActivity(Invoke.class, testSequence);
+            activity5.setName("act5");
+
+            Assign activity6 = (Assign) ActivityFactory.createActivity(Assign.class, testSequence);
+            activity6.setName("act6");
+            Assignment assignment1 = ActivityFactory.addAssignment(activity6, Assignment.VARIABLE_PART, Assignment.VARIABLE_PART);
+            assignment1.setFromFirstValue("var");
+            assignment1.setFromSecondValue("part");
+            assignment1.setToFirstValue("var2");
+            assignment1.setToSecondValue("part2");
+            Assignment assignment2 = ActivityFactory.addAssignment(activity6, Assignment.VARIABLE_PART, Assignment.VARIABLE_PART);
+            assignment2.setFromFirstValue("var2");
+            assignment2.setFromSecondValue("part2");
+            assignment2.setToFirstValue("var3");
+            assignment2.setToSecondValue("part3");
+
+			Switch testSwitch = (Switch) ActivityFactory.createActivity(Switch.class, testSequence);
+			{
+				Invoke activity7 = (Invoke) ActivityFactory.createActivity(Invoke.class, testSwitch);
+				activity7.setName("act7");
+				testSwitch.addCondition("today == monday", activity7);
+
+				Invoke activity8 = (Invoke) ActivityFactory.createActivity(Invoke.class, testSwitch);
+				activity8.setName("act8");
+				testSwitch.addCondition("today == thursday", activity8);
+
+				Terminate activity9 = (Terminate) ActivityFactory.createActivity(Terminate.class, testSwitch);
+				activity9.setName("act9");
+                testSwitch.setOtherwise(activity9);
+			}
+
+			Pick testPick = (Pick) ActivityFactory.createActivity(Pick.class, testSequence);
+			testPick.setCreateInstance(true);
+			{
+				Reply activity10 = (Reply) ActivityFactory.createActivity(Reply.class, testPick);
+				activity10.setName("act10");
+				Reply activity11 = (Reply) ActivityFactory.createActivity(Reply.class, testPick);
+				activity11.setName("act11");
+				Terminate activity12 = (Terminate) ActivityFactory.createActivity(Terminate.class, testPick);
+				activity12.setName("act12");
+
+				CorrelationRef cRef1 = ActivityFactory.createCorrelationRef("set1", false, CorrelationRef.OUT);
+				CorrelationRef cRef2 = ActivityFactory.createCorrelationRef("set2", false, CorrelationRef.OUT);
+				HashSet correlations1 = new HashSet();
+				correlations1.add(cRef1);
+				correlations1.add(cRef2);
+				
+				MessageEvent mEvent1 = ActivityFactory.addMessageEvent(testPick, activity10, "link1", "portType1", "operation1", "variable1", correlations1);
+
+				CorrelationRef cRef3 = ActivityFactory.createCorrelationRef("set3", true, CorrelationRef.IN);
+				HashSet correlations2 = new HashSet();
+				correlations2.add(cRef3);
+				
+				MessageEvent mEvent2 = ActivityFactory.addMessageEvent(testPick, activity11, "link2", "portType2", "operation2", "variable2", correlations2);
+				
+				ActivityFactory.addAlarmEvent(testPick, activity12, "2j", AlarmEvent.DURATION_EXPR);
+			}
+
+        }
+
+        TransactionManager.commitTransaction();
+        TransactionManager.beginTransaction();
+
+        AgilaProcess process =  ProcessFactory.getByName("TestProcess", "");
+        Activity rootActivity = process.getActivity();
+
+        assertTrue("The root activity is not a sequence as expected", rootActivity instanceof Sequence);
+        assertEquals("There are not 8 elements in the sequence", 8, ((Sequence)rootActivity).getActivities().size());
+
+        Iterator activities = ((Sequence)rootActivity).getActivities().iterator();
+
+        Activity first = (Activity) activities.next();
+        assertTrue("The first activity is not a Wait as expected", first instanceof Receive);
+        assertEquals("The first activity name is wrong", "act1", first.getName());
+
+        Activity second = (Activity) activities.next();
+        assertTrue("The second activity is not a Wait as expected", second instanceof Reply);
+        assertEquals("The second activity name is wrong", "act2", second.getName());
+
+        Activity third = (Activity) activities.next();
+        assertTrue("The third activity is not a Wait as expected", third instanceof Empty);
+        assertEquals("The third activity name is wrong", "act3", third.getName());
+
+        Activity aWhile = (Activity) activities.next();
+        assertTrue("The activity is not a While as expected", aWhile instanceof While);
+        assertEquals("The while doesn't have the right condition", "false", ((While)aWhile).getCondition());
+        assertTrue("The activity in the while is not a Wait as expected", ((Scope)((While)aWhile).getActivities().get(0)).getActivities().get(0) instanceof Wait);
+        assertEquals("The wait activity contained in the While name is wrong", "act4", ((Wait)((Scope)((While)aWhile).getActivities().get(0)).getActivities().get(0)).getName());
+
+        Activity fifth = (Activity) activities.next();
+        assertTrue("The fifth activity is not a Wait as expected", fifth instanceof Invoke);
+        assertEquals("The fifth activity name is wrong", "act5", fifth.getName());
+
+        Activity sixth = (Activity) activities.next();
+        assertTrue("The sixth activity is not a Assign as expected", sixth instanceof Assign);
+        assertEquals("The sixth activity name is wrong", "act6", sixth.getName());
+        assertEquals("The sixth activity assign doesn't have 2 assignments", 2, ((Assign)sixth).getAssignments().size());
+
+		Activity aSwitch = (Activity) activities.next();
+		assertTrue("The activity is not a Switch as expected", aSwitch instanceof Switch);
+		assertEquals("The Switch doesn't have 3 elements", 3, ((Switch)aSwitch).getActivityConditions().size());
+		{
+			Iterator switchActIter = ((Switch)aSwitch).getActivityConditions().keySet().iterator();
+
+			Activity seventh = (Activity) switchActIter.next();
+			assertTrue("The seventh activity is not a Invoke as expected", seventh instanceof Invoke);
+			assertEquals("The seventh activity name is wrong", "act7", seventh.getName());
+            assertEquals("The Switch first condition is wrong", "today == monday", ((Switch)aSwitch).getActivityConditions().get(seventh));
+
+			Activity eighth = (Activity) switchActIter.next();
+			assertTrue("The eighth activity is not a Invoke as expected", eighth instanceof Invoke);
+			assertEquals("The eighth activity name is wrong", "act8", eighth.getName());
+            assertEquals("The Switch second condition is wrong", "today == thursday", ((Switch)aSwitch).getActivityConditions().get(eighth));
+
+			Activity nineth = (Activity) switchActIter.next();
+			assertTrue("The nineth activity is not a Terminate as expected", nineth instanceof Terminate);
+			assertEquals("The nineth activity name is wrong", "act9", nineth.getName());
+		}
+
+		Activity aPick = (Pick) activities.next();
+		assertTrue("The activity is not a Pick as expected", aPick instanceof Pick);
+		assertEquals("The Pick doesn't have 3 elements", 3, ((Pick)aPick).getActivities().size());
+		assertEquals("The Pick doesn't have 2 message events", 2, ((Pick)aPick).getActivityMessageEvents().size());
+		assertEquals("The Pick doesn't have 1 alarm event", 1, ((Pick)aPick).getActivityAlarmEvents().size());
+		{
+			Iterator msgEventIter = ((Pick)aPick).getActivityMessageEvents().keySet().iterator();
+			Activity tenth = (Activity) msgEventIter.next();
+			assertTrue("The first activity in Pick is not a Reply as expected", tenth instanceof Reply);
+			assertEquals("The first activity in Pick name is wrong", "act10", tenth.getName());
+			MessageEvent msgEvent1 = ((Pick)aPick).getMessageEvent(tenth);
+			assertEquals("The message event associated with the first activity in Pick has not right link", "link1", msgEvent1.getPartnerLink());
+			{
+				Iterator corrIter1 = msgEvent1.getCorrelations().iterator();
+				CorrelationRef corr1 = (CorrelationRef) corrIter1.next();
+				assertTrue("The first correlation associated with the first activity in Pick has not right set", corr1.getSet().equals("set1") || corr1.getSet().equals("set2"));
+				CorrelationRef corr2 = (CorrelationRef) corrIter1.next();
+				assertTrue("The second correlation associated with the first activity in Pick has not right set", corr2.getSet().equals("set1") || corr2.getSet().equals("set2"));
+			}
+
+			Activity eleventh = (Activity) msgEventIter.next();
+			assertTrue("The second activity in Pick is not a Reply as expected", eleventh instanceof Reply);
+			assertEquals("The second activity in Pick name is wrong", "act11", eleventh.getName());
+			MessageEvent msgEvent2 = ((Pick)aPick).getMessageEvent(eleventh);
+			assertEquals("The message event associated with the second activity in Pick has not right link", "link2", msgEvent2.getPartnerLink());
+			{
+				Iterator corrIter2 = msgEvent2.getCorrelations().iterator();
+				CorrelationRef corr3 = (CorrelationRef) corrIter2.next();
+				assertEquals("The first correlation associated with the third activity in Pick has not right set", "set3", corr3.getSet());
+			}
+
+			Iterator alarmEventIter = ((Pick)aPick).getActivityAlarmEvents().keySet().iterator();
+			Activity twelveth = (Activity) alarmEventIter.next();
+			assertTrue("The third activity in Pick is not a Terminate as expected", twelveth instanceof Terminate);
+			assertEquals("The third activity in Pick name is wrong", "act12", twelveth.getName());
+			AlarmEvent alrmEvent = ((Pick)aPick).getAlarmEvent(twelveth);
+			assertEquals("The message event associated with the third activity in Pick has not right time expr", "2j", alrmEvent.getTimeExpression());
+			assertEquals("The message event associated with the third activity in Pick has not right type", AlarmEvent.DURATION_EXPR, alrmEvent.getType());
+
+		}
+    }
+}

Added: incubator/agila/trunk/modules/bpel/engine/core/src/test/junit/org/apache/agila/bpel/engine/core/definition/TestAssign.java
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpel/engine/core/src/test/junit/org/apache/agila/bpel/engine/core/definition/TestAssign.java?rev=165042&view=auto
==============================================================================
--- incubator/agila/trunk/modules/bpel/engine/core/src/test/junit/org/apache/agila/bpel/engine/core/definition/TestAssign.java (added)
+++ incubator/agila/trunk/modules/bpel/engine/core/src/test/junit/org/apache/agila/bpel/engine/core/definition/TestAssign.java Wed Apr 27 13:27:43 2005
@@ -0,0 +1,80 @@
+/*
+ * Copyright 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.agila.bpel.engine.core.definition;
+
+import junit.framework.TestCase;
+import net.sf.hibernate.cfg.Configuration;
+import net.sf.hibernate.tool.hbm2ddl.SchemaExport;
+
+import org.apache.agila.bpel.engine.common.lifecycle.LifecycleManager;
+import org.apache.agila.bpel.engine.common.transaction.TransactionManager;
+import org.apache.agila.bpel.engine.priv.core.definition.ActivityFactory;
+import org.apache.agila.bpel.engine.priv.core.definition.Assign;
+import org.apache.agila.bpel.engine.priv.core.definition.Assignment;
+import org.apache.agila.bpel.engine.priv.core.definition.CorrelationRef;
+import org.apache.agila.bpel.engine.priv.core.definition.ProcessFactory;
+import org.apache.agila.bpel.engine.priv.core.definition.Receive;
+import org.apache.agila.bpel.engine.priv.core.definition.Sequence;
+import org.apache.agila.bpel.util.BeanTester;
+
+public class TestAssign extends TestCase {
+
+	public static Assign assign = null;
+
+	private BeanTester beanTester = new BeanTester(new String[] {"Id", "Index"});
+	private TestProcess testProcess = new TestProcess();
+
+	protected void setUp() throws Exception {
+        LifecycleManager.getLifecycleManager().createResources();
+        LifecycleManager.getLifecycleManager().startResources();
+
+		SchemaExport schemaExport = new SchemaExport(new Configuration().configure());
+		schemaExport.create(true, true);
+
+        TransactionManager.beginTransaction();
+		testProcess.testCreate();
+	}
+
+	protected void tearDown() throws Exception {
+		TransactionManager.commitTransaction();
+
+        LifecycleManager.getLifecycleManager().stopResources();
+        LifecycleManager.getLifecycleManager().destroyResources();
+	}
+
+	public void testCreate() throws Exception {
+        Sequence sequence = (Sequence) ActivityFactory.createActivity(Sequence.class, TestProcess.testProcess);
+        Receive receive = (Receive) ActivityFactory.createActivity(Receive.class, sequence);
+        ActivityFactory.addCorrelationRef(receive, TestProcess.CORRELATION_NAME, false, CorrelationRef.NONE);
+		assign = (Assign) ActivityFactory.createActivity(Assign.class, sequence);
+        Assignment assignment = ActivityFactory.addAssignment(assign, Assignment.VARIABLE_PART, Assignment.VARIABLE_PART);
+        assignment.setFromFirstValue("variable1");
+        assignment.setFromSecondValue("part11");
+        assignment.setToFirstValue("variable2");
+        assignment.setToSecondValue("part21");
+
+		beanTester.initializeProperties("testAssign", assign);
+
+		TransactionManager.commitTransaction();
+        TransactionManager.beginTransaction();
+
+		Assign resultAssign = (Assign)((Sequence) ProcessFactory.getByName(TestProcess.testProcess.getName(),
+                TestProcess.testProcess.getNamespace()).getActivity()).getActivities().get(1);
+		assertTrue("Assign attributes values have been changed.", beanTester.testValues("testAssign", resultAssign));
+		assign = resultAssign;
+	}
+
+}

Added: incubator/agila/trunk/modules/bpel/engine/core/src/test/junit/org/apache/agila/bpel/engine/core/definition/TestEmpty.java
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpel/engine/core/src/test/junit/org/apache/agila/bpel/engine/core/definition/TestEmpty.java?rev=165042&view=auto
==============================================================================
--- incubator/agila/trunk/modules/bpel/engine/core/src/test/junit/org/apache/agila/bpel/engine/core/definition/TestEmpty.java (added)
+++ incubator/agila/trunk/modules/bpel/engine/core/src/test/junit/org/apache/agila/bpel/engine/core/definition/TestEmpty.java Wed Apr 27 13:27:43 2005
@@ -0,0 +1,67 @@
+/*
+ * Copyright 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.agila.bpel.engine.core.definition;
+
+import junit.framework.TestCase;
+import net.sf.hibernate.cfg.Configuration;
+import net.sf.hibernate.tool.hbm2ddl.SchemaExport;
+
+import org.apache.agila.bpel.engine.common.lifecycle.LifecycleManager;
+import org.apache.agila.bpel.engine.common.transaction.TransactionManager;
+import org.apache.agila.bpel.engine.priv.core.definition.ActivityFactory;
+import org.apache.agila.bpel.engine.priv.core.definition.Empty;
+import org.apache.agila.bpel.engine.priv.core.definition.ProcessFactory;
+import org.apache.agila.bpel.util.BeanTester;
+
+public class TestEmpty extends TestCase {
+
+	public static Empty empty = null;
+
+	private BeanTester beanTester = new BeanTester(new String[] {"Id", "Index"});
+	private TestProcess testProcess = new TestProcess();
+
+	protected void setUp() throws Exception {
+        LifecycleManager.getLifecycleManager().createResources();
+        LifecycleManager.getLifecycleManager().startResources();
+
+		SchemaExport schemaExport = new SchemaExport(new Configuration().configure());
+		schemaExport.create(true, true);
+
+        TransactionManager.beginTransaction();
+		testProcess.testCreate();
+	}
+
+	protected void tearDown() throws Exception {
+		TransactionManager.commitTransaction();
+
+        LifecycleManager.getLifecycleManager().stopResources();
+        LifecycleManager.getLifecycleManager().destroyResources();
+	}
+
+	public void testCreate() throws Exception {
+		empty = (Empty) ActivityFactory.createActivity(Empty.class, TestProcess.testProcess);
+		beanTester.initializeProperties("testEmpty", empty);
+
+		TransactionManager.commitTransaction();
+        TransactionManager.beginTransaction();
+
+		Empty resultEmpty = (Empty) ProcessFactory.getByName(TestProcess.testProcess.getName(),
+                TestProcess.testProcess.getNamespace()).getActivity();
+		assertTrue("Empty attributes values have been changed.", beanTester.testValues("testEmpty", resultEmpty));
+		empty = resultEmpty;
+	}
+
+}

Added: incubator/agila/trunk/modules/bpel/engine/core/src/test/junit/org/apache/agila/bpel/engine/core/definition/TestInvoke.java
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpel/engine/core/src/test/junit/org/apache/agila/bpel/engine/core/definition/TestInvoke.java?rev=165042&view=auto
==============================================================================
--- incubator/agila/trunk/modules/bpel/engine/core/src/test/junit/org/apache/agila/bpel/engine/core/definition/TestInvoke.java (added)
+++ incubator/agila/trunk/modules/bpel/engine/core/src/test/junit/org/apache/agila/bpel/engine/core/definition/TestInvoke.java Wed Apr 27 13:27:43 2005
@@ -0,0 +1,75 @@
+/*
+ * Copyright 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.agila.bpel.engine.core.definition;
+
+import junit.framework.TestCase;
+import net.sf.hibernate.cfg.Configuration;
+import net.sf.hibernate.tool.hbm2ddl.SchemaExport;
+
+import org.apache.agila.bpel.engine.common.lifecycle.LifecycleManager;
+import org.apache.agila.bpel.engine.common.transaction.TransactionManager;
+import org.apache.agila.bpel.engine.priv.core.definition.ActivityFactory;
+import org.apache.agila.bpel.engine.priv.core.definition.Invoke;
+import org.apache.agila.bpel.engine.priv.core.definition.ProcessFactory;
+import org.apache.agila.bpel.util.BeanTester;
+
+public class TestInvoke extends TestCase {
+
+	public static Invoke invoke = null;
+
+	private BeanTester beanTester = new BeanTester(new String[] {"Id", "Index"});
+	private TestProcess testProcess = new TestProcess();
+
+	protected void setUp() throws Exception {
+        LifecycleManager.getLifecycleManager().createResources();
+        LifecycleManager.getLifecycleManager().startResources();
+
+		SchemaExport schemaExport = new SchemaExport(new Configuration().configure());
+		schemaExport.create(true, true);
+
+        TransactionManager.beginTransaction();
+		testProcess.testCreate();
+	}
+
+	protected void tearDown() throws Exception {
+		TransactionManager.commitTransaction();
+
+        LifecycleManager.getLifecycleManager().stopResources();
+        LifecycleManager.getLifecycleManager().destroyResources();
+	}
+
+	public void testCreate() throws Exception {
+		invoke = (Invoke) ActivityFactory.createActivity(Invoke.class, TestProcess.testProcess);
+		invoke.setPortType("portType");
+		invoke.setNamespace("http://DefaulNS");
+		invoke.setPartner("partner");
+		invoke.setOperation("operation");
+		invoke.setOutputVariable("out");
+		invoke.setInputVariable("in");
+		/*CorrelationRef corRef = new CorrelationRefImp();
+		corRef.setSet();*/
+		beanTester.initializeProperties("testInvoke", invoke);
+
+		TransactionManager.commitTransaction();
+        TransactionManager.beginTransaction();
+
+		Invoke resultInvoke = (Invoke) ProcessFactory.getByName(TestProcess.testProcess.getName(),
+                TestProcess.testProcess.getNamespace()).getActivity();
+		assertTrue("Invoke attributes values have been changed.", beanTester.testValues("testInvoke", resultInvoke));
+		invoke = resultInvoke;
+	}
+
+}

Added: incubator/agila/trunk/modules/bpel/engine/core/src/test/junit/org/apache/agila/bpel/engine/core/definition/TestProcess.java
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpel/engine/core/src/test/junit/org/apache/agila/bpel/engine/core/definition/TestProcess.java?rev=165042&view=auto
==============================================================================
--- incubator/agila/trunk/modules/bpel/engine/core/src/test/junit/org/apache/agila/bpel/engine/core/definition/TestProcess.java (added)
+++ incubator/agila/trunk/modules/bpel/engine/core/src/test/junit/org/apache/agila/bpel/engine/core/definition/TestProcess.java Wed Apr 27 13:27:43 2005
@@ -0,0 +1,89 @@
+/*
+ * Copyright 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.agila.bpel.engine.core.definition;
+
+import junit.framework.TestCase;
+import net.sf.hibernate.cfg.Configuration;
+import net.sf.hibernate.tool.hbm2ddl.SchemaExport;
+
+import org.apache.agila.bpel.engine.common.lifecycle.LifecycleManager;
+import org.apache.agila.bpel.engine.common.transaction.TransactionManager;
+import org.apache.agila.bpel.engine.priv.core.definition.ProcessFactory;
+import org.apache.agila.bpel.engine.priv.core.definition.Property;
+import org.apache.agila.bpel.engine.priv.core.definition.impl.CorrelationSetImpl;
+import org.apache.agila.bpel.engine.priv.core.definition.impl.ProcessImpl;
+import org.apache.agila.bpel.util.BeanTester;
+
+public class TestProcess extends TestCase {
+
+    public static final String CORRELATION_NAME = "order";
+    public static final String CORRELATION_PROP1= "tns:orderid";
+    public static final String CORRELATION_PROP2= "tns:customerid";
+
+	public static ProcessImpl testProcess = null;
+
+	private BeanTester beanTester = new BeanTester(new String[] {"Id"});
+
+	protected void setUp() throws Exception {
+        LifecycleManager.getLifecycleManager().createResources();
+        LifecycleManager.getLifecycleManager().startResources();
+
+		SchemaExport schemaExport = new SchemaExport(new Configuration().configure());
+		schemaExport.create(true, true);
+
+        TransactionManager.beginTransaction();
+	}
+
+	protected void tearDown() throws Exception {
+		TransactionManager.commitTransaction();
+
+        LifecycleManager.getLifecycleManager().stopResources();
+        LifecycleManager.getLifecycleManager().destroyResources();
+	}
+
+	public void testCreate() throws Exception {
+		testProcess = (ProcessImpl) ProcessFactory.createProcess("TestProcess", "");
+		beanTester.initializeProperties("testProcess", testProcess);
+		TransactionManager.commitTransaction();
+        TransactionManager.beginTransaction();
+
+		ProcessImpl testProcessRes = (ProcessImpl) ProcessFactory.getByName(testProcess.getName(),
+                TestProcess.testProcess.getNamespace());
+		assertTrue("Process attributes values have been changed.", beanTester.testValues("testProcess", testProcessRes));
+		testProcess = testProcessRes;
+	}
+
+    public void testCreateWithCorrelation() throws Exception {
+        testProcess = (ProcessImpl) ProcessFactory.createProcess("TestProcess", "");
+        beanTester.initializeProperties("testProcess", testProcess);
+        ProcessFactory.addCorrelation(testProcess, CORRELATION_NAME, CORRELATION_PROP1 + " " + CORRELATION_PROP2);
+        Property prop1 = ProcessFactory.addProperty(testProcess, CORRELATION_PROP1, "xs:string");
+        ProcessFactory.addPropertyAlias(prop1, "tns:msg1", "main", "/root/orderid");
+        Property prop2 = ProcessFactory.addProperty(testProcess, CORRELATION_PROP2, "xs:string");
+        ProcessFactory.addPropertyAlias(prop2, "tns:msg2", "main", "/root/customerid");
+
+        TransactionManager.commitTransaction();
+        TransactionManager.beginTransaction();
+
+        ProcessImpl testProcessRes = (ProcessImpl) ProcessFactory.getByName(testProcess.getName(),
+                TestProcess.testProcess.getNamespace());
+        assertTrue("Process attributes values have been changed.", beanTester.testValues("testProcess", testProcessRes));
+        assertNotNull("Process is not linked with correlation", testProcessRes.getCorrelationSet(CORRELATION_NAME));
+        assertEquals("Correlation properties are wrong", CORRELATION_PROP1 + " " + CORRELATION_PROP2,
+                ((CorrelationSetImpl)testProcessRes.getCorrelationSet(CORRELATION_NAME)).getPropertiesString());
+        testProcess = testProcessRes;
+    }
+}



Mime
View raw message