# #-- # Copyright (c) 2006-2007, 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 'openwfe/rudefinitions' require 'openwfe/expressions/flowexpression' module OpenWFE # # An 'abstract' class storing bits (trees) of process definitions just # parsed. Upon application (apply()) these raw expressions get turned # into real expressions. # The first and classical extension of this class is XmlRawExpression. # class RawExpression < FlowExpression #attr_accessor \ # :raw_representation def initialize \ (fei, parent_id, env_id, application_context, raw_representation) super(fei, parent_id, env_id, application_context, nil) @raw_representation = raw_representation new_environment() if not @environment_id end def instantiate_real_expression \ (workitem, exp_class=nil, attributes=nil) exp_class = expression_class() unless exp_class raise "unknown expression '#{expression_name}'" \ unless exp_class #ldebug do # "instantiate_real_expression() exp_class is #{exp_class}" #end attributes = extract_attributes() unless attributes expression = exp_class.new( @fei, @parent_id, @environment_id, @application_context, attributes) expression.children = extract_children() expression.store_itself() return expression end def apply (workitem) exp_name = expression_name() exp_class = expression_class() attributes = nil template = lookup_variable(exp_name) # # is it a subprocess ? if (not template) and (not exp_class) template = get_participant_map.lookup_participant(exp_name) unless template exp_name = OpenWFE::to_underscore(exp_name) template = get_participant_map.lookup_participant(exp_name) end end # # is it a directly a participant ? if template if template.kind_of? OpenWFE::FlowExpressionId launch_template(template, workitem) return end if template.kind_of? OpenWFE::Participant exp_class = OpenWFE::ParticipantExpression attributes = extract_attributes() attributes["ref"] = exp_name end end # # the classical case... expression = instantiate_real_expression( workitem, exp_class, attributes) expression.apply(workitem) end #def reply (workitem) # no implementation necessary #end def is_definition? () return get_expression_map.is_definition?(expression_name()) end def expression_class () return get_expression_map().get_class(expression_name()) end def definition_name () return raw_representation.attributes['name'].to_s end def expression_name () return raw_representation.name end protected def launch_template (template, workitem) @attributes = extract_attributes() #require 'pp' #pp attributes #pp lookup_attributes(workitem, attributes) get_expression_pool().launch_template( self, 0, template, workitem, lookup_attributes(workitem)) end #def extract_attributes () # raise "abstract method : not implemented here" #end #def extract_children () # raise "abstract method : not implemented here" #end end end