close

Filter

loading table of contents...

Workflow Manual / Version 2010

Table Of Contents

5.4.4 Example Expression

This chapter describes how to create a Boolean expression and insert it in the workflow definition. Have a look at Example 5.10, “Example Expression” for the example of a simple Boolean expression which always returns "true".

Define the expression in the workflow definition

You can use your expression in the workflow definition via the <Expression> tag. See Example 5.9, “Including expressions in the workflow definition” for an expression inserted in an <If> tag.

<If name="One">
  <Condition>
    <Expression class="com.coremedia.example.expression.
                       DemoExpression"/>
  </Condition>
  <Then successor="True"/>
  <Else successor="False"/>
</If>

Example 5.9. Including expressions in the workflow definition


If the expression evaluates to true then the successor is the task named True, otherwise it is the task named False.

Programming the expression

See Example 5.10, “Example Expression” for the important lines of the code. Configuring the expression with variable names from the workflow is not shown in this example but it is similar to the method in the action example. The same is true for accessing the repository.

1:  package com.coremedia.examples.workflow.expression;
2:  
3:  import java.util.Map;
4:  import com.coremedia.workflow.WfInstance;
5:  import com.coremedia.workflow.common.expressions.
      AbstractBooleanExpression;
6:
7:  public class DemoExpression 
      extends AbstractBooleanExpression {
8:    
9:    public String getName() {
10:     return "DemoExpression";
11:   } 
12:  
13:   public String getSymbol() {
14:     return getName();
15:    } 
16:  
17:   public boolean isInfix() {
18:     return false;
19:   }
20:
21:   public boolean evaluateExpression(WfInstance instance, 
                                        Map localVariables) {
22:     return true;
23:   } 
24: } 

Example 5.10. Example Expression


Line 1: The package to which the action belongs.

Lines 3 - 5: All Java classes which are at least necessary for an expression to use.

Line 7: In order to create a Boolean expression you need to implement the interface WfBooleanExpression. For convenience you can extend the abstract AbstractBooleanExpression class.

Line 9 - 19: If you extend AbstractBooleanExpression, you need to implement four methods. Three of them getName(), getSymbol() and isInfix() are used for better reading of the log, if the expression is converted into a string using the toString() method.

Line 21 - 23: The fourth method to implement is the most important one, evaluateExpression(WfInstance instance, Map localVariables). This method will be called when the expression is evaluated. Here you can implement the logic of your expression. Using the parameter instance, you can access the workflow instance as shown in the action example. The Map localVariables gives access to expression local variables, which may be defined with ForAll and Let.

Search Results

Table Of Contents