Class | OpenWFE::RawExpression |
In: |
lib/openwfe/expressions/raw.rb
|
Parent: | FlowExpression |
A class storing bits (trees) of process definitions just parsed. Upon application (apply()) these raw expressions get turned into real expressions.
# File lib/openwfe/expressions/raw.rb, line 55 55: def self.new_raw ( 56: fei, parent_id, env_id, app_context, raw_representation) 57: 58: re = self.new 59: 60: re.fei = fei 61: re.parent_id = parent_id 62: re.environment_id = env_id 63: re.application_context = app_context 64: re.attributes = nil 65: re.children = [] 66: re.apply_time = nil 67: 68: re.raw_representation = raw_representation 69: re 70: end
When a raw expression is applied, it gets turned into the real expression which then gets applied.
# File lib/openwfe/expressions/raw.rb, line 127 127: def apply (workitem) 128: 129: exp_name, exp_class, attributes = determine_real_expression 130: 131: expression = instantiate_real_expression( 132: workitem, exp_name, exp_class, attributes) 133: 134: expression.apply_time = Time.now 135: expression.store_itself 136: 137: expression.apply workitem 138: end
This method is called by the expression pool when it is about to launch a process, it will interpret the ‘parameter’ statements in the process definition and raise an exception if the requirements are not met.
# File lib/openwfe/expressions/raw.rb, line 146 146: def check_parameters (workitem) 147: 148: extract_parameters.each do |param| 149: param.check(workitem) 150: end 151: end
# File lib/openwfe/expressions/raw.rb, line 169 169: def definition_name 170: 171: raw_representation[1]['name'].to_s 172: end
# File lib/openwfe/expressions/raw.rb, line 164 164: def expression_class 165: 166: get_expression_map.get_class(expression_name()) 167: end
# File lib/openwfe/expressions/raw.rb, line 174 174: def expression_name 175: 176: raw_representation.first 177: end
This method has been made public in order to have quick look at the attributes of an expression before it‘s really ‘instantiated’.
# File lib/openwfe/expressions/raw.rb, line 194 194: def extract_attributes 195: 196: raw_representation[1] 197: end
# File lib/openwfe/expressions/raw.rb, line 87 87: def instantiate_real_expression ( 88: workitem, exp_name=nil, exp_class=nil, attributes=nil) 89: 90: exp_name ||= expression_name 91: exp_class ||= expression_class 92: 93: raise "unknown expression '#{exp_name}'" \ 94: unless exp_class 95: 96: #ldebug do 97: # "instantiate_real_expression() exp_class is #{exp_class}" 98: #end 99: 100: attributes ||= raw_representation[1] 101: 102: exp = exp_class.new 103: exp.fei = @fei 104: exp.parent_id = @parent_id 105: exp.environment_id = @environment_id 106: exp.application_context = @application_context 107: exp.attributes = attributes 108: 109: exp.raw_representation = raw_representation 110: # 111: # keeping track of how the expression look at apply / 112: # instantiation time 113: 114: consider_tag workitem, exp 115: 116: handle_descriptions 117: 118: exp.children = extract_children 119: 120: exp 121: end
# File lib/openwfe/expressions/raw.rb, line 159 159: def is_definition? 160: 161: get_expression_map.is_definition?(expression_name()) 162: end
Forces the raw expression to load the attributes and set them in its @attributes instance variable. Currently only used by FilterDefinitionExpression.
# File lib/openwfe/expressions/raw.rb, line 184 184: def load_attributes 185: 186: @attributes = raw_representation[1] 187: end
Expressions can get tagged. Tagged expressions can easily be cancelled (undone) or redone.
# File lib/openwfe/expressions/raw.rb, line 383 383: def consider_tag (workitem, new_expression) 384: 385: tagname = new_expression.lookup_string_attribute :tag, workitem 386: 387: return unless tagname 388: 389: ldebug { "consider_tag() tag is '#{tagname}'" } 390: 391: set_variable tagname, Tag.new(self, workitem) 392: # 393: # keep copy of raw expression and workitem as applied 394: 395: new_expression.attributes["tag"] = tagname 396: # 397: # making sure that the value of tag doesn't change anymore 398: end
Determines if this raw expression points to a classical expression, a participant or a subprocess, or nothing at all…
# File lib/openwfe/expressions/raw.rb, line 224 224: def determine_real_expression 225: 226: exp_name = expression_name() 227: exp_class = expression_class() 228: var_value = lookup_variable exp_name 229: attributes = extract_attributes 230: 231: unless var_value 232: # 233: # accomodating "sub_process_name" and "sub-process-name" 234: # 235: alt = OpenWFE::to_underscore exp_name 236: var_value = lookup_variable(alt) if alt != exp_name 237: 238: exp_name = alt if var_value 239: end 240: 241: var_value = exp_name \ 242: if (not exp_class and not var_value) 243: 244: if var_value.is_a?(String) 245: 246: participant_name = lookup_participant var_value 247: 248: if participant_name 249: exp_name = participant_name 250: exp_class = ParticipantExpression 251: attributes['ref'] = participant_name 252: end 253: 254: elsif var_value.is_a?(FlowExpressionId) \ 255: or var_value.is_a?(RawExpression) 256: 257: exp_class = SubProcessRefExpression 258: attributes['ref'] = exp_name 259: end 260: # else, it's a standard expression 261: 262: [ exp_name, exp_class, attributes ] 263: end
# File lib/openwfe/expressions/raw.rb, line 311 311: def extract_children 312: 313: i = 0 314: result = [] 315: raw_representation.last.each do |child| 316: 317: #if child.kind_of?(SimpleExpRepresentation) 318: #if child.kind_of?(Array) 319: if is_not_a_node?(child) 320: 321: result << child 322: else 323: 324: cname = child.first.intern 325: 326: next if cname == :param 327: next if cname == :parameter 328: next if cname == :description 329: 330: cfei = @fei.dup 331: cfei.expression_name = child.first 332: cfei.expression_id = "#{cfei.expression_id}.#{i}" 333: 334: efei = @environment_id 335: 336: rawexp = RawExpression.new_raw( 337: cfei, @fei, efei, @application_context, child) 338: 339: get_expression_pool.update rawexp 340: 341: i = i + 1 342: 343: result << rawexp.fei 344: end 345: end 346: result 347: end
# File lib/openwfe/expressions/raw.rb, line 291 291: def extract_descriptions 292: 293: result = [] 294: raw_representation.last.each do |child| 295: 296: #next unless child.is_a?(SimpleExpRepresentation) 297: next if is_not_a_node?(child) 298: next if child.first.intern != :description 299: 300: attributes = child[1] 301: 302: lang = attributes[:language] 303: lang = attributes[:lang] unless lang 304: lang = "default" unless lang 305: 306: result << [ lang, child.last.first ] 307: end 308: result 309: end
# File lib/openwfe/expressions/raw.rb, line 349 349: def extract_parameters 350: 351: r = [] 352: raw_representation.last.each do |child| 353: 354: #next unless child.is_a?(SimpleExpRepresentation) 355: #next unless child.is_a?(Array) 356: next if is_not_a_node?(child) 357: 358: name = child.first.to_sym 359: next unless (name == :parameter or name == :param) 360: 361: attributes = child[1] 362: 363: r << Parameter.new( 364: attributes['field'], 365: attributes['match'], 366: attributes['default'], 367: attributes['type']) 368: end 369: r 370: end
Takes care of extracting the process definition descriptions if any and to set the description variables accordingly.
# File lib/openwfe/expressions/raw.rb, line 269 269: def handle_descriptions 270: 271: default = false 272: 273: ds = extract_descriptions 274: 275: ds.each do |k, description| 276: vname = if k == "default" 277: default = true 278: "description" 279: else 280: "description__#{k}" 281: end 282: set_variable vname, description.to_s 283: end 284: 285: return if ds.length < 1 286: 287: set_variable "description", ds[0][1].to_s \ 288: unless default 289: end
# File lib/openwfe/expressions/raw.rb, line 372 372: def is_not_a_node? (child) 373: 374: (( ! child.is_a?(Array)) || 375: child.size != 3 || 376: ( ! child.first.is_a?(String))) 377: end
looks up a participant in the participant map, considers "my-participant" and "my_participant" as the same (by doing two lookups).
# File lib/openwfe/expressions/raw.rb, line 206 206: def lookup_participant (name) 207: 208: p = get_participant_map.lookup_participant(name) 209: 210: unless p 211: name = OpenWFE::to_underscore(name) 212: p = get_participant_map.lookup_participant(name) 213: end 214: 215: return name if p 216: 217: nil 218: end