lib/openwfe/expressions/fe_define.rb in ruote-0.9.19 vs lib/openwfe/expressions/fe_define.rb in ruote-0.9.20
- old
+ new
@@ -1,43 +1,29 @@
-#
#--
-# Copyright (c) 2006-2008, John Mettraux, OpenWFE.org
-# All rights reserved.
+# Copyright (c) 2006-2009, John Mettraux, jmettraux@gmail.com
#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are met:
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
#
-# . Redistributions of source code must retain the above copyright notice, this
-# list of conditions and the following disclaimer.
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
#
-# . 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.
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
#
-# . 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.
+# Made in Japan.
#++
-#
-#
-# "made in Japan"
-#
-# John Mettraux at openwfe.org
-#
require 'openwfe/expressions/flowexpression'
require 'openwfe/expressions/fe_sequence'
@@ -91,101 +77,69 @@
names :define, :process_definition, :workflow_definition
#
# A pointer to the body expression of this process definition.
#
- attr_accessor :body_fei
+ attr_accessor :body_index
- #--
- # Evaluates the definition, but doesn't apply its body, will
- # simply return the body fei.
#
- #def evaluate (workitem)
- # @eval_only = true
- # apply workitem
- # @body_fei
- #end
- #++
+ # keeping track of whether the body of the process got started or not
+ #
+ attr_accessor :applied_body
#
# Called at the end of the 'evaluation', the 'apply' operation on
# the body of the definition is done here.
#
def reply_to_parent (workitem)
- #return if @eval_only
+ return super(workitem) if @body_index == nil or @applied_body
+ # no body or body just got applied
- #puts "/// \n bf #{@body_fei} \n wi.fei #{workitem.fei}"
+ # apply body of process definition now
- return super(workitem) \
- if @body_fei == nil or @body_fei == workitem.fei
- #unless @body_fei
+ @applied_body = true
- #_fei = @body_fei
- #@body_fei = nil
#store_itself
- #get_expression_pool.apply _fei, workitem
+ # now done in apply_child()
- get_expression_pool.apply @body_fei, workitem
+ apply_child(@body_index, workitem)
end
- #
- # Overrides the set_variable in FlowExpression to
- # make sure to intercept requests for binding subprocesses
- # at the engine level and to store a copy of the raw expression,
- # not only the flow expression id.
- #
- def set_variable (name, fei)
+ protected
- if name[0, 2] == "//"
+ def next_child_index (returning_fei)
- raw_exp = get_expression_pool.fetch_expression(fei).dup
- raw_exp.parent_id = nil
- raw_exp.fei = raw_exp.fei.dup
- fei = raw_exp.fei
- fei.wfid = get_wfid_generator.generate
+ child_index = super
- raw_exp.store_itself
- end
+ return nil unless child_index
- super name, fei
- end
+ child = raw_children[child_index]
- protected
+ if child.is_a?(Array) && ( ! [ 'param', 'parameter' ].include?(child[0]))
- #
- # Determines the flowExpressionId of the next child to apply.
- #
- def next_child (current_fei)
+ if get_expression_map.get_class(child[0]) == DefineExpression
- next_fei = super
+ name = child[1]['name'] || child[2].first
- return nil unless next_fei
+ raise "process definition without a 'name' attribute" \
+ unless name
- rawchild = get_expression_pool.fetch_expression next_fei
+ set_variable(name.to_s, child)
- return next_child(next_fei) unless rawchild
+ elsif get_expression_map.is_definition?(child[0])
- unless rawchild.is_definition?
+ return child_index # let it get 'applied'
- unless @body_fei
- @body_fei = next_fei
+ elsif @body_index == nil
+
+ @body_index = child_index
store_itself
end
- return next_child(next_fei)
- end
- exp_class = get_expression_map.get_class rawchild
-
- if exp_class == DefineExpression
- set_variable rawchild.definition_name, next_fei
- return next_child(next_fei)
end
- next_fei
- #
- # expression is a 'set', a 'filter-definition' or
- # something like that, let it get applied
+ next_child_index(child_index)
end
end
end