# # Copyright (c) 2006, John Mettraux, OpenWFE.org # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # . Redistributions of source code must retain the above copyright notice, this # list of conditions and the following disclaimer. # # . Redistributions in binary form must reproduce the above copyright notice, # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. # # . Neither the name of the "OpenWFE" nor the names of its contributors may be # used to endorse or promote products derived from this software without # specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # # $Id: definitions.rb 2725 2006-06-02 13:26:32Z jmettraux $ # # # "made in Japan" # # John Mettraux at openwfe.org # require 'rexml/document' require 'otime' require 'workitem' require 'ru/engine' require 'ru/rudefinitions' require 'ru/flowexpression' require 'ru/fe_base' module OpenWFEru class RawExpression < FlowExpression attr_accessor \ :xml_element def initialize \ (fei, parent_id, environment_id, application_context, xml_element) super(fei, parent_id, environment_id, application_context, nil) @xml_element = xml_element new_environment() if not @environment_id end def apply (workitem) #ldebug { "apply() parent is #{@parent_id}" } attributes = extract_attributes() #ldebug { "apply() expression_name is '#{expression_name()}'" } #ldebug { "apply() expression_class is '#{expression_class()}'" } template = lookup_variable(expression_name()) if template and template.kind_of? OpenWFE::FlowExpressionId get_expression_pool().launch_template(\ self, template, workitem, lookup_attributes(attributes, workitem)) return end eclass = expression_class() raise "unknown expression '#{expression_name}'" if not eclass expression = eclass.new(@fei, @parent_id, @environment_id, @application_context, attributes) expression.children = extract_children() expression.store_itself() expression.apply(workitem) end #def reply (workitem) #end def is_expression? () return false if not @xml_element.kind_of?(REXML::XMLElement) return expression_class() != nil end def is_definition? () return get_expression_map.is_definition?(expression_name()) end def expression_name () return @xml_element.name end def expression_class () return get_expression_map().get_class(expression_name()) end def definition_name () #return @xml_element.attributes['name'].to_str return @xml_element.attributes['name'].to_s end protected def extract_attributes () result = {} @xml_element.attributes.each_attribute do |a| result[a.name] = a.value end return result end def extract_children () c = [] i = 0 @xml_element.each_child do |elt| if elt.kind_of?(REXML::Element) cfei = @fei.dup pfei = @fei efei = @environment_id cfei.expressionName = elt.name cfei.expressionId = "#{cfei.expressionId}.#{i}" rawchild = RawExpression\ .new(cfei, pfei, efei, @application_context, elt) get_expression_pool().update(rawchild) c << rawchild.fei i = i+1 elsif elt.kind_of?(REXML::Comment) next else s = elt.to_s.strip c << s if s.length > 0 end end return c end end end