lib/openwfe/expressions/raw_prog.rb in openwferu-0.9.5 vs lib/openwfe/expressions/raw_prog.rb in openwferu-0.9.6

- old
+ new

@@ -53,11 +53,13 @@ # class ProgExpRepresentation attr_reader \ :name, - :attributes, + :attributes + + attr_accessor \ :children def initialize (name, attributes) super() @name = name @@ -73,11 +75,11 @@ end # # Always return the ProgRawExpression class. # - def rawExpressionClass + def raw_expression_class return ProgRawExpression end # # Returns an XML string, containing the equivalent process definition @@ -173,52 +175,30 @@ # engine.launch(li) # </tt> # class ProcessDefinition + attr_reader :top_expressions + #def initialize (exp_names=nil) def initialize () super() - #if not exp_names - # exp_names = $EXPRESSION_NAMES if $EXPRESSION_NAMES - #else - # if exp_names.kind_of? ExpressionMap - # exp_names = exp_names.expression_names - # elsif exp_names.kind_of? Engine - # exp_names = exp_names.get_expression_map.expression_names - # elsif exp_names.kind_of? Hash - # exp_names = exp_names[S_EXPRESSION_MAP].expression_names - # elsif not exp_names.kind_of? Array - # exp_names = $EXPRESSION_NAMES - # end - #end - #if not exp_names - # raise "no expression names found, please provide them" - #end - #@exp_names = exp_names - + @top_expressions = [] @previous_parent_expression = [] end def method_missing (m, *args, &block) methodname = m.to_s expname = OpenWFE.to_expression_name(methodname) - #if not @exp_names.include? expname - # #raise "No expression named '#{methodname}' (#{expname}) found" - # #raise "No expression named '#{expname}' found" - # params = args[0] - # params = {} if not params - # params["ref"] = methodname - # return make_expression("subprocess", params, &block) - #end + args = pack_args(args) - make_expression(expname, args[0], &block) + make_expression(expname, args, &block) end # # This method has to be overriden in order to define # a process definition. @@ -248,12 +228,15 @@ exp = ProgExpRepresentation.new(exp_name, attributes) exp.children << string_child \ if string_child - @parent_expression << exp \ - if @parent_expression + if @parent_expression + @parent_expression << exp + else + @top_expressions << exp + end return exp if not block @previous_parent_expression.push(@parent_expression) \ if @parent_expression @@ -278,12 +261,70 @@ # # A class method for actually "making" the process # segment raw representation # def ProcessDefinition.do_make () - self.new().make + + pdef = self.new + exp = pdef.make + + if pdef.top_expressions.size == 1 and \ + exp.name == "process-definition" + + return exp + end + + name, revision = extract_name_and_revision(pdef.class.name) + attributes = {} + attributes["name"] = name + attributes["revision"] = revision + + top_expression = ProgExpRepresentation.new( + "process-definition", attributes) + + top_expression.children = pdef.top_expressions + + top_expression end + + protected + + def pack_args (args) + return args[0] if args.length == 1 + a = {} + args.each_with_index do |arg, index| + if arg.is_a? Hash + a = a.merge(arg) + break + end + a[index.to_s] = arg + end + a + end + + def ProcessDefinition.extract_name_and_revision (s) + + #puts "s is >#{s}<" + + m = Regexp.compile(".*::([^0-9_]*)_*([0-9][0-9_]*)$").match(s) + return [ as_name(m[1]), as_revision(m[2]) ] if m + + m = Regexp.compile(".*::(.*$)").match(s) + return [ as_name(m[1]), '0' ] if m + + return [ as_name(s), '0' ] + end + + def ProcessDefinition.as_name (s) + + return s[0..-11] if s.match(".*Definition$") + return s + end + + def ProcessDefinition.as_revision (s) + s.gsub("_", ".") + end end # # The actual 'programmatic' raw expression. # Its raw_representation being an instance of ProgExpRepresentation. @@ -333,9 +374,16 @@ rawexp.fei else child end + end + end + + def extract_text_children () + raw_representation.children.collect do |child| + next if child.is_a? ProgExpRepresentation + child.to_s end end end private