openwferu 0.9.15 → 0.9.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) hide show
  1. data/README.txt +4 -2
  2. data/lib/openwfe/engine/engine.rb +143 -25
  3. data/lib/openwfe/engine/file_persisted_engine.rb +3 -3
  4. data/lib/openwfe/expool/errorjournal.rb +48 -25
  5. data/lib/openwfe/expool/expressionpool.rb +77 -106
  6. data/lib/openwfe/expool/expstorage.rb +6 -5
  7. data/lib/openwfe/expool/threadedexpstorage.rb +190 -0
  8. data/lib/openwfe/expool/yamlexpstorage.rb +5 -150
  9. data/lib/openwfe/expressions/condition.rb +6 -6
  10. data/lib/openwfe/expressions/environment.rb +7 -2
  11. data/lib/openwfe/expressions/expressionmap.rb +14 -0
  12. data/lib/openwfe/expressions/fe_command.rb +2 -1
  13. data/lib/openwfe/expressions/fe_concurrence.rb +40 -18
  14. data/lib/openwfe/expressions/fe_cron.rb +14 -11
  15. data/lib/openwfe/expressions/fe_cursor.rb +2 -3
  16. data/lib/openwfe/expressions/fe_define.rb +34 -31
  17. data/lib/openwfe/expressions/fe_equals.rb +11 -21
  18. data/lib/openwfe/expressions/fe_filter_definition.rb +0 -2
  19. data/lib/openwfe/expressions/fe_fqv.rb +1 -3
  20. data/lib/openwfe/expressions/fe_if.rb +37 -12
  21. data/lib/openwfe/expressions/fe_iterator.rb +1 -1
  22. data/lib/openwfe/expressions/fe_listen.rb +147 -28
  23. data/lib/openwfe/expressions/fe_losfor.rb +13 -1
  24. data/lib/openwfe/expressions/fe_misc.rb +70 -11
  25. data/lib/openwfe/expressions/fe_participant.rb +3 -3
  26. data/lib/openwfe/expressions/fe_reserve.rb +1 -1
  27. data/lib/openwfe/expressions/fe_save.rb +11 -12
  28. data/lib/openwfe/expressions/fe_sequence.rb +22 -29
  29. data/lib/openwfe/expressions/fe_sleep.rb +11 -7
  30. data/lib/openwfe/expressions/fe_subprocess.rb +24 -10
  31. data/lib/openwfe/expressions/fe_value.rb +35 -15
  32. data/lib/openwfe/expressions/fe_when.rb +2 -4
  33. data/lib/openwfe/expressions/flowexpression.rb +73 -37
  34. data/lib/openwfe/expressions/merge.rb +2 -4
  35. data/lib/openwfe/expressions/raw.rb +40 -31
  36. data/lib/openwfe/expressions/raw_prog.rb +18 -9
  37. data/lib/openwfe/expressions/raw_xml.rb +1 -8
  38. data/lib/openwfe/expressions/simplerep.rb +27 -5
  39. data/lib/openwfe/expressions/time.rb +45 -15
  40. data/lib/openwfe/expressions/timeout.rb +2 -1
  41. data/lib/openwfe/expressions/wtemplate.rb +2 -2
  42. data/lib/openwfe/flowexpressionid.rb +62 -16
  43. data/lib/openwfe/listeners/listener.rb +28 -37
  44. data/lib/openwfe/listeners/listeners.rb +1 -1
  45. data/lib/openwfe/listeners/socketlisteners.rb +7 -15
  46. data/lib/openwfe/logging.rb +5 -4
  47. data/lib/openwfe/{rest → orest}/controlclient.rb +3 -5
  48. data/lib/openwfe/{rest → orest}/definitions.rb +0 -2
  49. data/lib/openwfe/{rest → orest}/exception.rb +0 -0
  50. data/lib/openwfe/{rest → orest}/oldrestservlet.rb +1 -1
  51. data/lib/openwfe/{rest → orest}/osocket.rb +1 -1
  52. data/lib/openwfe/{rest → orest}/restclient.rb +0 -2
  53. data/lib/openwfe/orest/workitem.rb +206 -0
  54. data/lib/openwfe/{rest → orest}/worklistclient.rb +15 -5
  55. data/lib/openwfe/{rest → orest}/xmlcodec.rb +4 -1
  56. data/lib/openwfe/participants/enoparticipants.rb +4 -14
  57. data/lib/openwfe/participants/participantmap.rb +16 -12
  58. data/lib/openwfe/participants/participants.rb +46 -1
  59. data/lib/openwfe/participants/socketparticipants.rb +1 -6
  60. data/lib/openwfe/service.rb +15 -6
  61. data/lib/openwfe/storage/yamlcustom.rb +3 -0
  62. data/lib/openwfe/storage/yamlfilestorage.rb +3 -1
  63. data/lib/openwfe/util/dollar.rb +21 -14
  64. data/lib/openwfe/util/lru.rb +29 -10
  65. data/lib/openwfe/util/observable.rb +4 -1
  66. data/lib/openwfe/util/otime.rb +3 -0
  67. data/lib/openwfe/util/scheduler.rb +346 -114
  68. data/lib/openwfe/utils.rb +67 -13
  69. data/lib/openwfe/version.rb +1 -1
  70. data/lib/openwfe/workitem.rb +22 -165
  71. data/lib/openwfe/worklist/oldrest.rb +2 -2
  72. data/test/bm/bm_1_xml_vs_prog.rb +56 -0
  73. data/test/{ft_26_load.rb → bm/ft_26_load.rb} +0 -0
  74. data/test/{ft_26b_load.rb → bm/ft_26b_load.rb} +0 -0
  75. data/test/{ft_26c_load.rb → bm/ft_26c_load.rb} +16 -4
  76. data/test/clone_test.rb +62 -0
  77. data/test/cron_test.rb +56 -1
  78. data/test/cronline_test.rb +17 -8
  79. data/test/description_test.rb +57 -0
  80. data/test/dollar_test.rb +17 -6
  81. data/test/eno_test.rb +22 -9
  82. data/test/fe_lookup_att_test.rb +50 -0
  83. data/test/fei_test.rb +18 -9
  84. data/test/flowtestbase.rb +24 -2
  85. data/test/ft_0.rb +10 -12
  86. data/test/ft_0e_multibody.rb +34 -0
  87. data/test/ft_10_loop.rb +4 -6
  88. data/test/ft_11_ppd.rb +5 -20
  89. data/test/ft_14b_subprocess.rb +2 -2
  90. data/test/ft_15_iterator.rb +56 -4
  91. data/test/ft_15b_iterator.rb +48 -0
  92. data/test/ft_16_fqv.rb +18 -3
  93. data/test/ft_23c_wait.rb +7 -5
  94. data/test/ft_25_cancel.rb +5 -3
  95. data/test/ft_27_getflowpos.rb +14 -11
  96. data/test/ft_28_fileparticipant.rb +3 -4
  97. data/test/ft_2_concurrence.rb +8 -12
  98. data/test/ft_2b_concurrence.rb +3 -2
  99. data/test/ft_30_socketlistener.rb +5 -6
  100. data/test/ft_32c_journal.rb +2 -2
  101. data/test/ft_32d_journal.rb +5 -6
  102. data/test/ft_33_description.rb +8 -3
  103. data/test/ft_34_cancelwfid.rb +3 -3
  104. data/test/ft_38_tag.rb +7 -10
  105. data/test/ft_39_reserve.rb +4 -2
  106. data/test/ft_3_equals.rb +18 -13
  107. data/test/ft_44b_restore.rb +2 -6
  108. data/test/ft_49_condition.rb +16 -12
  109. data/test/ft_4_misc.rb +51 -12
  110. data/test/ft_50_xml_attribute.rb +1 -1
  111. data/test/ft_54_listen.rb +96 -10
  112. data/test/ft_54b_listen.rb +68 -0
  113. data/test/ft_55_ptimeout.rb +1 -2
  114. data/test/ft_58_ejournal.rb +8 -33
  115. data/test/ft_59_ps.rb +2 -3
  116. data/test/ft_59b_ps_for_pat.rb +59 -0
  117. data/test/ft_5_time.rb +45 -4
  118. data/test/ft_60_ecancel.rb +7 -7
  119. data/test/ft_61_elsub.rb +1 -1
  120. data/test/ft_64_alias.rb +1 -1
  121. data/test/ft_67_schedlaunch.rb +29 -16
  122. data/test/ft_69_cancelmissing.rb +1 -1
  123. data/test/ft_6_lambda.rb +8 -6
  124. data/test/ft_70_lookupvar.rb +2 -2
  125. data/test/ft_71_log.rb +60 -0
  126. data/test/ft_72_lookup_processes.rb +79 -0
  127. data/test/ft_73_cancel_sub.rb +144 -0
  128. data/test/ft_74_block_and_workitem_dup.rb +63 -0
  129. data/test/ft_75_ruby_attributes.rb +87 -0
  130. data/test/ft_76_merge_isolate.rb +90 -0
  131. data/test/ft_7_lose.rb +2 -1
  132. data/test/ft_tests.rb +9 -0
  133. data/test/lookup_att_test.rb +90 -0
  134. data/test/misc_test.rb +33 -50
  135. data/test/orest_test.rb +1 -1
  136. data/test/participant_test.rb +32 -8
  137. data/test/pending.rb +6 -7
  138. data/test/rake_ltest.rb +3 -0
  139. data/test/rake_qtest.rb +4 -1
  140. data/test/raw_prog_test.rb +1 -1
  141. data/test/restart_cron_test.rb +6 -6
  142. data/test/restart_sleep_test.rb +8 -8
  143. data/test/ruby_procdef_test.rb +2 -2
  144. data/test/rutest_utils.rb +9 -3
  145. data/test/scheduler_1_test.rb +88 -0
  146. data/test/scheduler_test.rb +49 -4
  147. data/test/sec_test.rb +18 -11
  148. metadata +51 -34
  149. data/test/cron_test_2.rb +0 -50
@@ -30,8 +30,6 @@
30
30
  # POSSIBILITY OF SUCH DAMAGE.
31
31
  #++
32
32
  #
33
- # $Id: definitions.rb 2725 2006-06-02 13:26:32Z jmettraux $
34
- #
35
33
 
36
34
  #
37
35
  # "made in Japan"
@@ -73,17 +71,20 @@ module OpenWFE
73
71
 
74
72
  def apply (workitem)
75
73
 
76
- field = lookup_attribute :to_field, workitem
77
- variable = lookup_attribute :to_variable, workitem
74
+ field = lookup_string_attribute :to_field, workitem
75
+ variable = lookup_string_attribute :to_variable, workitem
78
76
 
79
77
  wi = workitem.dup
80
78
 
81
79
  if field
82
- #workitem.attributes[field] = wi.attributes
80
+
83
81
  workitem.set_attribute field, wi.attributes
82
+
84
83
  elsif variable
84
+
85
85
  set_variable variable, wi
86
86
  end
87
+
87
88
  # else, simply don't save
88
89
 
89
90
  reply_to_parent workitem
@@ -134,9 +135,9 @@ module OpenWFE
134
135
 
135
136
  def apply (workitem)
136
137
 
137
- from_field = lookup_attribute :from_field, workitem
138
- from_variable = lookup_attribute :from_variable, workitem
139
- merge_lead = lookup_attribute :merge_lead, workitem
138
+ from_field = lookup_string_attribute :from_field, workitem
139
+ from_variable = lookup_string_attribute :from_variable, workitem
140
+ merge_lead = lookup_sym_attribute :merge_lead, workitem
140
141
 
141
142
  source = if from_field
142
143
 
@@ -186,10 +187,10 @@ module OpenWFE
186
187
  source
187
188
  end
188
189
 
189
- to_field = lookup_attribute :to_field, workitem
190
+ to_field = lookup_string_attribute :to_field, workitem
190
191
 
191
192
  if to_field
192
- workitem.set_attribute to_field.strip, attributes
193
+ workitem.set_attribute to_field, attributes
193
194
  else
194
195
  workitem.attributes = attributes
195
196
  end
@@ -209,8 +210,6 @@ module OpenWFE
209
210
  source = wi
210
211
  end
211
212
 
212
- merge_lead = merge_lead.strip.downcase.intern
213
-
214
213
  wiTarget, wiSource = if merge_lead == :current
215
214
  [ source, workitem ]
216
215
  else
@@ -30,8 +30,6 @@
30
30
  # POSSIBILITY OF SUCH DAMAGE.
31
31
  #++
32
32
  #
33
- # $Id: definitions.rb 2725 2006-06-02 13:26:32Z jmettraux $
34
- #
35
33
 
36
34
  #
37
35
  # "made in Japan"
@@ -57,61 +55,56 @@ module OpenWFE
57
55
 
58
56
  names :sequence
59
57
 
60
- attr_accessor \
61
- :current_child_id
62
-
63
58
 
64
59
  def apply (workitem)
65
60
 
66
- @current_child_id = -1
61
+ #store_itself
62
+ #
63
+ # remove that !
67
64
 
68
65
  reply workitem
69
66
  end
70
67
 
71
68
  def reply (workitem)
72
69
 
73
- cfei = get_to_next_child()
70
+ cfei = next_child workitem.fei
74
71
 
75
- unless cfei
76
- reply_to_parent workitem
77
- return
78
- end
72
+ return reply_to_parent(workitem) \
73
+ unless cfei
79
74
 
80
75
  #ldebug do
81
76
  # "reply() self : \n#{self.to_s}\n" +
82
77
  # "reply() next is #{@current_child_id} : #{cfei.to_debug_s}"
83
78
  #end
84
79
 
85
- store_itself()
86
-
87
80
  get_expression_pool.apply cfei, workitem
88
81
  end
89
82
 
90
83
  protected
91
84
 
92
- def get_to_next_child ()
85
+ #
86
+ # Returns the flowExpressionId of the next child to apply, or
87
+ # nil if the sequence is over.
88
+ #
89
+ def next_child (current_fei)
93
90
 
94
- #return nil if @children.length < 1
95
-
96
- @current_child_id += 1
97
-
98
- return nil if @current_child_id >= @children.length
91
+ next_id = if (current_fei == self.fei)
92
+ 0
93
+ else
94
+ current_fei.child_id.to_i + 1
95
+ end
99
96
 
100
- #ldebug do
101
- # "get_to_next_child() " +
102
- # "len: #{@children.length} / id: #{@current_child_id}"
103
- #end
97
+ loop do
104
98
 
105
- @children[@current_child_id..-1].each do |c|
99
+ break if next_id >= @children.length
106
100
 
107
- return c if c.kind_of? OpenWFE::FlowExpressionId
101
+ child = @children[next_id]
102
+ return child if child.is_a?(FlowExpressionId)
108
103
 
109
- @current_child_id += 1
104
+ next_id += 1
110
105
  end
111
106
 
112
- nil
113
- #
114
- # did not find any child expression
107
+ nil
115
108
  end
116
109
  end
117
110
 
@@ -69,8 +69,8 @@ module OpenWFE
69
69
 
70
70
  def apply (workitem)
71
71
 
72
- sfor = lookup_attribute(:for, workitem)
73
- suntil = lookup_attribute(:until, workitem)
72
+ sfor = lookup_string_attribute(:for, workitem)
73
+ suntil = lookup_string_attribute(:until, workitem)
74
74
 
75
75
  sfor = fetch_text_content(workitem) \
76
76
  if sfor == nil and suntil == nil
@@ -98,22 +98,23 @@ module OpenWFE
98
98
  @awakening_time = tuntil
99
99
  @applied_workitem = workitem.dup
100
100
 
101
+ determine_scheduler_tags
102
+
101
103
  reschedule(get_scheduler)
102
104
  end
103
105
 
104
- #def reply (workitem)
105
- #end
106
-
107
106
  #
108
107
  # This is the method called by the Scheduler instance attached to
109
108
  # the workflow engine when the 'sleep' of this expression is
110
109
  # over
111
110
  #
112
111
  def trigger (params)
112
+
113
113
  ldebug do
114
114
  "trigger() #{@fei.to_debug_s} waking up (#{Time.new.to_f}) "+
115
115
  "(scheduler #{get_scheduler.object_id})"
116
116
  end
117
+
117
118
  reply_to_parent(@applied_workitem)
118
119
  end
119
120
 
@@ -137,14 +138,17 @@ module OpenWFE
137
138
 
138
139
  scheduler.schedule_at(
139
140
  @awakening_time,
140
- { :schedulable => self, :job_id => @scheduler_job_id })
141
+ {
142
+ :schedulable => self,
143
+ :job_id => @scheduler_job_id,
144
+ :tags => @scheduler_tags })
141
145
 
142
146
  ldebug do
143
147
  "[re]schedule() @scheduler_job_id is '#{@scheduler_job_id}' "+
144
148
  " (scheduler #{scheduler.object_id})"
145
149
  end
146
150
 
147
- store_itself()
151
+ store_itself
148
152
  end
149
153
  end
150
154
 
@@ -101,15 +101,15 @@ module OpenWFE
101
101
 
102
102
  names :subprocess
103
103
 
104
+ attr_accessor :subprocess_fei
105
+
104
106
 
105
107
  def apply (workitem)
106
108
 
107
109
  conditional = eval_condition(:if, workitem, :unless)
108
110
 
109
- if conditional == false
110
- reply_to_parent workitem
111
- return
112
- end
111
+ return reply_to_parent(workitem) \
112
+ if conditional == false
113
113
 
114
114
  ref = lookup_ref(workitem)
115
115
 
@@ -124,8 +124,11 @@ module OpenWFE
124
124
 
125
125
  forget = lookup_boolean_attribute(:forget, workitem)
126
126
 
127
- requester = @fei
128
- requester = @fei.workflow_instance_id if forget
127
+ requester = if forget
128
+ @fei.workflow_instance_id
129
+ else
130
+ @fei
131
+ end
129
132
 
130
133
  params = lookup_attributes(workitem)
131
134
 
@@ -136,14 +139,25 @@ module OpenWFE
136
139
  #puts " ... params are #{params.keys.join(', ')}"
137
140
  #puts " ... values are #{params.values.join(', ')}"
138
141
 
139
- get_expression_pool.launch_template(
142
+ sub_fei = get_expression_pool.launch_template(
140
143
  requester, get_next_sub_id, template, workitem, params)
141
144
 
142
- reply_to_parent(workitem) if forget
145
+ if forget
146
+ reply_to_parent(workitem.dup)
147
+ else
148
+ @subprocess_fei = sub_fei.dup
149
+ store_itself # to keep track of @subprocess_fei
150
+ end
143
151
  end
144
152
 
145
- #def reply (workitem)
146
- #end
153
+ #
154
+ # Takes care of cancelling the subprocess as well if any
155
+ #
156
+ def cancel
157
+
158
+ return nil unless @subprocess_fei
159
+ get_expression_pool.cancel @subprocess_fei
160
+ end
147
161
  end
148
162
 
149
163
  end
@@ -65,7 +65,7 @@ module OpenWFE
65
65
  def lookup (name_array, workitem)
66
66
 
67
67
  name_array.each do |n|
68
- v = lookup_attribute(n, workitem)
68
+ v = lookup_string_attribute n, workitem
69
69
  return v if v
70
70
  end
71
71
 
@@ -88,7 +88,7 @@ module OpenWFE
88
88
  # they will be evaluated sequentially before the body gets applied
89
89
  # (executed).
90
90
  #
91
- # Since OpenWFEru 0.9.14, shorter attributes are OK :
91
+ # Shorter attributes are OK :
92
92
  #
93
93
  # <set f="price" val="CHF 12.00" />
94
94
  # <set v="/stage" val="3" />
@@ -98,6 +98,13 @@ module OpenWFE
98
98
  # set :f => "price", :val => "USD 12.50"
99
99
  # set :v => "toto", :val => "elvis"
100
100
  #
101
+ # In case you need the value not to be evaluated if it contains
102
+ # dollar expressions, you can do
103
+ #
104
+ # set :v => "v0", :val => "my ${template} thing", :escape => true
105
+ #
106
+ # to prevent evaluation (i.e. to escape).
107
+ #
101
108
  class SetValueExpression < FlowExpression
102
109
  include ValueMixin
103
110
 
@@ -108,23 +115,29 @@ module OpenWFE
108
115
 
109
116
  def apply (workitem)
110
117
 
118
+ escape = lookup_boolean_attribute('escape', workitem, false)
119
+
111
120
  if @children.length < 1
112
- workitem.attributes[FIELD_RESULT] = lookup_value(workitem)
113
- reply(workitem)
121
+
122
+ workitem.attributes[FIELD_RESULT] = \
123
+ lookup_value(workitem, :escape => escape)
124
+
125
+ reply workitem
114
126
  return
115
127
  end
116
128
 
117
129
  child = @children[0]
118
130
 
119
- if child.kind_of? OpenWFE::FlowExpressionId
120
- handle_child(child, workitem)
131
+ if child.kind_of?(OpenWFE::FlowExpressionId)
132
+
133
+ handle_child child, workitem
121
134
  return
122
135
  end
123
136
 
124
- #workitem.attributes[FIELD_RESULT] = child.to_s
125
- workitem.attributes[FIELD_RESULT] = fetch_text_content(workitem)
137
+ workitem.attributes[FIELD_RESULT] = \
138
+ fetch_text_content(workitem, escape)
126
139
 
127
- reply(workitem)
140
+ reply workitem
128
141
  end
129
142
 
130
143
  def reply (workitem)
@@ -151,14 +164,21 @@ module OpenWFE
151
164
 
152
165
  def handle_child (child, workitem)
153
166
 
154
- child, _fei = get_expression_pool().fetch(child)
167
+ raw_child, _fei = get_expression_pool.fetch(child)
168
+
169
+ if raw_child.is_definition?
170
+
171
+ #body_fei = get_expression_pool.evaluate child, workitem
172
+ #workitem.attributes[FIELD_RESULT] = body_fei
155
173
 
156
- if child.is_definition?
157
- fei = get_expression_pool().evaluate(child, workitem)
158
- workitem.attributes[FIELD_RESULT] = fei
159
- reply(workitem)
174
+ workitem.attributes[FIELD_RESULT] = raw_child
175
+ #
176
+ # storing the child raw expression
177
+
178
+ reply workitem
160
179
  else
161
- get_expression_pool().apply(child, workitem)
180
+
181
+ get_expression_pool.apply raw_child, workitem
162
182
  end
163
183
  end
164
184
  end
@@ -30,8 +30,6 @@
30
30
  # POSSIBILITY OF SUCH DAMAGE.
31
31
  #++
32
32
  #
33
- # $Id: definitions.rb 2725 2006-06-02 13:26:32Z jmettraux $
34
- #
35
33
 
36
34
  #
37
35
  # "made in Japan"
@@ -116,7 +114,7 @@ module OpenWFE
116
114
  @condition_sub_id = -1
117
115
  @consequence_triggered = false
118
116
 
119
- super(workitem)
117
+ super workitem
120
118
  end
121
119
 
122
120
  def reply (workitem)
@@ -130,7 +128,7 @@ module OpenWFE
130
128
  return
131
129
  end
132
130
 
133
- super(workitem)
131
+ super workitem
134
132
  end
135
133
 
136
134
  protected
@@ -144,7 +144,7 @@ module OpenWFE
144
144
  #
145
145
  def apply (workitem)
146
146
 
147
- get_parent().reply(workitem) if @parent_id
147
+ get_parent.reply(workitem) if @parent_id
148
148
  end
149
149
 
150
150
  #
@@ -180,7 +180,7 @@ module OpenWFE
180
180
 
181
181
  @children.each do |child|
182
182
 
183
- next if child.kind_of? String
183
+ next if child.kind_of?(String)
184
184
 
185
185
  i = get_expression_pool().cancel(child)
186
186
  inflowitem = i unless inflowitem
@@ -197,6 +197,7 @@ module OpenWFE
197
197
  # as the FlowExpression instance it is).
198
198
  #
199
199
  def get_parent
200
+
200
201
  #parent, parent_fei = get_expression_pool.fetch @parent_id
201
202
  #parent
202
203
  get_expression_pool.fetch_expression @parent_id
@@ -210,7 +211,8 @@ module OpenWFE
210
211
  # simply if the expression got swapped out of memory and reloaded later.
211
212
  #
212
213
  def store_itself
213
- #ldebug { "store_itself() for #{@fei.to_debug_s}" }
214
+
215
+ ldebug { "store_itself() for #{@fei.to_debug_s}" }
214
216
  #ldebug { "store_itself() \n#{OpenWFE::caller_to_s(0, 6)}" }
215
217
  get_expression_pool.update self
216
218
  end
@@ -307,10 +309,10 @@ module OpenWFE
307
309
 
308
310
  env, var = lookup_environment(varname)
309
311
 
310
- #ldebug do
311
- # "set_variable() '#{varname}' to '#{value}' " +
312
- # "in #{env.fei.to_debug_s}"
313
- #end
312
+ ldebug do
313
+ "set_variable() '#{varname}' to '#{value}' " +
314
+ "in #{env.fei.to_debug_s}"
315
+ end
314
316
 
315
317
  env[var] = value
316
318
  end
@@ -360,42 +362,58 @@ module OpenWFE
360
362
  # variable substitution.
361
363
  # It's ok to pass a Symbol for the attribute name.
362
364
  #
363
- def lookup_attribute (attname, workitem, default=nil)
365
+ def lookup_attribute (attname, workitem, options={})
366
+
367
+ default = options[:default]
368
+ escape = options[:escape]
364
369
 
365
370
  attname = OpenWFE::symbol_to_name(attname) \
366
- if attname.kind_of? Symbol
371
+ if attname.kind_of?(Symbol)
367
372
 
368
373
  #ldebug { "lookup_attribute() '#{attname}' in #{@fei.to_debug_s}" }
369
374
 
370
375
  text = @attributes[attname]
371
376
 
372
- default = default.to_s if default
377
+ return default if text == nil
378
+ return text unless text.is_a?(String)
373
379
 
374
- return default if not text
380
+ return text if escape == true
381
+ # returns text if escape is set and is set to true
375
382
 
376
- OpenWFE::dosub(text, self, workitem)
383
+ OpenWFE::dosub text, self, workitem
377
384
  end
378
385
 
379
386
  #
380
- # Like lookup_attribute() but returns the value downcased.
381
- # Returns nil if no such attribute was found.
387
+ # Returns the attribute value as a String (or nil if it's not found).
382
388
  #
383
- def lookup_downcase_attribute (attname, workitem, default=nil)
384
- result = lookup_attribute attname, workitem, default
385
- result = result.downcase if result
389
+ def lookup_string_attribute (attname, workitem, options={})
390
+
391
+ result = lookup_attribute attname, workitem, options
392
+ result = result.to_s if result
386
393
  result
387
394
  end
388
395
 
389
396
  #
390
- # Returns true if the expression has the given attribute.
391
- # The attname parameter can be a String or a Symbol.
397
+ # Like lookup_attribute() but returns the value downcased [
398
+ # (and stripped).
399
+ # Returns nil if no such attribute was found.
392
400
  #
393
- def has_attribute (attname)
401
+ def lookup_downcase_attribute (attname, workitem, options={})
394
402
 
395
- attname = OpenWFE::symbol_to_name(attname) \
396
- if attname.kind_of? Symbol
403
+ result = lookup_string_attribute attname, workitem, options
404
+ result = result.strip.downcase if result
405
+ result
406
+ end
397
407
 
398
- @attributes[attname] != nil
408
+ #
409
+ # Returns the value of the attribute as a Symbol.
410
+ # Returns nil if there is no attribute under the given name.
411
+ #
412
+ def lookup_sym_attribute (attname, workitem, options={})
413
+
414
+ result = lookup_downcase_attribute attname, workitem, options
415
+ result = result.to_sym if result
416
+ result
399
417
  end
400
418
 
401
419
  #
@@ -404,10 +422,22 @@ module OpenWFE
404
422
  #
405
423
  def lookup_boolean_attribute (attname, workitem, default=false)
406
424
 
407
- value = lookup_attribute(attname, workitem)
408
- return default if not value
425
+ result = lookup_downcase_attribute attname, workitem
426
+ return default if result == nil
427
+
428
+ (result == 'true')
429
+ end
430
+
431
+ #
432
+ # Returns true if the expression has the given attribute.
433
+ # The attname parameter can be a String or a Symbol.
434
+ #
435
+ def has_attribute (attname)
436
+
437
+ attname = OpenWFE::symbol_to_name(attname) \
438
+ if attname.kind_of?(Symbol)
409
439
 
410
- (value.downcase == 'true')
440
+ @attributes[attname] != nil
411
441
  end
412
442
 
413
443
  #
@@ -454,9 +484,9 @@ module OpenWFE
454
484
  #
455
485
  # [ 'a', 'b', 'c' ]
456
486
  #
457
- def lookup_comma_list_attribute (attname, workitem, default=nil)
487
+ def lookup_comma_list_attribute (attname, workitem, options={})
458
488
 
459
- a = lookup_attribute(attname, workitem, default)
489
+ a = lookup_attribute(attname, workitem, options)
460
490
 
461
491
  return nil if not a
462
492
 
@@ -595,10 +625,10 @@ module OpenWFE
595
625
  # looks up for 'value', 'variable-value' and then for 'field-value'
596
626
  # if necessary.
597
627
  #
598
- def lookup_value (workitem, prefix='')
628
+ def lookup_value (workitem, options={})
599
629
 
600
- v = lookup_vf_attribute(workitem, 'value', prefix)
601
- v = lookup_vf_attribute(workitem, 'val', prefix) unless v
630
+ v = lookup_vf_attribute(workitem, 'value', options)
631
+ v = lookup_vf_attribute(workitem, 'val', options) unless v
602
632
  v
603
633
  end
604
634
 
@@ -608,25 +638,31 @@ module OpenWFE
608
638
  #
609
639
  def lookup_ref (workitem, prefix='')
610
640
 
611
- lookup_vf_attribute(workitem, 'ref', prefix)
641
+ ref = lookup_vf_attribute(workitem, 'ref', :prefix => prefix)
642
+ return ref.to_s if ref
643
+ nil
612
644
  end
613
645
 
614
646
  #
615
647
  # Looks up for value attributes like 'field-ref' or 'variable-value'
616
648
  #
617
- def lookup_vf_attribute (workitem, att_name, prefix='')
649
+ def lookup_vf_attribute (workitem, att_name, options={})
618
650
 
651
+ prefix = options[:prefix] || ''
619
652
  prefix = "#{prefix.to_s}-" if prefix != ''
620
653
 
621
- v = lookup_attribute("#{prefix}#{att_name}", workitem)
654
+ v = lookup_attribute(
655
+ "#{prefix}#{att_name}", workitem, options)
622
656
 
623
657
  return v if v
624
658
 
625
- v = lookup_attribute("#{prefix}variable-#{att_name}", workitem)
659
+ v = lookup_attribute(
660
+ "#{prefix}variable-#{att_name}", workitem, options)
626
661
 
627
662
  return lookup_variable(v) if v
628
663
 
629
- v = lookup_attribute("#{prefix}field-#{att_name}", workitem)
664
+ v = lookup_attribute(
665
+ "#{prefix}field-#{att_name}", workitem, options)
630
666
 
631
667
  return workitem.attributes[v] if v
632
668
 
@@ -638,7 +674,7 @@ module OpenWFE
638
674
  #
639
675
  def to_s
640
676
 
641
- s = "* #{@fei.to_debug_s}"
677
+ s = "* #{@fei.to_debug_s} [#{self.class.name}]"
642
678
 
643
679
  s << "\n `--p--> #{@parent_id.to_debug_s}" \
644
680
  if @parent_id
@@ -30,8 +30,6 @@
30
30
  # POSSIBILITY OF SUCH DAMAGE.
31
31
  #++
32
32
  #
33
- # $Id: definitions.rb 2725 2006-06-02 13:26:32Z jmettraux $
34
- #
35
33
 
36
34
  #
37
35
  # "made in Japan"
@@ -66,8 +64,8 @@ module OpenWFE
66
64
 
67
65
  #puts "merge() '#{k}' => '#{v}'"
68
66
 
69
- nk = OpenWFE::fulldup(k)
70
- nv = OpenWFE::fulldup(v)
67
+ nk = OpenWFE::fulldup k
68
+ nv = OpenWFE::fulldup v
71
69
 
72
70
  wiTarget.attributes[nk] = nv
73
71
  end