[jbpm-commits] JBoss JBPM SVN: r5454 - in jbpm4/trunk/modules/bpmn/src: main/java/org/jbpm/bpmn/common and 7 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Mon Aug 10 06:59:46 EDT 2009
Author: kukeltje
Date: 2009-08-10 06:59:46 -0400 (Mon, 10 Aug 2009)
New Revision: 5454
Added:
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/common/
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/common/Resource.java
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/common/ResourceParameter.java
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/JavaServiceTaskActivity.java
jbpm4/trunk/modules/bpmn/src/test/java/org/jbpm/bpmn/example/
jbpm4/trunk/modules/bpmn/src/test/java/org/jbpm/bpmn/example/JavaServiceTask.java
jbpm4/trunk/modules/bpmn/src/test/java/org/jbpm/bpmn/flownodes/ServiceTaskTest.java
jbpm4/trunk/modules/bpmn/src/test/resources/org/jbpm/bpmn/flownodes/ServiceTaskJava.bpmn.xml
Removed:
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/Resource.java
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ResourceParameter.java
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ServiceTaskActivity.java
Modified:
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ActivityResource.java
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/BpmnAutomaticActivity.java
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/BpmnBinding.java
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ScriptTaskActivity.java
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ServiceTaskBinding.java
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/model/BpmnProcessDefinition.java
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/parser/BpmnParser.java
Log:
Java based service task
Copied: jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/common/Resource.java (from rev 5428, jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/Resource.java)
===================================================================
--- jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/common/Resource.java (rev 0)
+++ jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/common/Resource.java 2009-08-10 10:59:46 UTC (rev 5454)
@@ -0,0 +1,35 @@
+package org.jbpm.bpmn.common;
+
+import java.util.Map;
+
+public class Resource {
+
+ String id;
+ String name;
+ Map<String, ResourceParameter> parameters;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Map<String, ResourceParameter> getParameters() {
+ return parameters;
+ }
+
+ public void setParameters(Map<String, ResourceParameter> parameters) {
+ this.parameters = parameters;
+ }
+
+}
Copied: jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/common/ResourceParameter.java (from rev 5428, jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ResourceParameter.java)
===================================================================
--- jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/common/ResourceParameter.java (rev 0)
+++ jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/common/ResourceParameter.java 2009-08-10 10:59:46 UTC (rev 5454)
@@ -0,0 +1,37 @@
+package org.jbpm.bpmn.common;
+
+import javax.xml.namespace.QName;
+
+import org.jbpm.pvm.internal.model.VariableDefinitionImpl;
+
+
+public class ResourceParameter extends VariableDefinitionImpl {
+
+ String id;
+ QName type;
+ boolean required;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public QName getType() {
+ return type;
+ }
+
+ public void setType(QName type) {
+ this.type = type;
+ }
+
+ public boolean isRequired() {
+ return required;
+ }
+
+ public void setRequired(boolean required) {
+ this.required = required;
+ }
+}
Modified: jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ActivityResource.java
===================================================================
--- jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ActivityResource.java 2009-08-09 02:13:07 UTC (rev 5453)
+++ jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ActivityResource.java 2009-08-10 10:59:46 UTC (rev 5454)
@@ -1,5 +1,6 @@
package org.jbpm.bpmn.flownodes;
+import org.jbpm.bpmn.common.Resource;
import org.jbpm.pvm.internal.wire.descriptor.ExpressionEvaluatorDescriptor;
public class ActivityResource {
Modified: jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/BpmnAutomaticActivity.java
===================================================================
--- jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/BpmnAutomaticActivity.java 2009-08-09 02:13:07 UTC (rev 5453)
+++ jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/BpmnAutomaticActivity.java 2009-08-10 10:59:46 UTC (rev 5454)
@@ -3,6 +3,7 @@
import org.jbpm.api.activity.ActivityExecution;
import org.jbpm.api.listener.EventListener;
import org.jbpm.api.listener.EventListenerExecution;
+import org.jbpm.api.model.OpenExecution;
import org.jbpm.pvm.internal.model.ExecutionImpl;
@@ -17,8 +18,8 @@
}
public void notify(EventListenerExecution execution) throws Exception {
- perform((ExecutionImpl)execution);
+ perform(execution);
}
- abstract void perform(ExecutionImpl execution) throws Exception;
+ abstract void perform(OpenExecution execution) throws Exception;
}
Modified: jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/BpmnBinding.java
===================================================================
--- jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/BpmnBinding.java 2009-08-09 02:13:07 UTC (rev 5453)
+++ jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/BpmnBinding.java 2009-08-10 10:59:46 UTC (rev 5454)
@@ -21,13 +21,15 @@
*/
package org.jbpm.bpmn.flownodes;
+import org.jbpm.bpmn.parser.BpmnParser;
import org.jbpm.pvm.internal.util.TagBinding;
+import org.jbpm.pvm.internal.wire.xml.WireParser;
public abstract class BpmnBinding extends TagBinding {
-// protected static final WireParser wireParser = BpmnParser.wireParser;
+ protected static final WireParser wireParser = BpmnParser.wireParser;
public BpmnBinding(String tagName) {
super(tagName, "http://schema.omg.org/spec/BPMN/2.0", null);
Copied: jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/JavaServiceTaskActivity.java (from rev 5419, jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ServiceTaskActivity.java)
===================================================================
--- jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/JavaServiceTaskActivity.java (rev 0)
+++ jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/JavaServiceTaskActivity.java 2009-08-10 10:59:46 UTC (rev 5454)
@@ -0,0 +1,118 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.bpmn.flownodes;
+
+import java.lang.reflect.Method;
+import java.util.List;
+
+import org.jbpm.api.JbpmException;
+import org.jbpm.api.model.OpenExecution;
+import org.jbpm.pvm.internal.env.EnvironmentDefaults;
+import org.jbpm.pvm.internal.model.ExecutionImpl;
+import org.jbpm.pvm.internal.script.ScriptManager;
+import org.jbpm.pvm.internal.util.ReflectUtil;
+import org.jbpm.pvm.internal.wire.WireContext;
+import org.jbpm.pvm.internal.wire.WireException;
+import org.jbpm.pvm.internal.wire.descriptor.ArgDescriptor;
+import org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor;
+import org.jbpm.pvm.internal.wire.operation.InvokeOperation;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class JavaServiceTaskActivity extends BpmnAutomaticActivity {
+
+ private static final long serialVersionUID = 1L;
+
+ protected String targetExpression;
+ protected String targetLanguage;
+ protected Object target;
+
+ protected String methodName;
+ protected String variableName;
+ protected InvokeOperation invokeOperation;
+
+ public void perform(OpenExecution execution) throws Exception {
+
+ Object invocationTarget = null;
+
+ WireContext wireContext = new WireContext();
+
+ if (target!=null) {
+ invocationTarget = target;
+
+ } else if (targetExpression!=null) {
+ ScriptManager scriptManager = EnvironmentDefaults.getScriptManager();
+ invocationTarget = scriptManager.evaluateExpression(targetExpression, targetLanguage);
+
+ } else {
+ throw new JbpmException("no target specified");
+ }
+
+ try {
+ List<ArgDescriptor> argDescriptors = null;
+ Object[] args = null;
+ if (invokeOperation!=null) {
+ argDescriptors = invokeOperation.getArgDescriptors();
+ args = ObjectDescriptor.getArgs(wireContext, argDescriptors);
+ }
+
+ Class<?> clazz = invocationTarget.getClass();
+ Method method = ReflectUtil.findMethod(clazz, methodName, argDescriptors, args);
+ if (method==null) {
+ throw new WireException("method "+ReflectUtil.getSignature(methodName, argDescriptors, args)+" unavailable");
+ }
+
+ Object returnValue = ReflectUtil.invoke(method, invocationTarget, args);
+
+ if (variableName!=null) {
+ execution.setVariable(variableName, returnValue);
+ }
+
+ } catch (WireException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new WireException("couldn't invoke method "+methodName+": "+e.getMessage(), e);
+ }
+ proceed((ExecutionImpl)execution, findTransitions((ExecutionImpl)execution, CONDITIONS_CHECKED));
+ }
+
+ public void setTarget(Object target) {
+ this.target = target;
+ }
+ public void setMethodName(String methodName) {
+ this.methodName = methodName;
+ }
+ public void setVariableName(String variableName) {
+ this.variableName = variableName;
+ }
+ public void setInvokeOperation(InvokeOperation invokeOperation) {
+ this.invokeOperation = invokeOperation;
+ }
+ public void setTargetExpression(String expression) {
+ this.targetExpression = expression;
+ }
+ public void setTargetLanguage(String language) {
+ this.targetLanguage = language;
+ }
+}
Deleted: jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/Resource.java
===================================================================
--- jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/Resource.java 2009-08-09 02:13:07 UTC (rev 5453)
+++ jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/Resource.java 2009-08-10 10:59:46 UTC (rev 5454)
@@ -1,35 +0,0 @@
-package org.jbpm.bpmn.flownodes;
-
-import java.util.Map;
-
-public class Resource {
-
- String id;
- String name;
- Map<String, ResourceParameter> parameters;
-
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public Map<String, ResourceParameter> getParameters() {
- return parameters;
- }
-
- public void setParameters(Map<String, ResourceParameter> parameters) {
- this.parameters = parameters;
- }
-
-}
Deleted: jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ResourceParameter.java
===================================================================
--- jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ResourceParameter.java 2009-08-09 02:13:07 UTC (rev 5453)
+++ jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ResourceParameter.java 2009-08-10 10:59:46 UTC (rev 5454)
@@ -1,37 +0,0 @@
-package org.jbpm.bpmn.flownodes;
-
-import javax.xml.namespace.QName;
-
-import org.jbpm.pvm.internal.model.VariableDefinitionImpl;
-
-
-public class ResourceParameter extends VariableDefinitionImpl {
-
- String id;
- QName type;
- boolean required;
-
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- public QName getType() {
- return type;
- }
-
- public void setType(QName type) {
- this.type = type;
- }
-
- public boolean isRequired() {
- return required;
- }
-
- public void setRequired(boolean required) {
- this.required = required;
- }
-}
Modified: jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ScriptTaskActivity.java
===================================================================
--- jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ScriptTaskActivity.java 2009-08-09 02:13:07 UTC (rev 5453)
+++ jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ScriptTaskActivity.java 2009-08-10 10:59:46 UTC (rev 5454)
@@ -21,6 +21,7 @@
*/
package org.jbpm.bpmn.flownodes;
+import org.jbpm.api.model.OpenExecution;
import org.jbpm.pvm.internal.model.ExecutionImpl;
import org.jbpm.pvm.internal.model.ExpressionEvaluator;
import org.jbpm.pvm.internal.wire.WireContext;
@@ -33,7 +34,7 @@
private ExpressionEvaluatorDescriptor script;
- public void perform(ExecutionImpl execution) throws Exception {
+ public void perform(OpenExecution execution) throws Exception {
try {
//TODO: return values etc...
Deleted: jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ServiceTaskActivity.java
===================================================================
--- jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ServiceTaskActivity.java 2009-08-09 02:13:07 UTC (rev 5453)
+++ jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ServiceTaskActivity.java 2009-08-10 10:59:46 UTC (rev 5454)
@@ -1,208 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jbpm.bpmn.flownodes;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.jbpm.pvm.internal.model.ExecutionImpl;
-import org.jbpm.pvm.internal.wire.WireException;
-
-public class ServiceTaskActivity extends BpmnAutomaticActivity {
-
- private static final long serialVersionUID = 1L;
-
- public static class Data {
- private String id;
- private String xmlSchemaType;
- }
-
- public static class Assignment {
- private String fromExpression;
- private String toExpression;
- }
-
- // inputs
- Data inputData = null; // more than one allowed in BPMN 2
- List<Assignment> inputAssociation = new ArrayList<Assignment>();
-
- // outputs
- Data outputData = null; // more than one allowed in BPMN 2
- List<Assignment> outputAssociation = new ArrayList<Assignment>();
-
- // endpoint and binding
- private String operation;
- private String endpointAddress;
- private String portName;
- private String serviceName;
-
- public void perform(ExecutionImpl execution) throws Exception {
- try {
- callWebservice();
- } catch (Exception e) {
- throw new WireException("couldn't invoke WS " + operation + ": " + e.getMessage(), e);
- }
- }
-
- private void callWebservice() {
- System.out.println("calling ws: " + getOperation());
- // // Qnames for service as defined in wsdl.
- // QName serviceName =
- // new QName(getNamespace(), getServiceName());
- //
- // //QName for Port As defined in wsdl.
- // QName portName =
- // new QName(getNamespace(), getPort());
- //
- // //Endpoint Address
- // String endpointAddress = getEndpointAdress();
- //
- // // Create a dynamic Service instance
- // Service service = Service.create(serviceName);
- //
- // // Add a port to the Service
- // service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING,
- // endpointAddress);
- //
- // //Create a dispatch instance
- // Dispatch<SOAPMessage> dispatch =
- // service.createDispatch(portName, SOAPMessage.class,
- // Service.Mode.MESSAGE);
- //
- // // Use Dispatch as BindingProvider
- // BindingProvider bp = (BindingProvider) dispatch;
- //
- // // Optionally Configure RequestContext to send SOAPAction HTTP Header
- // Map<String, Object> rc = bp.getRequestContext();
- // rc.put(BindingProvider.SOAPACTION_USE_PROPERTY, Boolean.TRUE);
- // rc.put(BindingProvider.SOAPACTION_URI_PROPERTY, "hello");
- //
- // // Obtain a preconfigured SAAJ MessageFactory
- // MessageFactory factory =
- // ((SOAPBinding) bp.getBinding()).getMessageFactory();
- //
- // // Create SOAPMessage Request
- // SOAPMessage request = factory.createMessage();
- //
- // // Request Header
- // SOAPHeader header = request.getSOAPHeader();
- //
- // // Request Body
- // SOAPBody body = request.getSOAPBody();
- //
- // // Compose the soap:Body payload
- // QName payloadName =
- // new QName("http://www.example.com/schemas/HelloWorld", "hello",
- // "ns1");
- //
- // SOAPBodyElement payload = body.addBodyElement(payloadName);
- //
- // SOAPElement message = payload.addChildElement("message");
- //
- // message.addTextNode("Hello World!");
- //
- // // Invoke the endpoint synchronously
- // SOAPMessage reply = null;
- //
- // try {
- // //Invoke Endpoint Operation and read response
- // reply = dispatch.invoke(request);
- // } catch (WebServiceException wse){
- // wse.printStackTrace();
- // }
- //
- // // process the reply
- // body = reply.getSOAPBody();
- //
- // QName responseName =
- // new QName("http://www.example.com/schemas/HelloWorld",
- // "helloResponse");
- //
- // SOAPBodyElement bodyElement =
- // body.getChildElements(responseName).next());
- // String message = bodyElement.getValue();
- }
-
- public Data getInputData() {
- return inputData;
- }
-
- public void setInputData(Data inputData) {
- this.inputData = inputData;
- }
-
- public List<Assignment> getInputAssociation() {
- return inputAssociation;
- }
-
- public void setInputAssociation(List<Assignment> inputAssociation) {
- this.inputAssociation = inputAssociation;
- }
-
- public Data getOutputData() {
- return outputData;
- }
-
- public void setOutputData(Data outputData) {
- this.outputData = outputData;
- }
-
- public List<Assignment> getOutputAssociation() {
- return outputAssociation;
- }
-
- public void setOutputAssociation(List<Assignment> outputAssociation) {
- this.outputAssociation = outputAssociation;
- }
-
- public String getOperation() {
- return operation;
- }
-
- public void setOperation(String operation) {
- this.operation = operation;
- }
-
- public String getEndpointAddress() {
- return endpointAddress;
- }
-
- public void setEndpointAddress(String endpointAddress) {
- this.endpointAddress = endpointAddress;
- }
-
- public String getPortName() {
- return portName;
- }
-
- public void setPortName(String portName) {
- this.portName = portName;
- }
-
- public String getServiceName() {
- return serviceName;
- }
-
- public void setServiceName(String serviceName) {
- this.serviceName = serviceName;
- }
-}
Modified: jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ServiceTaskBinding.java
===================================================================
--- jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ServiceTaskBinding.java 2009-08-09 02:13:07 UTC (rev 5453)
+++ jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ServiceTaskBinding.java 2009-08-10 10:59:46 UTC (rev 5454)
@@ -21,50 +21,74 @@
*/
package org.jbpm.bpmn.flownodes;
+import java.util.List;
+
+import org.jbpm.bpmn.model.BpmnProcessDefinition;
import org.jbpm.pvm.internal.util.XmlUtil;
+import org.jbpm.pvm.internal.wire.WireContext;
+import org.jbpm.pvm.internal.wire.descriptor.ArgDescriptor;
+import org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor;
+import org.jbpm.pvm.internal.wire.operation.InvokeOperation;
import org.jbpm.pvm.internal.xml.Parse;
import org.jbpm.pvm.internal.xml.Parser;
+import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
-
public class ServiceTaskBinding extends BpmnBinding {
+ static final String TAG = "serviceTask";
public ServiceTaskBinding() {
- super("serviceTask");
+ super(TAG);
}
public Object parse(Element element, Parse parse, Parser parser) {
- ServiceTaskActivity wsActivity = new ServiceTaskActivity();
+ JavaServiceTaskActivity javaActivity = new JavaServiceTaskActivity();
+
+ BpmnProcessDefinition bpmnProcessDefinition = parse.findObject(BpmnProcessDefinition.class);
+ Document dom = element.getOwnerDocument();
+
+ String operationRef = XmlUtil.attribute(element, "operationRef", true, parse, null);
+
+ //Element operationElement = dom.getElementById(operationRef);
+ Element operationElement = bpmnProcessDefinition.getOperations().get(operationRef);
+ Element interfaceElement = (Element)operationElement.getParentNode();
+
+ javaActivity.setMethodName(operationElement.getAttribute("name"));
- String methodName = XmlUtil.attribute(element, "operationRef", true, parse, null);
-// javaActivity.setMethodName(methodName);
+ //TODO put in function
+ String outMessageRef = XmlUtil.element(operationElement, "outMessageRef").getTextContent().trim();
+ String outStructureRef = bpmnProcessDefinition.getMessages().get(outMessageRef).getAttribute("structureRef");
+ Element outItemDefinition = bpmnProcessDefinition.getItemDefinitions().get(outStructureRef);
+ Element var = XmlUtil.element(outItemDefinition, "var");
+ javaActivity.setVariableName(var.getAttribute("name"));
+ String inMessageRef = XmlUtil.element(operationElement, "inMessageRef").getTextContent().trim();
+ String inStructureRef = bpmnProcessDefinition.getMessages().get(inMessageRef).getAttribute("structureRef");
+ Element itemDefinition = bpmnProcessDefinition.getItemDefinitions().get(inStructureRef);
- String variableName = XmlUtil.attribute(element, "var");
-// javaActivity.setVariableName(variableName);
+ List<Element> argElements = XmlUtil.elements(itemDefinition, "arg");
+ if (!argElements.isEmpty()) {
+ List<ArgDescriptor> argDescriptors = wireParser.parseArgs(argElements, parse);
+ InvokeOperation invokeOperation = new InvokeOperation();
+ invokeOperation.setArgDescriptors(argDescriptors);
+ javaActivity.setInvokeOperation(invokeOperation);
+ }
-// List<Element> argElements = XmlUtil.elements(element, "arg");
-// if (!argElements.isEmpty()) {
-// List<ArgDescriptor> argDescriptors = wireParser.parseArgs(argElements, parse);
-// InvokeOperation invokeOperation = new InvokeOperation();
-// invokeOperation.setArgDescriptors(argDescriptors);
-// javaActivity.setInvokeOperation(invokeOperation);
-// }
-//
-// if (element.hasAttribute("class")) {
-// ObjectDescriptor objectDescriptor = JpdlParser.parseObjectDescriptor(element, parse);
-// javaActivity.setTargetDescriptor(objectDescriptor);
-//
-// } else if (element.hasAttribute("expr")) {
-// String expression = element.getAttribute("expr");
-// javaActivity.setTargetExpression(expression);
-// javaActivity.setTargetLanguage(XmlUtil.attribute(element, "lang"));
-//
-// } else {
-// // parse.addProblem("no target specified in "+TAG+": must specify attribute 'class' or 'expr'", element);
-// }
+ if (interfaceElement.getAttribute("name") != null) {
+ ObjectDescriptor objectDescriptor = new ObjectDescriptor();
+
+ objectDescriptor.setClassName(interfaceElement.getAttribute("name"));
+ Object target = WireContext.create(objectDescriptor);
+ if (target == null) {
+ parse.addProblem("name attribute must resolv to a class in "+TAG, element);
+ }
+ javaActivity.setTarget(target);
+ } else {
+ // parse.addProblem("no target specified in "+TAG+": must specify attribute 'class' or 'expr'", element);
+ }
- return wsActivity;
+ return javaActivity;
}
}
Modified: jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/model/BpmnProcessDefinition.java
===================================================================
--- jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/model/BpmnProcessDefinition.java 2009-08-09 02:13:07 UTC (rev 5453)
+++ jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/model/BpmnProcessDefinition.java 2009-08-10 10:59:46 UTC (rev 5454)
@@ -26,7 +26,7 @@
import java.util.List;
import java.util.Map;
-import org.jbpm.bpmn.flownodes.Resource;
+import org.jbpm.bpmn.common.Resource;
import org.jbpm.pvm.internal.model.ExecutionImpl;
import org.jbpm.pvm.internal.model.ProcessDefinitionImpl;
import org.jbpm.pvm.internal.model.VariableDefinitionImpl;
@@ -40,8 +40,9 @@
Map<String, TaskDefinitionImpl> taskDefinitions = new HashMap<String, TaskDefinitionImpl>();
List<VariableDefinitionImpl> processVariableDefinitions = new ArrayList<VariableDefinitionImpl>();
Map<String, Element> messages = new HashMap<String, Element>();
- Map<String, String> itemDefinitions = new HashMap<String, String>();
+ Map<String, Element> itemDefinitions = new HashMap<String, Element>();
Map<String, Element> interfaces = new HashMap<String, Element>();
+ Map<String, Element> operations = new HashMap<String, Element>();
Map<String, Resource> resources = new HashMap<String, Resource>();
protected ExecutionImpl newProcessInstance() {
@@ -59,7 +60,7 @@
}
public String getType(String typeRef) {
- return itemDefinitions.get(typeRef);
+ return itemDefinitions.get(typeRef).getAttribute("strutcureRef");
}
public void setVariableDefinition(List<VariableDefinitionImpl> variableDefinitions) {
@@ -73,4 +74,42 @@
public Map<String, Resource> getResources() {
return resources;
}
+
+ public Map<String, Element> getInterfaces() {
+ return interfaces;
+ }
+
+ public void setInterfaces(Map<String, Element> interfaces) {
+ this.interfaces = interfaces;
+ }
+
+
+ public Map<String, Element> getOperations() {
+ return operations;
+ }
+
+
+ public void setOperations(Map<String, Element> operations) {
+ this.operations = operations;
+ }
+
+ public Map<String, Element> getMessages() {
+ return messages;
+ }
+
+
+ public void setMessages(Map<String, Element> messages) {
+ this.messages = messages;
+ }
+
+
+ public Map<String, Element> getItemDefinitions() {
+ return itemDefinitions;
+ }
+
+
+ public void setItemDefinitions(Map<String, Element> itemDefinitions) {
+ this.itemDefinitions = itemDefinitions;
+ }
+
}
Modified: jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/parser/BpmnParser.java
===================================================================
--- jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/parser/BpmnParser.java 2009-08-09 02:13:07 UTC (rev 5453)
+++ jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/parser/BpmnParser.java 2009-08-10 10:59:46 UTC (rev 5454)
@@ -27,20 +27,17 @@
import java.util.List;
import javax.xml.namespace.QName;
-import javax.xml.parsers.DocumentBuilderFactory;
-import org.dom4j.DocumentFactory;
import org.jbpm.api.JbpmException;
import org.jbpm.api.activity.ActivityBehaviour;
+import org.jbpm.bpmn.common.Resource;
+import org.jbpm.bpmn.common.ResourceParameter;
import org.jbpm.bpmn.flownodes.BpmnBinding;
import org.jbpm.bpmn.flownodes.ExclusiveGatewayActivity;
-import org.jbpm.bpmn.flownodes.Resource;
-import org.jbpm.bpmn.flownodes.ResourceParameter;
import org.jbpm.bpmn.model.BpmnProcessDefinition;
import org.jbpm.internal.log.Log;
-import org.jbpm.pvm.internal.model.Activity;
import org.jbpm.pvm.internal.model.ActivityImpl;
import org.jbpm.pvm.internal.model.CompositeElementImpl;
import org.jbpm.pvm.internal.model.ProcessDefinitionImpl;
@@ -53,13 +50,10 @@
import org.jbpm.pvm.internal.util.XmlUtil;
import org.jbpm.pvm.internal.wire.binding.ObjectBinding;
import org.jbpm.pvm.internal.wire.descriptor.ExpressionEvaluatorDescriptor;
-import org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor;
-import org.jbpm.pvm.internal.wire.descriptor.ReferenceDescriptor;
import org.jbpm.pvm.internal.wire.xml.WireParser;
import org.jbpm.pvm.internal.xml.Bindings;
import org.jbpm.pvm.internal.xml.Parse;
import org.jbpm.pvm.internal.xml.Parser;
-import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
@@ -122,9 +116,17 @@
processDefinition.setDescription(description);
}
- // TODO: hack, should be done in a different way
- parseResources(processElement, parse, processDefinition);
+ // TODO: should be done in a different way? On a different level?
+ parseResources((Element)processElement.getParentNode(), parse, processDefinition);
+
+ parseInterfaces((Element)processElement.getParentNode(), parse, processDefinition);
+
+ parseItemDefinitions((Element)processElement.getParentNode(), parse, processDefinition);
+ parseMessages((Element)processElement.getParentNode(), parse, processDefinition);
+
+
+
parseDataObjects(processElement, parse, processDefinition);
// activities
@@ -273,9 +275,9 @@
}
public void parseDefinition(Element documentElement, Parse parse) {
parseImports(documentElement, parse);
- parseItemDefinitions(documentElement, parse);
- parseMessages(documentElement, parse);
- parseInterfaces(documentElement, parse);
+ ///parseItemDefinitions(documentElement, parse);
+ //parseMessages(documentElement, parse);
+ // parseInterfaces(documentElement, parse);
// parseResources(documentElement, parse);
}
@@ -348,8 +350,6 @@
// BpmnProcessDefinition processDefinition) {
private void parseResources(Element documentElement, Parse parse, BpmnProcessDefinition processDefinition) {
- List<Resource> resources = new ArrayList<Resource>();
-
for (Element resourceElement : XmlUtil.elements(documentElement, "resource")) {
Resource resource = new Resource();
@@ -372,20 +372,33 @@
}
- private void parseInterfaces(Element documentElement, Parse parse) {
-
+ private void parseInterfaces(Element documentElement, Parse parse, BpmnProcessDefinition processDefinition) {
+
+ for (Element interfaceElement : XmlUtil.elements(documentElement, "interface")) {
+ for (Element operationElement : XmlUtil.elements(interfaceElement, "operation")) {
+ processDefinition.getOperations().put(XmlUtil.attribute(operationElement, "id"), operationElement);
+ }
+ processDefinition.getInterfaces().put(XmlUtil.attribute(interfaceElement, "id"), interfaceElement);
+ }
}
- private void parseMessages(Element documentElement, Parse parse) {
+ private void parseMessages(Element documentElement, Parse parse, BpmnProcessDefinition processDefinition) {
+ for (Element messageElement : XmlUtil.elements(documentElement, "message")) {
+ processDefinition.getMessages().put(XmlUtil.attribute(messageElement, "id"), messageElement);
+ }
}
- private void parseItemDefinitions(Element documentElement, Parse parse) {
+ private void parseItemDefinitions(Element documentElement, Parse parse, BpmnProcessDefinition processDefinition) {
+ for (Element itemDefinitionElement : XmlUtil.elements(documentElement, "itemDefinition")) {
+ processDefinition.getItemDefinitions().put(XmlUtil.attribute(itemDefinitionElement, "id"), itemDefinitionElement);
+ }
+
}
private void parseImports(Element documentElement, Parse parse) {
}
-
+
}
Added: jbpm4/trunk/modules/bpmn/src/test/java/org/jbpm/bpmn/example/JavaServiceTask.java
===================================================================
--- jbpm4/trunk/modules/bpmn/src/test/java/org/jbpm/bpmn/example/JavaServiceTask.java (rev 0)
+++ jbpm4/trunk/modules/bpmn/src/test/java/org/jbpm/bpmn/example/JavaServiceTask.java 2009-08-10 10:59:46 UTC (rev 5454)
@@ -0,0 +1,9 @@
+package org.jbpm.bpmn.example;
+
+public class JavaServiceTask {
+
+ String myMethod(String arg1) {
+ return "myMethod with arg1: "+ arg1;
+ }
+
+}
Added: jbpm4/trunk/modules/bpmn/src/test/java/org/jbpm/bpmn/flownodes/ServiceTaskTest.java
===================================================================
--- jbpm4/trunk/modules/bpmn/src/test/java/org/jbpm/bpmn/flownodes/ServiceTaskTest.java (rev 0)
+++ jbpm4/trunk/modules/bpmn/src/test/java/org/jbpm/bpmn/flownodes/ServiceTaskTest.java 2009-08-10 10:59:46 UTC (rev 5454)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.bpmn.flownodes;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.jbpm.api.ProcessInstance;
+import org.jbpm.api.TaskQuery;
+import org.jbpm.api.task.Task;
+import org.jbpm.bpmn.parser.BpmnParser;
+//import org.jbpm.bpmn.model.BpmnProcessDefinition;
+//import org.jbpm.bpmn.parser.BpmnParser;
+import org.jbpm.pvm.internal.model.ExecutionImpl;
+import org.jbpm.pvm.internal.xml.Parse;
+import org.jbpm.pvm.internal.xml.Problem;
+import org.jbpm.test.JbpmTestCase;
+
+/**
+ * @author Bernd Ruecker (bernd.ruecker at camunda.com)
+ */
+public class ServiceTaskTest extends JbpmTestCase {
+
+ public void testNormalJavaServiceTaskCall() {
+ String deploymentId = repositoryService.createDeployment().addResourceFromClasspath("org/jbpm/bpmn/flownodes/ServiceTaskJava.bpmn.xml").deploy();
+
+ try {
+
+ Map variables = new HashMap();
+ variables.put("var1", "value");
+
+ ProcessInstance pi = executionService.startProcessInstanceByKey("ServiceTaskJavaProcess", variables);
+
+ assertNotNull(pi.getId());
+ assertEquals("myMethod with arg1: value",executionService.getVariable(pi.getId(), "returnVar"));
+
+ TaskQuery taskQuery = taskService.createTaskQuery();
+ List<Task> allTasks = taskQuery.list();
+ assertEquals(1, allTasks.size());
+
+ taskService.completeTask(allTasks.get(0).getId());
+
+ // process instance is ended
+ pi = executionService.findProcessInstanceById(pi.getId());
+ // One way or another I would also expect this to work... pi is gone from
+ // database immediately when ended. Only in History DB
+ // assertEquals(true, pi.isEnded());
+ assertNull(pi);
+ } finally {
+ repositoryService.deleteDeploymentCascade(deploymentId);
+ }
+ }
+
+}
Added: jbpm4/trunk/modules/bpmn/src/test/resources/org/jbpm/bpmn/flownodes/ServiceTaskJava.bpmn.xml
===================================================================
--- jbpm4/trunk/modules/bpmn/src/test/resources/org/jbpm/bpmn/flownodes/ServiceTaskJava.bpmn.xml (rev 0)
+++ jbpm4/trunk/modules/bpmn/src/test/resources/org/jbpm/bpmn/flownodes/ServiceTaskJava.bpmn.xml 2009-08-10 10:59:46 UTC (rev 5454)
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<bpmn:definitions id="ServiceTaskJava"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://schema.omg.org/spec/BPMN/2.0 ../../../../../../main/resources/BPMN20.xsd"
+ xmlns:bpmn="http://schema.omg.org/spec/BPMN/2.0" typeLanguage="http://www.w3.org/2001/XMLSchema"
+ expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://sample.bpmn.camunda.com/"
+ xmlns:jbpm="http://jbpm.org/4.0/bpmn2">
+
+ <bpmn:itemDefinition id="itemDefinition1">
+ <jbpm:arg>
+ <jbpm:object expr="#{var1}" />
+ </jbpm:arg>
+ </bpmn:itemDefinition>
+
+ <bpmn:itemDefinition id="itemDefinition2">
+ <jbpm:var name="returnVar" />
+ </bpmn:itemDefinition>
+
+ <bpmn:message id="inputMessage" name="input message"
+ structureRef="itemDefinition1"></bpmn:message>
+
+ <bpmn:message id="outputMessage" name="output message"
+ structureRef="itemDefinition2">
+ </bpmn:message>
+
+ <bpmn:interface id="interface21"
+ name="org.jbpm.bpmn.example.JavaServiceTask">
+ <bpmn:operation id="operation42" name="myMethod">
+ <bpmn:inMessageRef>inputMessage</bpmn:inMessageRef>
+ <bpmn:outMessageRef>outputMessage</bpmn:outMessageRef>
+ </bpmn:operation>
+ </bpmn:interface>
+
+ <bpmn:process id="ServiceTaskJavaProcess" name="Simple process with java service task">
+
+ <bpmn:startEvent id="Start" />
+
+ <bpmn:sequenceFlow id="flow1" name="fromStartToServiceTask"
+ sourceRef="Start" targetRef="ServiceTask" />
+
+ <bpmn:serviceTask id="ServiceTask" name="service task"
+ implementation="Other" operationRef="operation42">
+ </bpmn:serviceTask>
+
+ <bpmn:sequenceFlow id="flow2" name="fromServiceTaskToUT1"
+ sourceRef="ServiceTask" targetRef="UT1" />
+
+ <bpmn:userTask id="UT1" name="bla" implementation="other" />
+
+ <bpmn:sequenceFlow id="flow3" name="fromUT1toEnd"
+ sourceRef="UT1" targetRef="End" />
+
+ <bpmn:endEvent id="End" name="End" />
+
+ </bpmn:process>
+</bpmn:definitions>
More information about the jbpm-commits
mailing list