lib/openwfe/expressions/raw_prog.rb in openwferu-0.9.7 vs lib/openwfe/expressions/raw_prog.rb in openwferu-0.9.8
- old
+ new
@@ -41,124 +41,16 @@
require 'rexml/document'
require 'openwfe/utils'
require 'openwfe/expressions/fe_raw'
-require 'openwfe/expressions/fe_utils'
+require 'openwfe/expressions/simplerep'
module OpenWFE
#
- # A raw representation for a process definition, programmatic
- # process definitions are turned into trees of instances of this class.
- #
- class ProgExpRepresentation
-
- attr_reader \
- :name,
- :attributes
-
- attr_accessor \
- :children
-
- def initialize (name, attributes)
- super()
- @name = name
- @attributes = attributes
- @children = []
- end
-
- #
- # Adds a child to this expression representation.
- #
- def << (child)
- @children << child
- end
-
- #
- # Always return the ProgRawExpression class.
- #
- def raw_expression_class
- return ProgRawExpression
- end
-
- #
- # Returns an XML string, containing the equivalent process definition
- # in the classical OpenWFE process definition language.
- #
- def to_s
- doc = REXML::Document.new()
- doc << to_xml
- s = ""
- doc.write(s, 0)
- return s
- end
-
- #
- # Returns this representation tree as an XML element (and its children).
- #
- def to_xml
-
- elt = REXML::Element.new(@name)
-
- #elt.attributes.update(@attributes)
- @attributes.each do |k, v|
- elt.attributes[k] = v
- end
-
- @children.each do |child|
- if child.kind_of? ProgExpRepresentation
- elt << child.to_xml
- else
- elt << REXML::Text.new(child.to_s)
- end
- end
-
- return elt
- end
-
- #
- # Returns a string containing the ruby code that generated this
- # raw representation tree.
- #
- def to_code_s (indentation = 0)
-
- s = ""
- tab = " "
- ind = tab * indentation
-
- s << ind
- s << OpenWFE::make_safe(@name)
-
- sa = ""
- @attributes.each do |k, v|
- sa << ", :#{OpenWFE::to_underscore(k)} => '#{v}'"
- end
- s << sa[1..-1] if sa.length > 0
-
- if @children.length > 0
- s << " do\n"
- @children.each do |child|
- if child.respond_to? :to_code_s
- s << child.to_code_s(indentation + 1)
- else
- s << ind
- s << tab
- s << "'#{child.to_s}'"
- end
- s << "\n"
- end
- s << ind
- s << "end"
- end
-
- return s
- end
- end
-
- #
# This is the class to extend to create a programmatic process definition.
#
# A short example :
# <tt>
# class MyProcessDefinition < OpenWFE::ProcessDefinition
@@ -233,11 +125,11 @@
end
elsif params
string_child = params.to_s
end
- exp = ProgExpRepresentation.new(exp_name, attributes)
+ exp = SimpleExpRepresentation.new(exp_name, attributes)
exp.children << string_child \
if string_child
if context.parent_expression
@@ -291,11 +183,11 @@
attributes = {}
attributes["name"] = name
attributes["revision"] = revision
- top_expression = ProgExpRepresentation.new(
+ top_expression = SimpleExpRepresentation.new(
"process-definition", attributes)
top_expression.children = context.top_expressions
return top_expression
@@ -382,11 +274,11 @@
end
end
#
# The actual 'programmatic' raw expression.
- # Its raw_representation being an instance of ProgExpRepresentation.
+ # Its raw_representation being an instance of SimpleExpRepresentation.
#
class ProgRawExpression < RawExpression
attr_accessor \
:raw_representation
@@ -411,11 +303,11 @@
def extract_descriptions ()
result = []
raw_representation.children.each do |child|
- next unless child.is_a?(ProgExpRepresentation)
+ next unless child.is_a?(SimpleExpRepresentation)
next if child.name.intern != :description
lang = child.attributes[:language]
lang = child.attributes[:lang] unless lang
lang = "default" unless lang
@@ -429,11 +321,11 @@
i = 0
result = []
raw_representation.children.each do |child|
- if child.kind_of? ProgExpRepresentation
+ if child.kind_of? SimpleExpRepresentation
cname = child.name.intern
next if cname == :param
next if cname == :parameter
@@ -461,20 +353,20 @@
result
end
def extract_text_children ()
raw_representation.children.collect do |child|
- next if child.is_a? ProgExpRepresentation
+ next if child.is_a? SimpleExpRepresentation
child.to_s
end
end
def extract_parameters ()
r = []
raw_representation.children.each do |child|
- next unless child.is_a? ProgExpRepresentation
+ next unless child.is_a? SimpleExpRepresentation
name = child.name.intern
next unless (name == :parameter or name == :param)
r << Parameter.new(