lib/openwfe/expressions/raw.rb in openwferu-0.9.13 vs lib/openwfe/expressions/raw.rb in openwferu-0.9.14

- old
+ new

@@ -35,14 +35,13 @@ # "made in Japan" # # John Mettraux at openwfe.org # -#require 'rexml/document' - -require 'openwfe/rudefinitions' +require 'openwfe/exceptions' require 'openwfe/expressions/flowexpression' +require 'openwfe/rudefinitions' module OpenWFE # @@ -51,28 +50,29 @@ # into real expressions. # The first and classical extension of this class is XmlRawExpression. # class RawExpression < FlowExpression - def initialize \ - (fei, parent_id, env_id, application_context, 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 # # now done in the launch methods of the expression pool end - def instantiate_real_expression \ - (workitem, exp_class=nil, attributes=nil) + def instantiate_real_expression ( + workitem, exp_name=nil, exp_class=nil, attributes=nil) + exp_name = expression_name() unless exp_name exp_class = expression_class() unless exp_class - raise "unknown expression '#{expression_name}'" \ + raise "unknown expression '#{exp_name}'" \ unless exp_class #ldebug do # "instantiate_real_expression() exp_class is #{exp_class}" #end @@ -95,54 +95,20 @@ expression.store_itself() expression end + # + # When a raw expression is applied, it gets turned into the + # real expression which then gets applied. + # def apply (workitem) - exp_name = expression_name() + exp_name, exp_class, attributes = determine_real_expression - 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 - - exp_class = OpenWFE::SubProcessRefExpression - attributes = extract_attributes() - attributes["ref"] = exp_name - - elsif 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) + workitem, exp_name, exp_class, attributes) #expression.apply_time = OpenWFE::now() # # This method is extremely costly, now avoiding it @@ -192,9 +158,68 @@ def load_attributes @attributes = extract_attributes() end protected + + # + # looks up a participant in the participant map, considers + # "my-participant" and "my_participant" as the same + # (by doing two lookups). + # + def lookup_participant (name) + + p = get_participant_map.lookup_participant(name) + + unless p + name = OpenWFE::to_underscore(name) + p = get_participant_map.lookup_participant(name) + end + + if p + name + else + nil + end + end + + # + # Determines if this raw expression points to a classical + # expression, a participant or a subprocess, or nothing at all... + # + def determine_real_expression () + + exp_name = expression_name() + + exp_class = expression_class() + attributes = nil + + var_value = lookup_variable(exp_name) + + var_value = exp_name if (not exp_class and not var_value) + + if var_value + attributes = extract_attributes() + end + + if var_value.is_a?(String) + + participant_name = lookup_participant(var_value) + + if participant_name + exp_name = participant_name + exp_class = OpenWFE::ParticipantExpression + attributes['ref'] = participant_name + end + + elsif var_value.is_a?(OpenWFE::FlowExpressionId) + + exp_class = OpenWFE::SubProcessRefExpression + attributes['ref'] = exp_name + end + + [ exp_name, exp_class, attributes ] + end # # Takes care of extracting the process definition descriptions # if any and to set the description variables accordingly. #