openwferu 0.9.1 → 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. data/{README → README.txt} +16 -13
  2. data/bin/validate-workflow.rb +46 -22
  3. data/examples/README.txt +8 -0
  4. data/examples/homeworkreview.rb +66 -0
  5. data/examples/quotereporter.rb +154 -0
  6. data/lib/{openwferu.rb → openwfe.rb} +6 -8
  7. data/lib/{ru → openwfe}/contextual.rb +11 -3
  8. data/lib/{ru → openwfe/engine}/engine.rb +50 -36
  9. data/lib/{ru/participant.rb → openwfe/engine/file_persisted_engine.rb} +21 -22
  10. data/lib/openwfe/expool/expressionpool.rb +534 -0
  11. data/lib/openwfe/expool/expstorage.rb +184 -0
  12. data/lib/openwfe/expool/journalexpstorage.rb +312 -0
  13. data/lib/openwfe/expool/yamlexpstorage.rb +127 -0
  14. data/lib/{ru → openwfe/expressions}/environment.rb +19 -14
  15. data/lib/{ru → openwfe/expressions}/expressionmap.rb +48 -21
  16. data/lib/{ru → openwfe/expressions}/fe_concurrence.rb +111 -35
  17. data/lib/openwfe/expressions/fe_cursor.rb +236 -0
  18. data/lib/{ru → openwfe/expressions}/fe_define.rb +5 -5
  19. data/lib/openwfe/expressions/fe_fqv.rb +99 -0
  20. data/lib/openwfe/expressions/fe_iterator.rb +182 -0
  21. data/lib/{ru/fe_misc.rb → openwfe/expressions/fe_losfor.rb} +14 -56
  22. data/lib/openwfe/expressions/fe_misc.rb +102 -0
  23. data/lib/{ru → openwfe/expressions}/fe_participant.rb +25 -14
  24. data/lib/{ru → openwfe/expressions}/fe_raw.rb +39 -75
  25. data/lib/{ru/fe_base.rb → openwfe/expressions/fe_sequence.rb} +40 -35
  26. data/lib/{ru → openwfe/expressions}/fe_subprocess.rb +30 -14
  27. data/lib/{ru → openwfe/expressions}/fe_time.rb +59 -31
  28. data/lib/{ru → openwfe/expressions}/fe_utils.rb +42 -26
  29. data/lib/{ru → openwfe/expressions}/fe_value.rb +20 -14
  30. data/lib/openwfe/expressions/flowexpression.rb +434 -0
  31. data/lib/openwfe/expressions/raw_prog.rb +391 -0
  32. data/lib/openwfe/expressions/raw_xml.rb +128 -0
  33. data/lib/openwfe/flowexpressionid.rb +148 -0
  34. data/lib/{ru → openwfe}/logging.rb +10 -6
  35. data/lib/{osocket.rb → openwfe/osocket.rb} +36 -35
  36. data/lib/{otime.rb → openwfe/otime.rb} +71 -21
  37. data/lib/openwfe/participants/atomparticipants.rb +144 -0
  38. data/lib/openwfe/participants/enoparticipant.rb +73 -0
  39. data/lib/openwfe/participants/participant.rb +85 -0
  40. data/lib/{ru → openwfe/participants}/participantmap.rb +40 -12
  41. data/lib/{ru → openwfe/participants}/participants.rb +41 -12
  42. data/lib/openwfe/participants/soapparticipants.rb +96 -0
  43. data/lib/{controlclient.rb → openwfe/rest/controlclient.rb} +12 -13
  44. data/lib/{definitions.rb → openwfe/rest/definitions.rb} +3 -3
  45. data/lib/{exception.rb → openwfe/rest/exception.rb} +3 -3
  46. data/lib/{restclient.rb → openwfe/rest/restclient.rb} +13 -22
  47. data/lib/{worklistclient.rb → openwfe/rest/worklistclient.rb} +33 -46
  48. data/lib/openwfe/rest/xmlcodec.rb +575 -0
  49. data/lib/{ru → openwfe}/rudefinitions.rb +32 -4
  50. data/lib/{ru → openwfe}/service.rb +20 -8
  51. data/lib/openwfe/storage/yamlfilestorage.rb +159 -0
  52. data/lib/{ru → openwfe/util}/dollar.rb +10 -8
  53. data/lib/openwfe/util/lru_cache.rb +149 -0
  54. data/lib/{ru → openwfe/util}/scheduler.rb +18 -10
  55. data/lib/{ru → openwfe/util}/schedulers.rb +7 -7
  56. data/lib/{utils.rb → openwfe/utils.rb} +93 -9
  57. data/lib/openwfe/workitem.rb +366 -0
  58. data/lib/openwfe/worklist/worklists.rb +175 -0
  59. data/test/README.txt +27 -0
  60. data/test/atomtest.rb +99 -0
  61. data/test/crontest.rb +58 -0
  62. data/test/dollartest.rb +3 -3
  63. data/test/feitest.rb +42 -14
  64. data/test/file_persistence_test.rb +93 -0
  65. data/test/flowtestbase.rb +72 -26
  66. data/test/ft_0.rb +1 -97
  67. data/test/ft_0b_sequence.rb +33 -0
  68. data/test/ft_0c_testname.rb +29 -0
  69. data/test/ft_10_loop.rb +48 -0
  70. data/test/ft_11_ppd.rb +292 -0
  71. data/test/ft_12_blockparticipant.rb +45 -0
  72. data/test/ft_13_eno.rb +51 -0
  73. data/test/ft_14_subprocess.rb +90 -0
  74. data/test/ft_14b_subprocess.rb +40 -0
  75. data/test/ft_15_iterator.rb +70 -0
  76. data/test/ft_16_fqv.rb +57 -0
  77. data/test/ft_1_unset.rb +25 -1
  78. data/test/ft_2_concurrence.rb +10 -5
  79. data/test/ft_3_equals.rb +35 -1
  80. data/test/ft_4_misc.rb +16 -1
  81. data/test/ft_5_time.rb +26 -1
  82. data/test/ft_6_lambda.rb +2 -1
  83. data/test/{ft_7_losfor.rb → ft_7_lose.rb} +41 -35
  84. data/test/ft_8_forget.rb +46 -0
  85. data/test/ft_9_cursor.rb +94 -0
  86. data/test/journal_persistence_test.rb +147 -0
  87. data/test/misctest.rb +13 -9
  88. data/test/rake_ptest.rb +18 -0
  89. data/test/rake_qtest.rb +43 -0
  90. data/test/{fulltest.rb → rake_test.rb} +2 -2
  91. data/test/raw_prog_test.rb +236 -0
  92. data/test/rest_test.rb +189 -0
  93. data/test/rutest_utils.rb +1 -1
  94. data/test/timetest.rb +42 -34
  95. metadata +125 -82
  96. data/lib/codec.rb +0 -573
  97. data/lib/flowexpressionid.rb +0 -139
  98. data/lib/ru/expressionpool.rb +0 -382
  99. data/lib/ru/expressionstorage.rb +0 -99
  100. data/lib/ru/flowexpression.rb +0 -272
  101. data/lib/ru/ruutils.rb +0 -70
  102. data/lib/test.rb +0 -222
  103. data/lib/workitem.rb +0 -249
  104. data/test/quicktest.rb +0 -21
@@ -0,0 +1,236 @@
1
+ #
2
+ #--
3
+ # Copyright (c) 2007, John Mettraux, OpenWFE.org
4
+ # All rights reserved.
5
+ #
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted provided that the following conditions are met:
8
+ #
9
+ # . Redistributions of source code must retain the above copyright notice, this
10
+ # list of conditions and the following disclaimer.
11
+ #
12
+ # . Redistributions in binary form must reproduce the above copyright notice,
13
+ # this list of conditions and the following disclaimer in the documentation
14
+ # and/or other materials provided with the distribution.
15
+ #
16
+ # . Neither the name of the "OpenWFE" nor the names of its contributors may be
17
+ # used to endorse or promote products derived from this software without
18
+ # specific prior written permission.
19
+ #
20
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
+ # POSSIBILITY OF SUCH DAMAGE.
31
+ #++
32
+ #
33
+ # $Id: definitions.rb 2725 2006-06-02 13:26:32Z jmettraux $
34
+ #
35
+
36
+ #
37
+ # "made in Japan"
38
+ #
39
+ # John Mettraux at openwfe.org
40
+ #
41
+
42
+ require 'openwfe/expressions/flowexpression'
43
+
44
+
45
+ #
46
+ # 'cursor' and 'loop' expressions
47
+ #
48
+
49
+ module OpenWFE
50
+
51
+ A_COMMAND_FIELD = "command-field"
52
+ F_COMMAND = "__cursor_command__"
53
+ A_DISALLOW = "disallow"
54
+
55
+ C_BACK = "back"
56
+ C_SKIP = "skip"
57
+ C_BREAK = "break"
58
+ C_CANCEL = "cancel"
59
+ C_REWIND = "rewind"
60
+ C_CONTINUE = "continue"
61
+
62
+ A_STEP = "step"
63
+
64
+ #
65
+ # The 'cursor' is much like a sequence, but you can go
66
+ # back and forth within it.
67
+ #
68
+ class CursorExpression < WithTemplateExpression
69
+
70
+ attr_accessor \
71
+ :current_child_id,
72
+ :current_child_fei
73
+
74
+ #
75
+ # apply / reply
76
+
77
+ def apply (workitem)
78
+
79
+ @current_child_id = -1
80
+
81
+ clean_children_list()
82
+
83
+ reply(workitem)
84
+ end
85
+
86
+ def reply (workitem)
87
+
88
+ if @children.length < 1
89
+ #
90
+ # well, currently, no infinite empty loop allowed
91
+ #
92
+ reply_to_parent(workitem)
93
+ return
94
+ end
95
+
96
+ command_field = lookup_command_field(workitem)
97
+ command = lookup_command(command_field, workitem)
98
+ disallow_list = lookup_disallow(workitem)
99
+
100
+ command = nil \
101
+ if disallow_list and disallow_list.include? command
102
+
103
+ if command == C_BREAK or command == C_CANCEL
104
+ reply_to_parent(workitem)
105
+ return
106
+ end
107
+
108
+ if command == C_REWIND or command == C_CONTINUE
109
+ @current_child_id = 0
110
+ else
111
+ step = lookup_step(command)
112
+ @current_child_id = @current_child_id + step
113
+
114
+ @current_child_id = 0 if @current_child_id < 0
115
+
116
+ if @current_child_id >= @children.length
117
+ if not is_loop
118
+ reply_to_parent(workitem)
119
+ return
120
+ end
121
+ @current_child_id = 0
122
+ end
123
+ end
124
+
125
+ workitem.attributes.delete(command_field)
126
+
127
+ @current_child_fei = nil
128
+
129
+ store_itself()
130
+
131
+ @current_child_fei = @children[@current_child_id]
132
+
133
+ #
134
+ # launch the next child as a template
135
+
136
+ get_expression_pool\
137
+ .launch_template(self, @current_child_fei, workitem, nil)
138
+ end
139
+
140
+ #
141
+ # takes care of cancelling the current child if necessary
142
+ #
143
+ def cancel ()
144
+ get_expression_pool.cancel(@current_child_fei) \
145
+ if @current_child_fei
146
+ super()
147
+ end
148
+
149
+ #
150
+ # returns false, the child class LoopExpression does return true.
151
+ #
152
+ def is_loop
153
+ return false
154
+ end
155
+
156
+ protected
157
+
158
+ def lookup_step (command)
159
+
160
+ return 1 if not command
161
+
162
+ step = 1
163
+
164
+ ss = command.split()
165
+
166
+ if ss.length > 1
167
+ step = Integer(ss[1])
168
+ end
169
+
170
+ step = -step if OpenWFE::starts_with(command, C_BACK)
171
+
172
+ return step
173
+ end
174
+
175
+ def clean_children_list
176
+
177
+ c = @children
178
+ @children = []
179
+ c.each do |child|
180
+ @children << child \
181
+ if child.kind_of? OpenWFE::FlowExpressionId
182
+ end
183
+ end
184
+
185
+ def lookup_command_field (workitem)
186
+
187
+ return lookup_attribute(A_COMMAND_FIELD, workitem, F_COMMAND)
188
+ end
189
+
190
+ def lookup_command (command_field, workitem)
191
+
192
+ command = workitem.attributes[command_field]
193
+ command = command.strip() if command
194
+
195
+ return command
196
+ end
197
+
198
+ def lookup_disallow (workitem)
199
+
200
+ return lookup_comma_list_attribute(A_DISALLOW, workitem)
201
+ end
202
+ end
203
+
204
+ #
205
+ # The 'loop' expression is like 'cursor' but it doesn't exit until
206
+ # it's broken.
207
+ #
208
+ class LoopExpression < CursorExpression
209
+
210
+ def is_loop
211
+ return true
212
+ end
213
+ end
214
+
215
+ #
216
+ # 'skip', 'continue', and the like
217
+ #
218
+ class CursorCommandExpression < FlowExpression
219
+
220
+ def apply (workitem)
221
+
222
+ command = @fei.expression_name
223
+
224
+ step = lookup_attribute(A_STEP, workitem, "1")
225
+ step = Integer(step)
226
+
227
+ command = "#{command} #{step}" if step != 1
228
+
229
+ workitem.attributes[F_COMMAND] = command
230
+
231
+ reply_to_parent(workitem)
232
+ end
233
+ end
234
+
235
+ end
236
+
@@ -1,6 +1,6 @@
1
1
  #
2
2
  #--
3
- # Copyright (c) 2006, John Mettraux, OpenWFE.org
3
+ # Copyright (c) 2006-2007, John Mettraux, OpenWFE.org
4
4
  # All rights reserved.
5
5
  #
6
6
  # Redistribution and use in source and binary forms, with or without
@@ -39,11 +39,11 @@
39
39
  # John Mettraux at openwfe.org
40
40
  #
41
41
 
42
- require 'ru/rudefinitions'
43
- require 'ru/flowexpression'
42
+ require 'openwfe/rudefinitions'
43
+ require 'openwfe/expressions/flowexpression'
44
44
 
45
45
 
46
- module OpenWFEru
46
+ module OpenWFE
47
47
 
48
48
  class DefineExpression < FlowExpression
49
49
 
@@ -61,7 +61,7 @@ module OpenWFEru
61
61
 
62
62
  #ldebug { "evaluate() looking at #{fei.to_debug_s}" }
63
63
 
64
- rawchild = get_expression_pool().fetch(fei)
64
+ rawchild, _fei = get_expression_pool().fetch(fei)
65
65
 
66
66
  if not rawchild.is_definition?
67
67
  body_fei = rawchild.fei if not body_fei
@@ -0,0 +1,99 @@
1
+ #
2
+ #--
3
+ # Copyright (c) 2007, John Mettraux, OpenWFE.org
4
+ # All rights reserved.
5
+ #
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted provided that the following conditions are met:
8
+ #
9
+ # . Redistributions of source code must retain the above copyright notice, this
10
+ # list of conditions and the following disclaimer.
11
+ #
12
+ # . Redistributions in binary form must reproduce the above copyright notice,
13
+ # this list of conditions and the following disclaimer in the documentation
14
+ # and/or other materials provided with the distribution.
15
+ #
16
+ # . Neither the name of the "OpenWFE" nor the names of its contributors may be
17
+ # used to endorse or promote products derived from this software without
18
+ # specific prior written permission.
19
+ #
20
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
+ # POSSIBILITY OF SUCH DAMAGE.
31
+ #++
32
+ #
33
+ # $Id: definitions.rb 2725 2006-06-02 13:26:32Z jmettraux $
34
+ #
35
+
36
+ #
37
+ # "made in Japan"
38
+ #
39
+ # John Mettraux at openwfe.org
40
+ #
41
+
42
+ require 'openwfe/expressions/flowexpression'
43
+
44
+
45
+ #
46
+ # 'f', 'q' and 'v' expressions
47
+ #
48
+
49
+ module OpenWFE
50
+
51
+ #
52
+ # The 'cursor' is much like a sequence, but you can go
53
+ # back and forth within it.
54
+ #
55
+ class FqvExpression < FlowExpression
56
+
57
+ #
58
+ # apply / reply
59
+
60
+ def apply (workitem)
61
+
62
+ name = @fei.expression_name[0, 1]
63
+ text = OpenWFE::fetch_text_content(self, workitem)
64
+
65
+ method = MAP[name]
66
+
67
+ result = self.send(method, text, workitem)
68
+
69
+ OpenWFE::set_result(workitem, result) if result != nil
70
+
71
+ reply_to_parent(workitem)
72
+ end
73
+
74
+ #def reply (workitem)
75
+ #end
76
+
77
+ protected
78
+
79
+ MAP = {
80
+ "f" => :field,
81
+ "q" => :quote,
82
+ "v" => :variable
83
+ }
84
+
85
+ def field (text, workitem)
86
+ workitem.attributes[text]
87
+ end
88
+
89
+ def quote (text, workitem)
90
+ text
91
+ end
92
+
93
+ def variable (text, workitem)
94
+ self.lookup_variable(text)
95
+ end
96
+ end
97
+
98
+ end
99
+
@@ -0,0 +1,182 @@
1
+ #
2
+ #--
3
+ # Copyright (c) 2007, John Mettraux, OpenWFE.org
4
+ # All rights reserved.
5
+ #
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted provided that the following conditions are met:
8
+ #
9
+ # . Redistributions of source code must retain the above copyright notice, this
10
+ # list of conditions and the following disclaimer.
11
+ #
12
+ # . Redistributions in binary form must reproduce the above copyright notice,
13
+ # this list of conditions and the following disclaimer in the documentation
14
+ # and/or other materials provided with the distribution.
15
+ #
16
+ # . Neither the name of the "OpenWFE" nor the names of its contributors may be
17
+ # used to endorse or promote products derived from this software without
18
+ # specific prior written permission.
19
+ #
20
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
+ # POSSIBILITY OF SUCH DAMAGE.
31
+ #++
32
+ #
33
+ # $Id: definitions.rb 2725 2006-06-02 13:26:32Z jmettraux $
34
+ #
35
+
36
+ #
37
+ # "made in Japan"
38
+ #
39
+ # John Mettraux at openwfe.org
40
+ #
41
+
42
+ require 'openwfe/expressions/flowexpression'
43
+ require 'openwfe/expressions/fe_utils'
44
+
45
+
46
+ module OpenWFE
47
+
48
+ #
49
+ # The 'iterator' expression can be used like that for example :
50
+ #
51
+ # <iterator
52
+ # on-value="alice, bob, charles"
53
+ # to-variable="user-name"
54
+ # >
55
+ # <set
56
+ # field="${user-name} comment"
57
+ # value="(please fill this field)"
58
+ # />
59
+ # </iterator>
60
+ #
61
+ # Within the iteration, the workitem field "__ic__" contains the number
62
+ # of elements in the iteration and the field "__ip__" the index of the
63
+ # current iteration.
64
+ #
65
+ class IteratorExpression < WithTemplateExpression
66
+
67
+ attr_accessor :iterator
68
+
69
+ def apply (workitem)
70
+
71
+ if @children.length < 1
72
+ reply_to_parent(workitem)
73
+ return
74
+ end
75
+
76
+ @iterator = Iterator.new(self, workitem)
77
+
78
+ reply(workitem)
79
+ end
80
+
81
+ def reply (workitem)
82
+
83
+ unless @iterator.has_next?
84
+ reply_to_parent(workitem)
85
+ return
86
+ end
87
+
88
+ @iterator.next(self, workitem)
89
+
90
+ store_itself()
91
+
92
+ get_expression_pool\
93
+ .launch_template(self, @children[0], workitem, nil)
94
+ end
95
+ end
96
+
97
+ #
98
+ # Iterator instances keep track of the position of an iteration.
99
+ # This class is meant to be used both by <iterator> and
100
+ # <concurrent-iterator>.
101
+ #
102
+ class Iterator
103
+
104
+ attr_accessor \
105
+ :iteration_list,
106
+ :to_field,
107
+ :to_variable,
108
+ :value_separator,
109
+ :counter
110
+
111
+ def initialize (iterator_expression, workitem)
112
+
113
+ @to_field = iterator_expression\
114
+ .lookup_attribute(:to_field, workitem)
115
+ @to_variable = iterator_expression\
116
+ .lookup_attribute(:to_variable, workitem)
117
+
118
+ @value_separator = iterator_expression\
119
+ .lookup_attribute(:value_separator, workitem, /,\s*/)
120
+
121
+ @counter = 0
122
+
123
+ raw_list = OpenWFE::lookup_vf_attribute(
124
+ iterator_expression, workitem, :value, :on)
125
+
126
+ @iteration_list = extract_iteration_list(raw_list)
127
+
128
+ workitem.attributes['__ic__'] = @iteration_list.length
129
+ end
130
+
131
+ #
132
+ # Has the iteration a next element ?
133
+ #
134
+ def has_next?
135
+ @iteration_list.length > 0
136
+ end
137
+
138
+ #
139
+ # Prepares the iterator expression and the workitem for the next
140
+ # iteration.
141
+ #
142
+ def next (iterator_expression, workitem)
143
+
144
+ value = @iteration_list.pop
145
+
146
+ if @to_field
147
+ workitem.attributes[@to_field] = value
148
+ else
149
+ iterator_expression.set_variable(@to_variable, value)
150
+ end
151
+
152
+ workitem.attributes['__ip__'] = @counter
153
+
154
+ @counter = @counter + 1
155
+ end
156
+
157
+ protected
158
+
159
+ def extract_iteration_list (raw_list)
160
+
161
+ l = if is_suitable_list(raw_list)
162
+ raw_list
163
+ else
164
+ extract_list_from_string(raw_list.to_s)
165
+ end
166
+
167
+ return l.reverse
168
+ end
169
+
170
+ def is_suitable_list (instance)
171
+ instance.respond_to? :pop and \
172
+ instance.respond_to? :reverse and \
173
+ instance.respond_to? :length
174
+ end
175
+
176
+ def extract_list_from_string (s)
177
+ s.split(@value_separator)
178
+ end
179
+ end
180
+
181
+ end
182
+