[jbpm-commits] JBoss JBPM SVN: r5711 - in jbpm4/trunk/modules: jpdl/src/main/java/org/jbpm/jpdl/internal/activity and 4 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Wed Oct 7 11:01:43 EDT 2009
Author: tom.baeyens at jboss.com
Date: 2009-10-07 11:01:42 -0400 (Wed, 07 Oct 2009)
New Revision: 5711
Modified:
jbpm4/trunk/modules/api/src/main/resources/jpdl-4.2.xsd
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JavaActivity.java
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JavaBinding.java
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/xml/JpdlParser.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/ObjectDescriptor.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/usercode/UserCodeReference.java
jbpm4/trunk/modules/userguide/src/main/docbook/en/modules/ch06-Jpdl.xml
Log:
JBPM-2565 java activity refactoring in context of the new usercode facilities
Modified: jbpm4/trunk/modules/api/src/main/resources/jpdl-4.2.xsd
===================================================================
--- jbpm4/trunk/modules/api/src/main/resources/jpdl-4.2.xsd 2009-10-07 13:53:48 UTC (rev 5710)
+++ jbpm4/trunk/modules/api/src/main/resources/jpdl-4.2.xsd 2009-10-07 15:01:42 UTC (rev 5711)
@@ -179,6 +179,9 @@
<sequence>
<element name="condition" minOccurs="0" maxOccurs="unbounded">
<complexType>
+ <sequence>
+ <element name="handler" minOccurs="0" type="tns:wireObjectType" />
+ </sequence>
<attribute name="expr" type="string">
<annotation><documentation>The script text that will be evaluated.
</documentation></annotation>
@@ -879,10 +882,6 @@
<annotation><documentation>Method arguments.</documentation></annotation>
</element>
</sequence>
- <attribute name="object" type="string">
- <annotation><documentation>Name of the object in the environment
- </documentation></annotation>
- </attribute>
<attribute name="method" type="string" use="required">
<annotation><documentation>The name of the method to invoke.
</documentation></annotation>
@@ -1058,6 +1057,7 @@
any other custom event.
</documentation></annotation>
</attribute>
+ <attribute name="continue" type="tns:continueType" default="sync" />
</complexType>
</element>
Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JavaActivity.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JavaActivity.java 2009-10-07 13:53:48 UTC (rev 5710)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JavaActivity.java 2009-10-07 15:01:42 UTC (rev 5711)
@@ -22,20 +22,18 @@
package org.jbpm.jpdl.internal.activity;
import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
import java.util.List;
import org.jbpm.api.JbpmException;
import org.jbpm.api.model.OpenExecution;
-import org.jbpm.pvm.internal.env.EnvironmentImpl;
-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.Descriptor;
import org.jbpm.pvm.internal.wire.WireContext;
+import org.jbpm.pvm.internal.wire.WireDefinition;
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;
+import org.jbpm.pvm.internal.wire.usercode.UserCodeReference;
/**
@@ -44,75 +42,62 @@
public class JavaActivity extends JpdlAutomaticActivity {
private static final long serialVersionUID = 1L;
-
- protected String targetExpression;
- protected String targetLanguage;
- protected Object target;
- protected String methodName;
+ protected UserCodeReference invocationReference;
+
+ protected String methodName = null;
+ protected List<ArgDescriptor> argDescriptors = null;
+
protected String variableName;
- protected InvokeOperation invokeOperation;
public void perform(OpenExecution execution) throws Exception {
-
- Object invocationTarget = null;
+ if (invocationReference==null) {
+ throw new JbpmException("no target specified");
+ }
- WireContext wireContext = new WireContext();
+ Object target = invocationReference.getObject(execution);
+ Class<?> clazz;
+ // method invocation on object or static method invocation in case object is null
if (target!=null) {
- invocationTarget = target;
-
- } else if (targetExpression!=null) {
- ScriptManager scriptManager = ScriptManager.getScriptManager();
- invocationTarget = scriptManager.evaluateExpression(targetExpression, targetLanguage);
-
+ clazz = target.getClass();
} else {
- throw new JbpmException("no target specified");
+ ObjectDescriptor objectDescriptor = (ObjectDescriptor) invocationReference.getDescriptor();
+ String className = objectDescriptor.getClassName();
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ clazz = Class.forName(className, true, classLoader);
}
-
- 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);
+
+ WireContext wireContext = new WireContext(new WireDefinition());
+ Object returnValue = ObjectDescriptor.invokeMethod(methodName, argDescriptors, wireContext, target, clazz);
+
+ if (variableName!=null) {
+ execution.setVariable(variableName, returnValue);
}
}
- public void setTarget(Object target) {
- this.target = target;
+ public void setInvocationReference(UserCodeReference invocationReference) {
+ this.invocationReference = invocationReference;
}
+ public void setVariableName(String variableName) {
+ this.variableName = variableName;
+ }
+ public String getMethodName() {
+ return methodName;
+ }
public void setMethodName(String methodName) {
this.methodName = methodName;
}
- public void setVariableName(String variableName) {
- this.variableName = variableName;
+ public List<ArgDescriptor> getArgDescriptors() {
+ return argDescriptors;
}
- public void setInvokeOperation(InvokeOperation invokeOperation) {
- this.invokeOperation = invokeOperation;
+ public void setArgDescriptors(List<ArgDescriptor> argDescriptors) {
+ this.argDescriptors = argDescriptors;
}
- public void setTargetExpression(String expression) {
- this.targetExpression = expression;
+ public UserCodeReference getInvocationReference() {
+ return invocationReference;
}
- public void setTargetLanguage(String language) {
- this.targetLanguage = language;
+ public String getVariableName() {
+ return variableName;
}
}
Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JavaBinding.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JavaBinding.java 2009-10-07 13:53:48 UTC (rev 5710)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JavaBinding.java 2009-10-07 15:01:42 UTC (rev 5711)
@@ -21,14 +21,10 @@
*/
package org.jbpm.jpdl.internal.activity;
-import java.util.List;
-
import org.jbpm.jpdl.internal.xml.JpdlParser;
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.wire.usercode.UserCodeReference;
import org.jbpm.pvm.internal.xml.Parse;
import org.w3c.dom.Element;
@@ -47,34 +43,22 @@
public Object parseJpdl(Element element, Parse parse, JpdlParser parser) {
JavaActivity javaActivity = new JavaActivity();
- String methodName = XmlUtil.attribute(element, "method", true, parse, null);
- javaActivity.setMethodName(methodName);
+ if (XmlUtil.attribute(element, "method", true, parse, null)!=null) {
+ UserCodeReference invocationReference = parser.parseUserCodeReference(element, parse);
+ javaActivity.setInvocationReference(invocationReference);
+
+ ObjectDescriptor objectDescriptor = (ObjectDescriptor) invocationReference.getDescriptor();
+
+ javaActivity.setArgDescriptors(objectDescriptor.getArgDescriptors());
+ objectDescriptor.setArgDescriptors(null);
+ javaActivity.setMethodName(objectDescriptor.getMethodName());
+ objectDescriptor.setMethodName(null);
+ }
+
String variableName = XmlUtil.attribute(element, "var");
javaActivity.setVariableName(variableName);
- 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 = parser.parseObjectDescriptor(element, parse);
- Object target = WireContext.create(objectDescriptor);
- javaActivity.setTarget(target);
-
- } 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);
- }
-
return javaActivity;
}
}
Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/xml/JpdlParser.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/xml/JpdlParser.java 2009-10-07 13:53:48 UTC (rev 5710)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/xml/JpdlParser.java 2009-10-07 15:01:42 UTC (rev 5711)
@@ -730,19 +730,22 @@
return null;
}
- // generic helper methods for jpdl activity and event listener bindings /////
-
public UserCodeReference parseUserCodeReference(Element element, Parse parse) {
UserCodeReference userCodeReference = new UserCodeReference();
ObjectDescriptor objectDescriptor = (ObjectDescriptor) objectBinding.parse(element, parse, wireParser);
userCodeReference.setDescriptor(objectDescriptor);
+
+ if (objectDescriptor.getExpr()!=null) {
+ // expressions are not cached by default
+ userCodeReference.setCached(false);
+ }
Boolean isCached = XmlUtil.attributeBoolean(element, "cache", false, parse, null);
if (isCached!=null) {
userCodeReference.setCached(isCached.booleanValue());
}
-
+
return userCodeReference;
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/ObjectDescriptor.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/ObjectDescriptor.java 2009-10-07 13:53:48 UTC (rev 5710)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/ObjectDescriptor.java 2009-10-07 15:01:42 UTC (rev 5711)
@@ -181,23 +181,8 @@
}
if (methodName!=null) {
- // method invocation on object or static method invocation in case object is null
- if (object!=null) {
- clazz = object.getClass();
- }
try {
- Object[] args = ObjectDescriptor.getArgs(wireContext, argDescriptors);
- Method method = ReflectUtil.findMethod(clazz, methodName, argDescriptors, args);
- if (method==null) {
- // throw exception but first, generate decent message
- throw new WireException("method "+ReflectUtil.getSignature(methodName, argDescriptors, args)+" is not available on "+
- (object!=null ? "object "+object+" ("+clazz.getName()+")" : "class "+clazz.getName()));
- }
- if (object == null && (!Modifier.isStatic(method.getModifiers()))) {
- // A non static method is invoked on a null object
- throw new WireException("method "+ clazz.getName() + "." + ReflectUtil.getSignature(methodName, argDescriptors, args)+" is not static. It cannot be called on a null object.");
- }
- object = ReflectUtil.invoke(method, object, args);
+ object = invokeMethod(methodName, argDescriptors, wireContext, object, clazz);
} catch (WireException e) {
throw e;
@@ -209,6 +194,26 @@
return object;
}
+ public static Object invokeMethod(String methodName, List<ArgDescriptor> argDescriptors, WireContext wireContext, Object object, Class< ? > clazz) throws Exception {
+ // method invocation on object or static method invocation in case object is null
+ if (object!=null) {
+ clazz = object.getClass();
+ }
+ Object[] args = ObjectDescriptor.getArgs(wireContext, argDescriptors);
+ Method method = ReflectUtil.findMethod(clazz, methodName, argDescriptors, args);
+ if (method==null) {
+ // throw exception but first, generate decent message
+ throw new WireException("method "+ReflectUtil.getSignature(methodName, argDescriptors, args)+" is not available on "+
+ (object!=null ? "object "+object+" ("+clazz.getName()+")" : "class "+clazz.getName()));
+ }
+ if (object == null && (!Modifier.isStatic(method.getModifiers()))) {
+ // A non static method is invoked on a null object
+ throw new WireException("method "+ clazz.getName() + "." + ReflectUtil.getSignature(methodName, argDescriptors, args)+" is not static. It cannot be called on a null object.");
+ }
+ object = ReflectUtil.invoke(method, object, args);
+ return object;
+ }
+
/**
* Initializes the specified object.
* If auto-wiring was set to <code>true</code>, auto-wiring is performed (see {@link #autoWire(Object, WireContext)}). Fields and properties injections are then performed.
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/usercode/UserCodeReference.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/usercode/UserCodeReference.java 2009-10-07 13:53:48 UTC (rev 5710)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/usercode/UserCodeReference.java 2009-10-07 15:01:42 UTC (rev 5711)
@@ -91,4 +91,7 @@
public void setDescriptor(Descriptor descriptor) {
this.descriptor = descriptor;
}
+ public Descriptor getDescriptor() {
+ return descriptor;
+ }
}
Modified: jbpm4/trunk/modules/userguide/src/main/docbook/en/modules/ch06-Jpdl.xml
===================================================================
--- jbpm4/trunk/modules/userguide/src/main/docbook/en/modules/ch06-Jpdl.xml 2009-10-07 13:53:48 UTC (rev 5710)
+++ jbpm4/trunk/modules/userguide/src/main/docbook/en/modules/ch06-Jpdl.xml 2009-10-07 15:01:42 UTC (rev 5711)
@@ -2912,7 +2912,7 @@
<entry></entry>
<entry>one of {class|expr} is required</entry>
<entry>The fully qualified classname. Instantiation is done only once and
- the user object is cached as part of the process definition.
+ the user object is cached as part of the process definition.
</entry>
</row>
<row>
@@ -2920,7 +2920,10 @@
<entry>expression</entry>
<entry></entry>
<entry>one of {class|expr} is required</entry>
- <entry>Expression for which the resulting value will be taken as the target object.</entry>
+ <entry>Expression for which the resulting value will be taken as the target object.
+ Expressions will be evaluated for every usage. In other words, the resulting
+ value of the evaluation will not be cached.
+ </entry>
</row>
</tbody>
</tgroup>
More information about the jbpm-commits
mailing list