| Class | OpenWFE::CaseExpression |
| In: |
lib/openwfe/expressions/fe_if.rb
|
| Parent: | FlowExpression |
The ‘case’ expression.
<case>
<equals field="f0" other-value="ready" />
<participant ref="alpha" />
<if test="${supply_level} == ${field:supply_request}" />
<participant ref="bravo" />
<participant ref="charly" />
</case>
A generalized ‘if’. Will evaluate its children, expecting the order :
- condition
- consequence
- condition
- consequence
...
- else consequence (optional)
The ‘switch’ nickname can be used for ‘case’.
| evaluating_condition | [RW] | set to ‘true’ when the case expression is actually evaluating a condition (ie not triggering a consequence). |
| offset | [RW] | keeping track of where we are in the case iteration |
# File lib/openwfe/expressions/fe_if.rb, line 231
231: def apply (workitem)
232:
233: #workitem.unset_result
234: #
235: # since OpenWFEru 0.9.16 previous __result__ values
236: # are not erased before a 'case'.
237:
238: @offset = nil
239:
240: trigger_child workitem, true
241: end
# File lib/openwfe/expressions/fe_if.rb, line 243
243: def reply (workitem)
244:
245: if @evaluating_condition
246:
247: result = workitem.get_boolean_result
248:
249: #ldebug { "reply() result : '#{result.to_s}' (#{result.class})" }
250:
251: trigger_child workitem, !result
252: else
253:
254: reply_to_parent workitem
255: end
256: end
# File lib/openwfe/expressions/fe_if.rb, line 260
260: def trigger_child (workitem, is_condition)
261:
262: @offset = if !@offset
263: 0
264: elsif is_condition
265: @offset + 2
266: else
267: @offset + 1
268: end
269:
270: #ldebug { "trigger_child() is_condition ? #{is_condition}" }
271: #ldebug { "trigger_child() next offset is #{@offset}" }
272:
273: unless @children[@offset]
274: reply_to_parent workitem
275: return
276: end
277:
278: @evaluating_condition = is_condition
279:
280: store_itself
281:
282: get_expression_pool.apply(@children[@offset], workitem)
283: end