ruote 0.9.18

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 (291) hide show
  1. data/README.txt +24 -0
  2. data/bin/validate-workflow.rb +89 -0
  3. data/examples/about_state.rb +81 -0
  4. data/examples/bigflow.rb +19 -0
  5. data/examples/csv_weather.rb +23 -0
  6. data/examples/engine_template.rb +247 -0
  7. data/examples/flowtracing.rb +24 -0
  8. data/examples/homeworkreview.rb +68 -0
  9. data/examples/kotoba.rb +22 -0
  10. data/examples/mano_tracker.rb +172 -0
  11. data/examples/openwferu.rb +58 -0
  12. data/examples/quotereporter.rb +157 -0
  13. data/examples/scheduler_cron_usage.rb +48 -0
  14. data/examples/scheduler_usage.rb +56 -0
  15. data/lib/openwfe.rb +41 -0
  16. data/lib/openwfe/contextual.rb +111 -0
  17. data/lib/openwfe/def.rb +46 -0
  18. data/lib/openwfe/engine.rb +37 -0
  19. data/lib/openwfe/engine/engine.rb +756 -0
  20. data/lib/openwfe/engine/expool_methods.rb +172 -0
  21. data/lib/openwfe/engine/file_persisted_engine.rb +105 -0
  22. data/lib/openwfe/engine/participant_methods.rb +133 -0
  23. data/lib/openwfe/engine/status_methods.rb +353 -0
  24. data/lib/openwfe/engine/update_exp_methods.rb +112 -0
  25. data/lib/openwfe/exceptions.rb +51 -0
  26. data/lib/openwfe/expool/errorjournal.rb +476 -0
  27. data/lib/openwfe/expool/expressionpool.rb +1144 -0
  28. data/lib/openwfe/expool/expstorage.rb +403 -0
  29. data/lib/openwfe/expool/history.rb +174 -0
  30. data/lib/openwfe/expool/journal.rb +224 -0
  31. data/lib/openwfe/expool/journal_replay.rb +321 -0
  32. data/lib/openwfe/expool/parser.rb +242 -0
  33. data/lib/openwfe/expool/representation.rb +121 -0
  34. data/lib/openwfe/expool/threadedexpstorage.rb +188 -0
  35. data/lib/openwfe/expool/wfidgen.rb +388 -0
  36. data/lib/openwfe/expool/yamlexpstorage.rb +224 -0
  37. data/lib/openwfe/expressions/condition.rb +244 -0
  38. data/lib/openwfe/expressions/environment.rb +246 -0
  39. data/lib/openwfe/expressions/expressionmap.rb +258 -0
  40. data/lib/openwfe/expressions/fe_cancel.rb +109 -0
  41. data/lib/openwfe/expressions/fe_command.rb +241 -0
  42. data/lib/openwfe/expressions/fe_concurrence.rb +662 -0
  43. data/lib/openwfe/expressions/fe_cron.rb +259 -0
  44. data/lib/openwfe/expressions/fe_cursor.rb +259 -0
  45. data/lib/openwfe/expressions/fe_define.rb +192 -0
  46. data/lib/openwfe/expressions/fe_do.rb +168 -0
  47. data/lib/openwfe/expressions/fe_equals.rb +291 -0
  48. data/lib/openwfe/expressions/fe_filter.rb +129 -0
  49. data/lib/openwfe/expressions/fe_filter_definition.rb +168 -0
  50. data/lib/openwfe/expressions/fe_fqv.rb +250 -0
  51. data/lib/openwfe/expressions/fe_if.rb +303 -0
  52. data/lib/openwfe/expressions/fe_iterator.rb +145 -0
  53. data/lib/openwfe/expressions/fe_listen.rb +371 -0
  54. data/lib/openwfe/expressions/fe_losfor.rb +111 -0
  55. data/lib/openwfe/expressions/fe_misc.rb +421 -0
  56. data/lib/openwfe/expressions/fe_participant.rb +269 -0
  57. data/lib/openwfe/expressions/fe_reserve.rb +212 -0
  58. data/lib/openwfe/expressions/fe_save.rb +274 -0
  59. data/lib/openwfe/expressions/fe_sequence.rb +117 -0
  60. data/lib/openwfe/expressions/fe_set.rb +139 -0
  61. data/lib/openwfe/expressions/fe_sleep.rb +166 -0
  62. data/lib/openwfe/expressions/fe_step.rb +159 -0
  63. data/lib/openwfe/expressions/fe_subprocess.rb +168 -0
  64. data/lib/openwfe/expressions/fe_timeout.rb +127 -0
  65. data/lib/openwfe/expressions/fe_wait.rb +78 -0
  66. data/lib/openwfe/expressions/fe_when.rb +142 -0
  67. data/lib/openwfe/expressions/filter.rb +104 -0
  68. data/lib/openwfe/expressions/flowexpression.rb +847 -0
  69. data/lib/openwfe/expressions/iterator.rb +221 -0
  70. data/lib/openwfe/expressions/merge.rb +84 -0
  71. data/lib/openwfe/expressions/raw.rb +547 -0
  72. data/lib/openwfe/expressions/rprocdef.rb +375 -0
  73. data/lib/openwfe/expressions/time.rb +333 -0
  74. data/lib/openwfe/expressions/timeout.rb +178 -0
  75. data/lib/openwfe/expressions/value.rb +126 -0
  76. data/lib/openwfe/filterdef.rb +259 -0
  77. data/lib/openwfe/flowexpressionid.rb +357 -0
  78. data/lib/openwfe/listeners/listener.rb +97 -0
  79. data/lib/openwfe/listeners/listeners.rb +139 -0
  80. data/lib/openwfe/listeners/socketlisteners.rb +272 -0
  81. data/lib/openwfe/logging.rb +122 -0
  82. data/lib/openwfe/omixins.rb +95 -0
  83. data/lib/openwfe/orest/controlclient.rb +119 -0
  84. data/lib/openwfe/orest/definitions.rb +113 -0
  85. data/lib/openwfe/orest/exception.rb +60 -0
  86. data/lib/openwfe/orest/oldrestservlet.rb +279 -0
  87. data/lib/openwfe/orest/osocket.rb +148 -0
  88. data/lib/openwfe/orest/restclient.rb +176 -0
  89. data/lib/openwfe/orest/workitem.rb +206 -0
  90. data/lib/openwfe/orest/worklistclient.rb +272 -0
  91. data/lib/openwfe/orest/xmlcodec.rb +670 -0
  92. data/lib/openwfe/participants.rb +38 -0
  93. data/lib/openwfe/participants/enoparticipants.rb +230 -0
  94. data/lib/openwfe/participants/participant.rb +141 -0
  95. data/lib/openwfe/participants/participantmap.rb +249 -0
  96. data/lib/openwfe/participants/participants.rb +407 -0
  97. data/lib/openwfe/participants/soapparticipants.rb +135 -0
  98. data/lib/openwfe/participants/socketparticipants.rb +202 -0
  99. data/lib/openwfe/participants/storeparticipants.rb +254 -0
  100. data/lib/openwfe/rudefinitions.rb +130 -0
  101. data/lib/openwfe/service.rb +103 -0
  102. data/lib/openwfe/storage/yamlcustom.rb +106 -0
  103. data/lib/openwfe/storage/yamlfilestorage.rb +245 -0
  104. data/lib/openwfe/tools/flowtracer.rb +81 -0
  105. data/lib/openwfe/util/dollar.rb +217 -0
  106. data/lib/openwfe/util/irb.rb +86 -0
  107. data/lib/openwfe/util/observable.rb +144 -0
  108. data/lib/openwfe/util/ometa.rb +62 -0
  109. data/lib/openwfe/util/workqueue.rb +124 -0
  110. data/lib/openwfe/util/xml.rb +418 -0
  111. data/lib/openwfe/utils.rb +554 -0
  112. data/lib/openwfe/version.rb +37 -0
  113. data/lib/openwfe/workitem.rb +499 -0
  114. data/lib/openwfe/worklist/oldrest.rb +244 -0
  115. data/lib/openwfe/worklist/storelocks.rb +293 -0
  116. data/lib/openwfe/worklist/storeparticipant.rb +44 -0
  117. data/lib/openwfe/worklist/worklist.rb +297 -0
  118. data/test/README.txt +27 -0
  119. data/test/back_0916_test.rb +111 -0
  120. data/test/bm/bm_1_xml_vs_prog.rb +56 -0
  121. data/test/bm/bm_2_step.rb +109 -0
  122. data/test/bm/ft_0f_5ms.rb +35 -0
  123. data/test/bm/ft_26_load.rb +210 -0
  124. data/test/bm/ft_26b_load.rb +86 -0
  125. data/test/bm/ft_26c_load.rb +97 -0
  126. data/test/bm/ft_26d_load.rb +97 -0
  127. data/test/bm/ft_recu.rb +71 -0
  128. data/test/clone_test.rb +122 -0
  129. data/test/concurrence_test.rb +77 -0
  130. data/test/condition_test.rb +155 -0
  131. data/test/console_test.rb +12 -0
  132. data/test/cron_ltest.rb +15 -0
  133. data/test/description_test.rb +87 -0
  134. data/test/eno_test.rb +76 -0
  135. data/test/expmap_test.rb +54 -0
  136. data/test/expool_20031219_0916.tgz +0 -0
  137. data/test/fe_lookup_att_test.rb +62 -0
  138. data/test/fei_test.rb +181 -0
  139. data/test/file_persisted_engine_test.rb +64 -0
  140. data/test/file_persistence_test.rb +134 -0
  141. data/test/filep_cancel_test.rb +123 -0
  142. data/test/filter_test.rb +109 -0
  143. data/test/flowtestbase.rb +351 -0
  144. data/test/ft_0.rb +68 -0
  145. data/test/ft_0b_sequence.rb +36 -0
  146. data/test/ft_0c_testname.rb +33 -0
  147. data/test/ft_0d_participant.rb +30 -0
  148. data/test/ft_0e_multibody.rb +34 -0
  149. data/test/ft_10_loop.rb +134 -0
  150. data/test/ft_11_ppd.rb +415 -0
  151. data/test/ft_11b_ppd.rb +54 -0
  152. data/test/ft_12_blockparticipant.rb +97 -0
  153. data/test/ft_13_eno.rb +52 -0
  154. data/test/ft_14_subprocess.rb +88 -0
  155. data/test/ft_14b_subprocess.rb +192 -0
  156. data/test/ft_14c_subprocess.rb +68 -0
  157. data/test/ft_15_iterator.rb +216 -0
  158. data/test/ft_15b_iterator.rb +74 -0
  159. data/test/ft_16_fqv.rb +73 -0
  160. data/test/ft_17_condition.rb +84 -0
  161. data/test/ft_18_pname.rb +56 -0
  162. data/test/ft_1_unset.rb +175 -0
  163. data/test/ft_1b_unset.rb +39 -0
  164. data/test/ft_20_cron.rb +53 -0
  165. data/test/ft_21_cron.rb +87 -0
  166. data/test/ft_21b_cron_pause.rb +82 -0
  167. data/test/ft_22_history.rb +74 -0
  168. data/test/ft_23_when.rb +77 -0
  169. data/test/ft_23b_when.rb +70 -0
  170. data/test/ft_23c_wait.rb +80 -0
  171. data/test/ft_23d_cww.rb +58 -0
  172. data/test/ft_24_def.rb +44 -0
  173. data/test/ft_25_cancel.rb +89 -0
  174. data/test/ft_27_getflowpos.rb +147 -0
  175. data/test/ft_28_fileparticipant.rb +63 -0
  176. data/test/ft_29_httprb.rb +106 -0
  177. data/test/ft_2_concurrence.rb +135 -0
  178. data/test/ft_2b_concurrence.rb +188 -0
  179. data/test/ft_2c_concurrence.rb +64 -0
  180. data/test/ft_30_socketlistener.rb +203 -0
  181. data/test/ft_31_flowname.rb +40 -0
  182. data/test/ft_32_journal.rb +91 -0
  183. data/test/ft_32c_journal.rb +102 -0
  184. data/test/ft_32d_journal.rb +84 -0
  185. data/test/ft_33_description.rb +107 -0
  186. data/test/ft_34_cancelwfid.rb +80 -0
  187. data/test/ft_35_localdefs.rb +75 -0
  188. data/test/ft_36_subprocids.rb +97 -0
  189. data/test/ft_37_pnames.rb +70 -0
  190. data/test/ft_38_tag.rb +127 -0
  191. data/test/ft_38b_tag.rb +161 -0
  192. data/test/ft_38c_tag.rb +100 -0
  193. data/test/ft_39_reserve.rb +63 -0
  194. data/test/ft_39b_reserve.rb +84 -0
  195. data/test/ft_3_equals.rb +170 -0
  196. data/test/ft_3b_lookup_vf.rb +83 -0
  197. data/test/ft_40_defined.rb +61 -0
  198. data/test/ft_41_case.rb +110 -0
  199. data/test/ft_42_environments.rb +75 -0
  200. data/test/ft_43_pat10.rb +85 -0
  201. data/test/ft_44_save.rb +70 -0
  202. data/test/ft_44b_restore.rb +212 -0
  203. data/test/ft_45_citerator.rb +214 -0
  204. data/test/ft_46_pparams.rb +62 -0
  205. data/test/ft_47_filter.rb +160 -0
  206. data/test/ft_48_fe_filter.rb +88 -0
  207. data/test/ft_49_condition.rb +126 -0
  208. data/test/ft_4_misc.rb +237 -0
  209. data/test/ft_50_xml_attribute.rb +155 -0
  210. data/test/ft_51_stack.rb +55 -0
  211. data/test/ft_52_obs_participant.rb +123 -0
  212. data/test/ft_53_null_noop_participant.rb +62 -0
  213. data/test/ft_54_listen.rb +288 -0
  214. data/test/ft_54b_listen.rb +66 -0
  215. data/test/ft_54c_listen.rb +99 -0
  216. data/test/ft_55_ptimeout.rb +59 -0
  217. data/test/ft_56_timeout.rb +59 -0
  218. data/test/ft_57_a.rb +145 -0
  219. data/test/ft_58_ejournal.rb +151 -0
  220. data/test/ft_59_ps.rb +150 -0
  221. data/test/ft_59b_ps_for_pat.rb +58 -0
  222. data/test/ft_5_time.rb +118 -0
  223. data/test/ft_60_ecancel.rb +161 -0
  224. data/test/ft_61_elsub.rb +51 -0
  225. data/test/ft_62_procparticipant.rb +71 -0
  226. data/test/ft_63_pause.rb +124 -0
  227. data/test/ft_64_alias.rb +102 -0
  228. data/test/ft_64_clone.rb +69 -0
  229. data/test/ft_65_stringlaunch.rb +59 -0
  230. data/test/ft_66_subforget.rb +70 -0
  231. data/test/ft_67_schedlaunch.rb +116 -0
  232. data/test/ft_68_ifparticipant.rb +70 -0
  233. data/test/ft_69_cancelmissing.rb +51 -0
  234. data/test/ft_6_lambda.rb +64 -0
  235. data/test/ft_70_lookupvar.rb +55 -0
  236. data/test/ft_71_log.rb +60 -0
  237. data/test/ft_72_lookup_processes.rb +76 -0
  238. data/test/ft_73_cancel_sub.rb +139 -0
  239. data/test/ft_74_block_and_workitem_dup.rb +63 -0
  240. data/test/ft_75_ruby_attributes.rb +87 -0
  241. data/test/ft_76_merge_isolate.rb +88 -0
  242. data/test/ft_77_segments.rb +35 -0
  243. data/test/ft_78_eval.rb +150 -0
  244. data/test/ft_79_tticket.rb +187 -0
  245. data/test/ft_79b_tticket.rb +172 -0
  246. data/test/ft_79c_outcome.rb +56 -0
  247. data/test/ft_7_lose.rb +104 -0
  248. data/test/ft_7b_lose.rb +78 -0
  249. data/test/ft_80_spname.rb +91 -0
  250. data/test/ft_81_exp.rb +60 -0
  251. data/test/ft_82_trecu.rb +46 -0
  252. data/test/ft_83_badpause.rb +58 -0
  253. data/test/ft_84_updateexp.rb +198 -0
  254. data/test/ft_85_dolhash.rb +43 -0
  255. data/test/ft_86_dollar_fv.rb +68 -0
  256. data/test/ft_87_define.rb +74 -0
  257. data/test/ft_8_forget.rb +44 -0
  258. data/test/ft_9_cursor.rb +145 -0
  259. data/test/ft_9b_cursor.rb +105 -0
  260. data/test/ft_tests.rb +124 -0
  261. data/test/hash_test.rb +75 -0
  262. data/test/hparticipant_test.rb +164 -0
  263. data/test/lookup_att_test.rb +90 -0
  264. data/test/lookup_vf_test.rb +94 -0
  265. data/test/misc_test.rb +90 -0
  266. data/test/nut_0_irb.rb +20 -0
  267. data/test/obs_test.rb +142 -0
  268. data/test/orest_test.rb +251 -0
  269. data/test/param_test.rb +290 -0
  270. data/test/participant_test.rb +101 -0
  271. data/test/pending.rb +23 -0
  272. data/test/ps_representation.rb +133 -0
  273. data/test/rake_ltest.rb +38 -0
  274. data/test/rake_qtest.rb +68 -0
  275. data/test/raw_prog_test.rb +412 -0
  276. data/test/restart_cron_test.rb +136 -0
  277. data/test/restart_paused_test.rb +98 -0
  278. data/test/restart_sleep_test.rb +140 -0
  279. data/test/restart_tests.rb +18 -0
  280. data/test/restart_when_test.rb +112 -0
  281. data/test/ruby_procdef_test.rb +132 -0
  282. data/test/rutest_utils.rb +63 -0
  283. data/test/sec_test.rb +205 -0
  284. data/test/slock_test.rb +80 -0
  285. data/test/storage_test.rb +44 -0
  286. data/test/test.rb +3 -0
  287. data/test/timeout_test.rb +105 -0
  288. data/test/util_xml_test.rb +112 -0
  289. data/test/wfid_test.rb +175 -0
  290. data/test/wi_test.rb +75 -0
  291. metadata +433 -0
@@ -0,0 +1,272 @@
1
+ #
2
+ #--
3
+ # Copyright (c) 2005-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
+
34
+ #
35
+ # "hecho en Costa Rica"
36
+ #
37
+
38
+ require 'openwfe/workitem'
39
+ require 'openwfe/orest/xmlcodec'
40
+ require 'openwfe/orest/definitions'
41
+ require 'openwfe/orest/restclient'
42
+
43
+
44
+ module OpenWFE
45
+
46
+ #
47
+ # Reopening WorkItem to set the MAP_TYPE (as it's used by OpenWFEja...)
48
+ #
49
+ class WorkItem
50
+ def initialize
51
+ @last_modified = nil
52
+ @attributes = {}
53
+ @attributes[MAP_TYPE] = E_SMAP
54
+ end
55
+ end
56
+
57
+ #
58
+ # a client to an OpenWFE worklists.
59
+ #
60
+ class WorklistClient < RestClient
61
+
62
+ def initialize (url, username, password)
63
+ super
64
+ end
65
+
66
+ #
67
+ # Returns the list of stores the worklist hosts
68
+ #
69
+ def list_stores
70
+ r = get('listStores', nil, nil)
71
+ decode(r)
72
+ end
73
+
74
+ #
75
+ # An alias for list_stores()
76
+ #
77
+ alias :get_store_names :list_stores
78
+
79
+ #
80
+ # Returns the headers of a given store.
81
+ #
82
+ def get_headers (storeName, limit=1000)
83
+
84
+ params = {}
85
+ params["limit"] = limit
86
+
87
+ decode(get('getHeaders', storeName, params))
88
+ end
89
+
90
+ #
91
+ # TODO : rdoc me
92
+ #
93
+ def find_flow_instance (store_name, workflow_instance_id)
94
+
95
+ params = {}
96
+ params["id"] = workflow_instance_id
97
+
98
+ decode(get('findFlowInstance', store_name, params))
99
+ end
100
+
101
+ #
102
+ # Launches a flow (on a given engine and with a given launchitem).
103
+ # The 'engineId' corresponds to an engine's participant name
104
+ # (see etc/engine/participant-map.xml)
105
+ #
106
+ def launch_flow (engineId, launchitem)
107
+
108
+ eli = OpenWFE::XmlCodec::encode(launchitem)
109
+
110
+ params = {}
111
+ params[ENGINEID] = engineId
112
+
113
+ decode(post('launchFlow', nil, params, eli))
114
+ end
115
+
116
+ #
117
+ # Returns a workitem (but doesn't put a lock on it, thus modifications
118
+ # to it cannot be communicated with saveWorkitem() or forwardWorkitem()
119
+ # to the worklist)
120
+ #
121
+ def get_workitem (storeName, flowExpressionId)
122
+
123
+ get_item('getWorkitem', storeName, flowExpressionId)
124
+ end
125
+
126
+ #
127
+ # Returns a workitem and makes sure it's locked in the worklist. Thus,
128
+ # the usage of the methods saveWorkitem() and forwardWorkitem() is
129
+ # possible.
130
+ #
131
+ def get_and_lock_workitem (storeName, flowExpressionId)
132
+
133
+ #puts "...getAndLockWorkitem() for #{flowExpressionId}"
134
+
135
+ get_item('getAndLockWorkitem', storeName, flowExpressionId)
136
+ end
137
+
138
+ #
139
+ # Given a queryMap (a dict of keys and values), locks and returns
140
+ # the first workitem matching.
141
+ #
142
+ def query_and_lock_workitem (storeName, queryMap)
143
+
144
+ hs = get_headers(storeName)
145
+ hs.each do |h|
146
+
147
+ #puts "...h.id #{h.flowExpressionId}"
148
+ #h.attributes.each do |k, v|
149
+ # puts "......h '#{k}' => '#{v}'"
150
+ #end
151
+
152
+ ok = true
153
+ id = nil
154
+
155
+ queryMap.each do |key, value|
156
+
157
+ #puts "...'#{key}' => '#{h.attributes[key]}' ?= '#{value}'"
158
+ ok = (ok and h.attributes[key] == value)
159
+ #
160
+ # the parenthesis are very important
161
+
162
+ #puts " .ok is #{ok}"
163
+ #puts " .id is #{h.flowExpressionId}"
164
+ break unless ok
165
+ end
166
+
167
+ #puts " .id is #{h.flowExpressionId}"
168
+
169
+ get_and_lock_workitem(storeName, h.flow_expression_id) if ok
170
+ end
171
+
172
+ nil
173
+ end
174
+
175
+ #
176
+ # Notifies the worklist that the given workitem has to be unlocked
177
+ # any local (client-side) modification to it are ignored.
178
+ #
179
+ def release_workitem (workitem)
180
+
181
+ post_item('releaseWorkitem', workitem)
182
+ end
183
+
184
+ #
185
+ # Saves back the workitem in the worklist (and releases it)
186
+ #
187
+ def save_workitem (workitem)
188
+
189
+ post_item('saveWorkitem', workitem)
190
+ end
191
+
192
+ #
193
+ # Returns the workitem to the worklist so that it can resume
194
+ # its flow (changes to the workitem are saved).
195
+ #
196
+ def proceed_workitem (workitem)
197
+
198
+ post_item('forwardWorkitem', workitem)
199
+ end
200
+
201
+ alias :forward_workitem :proceed_workitem
202
+
203
+ #
204
+ # Returns the list of flow URLs the user owning this session may
205
+ # launch.
206
+ #
207
+ def list_launchables ()
208
+
209
+ params = {}
210
+
211
+ decode(get('listLaunchables', nil, params))
212
+ end
213
+
214
+ #
215
+ # Delegate the workitem (transfer it to another store).
216
+ #
217
+ def delegate (workitem, targetStoreName)
218
+
219
+ ewi = OpenWFE.encode(workitem)
220
+
221
+ params = {}
222
+ params[TARGETSTORE] = targetStoreName
223
+
224
+ decode(post('delegate', workitem.store, params, ewi))
225
+ end
226
+
227
+ #
228
+ # Delegate the workitem (ask the worklist to deliver it to
229
+ # another participant).
230
+ #
231
+ def delegate_to_participant (workitem, targetParticipantName)
232
+
233
+ ewi = OpenWFE.encode(workitem)
234
+
235
+ params = {}
236
+ params[TARGETPARTICIPANT] = targetParticipantName
237
+
238
+ decode(post('delegate', workitem.store, params, ewi))
239
+ end
240
+
241
+ #def queryStore (storeName, query)
242
+ #end
243
+
244
+ protected
245
+
246
+ def get_item (rest_method_name, store_name, flow_expression_id)
247
+
248
+ fei = OpenWFE::XmlCodec::encode flow_expression_id
249
+ fei = OpenWFE::xmldoc_to_string fei, false
250
+
251
+ params = {}
252
+
253
+ wi = decode(post(rest_method_name, store_name, params, fei))
254
+
255
+ wi.store = store_name if wi
256
+
257
+ wi
258
+ end
259
+
260
+ def post_item (rest_method_name, workitem)
261
+
262
+ ewi = OpenWFE::XmlCodec::encode(workitem)
263
+
264
+ params = {}
265
+
266
+ decode(post(rest_method_name, workitem.store, params, ewi))
267
+ end
268
+
269
+ end
270
+
271
+ end
272
+
@@ -0,0 +1,670 @@
1
+ #
2
+ #--
3
+ # Copyright (c) 2005-2008, 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
+
34
+ #
35
+ # "hecho en Costa Rica" (with just the PickAxe at hand)
36
+ #
37
+
38
+ require 'base64'
39
+ require 'rexml/document'
40
+
41
+ require 'openwfe/utils'
42
+ require 'openwfe/workitem'
43
+ require 'openwfe/flowexpressionid'
44
+ require 'openwfe/orest/definitions'
45
+ require 'openwfe/orest/workitem'
46
+
47
+
48
+ module OpenWFE
49
+
50
+ #
51
+ # Ugly XML codec for OpenWFE workitems
52
+ #
53
+ # (one of the first things I wrote in Ruby...)
54
+ #
55
+ module XmlCodec
56
+
57
+ #
58
+ # Returns the first subelt of xmlElt that matches the given elt_name.
59
+ # If the name is null, the first elt will be returned.
60
+ #
61
+ def self.first_element (xml_elt, elt_name=nil)
62
+
63
+ return nil if not xml_elt
64
+
65
+ return xml_elt.elements.find { |e| e.is_a?(REXML::Element) } \
66
+ unless elt_name
67
+
68
+ xml_elt.elements.find do |e|
69
+ e.is_a?(REXML::Element) and e.name == elt_name
70
+ end
71
+ end
72
+
73
+ #
74
+ # Takes as input some XML element and returns is decoded
75
+ # (as an instance)
76
+ #
77
+ def XmlCodec.decode (xmlElt)
78
+
79
+ return nil unless xmlElt
80
+
81
+ if xmlElt.kind_of? String
82
+
83
+ xmlElt = REXML::Document.new(
84
+ xmlElt,
85
+ :compress_whitespace => :all,
86
+ :ignore_whitespace_nodes => :all)
87
+
88
+ xmlElt = xmlElt.root
89
+ end
90
+
91
+ #puts "decode() xmlElt.name is >#{xmlElt.name}<"
92
+
93
+ return decode_session_id(xmlElt) if xmlElt.name == 'session'
94
+ return decode_list(xmlElt) if xmlElt.name == STORES
95
+ return decode_store(xmlElt) if xmlElt.name == STORE
96
+ return decode_list(xmlElt) if xmlElt.name == HEADERS
97
+ return decode_header(xmlElt) if xmlElt.name == HEADER
98
+
99
+ return decode_launch_ok(xmlElt) if xmlElt.name == OK
100
+
101
+ return decode_list(xmlElt) if xmlElt.name == HISTORY
102
+ return decode_historyitem(xmlElt) if xmlElt.name == HISTORY_ITEM
103
+
104
+ return decode_list(xmlElt) if xmlElt.name == FLOW_EXPRESSION_IDS
105
+ return decode_fei(xmlElt) if xmlElt.name == FLOW_EXPRESSION_ID
106
+
107
+ return decode_inflowworkitem(xmlElt) \
108
+ if xmlElt.name == IN_FLOW_WORKITEM
109
+ return decode_launchitem(xmlElt) \
110
+ if xmlElt.name == LAUNCHITEM
111
+
112
+ return decode_list(xmlElt) if xmlElt.name == LAUNCHABLES
113
+ return decode_launchable(xmlElt) if xmlElt.name == LAUNCHABLE
114
+
115
+ return decode_list(xmlElt) if xmlElt.name == EXPRESSIONS
116
+ return decode_expression(xmlElt) if xmlElt.name == EXPRESSION
117
+
118
+ return decode_attribute(xmlElt.elements[1]) if xmlElt.name == ATTRIBUTES
119
+
120
+ #
121
+ # default
122
+
123
+ decode_attribute(xmlElt)
124
+
125
+ #raise \
126
+ # ArgumentError, \
127
+ # "Cannot decode : '"+xmlElt.name+"' "+xmlElt.to_s()
128
+ end
129
+
130
+ #
131
+ # Takes some OpenWFE Ruby instance and returns it as XML
132
+ #
133
+ def XmlCodec.encode (owfeData)
134
+
135
+ #puts "encode() #{owfeData.inspect}"
136
+
137
+ return encode_launchitem(owfeData) \
138
+ if owfeData.kind_of? LaunchItem
139
+
140
+ return encode_fei(owfeData) \
141
+ if owfeData.kind_of? FlowExpressionId
142
+
143
+ return encode_inflowworkitem(owfeData) \
144
+ if owfeData.kind_of? InFlowWorkItem
145
+
146
+ raise \
147
+ ArgumentError, \
148
+ "Cannot encode : "+owfeData.inspect()
149
+ end
150
+
151
+ def XmlCodec.encode_workitem_as_header (in_flow_workitem, locked)
152
+
153
+ e = REXML::Element.new HEADER
154
+
155
+ e.add_attribute A_LAST_MODIFIED, "#{in_flow_workitem.last_modified}"
156
+ e.add_attribute A_LOCKED, locked
157
+
158
+ e << XmlCodec::encode_fei(in_flow_workitem.fei)
159
+ e << XmlCodec::encode_attributes(in_flow_workitem)
160
+
161
+ e
162
+ end
163
+
164
+ private
165
+
166
+ #
167
+ # DECODE
168
+ #
169
+
170
+ def XmlCodec.decode_session_id (xmlElt)
171
+ Integer(xmlElt.attributes['id'])
172
+ end
173
+
174
+ def XmlCodec.decode_list (xmlElt)
175
+ xmlElt.elements.collect { |elt| decode(elt) }
176
+ end
177
+
178
+
179
+ def XmlCodec.decode_launchable (xmlElt)
180
+
181
+ launchable = Launchable.new()
182
+
183
+ launchable.url = xmlElt.attributes[URL]
184
+ launchable.engine_id = xmlElt.attributes[ENGINE_ID]
185
+
186
+ launchable
187
+ end
188
+
189
+
190
+ def XmlCodec.decode_expression (xmlElt)
191
+
192
+ exp = Expression.new()
193
+
194
+ exp.id = decode(first_element(xmlElt))
195
+
196
+ exp.apply_time = xmlElt.attributes[APPLY_TIME]
197
+ exp.state = xmlElt.attributes[STATE]
198
+ exp.state_since = xmlElt.attributes[STATE_SINCE]
199
+
200
+ exp
201
+ end
202
+
203
+
204
+ def XmlCodec.decode_store (xmlElt)
205
+
206
+ store = Store.new()
207
+
208
+ store.name = xmlElt.attributes[NAME]
209
+ store.workitem_count = xmlElt.attributes[WORKITEM_COUNT]
210
+ store.workitem_count = Integer(store.workitem_count)
211
+ store.permissions = xmlElt.attributes[PERMISSIONS]
212
+
213
+ store
214
+ end
215
+
216
+
217
+ def XmlCodec.decode_header (xmlElt)
218
+
219
+ header = Header.new()
220
+
221
+ header.last_modified = xmlElt.attributes[A_LAST_MODIFIED]
222
+ header.locked = parse_boolean(xmlElt.attributes[A_LOCKED])
223
+ header.flow_expression_id = decode(first_element(xmlElt, FLOW_EXPRESSION_ID))
224
+ header.attributes = decode(first_element(xmlElt, ATTRIBUTES))
225
+
226
+ header
227
+ end
228
+
229
+
230
+ def XmlCodec.decode_fei (xmlElt)
231
+
232
+ fei = FlowExpressionId.new
233
+
234
+ fei.owfe_version = xmlElt.attributes[OWFE_VERSION]
235
+ fei.engine_id = xmlElt.attributes[ENGINE_ID]
236
+ fei.initial_engine_id = xmlElt.attributes[INITIAL_ENGINE_ID]
237
+
238
+ fei.workflow_definition_url = xmlElt.attributes[WORKFLOW_DEFINITION_URL]
239
+ fei.workflow_definition_name = xmlElt.attributes[WORKFLOW_DEFINITION_NAME]
240
+ fei.workflow_definition_revision = xmlElt.attributes[WORKFLOW_DEFINITION_REVISION]
241
+
242
+ fei.workflow_instance_id = xmlElt.attributes[WORKFLOW_INSTANCE_ID]
243
+
244
+ fei.expression_name = xmlElt.attributes[EXPRESSION_NAME]
245
+ fei.expression_id = xmlElt.attributes[EXPRESSION_ID]
246
+
247
+ #puts " ... fei.expressionName is >#{fei.expressionName}<"
248
+ #puts " ... fei.wfid is >#{fei.workflowInstanceId}<"
249
+
250
+ fei
251
+ end
252
+
253
+
254
+ def XmlCodec.decode_attribute (xmlElt)
255
+
256
+ #puts "decodeAttribute() '#{xmlElt.name}' --> '#{xmlElt.text}'"
257
+
258
+ #
259
+ # atomic types
260
+
261
+ return xmlElt.text.strip \
262
+ if xmlElt.name == E_STRING
263
+ return Integer(xmlElt.text.strip) \
264
+ if xmlElt.name == E_INTEGER
265
+ return Integer(xmlElt.text.strip) \
266
+ if xmlElt.name == E_LONG
267
+ return Float(xmlElt.text.strip) \
268
+ if xmlElt.name == E_DOUBLE
269
+ return parse_boolean(xmlElt.text) \
270
+ if xmlElt.name == E_BOOLEAN
271
+
272
+ return decode_xmldocument(xmlElt) \
273
+ if xmlElt.name == E_XML_DOCUMENT
274
+ return xmlElt.children[0] \
275
+ if xmlElt.name == E_RAW_XML
276
+
277
+ return Base64Attribute.new(xmlElt.text) \
278
+ if xmlElt.name == E_BASE64
279
+
280
+ #
281
+ # composite types
282
+
283
+ return decode_list(xmlElt) \
284
+ if xmlElt.name == E_LIST
285
+
286
+ if xmlElt.name == E_SMAP or xmlElt.name == E_MAP
287
+
288
+ map = {}
289
+ map[MAP_TYPE] = xmlElt.name
290
+
291
+ #xmlElt.elements.each("//"+M_ENTRY) do |e|
292
+ xmlElt.elements.each(M_ENTRY) do |e|
293
+ #puts "decodeAttribute() >#{e}<"
294
+ decode_entry(e, map)
295
+ end
296
+
297
+ return map
298
+ end
299
+
300
+ #puts OpenWFE.xmldoc_to_string(xmlElt.document())
301
+
302
+ raise \
303
+ ArgumentError, \
304
+ "Cannot decode <#{xmlElt.name}/> in \n"+\
305
+ OpenWFE.xmldoc_to_string(xmlElt.document())
306
+ end
307
+
308
+ def XmlCodec.decode_xmldocument (xmlElt)
309
+
310
+ s = Base64::decode64 xmlElt.text.strip
311
+ REXML::Document.new s
312
+ end
313
+
314
+ def XmlCodec.decode_entry (xmlElt, map)
315
+
316
+ key = xmlElt.elements[1]
317
+ val = xmlElt.elements[2]
318
+
319
+ #
320
+ # this parse method supports the old style and the [new] light
321
+ # style/schema
322
+ #
323
+
324
+ key = key.elements[1] if key.name == M_KEY
325
+ val = val.elements[1] if val.name == M_VALUE
326
+
327
+ key = decode(key)
328
+ val = decode(val)
329
+
330
+ #puts "decodeEntry() k >#{key}< v >#{val}<"
331
+ #puts "decodeEntry() subject '#{val}'" if key == '__subject__'
332
+
333
+ key = key.strip if key.is_a?(String)
334
+ val = val.strip if val.is_a?(String)
335
+
336
+ map[key] = val
337
+ end
338
+
339
+ def XmlCodec.parse_boolean (string)
340
+
341
+ string.strip.downcase == 'true'
342
+ end
343
+
344
+ def XmlCodec.decode_historyitem (xmlElt)
345
+
346
+ hi = HistoryItem.new
347
+
348
+ hi.author = xmlElt.attributes[A_AUTHOR]
349
+ hi.date = xmlElt.attributes[A_DATE]
350
+ hi.host = xmlElt.attributes[A_HOST]
351
+ hi.text = xmlElt.text
352
+
353
+ hi.wfd_name = xmlElt.attributes[WORKFLOW_DEFINITION_NAME]
354
+ hi.wfd_revision = xmlElt.attributes[WORKFLOW_DEFINITION_REVISION]
355
+ hi.wf_instance_id = xmlElt.attributes[WORKFLOW_INSTANCE_ID]
356
+ hi.expression_id = xmlElt.attributes[EXPRESSION_ID]
357
+
358
+ hi
359
+ end
360
+
361
+
362
+ def XmlCodec.decode_launch_ok (xmlElt)
363
+
364
+ sFei = xmlElt.attributes[A_FLOW_ID]
365
+
366
+ return true unless sFei
367
+
368
+ FlowExpressionId.to_fei(sFei)
369
+ end
370
+
371
+
372
+ def XmlCodec.decode_inflowworkitem (xmlElt)
373
+
374
+ wi = InFlowWorkItem.new()
375
+
376
+ wi.last_modified = xmlElt.attributes[A_LAST_MODIFIED]
377
+ wi.attributes = decode(first_element(xmlElt, ATTRIBUTES))
378
+
379
+ wi.participant_name = xmlElt.attributes[A_PARTICIPANT_NAME]
380
+ wi.flow_expression_id = decode(first_element(first_element(xmlElt, E_LAST_EXPRESSION_ID), FLOW_EXPRESSION_ID))
381
+
382
+ wi.dispatch_time = xmlElt.attributes[A_DISPATCH_TIME]
383
+
384
+ # TODO : decode filter
385
+
386
+ wi.history = decode(first_element(xmlElt, HISTORY))
387
+
388
+ wi
389
+ end
390
+
391
+ def XmlCodec.decode_launchitem (xmlElt)
392
+
393
+ li = LaunchItem.new
394
+
395
+ li.workflow_definition_url =
396
+ xmlElt.attributes[WORKFLOW_DEFINITION_URL]
397
+
398
+ li.attributes =
399
+ decode(first_element(xmlElt, ATTRIBUTES))
400
+
401
+ li
402
+ end
403
+
404
+
405
+ #
406
+ # ENCODE
407
+ #
408
+
409
+
410
+ def XmlCodec.encode_item (item, elt)
411
+
412
+ elt.attributes[A_LAST_MODIFIED] = item.last_modified
413
+
414
+ elt << encode_attributes(item)
415
+ end
416
+
417
+ def XmlCodec.encode_attributes (item)
418
+
419
+ eAttributes = REXML::Element.new(ATTRIBUTES)
420
+
421
+ eAttributes << encode_attribute(item.attributes)
422
+
423
+ eAttributes
424
+ end
425
+
426
+
427
+ def XmlCodec.encode_launchitem (launchitem)
428
+
429
+ doc = REXML::Document.new()
430
+
431
+ root = REXML::Element.new(LAUNCHITEM)
432
+
433
+ encode_item(launchitem, root)
434
+
435
+ root.attributes[WORKFLOW_DEFINITION_URL] = \
436
+ launchitem.workflow_definition_url
437
+
438
+ # TODO :
439
+ #
440
+ # - encode descriptionMap
441
+ #
442
+ # - replyTo is not necessary
443
+
444
+ doc << root
445
+
446
+ OpenWFE.xmldoc_to_string(doc)
447
+ end
448
+
449
+
450
+ def XmlCodec.encode_inflowitem (item, elt)
451
+
452
+ encode_item(item, elt)
453
+
454
+ elt.attributes[A_PARTICIPANT_NAME] = item.participant_name
455
+
456
+ eLastExpressionId = REXML::Element.new(E_LAST_EXPRESSION_ID)
457
+
458
+ eLastExpressionId << encode_fei(item.last_expression_id)
459
+
460
+ elt << eLastExpressionId
461
+ end
462
+
463
+
464
+ def XmlCodec.encode_inflowworkitem (item)
465
+
466
+ doc = REXML::Document.new()
467
+
468
+ root = REXML::Element.new(IN_FLOW_WORKITEM)
469
+
470
+ encode_inflowitem(item, root)
471
+
472
+ root.attributes[A_DISPATCH_TIME] = item.dispatch_time
473
+
474
+ # add filter ? no
475
+
476
+ encode_history(item, root) if item.history
477
+
478
+ doc << root
479
+
480
+ s = OpenWFE.xmldoc_to_string(doc)
481
+ #puts "encoded :\n#{s}"
482
+ s
483
+ end
484
+
485
+
486
+ def XmlCodec.encode_history (item, elt)
487
+
488
+ eHistory = REXML::Element.new(HISTORY)
489
+
490
+ item.history.each do |hi|
491
+
492
+ ehi = REXML::Element.new(HISTORY_ITEM)
493
+
494
+ ehi.attributes[A_AUTHOR] = hi.author
495
+ ehi.attributes[A_DATE] = hi.date
496
+ ehi.attributes[A_HOST] = hi.host
497
+
498
+ ehi.attributes[WORKFLOW_DEFINITION_NAME] = hi.wfd_name
499
+ ehi.attributes[WORKFLOW_DEFINITION_REVISION] = hi.wfd_revision
500
+ ehi.attributes[WORKFLOW_INSTANCE_ID] = hi.wf_instance_id
501
+ ehi.attributes[EXPRESSION_ID] = hi.expression_id
502
+
503
+ eHistory << ehi
504
+ end
505
+
506
+ elt << eHistory
507
+ end
508
+
509
+
510
+ def XmlCodec.encode_attribute (att)
511
+
512
+ #puts "encodeAttribute() att.class is #{att.class}"
513
+
514
+ return encode_atomicattribute(E_STRING, att) \
515
+ if att.kind_of?(String)
516
+ return encode_atomicattribute(E_INTEGER, att) \
517
+ if att.kind_of?(Fixnum)
518
+ return encode_atomicattribute(E_DOUBLE, att) \
519
+ if att.kind_of?(Float)
520
+
521
+ return encode_xmldocument(att) \
522
+ if att.kind_of?(REXML::Document)
523
+ return encode_xmlattribute(att) \
524
+ if att.kind_of?(REXML::Element)
525
+
526
+ return encode_atomicattribute(E_BOOLEAN, true) \
527
+ if att.kind_of?(TrueClass)
528
+ return encode_atomicattribute(E_BOOLEAN, false) \
529
+ if att.kind_of?(FalseClass)
530
+
531
+ return encode_base64attribute(att) \
532
+ if att.kind_of?(Base64Attribute)
533
+
534
+ return encode_mapattribute(att) if att.kind_of?(Hash)
535
+ return encode_listattribute(att) if att.kind_of?(Array)
536
+
537
+ #
538
+ # default
539
+
540
+ encode_atomicattribute(E_STRING, att)
541
+
542
+ #raise \
543
+ # ArgumentError, \
544
+ # "Cannot encode attribute of class '#{att.class}'"
545
+ end
546
+
547
+ def XmlCodec.encode_xmldocument (elt)
548
+
549
+ e = REXML::Element.new(E_XML_DOCUMENT)
550
+ e.text = Base64::encode64(elt.to_s)
551
+ e
552
+ end
553
+
554
+ def XmlCodec.encode_xmlattribute (elt)
555
+
556
+ return elt if elt.name == E_RAW_XML
557
+
558
+ #
559
+ # else, wrap within <raw-xml>...</raw-xml>
560
+
561
+ e = REXML::Element.new(E_RAW_XML)
562
+ e << elt
563
+
564
+ e
565
+ end
566
+
567
+
568
+ def XmlCodec.encode_base64attribute (att)
569
+
570
+ e = REXML::Element.new(E_BASE64)
571
+ e.text = att.content
572
+
573
+ e
574
+ end
575
+
576
+
577
+ def XmlCodec.encode_atomicattribute (name, value)
578
+
579
+ elt = REXML::Element.new(name)
580
+ #elt << REXML::Text.new(value.to_s())
581
+ elt.add_text(value.to_s())
582
+
583
+ elt
584
+ end
585
+
586
+
587
+ def XmlCodec.encode_listattribute (list)
588
+
589
+ elt = REXML::Element.new(E_LIST)
590
+
591
+ list.each do |e|
592
+ elt << encode_attribute(e)
593
+ end
594
+
595
+ elt
596
+ end
597
+
598
+
599
+ def XmlCodec.encode_mapattribute (hash)
600
+
601
+ name = hash[MAP_TYPE]
602
+ name = 'map' if name == nil
603
+
604
+ elt = REXML::Element.new(name)
605
+
606
+ hash.each_key do |key|
607
+
608
+ next if key == MAP_TYPE
609
+
610
+ eEntry = REXML::Element.new(M_ENTRY)
611
+
612
+ val = hash[key]
613
+
614
+ eEntry << encode_attribute(key)
615
+ eEntry << encode_attribute(val)
616
+
617
+ elt << eEntry
618
+ end
619
+
620
+ elt
621
+ end
622
+
623
+
624
+ def XmlCodec.encode_fei (fei)
625
+
626
+ elt = REXML::Element.new(FLOW_EXPRESSION_ID)
627
+
628
+ elt.attributes[OWFE_VERSION] = fei.owfe_version
629
+ elt.attributes[ENGINE_ID] = fei.engine_id
630
+ elt.attributes[INITIAL_ENGINE_ID] = fei.initial_engine_id
631
+
632
+ elt.attributes[WORKFLOW_DEFINITION_URL] = fei.workflow_definition_url
633
+ elt.attributes[WORKFLOW_DEFINITION_NAME] = fei.workflow_definition_name
634
+ elt.attributes[WORKFLOW_DEFINITION_REVISION] = fei.workflow_definition_revision
635
+ elt.attributes[WORKFLOW_INSTANCE_ID] = fei.workflow_instance_id
636
+
637
+ elt.attributes[EXPRESSION_NAME] = fei.expression_name
638
+ elt.attributes[EXPRESSION_ID] = fei.expression_id
639
+
640
+ elt
641
+ end
642
+ end
643
+
644
+ #
645
+ # Just turns some XML to a String (if decl is set to false, no
646
+ # XML declaration will be printed).
647
+ #
648
+ def OpenWFE.xmldoc_to_string (xml, decl=true)
649
+
650
+ #return xml if xml.is_a?(String)
651
+
652
+ xml << REXML::XMLDecl.new \
653
+ if decl and (not xml[0].is_a?(REXML::XMLDecl))
654
+
655
+ #s = ""
656
+ #xml.write(s, 0)
657
+ #return s
658
+ xml.to_s
659
+ end
660
+
661
+ #
662
+ # An alias for OpenWFE::xmldoc_to_string()
663
+ #
664
+ def OpenWFE.xml_to_s (xml, decl=true)
665
+
666
+ OpenWFE::xmldoc_to_string(xml, decl)
667
+ end
668
+
669
+ end
670
+