lib/openwfe/expressions/expressionmap.rb in openwferu-0.9.6 vs lib/openwfe/expressions/expressionmap.rb in openwferu-0.9.7

- old
+ new

@@ -37,20 +37,22 @@ # "made in Japan" # # John Mettraux at openwfe.org # -require 'openwfe/service' +#require 'openwfe/util/model' require 'openwfe/expressions/environment' require 'openwfe/expressions/fe_define' require 'openwfe/expressions/fe_misc' require 'openwfe/expressions/fe_value' require 'openwfe/expressions/fe_sequence' require 'openwfe/expressions/fe_subprocess' require 'openwfe/expressions/fe_concurrence' require 'openwfe/expressions/fe_participant' -require 'openwfe/expressions/fe_time' +require 'openwfe/expressions/fe_sleep' +require 'openwfe/expressions/fe_cron' +require 'openwfe/expressions/fe_when' require 'openwfe/expressions/fe_losfor' require 'openwfe/expressions/fe_cursor' require 'openwfe/expressions/fe_iterator' require 'openwfe/expressions/fe_fqv' require 'openwfe/expressions/fe_cancel' @@ -60,118 +62,122 @@ # # The mapping between expression names like 'sequence', 'participant', etc # and classes like 'ParticipantExpression', 'SequenceExpression', etc. # - class ExpressionMap < Service + class ExpressionMap - def initialize (serviceName, applicationContext) - super(serviceName, applicationContext) + def initialize () - @map = {} - @sync_map = {} + super - @map["process-definition"] = DefineExpression - @map["workflow-definition"] = DefineExpression - @map["define"] = DefineExpression + @expressions = {} - @map["sequence"] = SequenceExpression - @map["participant"] = ParticipantExpression + register DefineExpression - @map["concurrence"] = ConcurrenceExpression - @sync_map["generic"] = GenericSyncExpression + register SequenceExpression + register ParticipantExpression - @map["subprocess"] = SubProcessRefExpression + register ConcurrenceExpression + register GenericSyncExpression - @map["set"] = SetValueExpression - @map["unset"] = UnsetValueExpression + register SubProcessRefExpression - @map["if"] = IfExpression - @map["equals"] = EqualsExpression + register SetValueExpression + register UnsetValueExpression - @map["sleep"] = SleepExpression - @map["cron"] = CronExpression - @map["when"] = WhenExpression + register IfExpression + register EqualsExpression - @map["reval"] = RevalExpression - @map["print"] = PrintExpression + register SleepExpression + register CronExpression + register WhenExpression - @map["lose"] = LoseExpression - @map["forget"] = ForgetExpression + register RevalExpression + register PrintExpression - @map["cursor"] = CursorExpression - @map["loop"] = LoopExpression + register LoseExpression + register ForgetExpression - @map["back"] = CursorCommandExpression - @map["skip"] = CursorCommandExpression - @map["break"] = CursorCommandExpression - @map["cancel"] = CursorCommandExpression - @map["rewind"] = CursorCommandExpression - @map["continue"] = CursorCommandExpression + register CursorExpression + register LoopExpression - @map["iterator"] = IteratorExpression + register CursorCommandExpression - @map["field"] = FqvExpression - @map["quote"] = FqvExpression - @map["variable"] = FqvExpression - @map["f"] = FqvExpression - @map["q"] = FqvExpression - @map["v"] = FqvExpression + register IteratorExpression - #@map["do"] = DoExpression - #@map["undo"] = UndoExpression - #@map["redo"] = RedoExpression + register FqvExpression - @map["cancel-process"] = CancelProcessExpression - #@map["cancel"] = CancelExpression + register CancelProcessExpression - @map["environment"] = Environment + register Environment # # only used by get_expression_names() end # # Returns the expression class corresponding to the given # expression name # - def get_class (expressionname) - return @map[expressionname] + def get_class (expression_name) + + expression_name = OpenWFE::symbol_to_name(expression_name) + + @expressions[expression_name] end - def get_sync_class (expressionname) - return @sync_map[expressionname] + def get_sync_class (expression_name) + + get_class(expression_name) end # # Returns true if the given expression name ('sequence', # 'process-definition', ...) is a DefineExpression. # - def is_definition? (expressionname) - c = get_class(expressionname) - return \ - (c == OpenWFE::DefineExpression or - c == OpenWFE::SetValueExpression) - end + def is_definition? (expression_name) - # - # Returns the list of expression names registered in this - # expression map. - # - def expression_names - return @map.keys + c = get_class(expression_name) + + c == DefineExpression end # # Returns an array of expression names whose class are assignable # from the given expression_class. # def get_expression_names (expression_class) + + return expression_class.expression_names \ + if expression_class.method_defined? :expression_names + names = [] - @map.each do |name, exp_class| - names << name \ - if exp_class.ancestors.include? expression_class + @expressions.each do |k, v| + names << k if v.ancestors.include? expression_class end - return names + names + end + + # + # Registers an Expression class within this expression map. + # This method is usually never called from out of the ExpressionMap + # class, but, who knows, it could prove useful one day as a 'public' + # method. + # + def register (expression_class) + + expression_class.expression_names.each do |name| + name = OpenWFE::to_dash(name) + @expressions[name] = expression_class + end + end + + def to_s + s = "" + @expressions.keys.sort.each do |name| + s << "- '#{name}' -> '#{@expressions[name].to_s}'\n" + end + s end end end