lib/openwfe/expressions/fe_cursor.rb in openwferu-0.9.16 vs lib/openwfe/expressions/fe_cursor.rb in openwferu-0.9.17
- old
+ new
@@ -1,8 +1,8 @@
#
#--
-# Copyright (c) 2007, John Mettraux, OpenWFE.org
+# Copyright (c) 2007-2008, John Mettraux, OpenWFE.org
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
@@ -76,43 +76,47 @@
class CursorExpression < WithTemplateExpression
include CommandMixin
names :cursor
- attr_accessor \
- :loop_id,
- :current_child_id,
- :current_child_fei
+ #
+ # the integer identifier for the current loop
+ #
+ attr_accessor :loop_id
+ #
+ # what is the index of the child we're currently executing
+ #
+ attr_accessor :current_child_id
+
+
def apply (workitem)
+ new_environment
+
@loop_id = 0
@current_child_id = -1
- clean_children_list()
+ clean_children_list
- reply(workitem)
+ reply workitem
end
def reply (workitem)
- if @children.length < 1
- #
- # well, currently, no infinite empty loop allowed
- #
- reply_to_parent(workitem)
- return
- end
+ return reply_to_parent(workitem) \
+ if @children.length < 1
+ #
+ # well, currently, no infinite empty loop allowed
command, step = determine_command_and_step workitem
ldebug { "reply() command is '#{command} #{step}'" }
if command == C_BREAK or command == C_CANCEL
- reply_to_parent workitem
- return
+ return reply_to_parent(workitem)
end
if command == C_REWIND or command == C_CONTINUE
@current_child_id = 0
@@ -130,53 +134,71 @@
@current_child_id = @current_child_id + step
@current_child_id = 0 if @current_child_id < 0
if @current_child_id >= @children.length
- if not is_loop
- reply_to_parent(workitem)
- return
- end
+
+ return reply_to_parent(workitem) unless is_loop
+
@loop_id += 1
@current_child_id = 0
end
end
- @current_child_fei = nil
+ template_fei = @children[@current_child_id]
- store_itself()
-
- @current_child_fei = @children[@current_child_id]
-
#
# launch the next child as a template
+ #@current_child_fei = get_expression_pool.launch_template(
get_expression_pool.launch_template(
- self, @loop_id, @current_child_fei, workitem, nil)
+ self,
+ @environment_id,
+ @loop_id,
+ template_fei,
+ workitem,
+ nil)
+
+ store_itself
end
#
# takes care of cancelling the current child if necessary
#
def cancel
- get_expression_pool.cancel(@current_child_fei) \
- if @current_child_fei
+ cfei = current_child_fei
+ get_expression_pool.cancel(cfei) if cfei
super
end
#
# Returns false, the child class LoopExpression does return true.
#
def is_loop
+
false
end
protected
#
+ # Determines the fei of the child being currently executed.
+ # This method is used by cancel().
+ #
+ def current_child_fei
+
+ cfei = @children[@current_child_id].dup
+
+ return nil unless cfei
+
+ cfei.wfid = cfei.wfid + '.' + @loop_id.to_s
+ cfei
+ end
+
+ #
# Makes sure that only flow expression are left in the cursor
# children list (text and comment nodes get discarded).
#
def clean_children_list
@@ -191,14 +213,33 @@
#
# The 'loop' expression is like 'cursor' but it doesn't exit until
# it's broken (with 'break' or 'cancel').
#
+ # <loop>
+ # <participant ref="toto" />
+ # <break if="${f:done} == true" />
+ # </loop>
+ #
+ # or, in a Ruby process definition :
+ #
+ # _loop do
+ # participant "toto"
+ # _break :if => "${f:done} == true"
+ # end
+ #
+ # (notice the _ (underscores) to distinguish the OpenWFEru expressions
+ # from the native Ruby ones).
+ #
class LoopExpression < CursorExpression
names :loop
+ #
+ # Returns true as, well, it's a loop...
+ #
def is_loop
+
true
end
end
end