openwferu 0.9.7 → 0.9.8
Sign up to get free protection for your applications and to get access to all the features.
- data/examples/engine_template.rb +182 -0
- data/examples/openwferu.rb +6 -7
- data/lib/openwfe/contextual.rb +8 -6
- data/lib/openwfe/engine/engine.rb +49 -14
- data/lib/openwfe/expool/expressionpool.rb +48 -17
- data/lib/openwfe/expool/history.rb +64 -14
- data/lib/openwfe/expool/journal.rb +66 -28
- data/lib/openwfe/expool/journal_replay.rb +190 -48
- data/lib/openwfe/expool/wfidgen.rb +51 -6
- data/lib/openwfe/expressions/condition.rb +49 -5
- data/lib/openwfe/expressions/environment.rb +9 -37
- data/lib/openwfe/expressions/expressionmap.rb +15 -1
- data/lib/openwfe/expressions/fe_concurrence.rb +4 -4
- data/lib/openwfe/expressions/fe_cron.rb +1 -5
- data/lib/openwfe/expressions/fe_do.rb +96 -26
- data/lib/openwfe/expressions/fe_equals.rb +190 -0
- data/lib/openwfe/expressions/fe_fqv.rb +25 -7
- data/lib/openwfe/expressions/fe_if.rb +262 -0
- data/lib/openwfe/expressions/fe_iterator.rb +3 -4
- data/lib/openwfe/expressions/fe_losfor.rb +0 -1
- data/lib/openwfe/expressions/fe_misc.rb +4 -5
- data/lib/openwfe/expressions/fe_participant.rb +2 -3
- data/lib/openwfe/expressions/fe_raw.rb +71 -31
- data/lib/openwfe/expressions/fe_reserve.rb +141 -0
- data/lib/openwfe/expressions/fe_sequence.rb +0 -1
- data/lib/openwfe/expressions/fe_sleep.rb +3 -58
- data/lib/openwfe/expressions/fe_subprocess.rb +6 -5
- data/lib/openwfe/expressions/fe_value.rb +20 -121
- data/lib/openwfe/expressions/fe_wait.rb +79 -0
- data/lib/openwfe/expressions/fe_when.rb +31 -96
- data/lib/openwfe/expressions/flowexpression.rb +112 -19
- data/lib/openwfe/expressions/raw_prog.rb +8 -116
- data/lib/openwfe/expressions/simplerep.rb +197 -0
- data/lib/openwfe/expressions/time.rb +266 -0
- data/lib/openwfe/expressions/timeout.rb +2 -2
- data/lib/openwfe/flowexpressionid.rb +22 -0
- data/lib/openwfe/listeners/socketlisteners.rb +15 -1
- data/lib/openwfe/participants/participantmap.rb +12 -1
- data/lib/openwfe/participants/participants.rb +7 -1
- data/lib/openwfe/rudefinitions.rb +1 -6
- data/lib/openwfe/service.rb +8 -0
- data/lib/openwfe/util/irb.rb +86 -0
- data/lib/openwfe/util/ometa.rb +3 -3
- data/lib/openwfe/util/safe.rb +26 -34
- data/lib/openwfe/util/scheduler.rb +133 -76
- data/lib/openwfe/utils.rb +1 -1
- data/lib/openwfe/version.rb +2 -2
- data/lib/openwfe/workitem.rb +38 -0
- data/lib/openwfe/worklist/storeparticipant.rb +27 -2
- data/test/console_test.rb +15 -0
- data/test/flowtestbase.rb +20 -28
- data/test/ft_12_blockparticipant.rb +24 -0
- data/test/ft_14b_subprocess.rb +18 -0
- data/test/ft_22_history.rb +22 -1
- data/test/ft_23_when.rb +29 -2
- data/test/ft_23b_when.rb +17 -0
- data/test/ft_23c_wait.rb +87 -0
- data/test/ft_2_concurrence.rb +15 -14
- data/test/ft_2b_concurrence.rb +4 -4
- data/test/ft_32_journal.rb +29 -6
- data/test/ft_32b_journal.rb +76 -0
- data/test/ft_36_subprocids.rb +96 -0
- data/test/ft_37_pnames.rb +55 -0
- data/test/ft_38_tag.rb +128 -0
- data/test/ft_39_reserve.rb +119 -0
- data/test/ft_3_equals.rb +20 -1
- data/test/ft_40_defined.rb +72 -0
- data/test/ft_41_case.rb +124 -0
- data/test/ft_4_misc.rb +17 -0
- data/test/ft_5_time.rb +15 -20
- data/test/ft_7_lose.rb +2 -3
- data/test/ft_8_forget.rb +1 -1
- data/test/ft_tests.rb +9 -0
- data/test/hparticipant_test.rb +47 -1
- data/test/nut_0_irb.rb +20 -0
- data/test/raw_prog_test.rb +6 -0
- data/test/safely_test.rb +31 -41
- data/test/wfid_test.rb +43 -0
- metadata +21 -4
- data/lib/openwfe/expressions/fe_utils.rb +0 -151
@@ -61,11 +61,11 @@ module OpenWFE
|
|
61
61
|
include Contextual, Logging, OwfeServiceLocator
|
62
62
|
|
63
63
|
attr_accessor \
|
64
|
-
:fei,
|
65
|
-
:parent_id,
|
66
|
-
:environment_id,
|
67
|
-
:attributes,
|
68
|
-
:children,
|
64
|
+
:fei,
|
65
|
+
:parent_id,
|
66
|
+
:environment_id,
|
67
|
+
:attributes,
|
68
|
+
:children,
|
69
69
|
:apply_time
|
70
70
|
|
71
71
|
|
@@ -124,7 +124,7 @@ module OpenWFE
|
|
124
124
|
# cancels all the children
|
125
125
|
# Attempts to return an InFlowWorkItem
|
126
126
|
#
|
127
|
-
def cancel
|
127
|
+
def cancel
|
128
128
|
|
129
129
|
return nil if not @children
|
130
130
|
|
@@ -138,7 +138,7 @@ module OpenWFE
|
|
138
138
|
inflowitem = i if not inflowitem
|
139
139
|
end
|
140
140
|
|
141
|
-
|
141
|
+
inflowitem
|
142
142
|
end
|
143
143
|
|
144
144
|
#
|
@@ -150,7 +150,7 @@ module OpenWFE
|
|
150
150
|
#
|
151
151
|
def get_parent ()
|
152
152
|
parent, parent_fei = get_expression_pool().fetch(@parent_id)
|
153
|
-
|
153
|
+
parent
|
154
154
|
end
|
155
155
|
|
156
156
|
#
|
@@ -163,7 +163,7 @@ module OpenWFE
|
|
163
163
|
def store_itself ()
|
164
164
|
ldebug { "store_itself() for #{@fei.to_debug_s}" }
|
165
165
|
#ldebug { "store_itself() \n#{OpenWFE::caller_to_s(0, 6)}" }
|
166
|
-
|
166
|
+
get_expression_pool().update(self)
|
167
167
|
end
|
168
168
|
|
169
169
|
#
|
@@ -175,7 +175,7 @@ module OpenWFE
|
|
175
175
|
def get_environment ()
|
176
176
|
return nil if not @environment_id
|
177
177
|
env, fei = get_expression_pool().fetch(@environment_id)
|
178
|
-
|
178
|
+
env
|
179
179
|
end
|
180
180
|
|
181
181
|
#
|
@@ -282,7 +282,19 @@ module OpenWFE
|
|
282
282
|
|
283
283
|
return default if not text
|
284
284
|
|
285
|
-
|
285
|
+
OpenWFE::dosub(text, self, workitem)
|
286
|
+
end
|
287
|
+
|
288
|
+
#
|
289
|
+
# Returns true if the expression has the given attribute.
|
290
|
+
# The attname parameter can be a String or a Symbol.
|
291
|
+
#
|
292
|
+
def has_attribute (attname)
|
293
|
+
|
294
|
+
attname = OpenWFE::symbol_to_name(attname) \
|
295
|
+
if attname.kind_of? Symbol
|
296
|
+
|
297
|
+
@attributes[attname] != nil
|
286
298
|
end
|
287
299
|
|
288
300
|
#
|
@@ -322,7 +334,7 @@ module OpenWFE
|
|
322
334
|
#end
|
323
335
|
end
|
324
336
|
|
325
|
-
|
337
|
+
result
|
326
338
|
end
|
327
339
|
|
328
340
|
#
|
@@ -419,6 +431,69 @@ module OpenWFE
|
|
419
431
|
#ldebug { "synchronize() --out-- for #{@fei.to_debug_s}" }
|
420
432
|
end
|
421
433
|
|
434
|
+
#
|
435
|
+
# Returns the text stored as the children of the given expression
|
436
|
+
#
|
437
|
+
def fetch_text_content (workitem, escape=false)
|
438
|
+
|
439
|
+
text = ""
|
440
|
+
|
441
|
+
children.each do |child|
|
442
|
+
if child.kind_of?(RawExpression)
|
443
|
+
text << child.fei.to_s
|
444
|
+
else
|
445
|
+
text << child.to_s
|
446
|
+
end
|
447
|
+
end
|
448
|
+
|
449
|
+
return nil if text == ""
|
450
|
+
|
451
|
+
text = OpenWFE::dosub(text, self, workitem) \
|
452
|
+
unless escape
|
453
|
+
|
454
|
+
text
|
455
|
+
end
|
456
|
+
|
457
|
+
#
|
458
|
+
# looks up for 'value', 'variable-value' and then for 'field-value'
|
459
|
+
# if necessary.
|
460
|
+
#
|
461
|
+
def lookup_value (workitem, prefix='')
|
462
|
+
|
463
|
+
lookup_vf_attribute(workitem, 'value', prefix)
|
464
|
+
end
|
465
|
+
|
466
|
+
#
|
467
|
+
# looks up for 'ref', 'variable-ref' and then for 'field-ref'
|
468
|
+
# if necessary.
|
469
|
+
#
|
470
|
+
def lookup_ref (workitem, prefix='')
|
471
|
+
|
472
|
+
lookup_vf_attribute(workitem, 'ref', prefix)
|
473
|
+
end
|
474
|
+
|
475
|
+
#
|
476
|
+
# Looks up for value attributes like 'field-ref' or 'variable-value'
|
477
|
+
#
|
478
|
+
def lookup_vf_attribute (workitem, att_name, prefix='')
|
479
|
+
|
480
|
+
prefix = "#{prefix.to_s}-" if prefix != ''
|
481
|
+
|
482
|
+
v = lookup_attribute("#{prefix}#{att_name}", workitem)
|
483
|
+
|
484
|
+
return v if v
|
485
|
+
|
486
|
+
v = lookup_attribute("#{prefix}variable-#{att_name}", workitem)
|
487
|
+
|
488
|
+
return lookup_variable(v) if v
|
489
|
+
|
490
|
+
v = lookup_attribute("#{prefix}field-#{att_name}", workitem)
|
491
|
+
|
492
|
+
return workitem.attributes[v] if v
|
493
|
+
|
494
|
+
nil
|
495
|
+
end
|
496
|
+
|
422
497
|
#
|
423
498
|
# Some eye candy
|
424
499
|
#
|
@@ -461,13 +536,6 @@ module OpenWFE
|
|
461
536
|
end
|
462
537
|
end
|
463
538
|
|
464
|
-
#def self.sync_expression (bool)
|
465
|
-
# meta_def :is_sync_expression? do
|
466
|
-
# bool
|
467
|
-
# end
|
468
|
-
#end
|
469
|
-
#sync_expression false
|
470
|
-
|
471
539
|
protected
|
472
540
|
|
473
541
|
#
|
@@ -494,6 +562,31 @@ module OpenWFE
|
|
494
562
|
|
495
563
|
return [ get_environment, varname]
|
496
564
|
end
|
565
|
+
|
566
|
+
#
|
567
|
+
# Returns the next sub process id available (this counter
|
568
|
+
# is stored in the local environment under the key :next_sub_id)
|
569
|
+
#
|
570
|
+
def get_next_sub_id
|
571
|
+
|
572
|
+
env = get_environment
|
573
|
+
|
574
|
+
c = nil
|
575
|
+
|
576
|
+
env.synchronize do
|
577
|
+
c = env.variables[:next_sub_id]
|
578
|
+
n = if c
|
579
|
+
c + 1
|
580
|
+
else
|
581
|
+
c = 0
|
582
|
+
1
|
583
|
+
end
|
584
|
+
env.variables[:next_sub_id] = n
|
585
|
+
env.store_itself
|
586
|
+
end
|
587
|
+
|
588
|
+
c
|
589
|
+
end
|
497
590
|
end
|
498
591
|
|
499
592
|
end
|
@@ -43,119 +43,11 @@ require 'rexml/document'
|
|
43
43
|
|
44
44
|
require 'openwfe/utils'
|
45
45
|
require 'openwfe/expressions/fe_raw'
|
46
|
-
require 'openwfe/expressions/
|
46
|
+
require 'openwfe/expressions/simplerep'
|
47
47
|
|
48
48
|
|
49
49
|
module OpenWFE
|
50
50
|
|
51
|
-
#
|
52
|
-
# A raw representation for a process definition, programmatic
|
53
|
-
# process definitions are turned into trees of instances of this class.
|
54
|
-
#
|
55
|
-
class ProgExpRepresentation
|
56
|
-
|
57
|
-
attr_reader \
|
58
|
-
:name,
|
59
|
-
:attributes
|
60
|
-
|
61
|
-
attr_accessor \
|
62
|
-
:children
|
63
|
-
|
64
|
-
def initialize (name, attributes)
|
65
|
-
super()
|
66
|
-
@name = name
|
67
|
-
@attributes = attributes
|
68
|
-
@children = []
|
69
|
-
end
|
70
|
-
|
71
|
-
#
|
72
|
-
# Adds a child to this expression representation.
|
73
|
-
#
|
74
|
-
def << (child)
|
75
|
-
@children << child
|
76
|
-
end
|
77
|
-
|
78
|
-
#
|
79
|
-
# Always return the ProgRawExpression class.
|
80
|
-
#
|
81
|
-
def raw_expression_class
|
82
|
-
return ProgRawExpression
|
83
|
-
end
|
84
|
-
|
85
|
-
#
|
86
|
-
# Returns an XML string, containing the equivalent process definition
|
87
|
-
# in the classical OpenWFE process definition language.
|
88
|
-
#
|
89
|
-
def to_s
|
90
|
-
doc = REXML::Document.new()
|
91
|
-
doc << to_xml
|
92
|
-
s = ""
|
93
|
-
doc.write(s, 0)
|
94
|
-
return s
|
95
|
-
end
|
96
|
-
|
97
|
-
#
|
98
|
-
# Returns this representation tree as an XML element (and its children).
|
99
|
-
#
|
100
|
-
def to_xml
|
101
|
-
|
102
|
-
elt = REXML::Element.new(@name)
|
103
|
-
|
104
|
-
#elt.attributes.update(@attributes)
|
105
|
-
@attributes.each do |k, v|
|
106
|
-
elt.attributes[k] = v
|
107
|
-
end
|
108
|
-
|
109
|
-
@children.each do |child|
|
110
|
-
if child.kind_of? ProgExpRepresentation
|
111
|
-
elt << child.to_xml
|
112
|
-
else
|
113
|
-
elt << REXML::Text.new(child.to_s)
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
return elt
|
118
|
-
end
|
119
|
-
|
120
|
-
#
|
121
|
-
# Returns a string containing the ruby code that generated this
|
122
|
-
# raw representation tree.
|
123
|
-
#
|
124
|
-
def to_code_s (indentation = 0)
|
125
|
-
|
126
|
-
s = ""
|
127
|
-
tab = " "
|
128
|
-
ind = tab * indentation
|
129
|
-
|
130
|
-
s << ind
|
131
|
-
s << OpenWFE::make_safe(@name)
|
132
|
-
|
133
|
-
sa = ""
|
134
|
-
@attributes.each do |k, v|
|
135
|
-
sa << ", :#{OpenWFE::to_underscore(k)} => '#{v}'"
|
136
|
-
end
|
137
|
-
s << sa[1..-1] if sa.length > 0
|
138
|
-
|
139
|
-
if @children.length > 0
|
140
|
-
s << " do\n"
|
141
|
-
@children.each do |child|
|
142
|
-
if child.respond_to? :to_code_s
|
143
|
-
s << child.to_code_s(indentation + 1)
|
144
|
-
else
|
145
|
-
s << ind
|
146
|
-
s << tab
|
147
|
-
s << "'#{child.to_s}'"
|
148
|
-
end
|
149
|
-
s << "\n"
|
150
|
-
end
|
151
|
-
s << ind
|
152
|
-
s << "end"
|
153
|
-
end
|
154
|
-
|
155
|
-
return s
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
51
|
#
|
160
52
|
# This is the class to extend to create a programmatic process definition.
|
161
53
|
#
|
@@ -235,7 +127,7 @@ module OpenWFE
|
|
235
127
|
string_child = params.to_s
|
236
128
|
end
|
237
129
|
|
238
|
-
exp =
|
130
|
+
exp = SimpleExpRepresentation.new(exp_name, attributes)
|
239
131
|
|
240
132
|
exp.children << string_child \
|
241
133
|
if string_child
|
@@ -293,7 +185,7 @@ module OpenWFE
|
|
293
185
|
attributes["name"] = name
|
294
186
|
attributes["revision"] = revision
|
295
187
|
|
296
|
-
top_expression =
|
188
|
+
top_expression = SimpleExpRepresentation.new(
|
297
189
|
"process-definition", attributes)
|
298
190
|
|
299
191
|
top_expression.children = context.top_expressions
|
@@ -384,7 +276,7 @@ module OpenWFE
|
|
384
276
|
|
385
277
|
#
|
386
278
|
# The actual 'programmatic' raw expression.
|
387
|
-
# Its raw_representation being an instance of
|
279
|
+
# Its raw_representation being an instance of SimpleExpRepresentation.
|
388
280
|
#
|
389
281
|
class ProgRawExpression < RawExpression
|
390
282
|
|
@@ -413,7 +305,7 @@ module OpenWFE
|
|
413
305
|
result = []
|
414
306
|
raw_representation.children.each do |child|
|
415
307
|
|
416
|
-
next unless child.is_a?(
|
308
|
+
next unless child.is_a?(SimpleExpRepresentation)
|
417
309
|
next if child.name.intern != :description
|
418
310
|
|
419
311
|
lang = child.attributes[:language]
|
@@ -431,7 +323,7 @@ module OpenWFE
|
|
431
323
|
result = []
|
432
324
|
raw_representation.children.each do |child|
|
433
325
|
|
434
|
-
if child.kind_of?
|
326
|
+
if child.kind_of? SimpleExpRepresentation
|
435
327
|
|
436
328
|
cname = child.name.intern
|
437
329
|
|
@@ -463,7 +355,7 @@ module OpenWFE
|
|
463
355
|
|
464
356
|
def extract_text_children ()
|
465
357
|
raw_representation.children.collect do |child|
|
466
|
-
next if child.is_a?
|
358
|
+
next if child.is_a? SimpleExpRepresentation
|
467
359
|
child.to_s
|
468
360
|
end
|
469
361
|
end
|
@@ -473,7 +365,7 @@ module OpenWFE
|
|
473
365
|
r = []
|
474
366
|
raw_representation.children.each do |child|
|
475
367
|
|
476
|
-
next unless child.is_a?
|
368
|
+
next unless child.is_a? SimpleExpRepresentation
|
477
369
|
|
478
370
|
name = child.name.intern
|
479
371
|
next unless (name == :parameter or name == :param)
|
@@ -0,0 +1,197 @@
|
|
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 'rexml/document'
|
43
|
+
|
44
|
+
require 'openwfe/expressions/raw_prog'
|
45
|
+
|
46
|
+
|
47
|
+
module OpenWFE
|
48
|
+
|
49
|
+
#
|
50
|
+
# A raw representation for a process definition, programmatic
|
51
|
+
# process definitions are turned into trees of instances of this class.
|
52
|
+
#
|
53
|
+
class SimpleExpRepresentation
|
54
|
+
|
55
|
+
attr_reader \
|
56
|
+
:name,
|
57
|
+
:attributes
|
58
|
+
|
59
|
+
attr_accessor \
|
60
|
+
:children
|
61
|
+
|
62
|
+
def initialize (name, attributes)
|
63
|
+
super()
|
64
|
+
@name = name
|
65
|
+
@attributes = attributes
|
66
|
+
@children = []
|
67
|
+
end
|
68
|
+
|
69
|
+
#
|
70
|
+
# Adds a child to this expression representation.
|
71
|
+
#
|
72
|
+
def << (child)
|
73
|
+
@children << child
|
74
|
+
end
|
75
|
+
|
76
|
+
#
|
77
|
+
# Always return the ProgRawExpression class.
|
78
|
+
#
|
79
|
+
def raw_expression_class
|
80
|
+
return ProgRawExpression
|
81
|
+
end
|
82
|
+
|
83
|
+
#
|
84
|
+
# Returns an XML string, containing the equivalent process definition
|
85
|
+
# in the classical OpenWFE process definition language.
|
86
|
+
#
|
87
|
+
def to_s
|
88
|
+
doc = REXML::Document.new()
|
89
|
+
doc << to_xml
|
90
|
+
s = ""
|
91
|
+
doc.write(s, 0)
|
92
|
+
return s
|
93
|
+
end
|
94
|
+
|
95
|
+
#
|
96
|
+
# Returns this representation tree as an XML element (and its children).
|
97
|
+
#
|
98
|
+
def to_xml
|
99
|
+
|
100
|
+
elt = REXML::Element.new(@name)
|
101
|
+
|
102
|
+
#elt.attributes.update(@attributes)
|
103
|
+
@attributes.each do |k, v|
|
104
|
+
elt.attributes[k] = v
|
105
|
+
end
|
106
|
+
|
107
|
+
@children.each do |child|
|
108
|
+
if child.kind_of? SimpleExpRepresentation
|
109
|
+
elt << child.to_xml
|
110
|
+
else
|
111
|
+
elt << REXML::Text.new(child.to_s)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
return elt
|
116
|
+
end
|
117
|
+
|
118
|
+
#
|
119
|
+
# Turns an XML tree into a simple representation
|
120
|
+
# (beware embedded XML, should do something to stop that,
|
121
|
+
# CDATA is perhaps sufficient).
|
122
|
+
#
|
123
|
+
def self.from_xml (xml)
|
124
|
+
|
125
|
+
xml = REXML::Document.new(xml) \
|
126
|
+
if xml.is_a? String
|
127
|
+
|
128
|
+
xml = xml.root \
|
129
|
+
if xml.is_a? REXML::Document
|
130
|
+
|
131
|
+
if xml.is_a? REXML::Text
|
132
|
+
s = xml.to_s
|
133
|
+
return s if s.strip.length > 1
|
134
|
+
return nil
|
135
|
+
end
|
136
|
+
|
137
|
+
# xml element thus...
|
138
|
+
|
139
|
+
name = xml.name
|
140
|
+
|
141
|
+
attributes = {}
|
142
|
+
|
143
|
+
xml.attributes.each do |k, v|
|
144
|
+
attributes[k] = v
|
145
|
+
end
|
146
|
+
|
147
|
+
rep = SimpleExpRepresentation.new(name, attributes)
|
148
|
+
|
149
|
+
xml.children.each do |c|
|
150
|
+
r = from_xml(c)
|
151
|
+
rep << r if r
|
152
|
+
end
|
153
|
+
|
154
|
+
rep
|
155
|
+
end
|
156
|
+
|
157
|
+
#
|
158
|
+
# Returns a string containing the ruby code that generated this
|
159
|
+
# raw representation tree.
|
160
|
+
#
|
161
|
+
def to_code_s (indentation = 0)
|
162
|
+
|
163
|
+
s = ""
|
164
|
+
tab = " "
|
165
|
+
ind = tab * indentation
|
166
|
+
|
167
|
+
s << ind
|
168
|
+
s << OpenWFE::make_safe(@name)
|
169
|
+
|
170
|
+
sa = ""
|
171
|
+
@attributes.each do |k, v|
|
172
|
+
sa << ", :#{OpenWFE::to_underscore(k)} => '#{v}'"
|
173
|
+
end
|
174
|
+
s << sa[1..-1] if sa.length > 0
|
175
|
+
|
176
|
+
if @children.length > 0
|
177
|
+
s << " do\n"
|
178
|
+
@children.each do |child|
|
179
|
+
if child.respond_to? :to_code_s
|
180
|
+
s << child.to_code_s(indentation + 1)
|
181
|
+
else
|
182
|
+
s << ind
|
183
|
+
s << tab
|
184
|
+
s << "'#{child.to_s}'"
|
185
|
+
end
|
186
|
+
s << "\n"
|
187
|
+
end
|
188
|
+
s << ind
|
189
|
+
s << "end"
|
190
|
+
end
|
191
|
+
|
192
|
+
return s
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
end
|
197
|
+
|