lib/openwfe/expressions/flowexpression.rb in openwferu-0.9.13 vs lib/openwfe/expressions/flowexpression.rb in openwferu-0.9.14
- old
+ new
@@ -27,10 +27,11 @@
# 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"
#
# John Mettraux at openwfe.org
@@ -45,10 +46,16 @@
module OpenWFE
#
+ # When this variable is set to true (at the process root),
+ # it means the process is paused.
+ #
+ VAR_PAUSED = '/__paused__'
+
+ #
# FlowExpression
#
# The base class for all OpenWFE flow expression classes.
# It gathers all the methods for attributes and variable lookup.
#
@@ -74,10 +81,12 @@
@parent_id = parent_id
@environment_id = env_id
@application_context = app_context
@attributes = attributes
+ @children = []
+
@apply_time = nil
#ldebug do
# "initialize()\n"+
# "self : #{@fei}\n"+
@@ -91,28 +100,31 @@
#
# this default implementation immediately replies to the
# parent expression
#
def apply (workitem)
+
get_parent().reply(workitem) if @parent_id
end
#
# this default implementation immediately replies to the
# parent expression
#
def reply (workitem)
+
reply_to_parent(workitem)
end
#
# Triggers the reply to the parent expression (of course, via the
# expression pool).
# Expressions do call this method when their job is done and the flow
# should resume without them.
#
def reply_to_parent (workitem)
+
get_expression_pool.reply_to_parent(self, workitem)
end
#
# a default implementation for cancel :
@@ -184,25 +196,27 @@
#
# Returns the environment of the top process (the environement
# just before the engine environment in the hierarchy).
#
def get_root_environment
+
fetch_environment.get_root_environment
end
- #
+ #--
# A shortcut for fetch_environment.get_process_environment
#
#def get_subprocess_environment
# fetch_environment.get_subprocess_environment
#end
+ #++
#
# Just fetches the environment for this expression.
#
def fetch_environment
- #return nil unless @environment_id
+
get_expression_pool.fetch_expression @environment_id
end
#
# Returns true if the expression's environment was generated
@@ -228,14 +242,22 @@
# "owns_its_environment?()\n"+
# " exp #{ei.to_debug_s}\n"+
# " env #{vi.to_debug_s}"
#end
- return ei == vi
+ ei == vi
end
#
+ # Returns true if this expression belongs to a paused flow
+ #
+ def paused?
+
+ lookup_variable(VAR_PAUSED) == true
+ end
+
+ #
# Sets a variable in the current environment. Is usually
# called by the 'set' expression.
#
# The variable name may be prefixed by / to indicate process level scope
# or by // to indicate engine level (global) scope.
@@ -276,10 +298,12 @@
env, var = lookup_environment(varname)
env.delete var
end
+ alias :unset_variable :delete_variable
+
#
# Looks up the value for an attribute of this expression.
#
# if the expression is
#
@@ -339,11 +363,12 @@
#
def lookup_boolean_attribute (attname, workitem, default=false)
value = lookup_attribute(attname, workitem)
return default if not value
- return value.downcase == 'true'
+
+ (value.downcase == 'true')
end
#
# Returns a hash of all the FlowExpression attributes with their
# values having undergone dollar variable substitution.
@@ -397,11 +422,12 @@
result = []
a.split(',').each do |elt|
elt = elt.strip
result << elt if elt.length > 0
end
- return result
+
+ result
end
#
# creates a new environment just for this expression
#
@@ -425,26 +451,28 @@
env.variables.merge!(initial_vars) if initial_vars
ldebug { "new_environment() is #{env.fei.to_debug_s}" }
- return env.store_itself()
+ env.store_itself()
end
#
# This method is called in expressionpool.forget(). It duplicates
# the expression's current environment (deep copy) and attaches
# it as the expression own environment.
# Returns the duplicated environment.
#
def dup_environment
+
env = fetch_environment
env = env.dup
env.fei = @fei.dup
env.fei.expression_name = EN_ENVIRONMENT
@environment_id = env.fei
- return env.store_itself
+
+ env.store_itself
end
#
# Takes care of removing all the children of this expression, if any.
#
@@ -474,11 +502,11 @@
# Currently only used by dollar.rb and its ${r:some_ruby_code},
# returns the binding in this flow expression.
#
def get_binding
- return binding()
+ binding()
end
#
# Used like the classical Ruby synchronize, but as the OpenWFE
# expression pool manages its own set of monitores, it's one of those
@@ -526,10 +554,12 @@
# looks up for 'value', 'variable-value' and then for 'field-value'
# if necessary.
#
def lookup_value (workitem, prefix='')
- lookup_vf_attribute(workitem, 'value', prefix)
+ v = lookup_vf_attribute(workitem, 'value', prefix)
+ v = lookup_vf_attribute(workitem, 'val', prefix) unless v
+ v
end
#
# looks up for 'ref', 'variable-ref' and then for 'field-ref'
# if necessary.