Class OpenWFE::IfExpression
In: lib/openwfe/expressions/fe_if.rb
Parent: FlowExpression

The ‘if’ expression.

    <if>
        <equals field-value="f0" other-value="true" />
        <participant ref="alpha" />
    </if>

It accepts an ‘else’ clause :

    <if>
        <equals field-value="f0" other-value="true" />
        <participant ref="alpha" />
        <participant ref="bravo" />
    </if>

The ‘test’ attribute can be used instead of a condition child :

    <if test="${f:f0}">
        <participant ref="alpha" />
    </if>

The ‘rtest’ attribute can be used to embed a condition expressed directly in Ruby :

    <if rtest="5 * 12 == 61">
        <participant ref="alpha" />
    </if>

(Note that ‘rtest’ may only be used if the :ruby_eval_allowed parameter has been set in the engine‘s application_context :

    engine.application_context[:ruby_eval_allowed] = true

but this is dangerous if the origin of the process defintions to run are not trusted)

Used alone with ‘test’ or ‘rtest’, the ‘if’ expression simply sets the the result field of its workitem to the result of its attribute evaluation :

    <if test="5 == 6"/>

will set the result field of the workitem to ‘false’.

Methods

Included Modules

ConditionMixin

Attributes

condition_replied  [RW]  This boolean is set to true when the conditional claused has been evaluated and the ‘if’ is waiting for the consequence‘s reply.

Public Instance methods

[Source]

     # File lib/openwfe/expressions/fe_if.rb, line 110
110:         def apply (workitem)
111: 
112:             #workitem.unset_result
113:                 #
114:                 # since OpenWFEru 0.9.16 previous __result__ values
115:                 # are not erased before an 'if'.
116: 
117:             test = eval_condition(:test, workitem, :not)
118: 
119:             if @children.length < 1
120:                 #workitem.set_result test if test
121:                 workitem.set_result((test != nil and test != false))
122:                 reply_to_parent(workitem) 
123:                 return
124:             end
125: 
126:             @condition_replied = (test != nil)
127:                 #
128:                 # if the "test" attribute is not used, test will be null
129: 
130:             store_itself()
131: 
132:             if test != nil
133:                 apply_consequence(test, workitem, 0)
134:             else
135:                 get_expression_pool.apply(@children[0], workitem)
136:             end
137:         end

[Source]

     # File lib/openwfe/expressions/fe_if.rb, line 139
139:         def reply (workitem)
140: 
141:             return reply_to_parent(workitem) \
142:                 if @condition_replied
143: 
144:             result = workitem.attributes[FIELD_RESULT]
145: 
146:             @condition_replied = true
147: 
148:             store_itself()
149: 
150:             apply_consequence result, workitem
151:         end

This reply_to_parent takes care of cleaning all the children before replying to the parent expression, this is important because only the ‘then’ or the ‘else’ child got evaluated, the remaining one has to be cleaned out here.

[Source]

     # File lib/openwfe/expressions/fe_if.rb, line 159
159:         def reply_to_parent(workitem)
160: 
161:             clean_children()
162:             super workitem
163:         end

Protected Instance methods

[Source]

     # File lib/openwfe/expressions/fe_if.rb, line 167
167:             def apply_consequence (index, workitem, offset=1)
168: 
169:                 if index == true
170:                     index = 0
171:                 elsif index == false
172:                     index = 1
173:                 elsif index == nil
174:                     index = 1
175:                 elsif not index.integer?
176:                     index = 0
177:                 end
178: 
179:                 index = index + offset
180: 
181:                 if index >= @children.length
182:                     reply_to_parent workitem
183:                 else
184:                     get_expression_pool.apply @children[index], workitem
185:                 end
186:             end

[Validate]