XPath expressions can be used at different points inside a BPEL process, i.e. conditions, expressions, queries, and in replacement variables inside descriptions and staff assignments.
XPath can be used to implement all kinds of conditions inside the BPEL process. To specify a condition in XPath, the expression language has to be set to XPath accordingly. To do this, select 'XPath 1.0' from the 'Expression language' drop down list on the condition's 'Details' view as shown below:
The library process uses a XPath condition to determine whether the requested book is available. So the link condition from the link leading from ReadLibraryAsset to BookAvailable has the following condition:
Formulating this expression in natural language results in something like the following: from the library_asset variable count all book instances where the book_id of the instance equals the book_id passed to the process in the input message (lend_book_request) and the status of this book_instance is "onShelf". If there is one or more book instances return true and false otherwise.
Since the library_asset variable is xsd-typed, the second argument of the getVariableData function names an XPath expression and no part name is required. The same is true for the second usage of the getVariableData function that refers to the also xsd-typed variable lend_book_request.
XPath expressions are especially valuable inside assign activities, since using XPath is the only way to access the contents of a variable on a more granular level than the the whole message or a WSDL message part of variable. XPath expression can be used in the from and to specification on an assignment.
On the to side, XPath is exclusively used to specify a query based on a variable or a variable part. For the from side, a user can alternatively specify a pure XPath expression without referring to a variable. To do this, select "XPath Expression" from the "From" drop down list as it is done for the ReadLibraryAsset in the library process:
The XPath Expression Builder window opens:
In the first assignment of the ReadLibraryAsset activity we have used the following expression to create an empty message of the library_asset data structure and assign it to the library_asset variable.
The variable is filled with data in proceeding assignments.
An XPath query expression on the to specification is, for example, used in the ReadLibraryAsset activity after receiving a lend-out request. To assign a name from a literal to the first user of the library asset we apply /users[1]/user_id on the library_asset variable and use this expression on the to side of the assign. The picture below shows how this is modeled with WebSphere Integration Developer:
To edit the XPath query expression, click on the Edit Query button
next to the entry on the to side of the assign. The XPath Expression Builder window opens.
To model the timer that guards on the lend-out period we have set-up a time-out branch in the receive choice WaitForBookToBeReturned. The time-out expression is defined as an XPath duration expression; this type of expression must resolve to a string that is of the xsd:duration format.
The lexical representation for xsd duration has the following form: PnYnMnDTnHnMnS, where nY represents the number of years, nM the number of months, nD the number of days, 'T' is the date/time separator, nH the number of hours, nM the number of minutes and nS the number of seconds. The number of seconds can include decimal.
The time-out expression of the lend-out period is set to 2 minutes. This is an rather short period to read a book, however, it is a realistic time to wait when the sample process is run. Two minutes expressed as an xsd duration is PT2M.
It is important to note that this expression is put into single quotes. The expression language has to be set again to 'XPath 1.0'. The picture below shows how to specify the time-out expression in WebSphere Integration Developer:
The description of activity and process templates can contain replacement strings that are evaluated when the according instance is started. As a result each process or activity instance of one process model can have different descriptions depending on the contents of process variables. This dynamic character of the description allows a user to better identify a process or activity instance, especially in process or activity list views.
The replacement strings in descriptions must match the following syntax:
The name of the variable is optional in cases where a default message is defined. For example, the description of an invoke activity uses the invoke's input message as default variable. The table below lists all default messages that are defined for the respective process entities:
Entity | Default Message | Entity | Default Message | Process | The input message of the process. | Receive | The message received. |
---|---|---|---|
Invoke | The input message of the invoke. | Pick | The message received. |
Staff | The input message of the staff activity. | Reply | The reply message. |
For a process instance description, the default variable for the replacement is the actual input message that started the process. Note that for processes with multiple creating activities the replacement string must be applicable for all the different types of input messages. Note further that the variables of the process are not initialized at the point in time when the process description is resolved. Thus, the input message of the process is the only source that can be used in the replacement strings.
The library process has its description set to:
Both replacement strings refer to the WSDL input message of the operation that started
the process. So even though the process uses data object typed variables in the receive,
the WSDL part name lend_bookParameters has to be specified. The second part of the
replacement defines the XPath expressions starting form the WSDL part as root element. I.e.
there is another xsd complex typed wrapped around the actual lend_book_input object.
The complete data structure and its relationship to the WSDL operation is shown in the
following picture:
When the library service is started with a lend-out request that specifies 10 for the user Id and 1 for the book Id, the process description of this instance is set to:
The receive choice WaitForBookToBeReturned in the sample process has also a description with replacement variables defined:
Here, the replacement string refer to data object variables -- names book and user --
inside the process, so no part name is specified. The replacement strings just contain the variable
name and the XPath expression, which select the top-level elements name and title,
respectively.
The description is then resolved to:
The same syntax as for descriptions can be applied for replacement variables inside staff assignments. The replacement variables are first scanned by the human task container, so replacement expressions that refer to process variables need to be marked explicitly with the prefix "wf:variable". The human task manager will then delegate the resolution to the flow manager. The complete syntax is as follows:
In the library sample we allow users who did not return a book in time to read the staff task. This can be implemented by assigning the reader role to:
Note that there are no extension functions available for XPath expressions used in replacement variables of process or activity description and staff assignments.