Introducing Variables and Expressions into WLMSE is to allow the elements (Assignment, Escalation, Timeout, etc) in task definition and properties of task instance (Priority, Title, etc) to be dynamically derived from input message.
Variables
Internal Variables
Three Internal variables are provided by WLMSE:
TaskInput and
TaskOutput.
TaskInput automatically holds the
single element of input message received from BPEL that triggers the task instance creation
1.
TaskOutput variable holds the output message to be returned to BPEL when task completes, initially it is an empty element.
$TaskInput is read-only
Note: Currently, we only support single part for $TaskInput and $TaskOutput
Note: User can use Mapper to create xpath in Init and Action/ChangeVariables (http://wiki.open-esb.java.net/Wiki.jsp?page=WLMSEInit-Action
), but currently user has to type xpath in Assignment, Escalation, Notification, etc starting with "="
WLM XPath functions
The set of unique Xpath functions provided by WLM are:
LDAP Xpath functions:
Please see
LDAP Xpath functions 
, LDAP Xpath functions are only available when LDAP is used
Get Task Owner:
wlmfn:get-task-owner () as xs:string
This function returns the user who claimed the task, if the task is not claimed by anyone, null will be returned.
TaskInstance.Owner is automatically assigned by WLMSE when a user claims the task.
Task Initialization
Task initialization section on task definition (.wf) file is optional, it consists of variable definitions and initialization.
<init>
( <variables>
...
</variables>) ?
( <variable-init>
...
</variable-init> ) ? +
/init>
<variable-init> initializes a variable by assignment, similar to BPEL's assignment
<variable-init>
(<copy>
<from>VariableXpathExpression</from>
<to> VariableXpathExpression</to>
</copy>
)+
</variable-init>
VariableXpathExpression takes the form : $VariableName.partName{/Xpath expression}, for $TaskInput and $TaskOutput, partName can be omitted because $TaskInput and $TaskOutput always contain only one part,
but Mapper supports xpath in the form of $VariableName.partName{/Xpath expression} only, thus it is the preferred to have partName
An example is to assign orderId from the input message to the output message to initialize the output message
<variable-init>
<copy>
<from>$TaskInput.part1/orderId</from>
<to>$TaskOutput.part1/orderId</to>
</copy>
</variable-init>
The binding of WLM variable to Xpath is similar to what BPEL does, the default xpath support is Xpath 1.0
Note: The variable initialization happens before the task is created and the variable once assigned can not be changed
Dynamic Assignment, Timeout & Escalation
Variables can be used in Assignment, Timeout & Escalation, for example, the user comes from the TaskInput variable:
<assignment>
<user>$TaskInput.part1/users</user>
<group>$TaskInput.part1/groups</group>
</assignment>
Multiple users/groups can be obtained as a collection returned by the xpath, for example:
<sampleInput>
....
<users>
Mary
</users>
<users>
John
</users>
</sampleOutput>
When the input message is above, using $TaskInput.part1/users in assignment as <assignment><user>$TaskInput/users</user></assignment> also result in two assignees: Mary and John
The same rule applies to group.
The duration and deadline expression Timeout & Escalation can come from input message too, for example:
<sampleInput>
....
<deadline>
'2007-12-01T23:00:00Z'
</deadline>
</sampleOutput>
<escalation>
<deadline expressionLanguage="xpath">$TaskInput.part1/deadline</deadline>
... ...
</escalation>
Literals
Literals are constants expression with no variables. To indicate an expression is literal, the expression must be surrounded by quotes , for example:
<escalation>
<deadline expressionLanguage="xpath">'2007-12-01T23:00:00Z'</deadline>
... ...
</escalation>
<assignment>
<user>'Mary'</user>
<user>'John'</user>
<group>'CustomerServiceRep'</group>
</assignment>
Use Case
Use Case 1:
A purchase order received by BPEL, BPEL checks the purchase order's customer id, if it is a large account, assigns the High priority to the input message priority part, and changes the assignees part to a large account manager. If else, the priority is Normal and another assignee group is assigned.
Conditional language such as if-then-else
Conditional language will be supported later. Although we do not want to duplicate BPEL's constructs into WLMSE to be make it unnecessarily complex, we may need it for adding/removing escalation/timeout constructs dynamically.
we could use xpath 2.0 if else expression which will allow us to use if else without introducing if else constructs in task definition.
http://www.w3.org/TR/2003/WD-xpath20-20030502/#id-conditionals
Implementation notes
Currently, as the variables do not change values during the life span of the task, they are not persisted. Every time the task is recreated from DB, it goes through the init process to initialize variables. Thus, no special treatment is needed for recovery