Class OpenWFE::CursorExpression
In: lib/openwfe/expressions/fe_cursor.rb
Parent: WithTemplateExpression

The ‘cursor’ is much like a sequence, but you can go back and forth within it, as it reads the field ‘__cursor_command__’ (or the field specified in the ‘command-field’ attribute) at each transition (each time it‘s supposed to move from one child expression to the next).

    cursor do
        participant "alpha"
        skip :step => "2"
        participant "bravo"
        participant "charly"
        set :field => "__cursor_command__", value => "2"
        participant "delta"
        participant "echo"
        skip 2
        participant "fox"
        #
        # in that cursor example, only the participants alpha, charly and
        # echo will be handed a workitem
        # (notice the last 'skip' with its light syntax)
        #
    end

As you can see, you can directly set the value of the field ‘__cursor_command__’ or use a CursorCommandExpression like ‘skip’ or ‘jump’.

Methods

Included Modules

CommandMixin

Attributes

current_child_id  [RW]  what is the index of the child we‘re currently executing
loop_id  [RW]  the integer identifier for the current loop

Public Instance methods

[Source]

     # File lib/openwfe/expressions/fe_cursor.rb, line 92
 92:         def apply (workitem)
 93: 
 94:             new_environment
 95: 
 96:             @loop_id = 0
 97: 
 98:             @current_child_id = -1
 99: 
100:             clean_children_list
101: 
102:             reply workitem
103:         end

takes care of cancelling the current child if necessary

[Source]

     # File lib/openwfe/expressions/fe_cursor.rb, line 166
166:         def cancel
167: 
168:             cfei = current_child_fei
169:             get_expression_pool.cancel(cfei) if cfei
170: 
171:             super
172:         end

Returns false, the child class LoopExpression does return true.

[Source]

     # File lib/openwfe/expressions/fe_cursor.rb, line 177
177:         def is_loop
178: 
179:             false
180:         end

[Source]

     # File lib/openwfe/expressions/fe_cursor.rb, line 105
105:         def reply (workitem)
106: 
107:             return reply_to_parent(workitem) \
108:                 if @children.length < 1
109:                     #
110:                     # well, currently, no infinite empty loop allowed
111: 
112:             command, step = determine_command_and_step workitem
113: 
114:             ldebug { "reply() command is '#{command} #{step}'" }
115: 
116:             if command == C_BREAK or command == C_CANCEL
117:                 return reply_to_parent(workitem)
118:             end
119: 
120:             if command == C_REWIND or command == C_CONTINUE
121: 
122:                 @current_child_id = 0
123: 
124:             elsif command and command.match("^#{C_JUMP}")
125: 
126:                 @current_child_id = step
127:                 @current_child_id = 0 if @current_child_id < 0
128: 
129:                 @current_child_id = @children.length - 1 \
130:                     if @current_child_id >= @children.length
131: 
132:             else # C_SKIP or C_BACK
133: 
134:                 @current_child_id = @current_child_id + step
135: 
136:                 @current_child_id = 0 if @current_child_id < 0
137: 
138:                 if @current_child_id >= @children.length
139: 
140:                     return reply_to_parent(workitem) unless is_loop
141: 
142:                     @loop_id += 1
143:                     @current_child_id = 0
144:                 end
145:             end
146: 
147:             template_fei = @children[@current_child_id]
148: 
149:             #
150:             # launch the next child as a template
151: 
152:             get_expression_pool.launch_template(
153:                 self, 
154:                 @environment_id, 
155:                 @loop_id, 
156:                 template_fei,
157:                 workitem, 
158:                 nil)
159: 
160:             store_itself
161:         end

Protected Instance methods

Makes sure that only flow expression are left in the cursor children list (text and comment nodes get discarded).

[Source]

     # File lib/openwfe/expressions/fe_cursor.rb, line 202
202:             def clean_children_list
203: 
204:                 c = @children
205:                 @children = []
206:                 c.each do |child|
207:                     @children << child \
208:                         if child.kind_of?(OpenWFE::FlowExpressionId)
209:                 end
210:             end

Determines the fei of the child being currently executed. This method is used by cancel().

[Source]

     # File lib/openwfe/expressions/fe_cursor.rb, line 188
188:             def current_child_fei
189: 
190:                 cfei = @children[@current_child_id].dup
191: 
192:                 return nil unless cfei
193: 
194:                 cfei.wfid = cfei.wfid + '.' + @loop_id.to_s
195:                 cfei
196:             end

[Validate]