[
https://jira.jboss.org/jira/browse/JBPM-1752?page=com.atlassian.jira.plug...
]
Britt Miner commented on JBPM-1752:
-----------------------------------
I have a fear that automatic expression evaluation for ActionHandler configuration could
interfere with the ability to solve some interesting problems. I'll provide an
example below.
A recommendation:
Rather than hard coding the expression handling logic, provide an example of a base class
that users can extend if they want to take advantage of expression handling/syntax in any
of their Handlers. With a base class, users can take advantage of expression handling
when they want to, customize it if they need to, or intentionally ignore it. Below is a
class that I use consistently--if you like it, just re-brand it, re-write it or whatever
you like.
As an example of customizing the handling of expressions, this particular class provides a
special 'concatenateEL' method--for instance, if you want to assign swimlanes to a
particular Sales queue based on Market, in your AssignmentHandler configuration you could
write <group>Sales-#{market}</group>, which would evaluate to something like
"Sales-London". The stock JbpmExpressionEvaluator doesn't provide for this
type of evaluation (and I really don't know if it should.)
No, this is not completely automatic for the user, they have to call one of the methods
from their Handler, but it does allow them much more flexibility.
/*
* GenericHandler.java
* Created on April 1, 2008, 7:06 PM
* Copyright 2008, Britt Miner.
*/
package org.bminer.jbpm.pd;
import java.util.regex.*;
import org.jbpm.graph.exe.ExecutionContext;
import org.jbpm.jpdl.el.impl.JbpmExpressionEvaluator;
/**
* @author bminer
*/
public abstract class GenericHandler {
// Prepare to identify any EL expressions, #{...}, regex: "#\{.*?\}"
String elPatternStr = "#\\{.*?\\}";
Pattern elPattern = Pattern.compile(elPatternStr);
protected String conditionExpression = null;
/* Evaluate the input as a possible EL expression. */
protected Object evaluateEL(String inputStr, ExecutionContext ec) {
if (inputStr == null) {
return null;
}
Matcher matcher = elPattern.matcher(inputStr);
if (matcher.matches()) { //input is one big EL expression
return JbpmExpressionEvaluator.evaluate(inputStr, ec);
} else {
return inputStr;
}
}
/* Treats input as a possible series of EL expressions and concatenates what
* is found.
*/
protected String concatenateEL(String inputStr, ExecutionContext ec) {
if (inputStr == null) {
return null;
}
Matcher matcher = elPattern.matcher(inputStr);
StringBuffer buf = new StringBuffer();
while (matcher.find()) {
// Get the match result
String elExpr = matcher.group();
// Evaluate EL expression
Object o = JbpmExpressionEvaluator.evaluate(elExpr, ec);
String elValue = "";
if (o != null) {
elValue = String.valueOf(JbpmExpressionEvaluator.evaluate(elExpr, ec));
}
// Insert the calculated value in place of the EL expression
matcher.appendReplacement(buf, elValue);
}
matcher.appendTail(buf);
// Deliver result
if (buf.length() > 0) {
return buf.toString();
} else {
return null;
}
}
/* Returns true if the value is a String which contains the pattern delineating
* an EL expression.
*/
protected boolean hasEL(Object value) {
if (value instanceof String) {
Matcher matcher = elPattern.matcher((String) value);
return matcher.find();
}
return false;
}
/* Returns true if the value is a String which in its entirety composes
* one EL expression.
*/
protected boolean isEL(Object value) {
if (value instanceof String) {
Matcher matcher = elPattern.matcher((String) value);
return matcher.matches();
}
return false;
}
public void setConditionExpression(String condition) {
this.conditionExpression = condition;
}
public void setCondition(String condition) {
this.conditionExpression = condition;
}
}
Expression Evaluation in ActionHandler Properties
-------------------------------------------------
Key: JBPM-1752
URL:
https://jira.jboss.org/jira/browse/JBPM-1752
Project: JBoss jBPM
Issue Type: Feature Request
Security Level: Public(Everyone can see)
Components: Core Engine
Reporter: Alejandro Guizar
Assignee: Alejandro Guizar
Fix For: jBPM 3.3.0 GA
The parameters for an ActionHandler should be able to use expressions in it, so you could
write
<action class="...">
<x>#{someObject.x}</x>
</action>
This could be done in the FieldInstatiator class (around line 67 we have
"setPropertyValue(Class clazz, Object newInstance, String propertyName, Element
propertyElement)"), but the execution context is not available there.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira