#created on: 4/11/2008 package org.openiaml.model.drools.rules.dynamic_sources #list any import classes here. import org.openiaml.model.drools.*; import org.openiaml.model.inference.*; import org.openiaml.model.model.*; import org.openiaml.model.model.impl.*; import org.openiaml.model.model.wires.*; import org.openiaml.model.model.visual.*; import org.openiaml.model.model.operations.*; import org.openiaml.model.model.domain.*; #declare any global variables here global EcoreCreateElementsHelper handler; global DroolsInsertionQueue queue; global DroolsHelperFunctions functions; rule "Connect SyncWires for a dynamic source, referenced by XPath" when container : InternetApplication ( ) ds : DynamicApplicationElementSet( eval(functions.isXPath(query)), overridden == false, eContainer == container ) source : Page ( ) sw : SyncWire ( eval(functions.connects(sw, ds, source)) ) target : Page ( eval(source != target), eval(functions.potentialXPathMatch(container, ds, target)) ) not ( tw : SyncWire( eval(functions.connects(tw, source, target)) ) ) then SyncWire sw2 = handler.generatedSyncWire( container, container, source, target ); handler.setName(sw2, "dynamic sync"); queue.add(sw2, drools); end rule "Create the Condition for an XPath set" when ds : DynamicApplicationElementSet( eval(functions.isXPath(query)), overridden == false ) not ( CompositeCondition(eContainer == ds, name == 'xpath' ) ) then CompositeCondition c = handler.generatedCompositeCondition(ds, ds); handler.setName(c, "xpath"); queue.add(c, drools); end rule "Create the contents of the XPath condition" when container : InternetApplication( ) ds : DynamicApplicationElementSet( eval(functions.isXPath(query)), overridden == false, eContainer == container ) source : Page ( ) sw : SyncWire ( eval(functions.connects(sw, ds, source)) ) target : Page ( eval(source != target), eval(functions.potentialXPathMatch(container, ds, target)) ) tw : SyncWire ( eval(functions.connects(tw, source, target)) ) o : CompositeCondition ( eContainer == ds, name == "xpath" ) cw : ConditionWire ( from == o, to == tw ) not ( StartNode( eContainer == o )) then # create contents Parameter parameter = handler.generatedParameter(o, o); handler.setName(parameter, "element"); queue.add(parameter, drools); Parameter xpath = handler.generatedParameter(o, o); handler.setName(xpath, "xpath"); queue.add(xpath, drools); DecisionCondition dc = handler.generatedDecisionCondition(o, o); handler.setName(dc, "xpathMatch"); queue.add(dc, drools); StartNode start = handler.generatedStartNode(o, o); queue.add(start, drools); FinishNode finish = handler.generatedFinishNode(o, o); queue.add(finish, drools); CancelNode cancel = handler.generatedCancelNode(o, o); queue.add(cancel, drools); DataFlowEdge data1 = handler.generatedDataFlowEdge(o, o); handler.setFrom(data1, parameter); handler.setTo(data1, dc); queue.add(data1, drools); DataFlowEdge data2 = handler.generatedDataFlowEdge(o, o); handler.setFrom(data2, xpath); handler.setTo(data2, dc); queue.add(data2, drools); ExecutionEdge edge1 = handler.generatedExecutionEdge(o, o); handler.setFrom(edge1, start); handler.setTo(edge1, dc); queue.add(edge1, drools); ExecutionEdge edge2 = handler.generatedExecutionEdge(o, o); handler.setFrom(edge2, dc); handler.setTo(edge2, finish); queue.add(edge2, drools); ExecutionEdge edge3 = handler.generatedExecutionEdge(o, o); handler.setFrom(edge3, dc); handler.setTo(edge3, cancel); queue.add(edge3, drools); end /** * This rule used to contain the following negative existential: * * not ( * tw_cw : ConditionWire ( from == condition, to == tw ) and * tw_pw : ParameterWire ( from == ds, to == tw_cw ) and * tw_pw2 : ParameterWire ( from == target, to == tw_cw ) * ) * * In order to satisfy our requirement that there are no more than * one negative existential in each rule [TODO see upcoming paper], * we can decompose this into two rules. */ rule "Create the XPath ConditionWire for generated SyncWires" when container : InternetApplication( ) ds : DynamicApplicationElementSet( eval(functions.isXPath(query)), overridden == false, eContainer == container ) source : Page ( ) sw : SyncWire ( eval(functions.connects(sw, ds, source)) ) target : Page ( eval(source != target), eval(functions.potentialXPathMatch(container, ds, target)) ) tw : SyncWire ( eval(functions.connects(tw, source, target)) ) condition : CompositeCondition ( eContainer == ds ) not ( tw_cw : ConditionWire ( from == condition, to == tw ) ) then ConditionWire cwt = handler.generatedConditionWire( ds, ds, condition, tw ); handler.setName(cwt, "xpath condition (target)"); queue.add(cwt, drools); # Create the contents like normal ParameterWire pwt = handler.generatedParameterWire( cwt, cwt, ds, cwt); handler.setName(pwt, "[xpath] from ds 2"); queue.add(pwt, drools); ParameterWire pwt2 = handler.generatedParameterWire( cwt, cwt, target, cwt); handler.setName(pwt2, "[xpath] from target"); queue.add(pwt2, drools); end /** * This is a decomposition of the rule above. */ rule "Connect ParameterWires to empty ConditionWire for XPath" when container : InternetApplication( ) ds : DynamicApplicationElementSet( eval(functions.isXPath(query)), overridden == false, eContainer == container ) source : Page ( ) sw : SyncWire ( eval(functions.connects(sw, ds, source)) ) target : Page ( eval(source != target), eval(functions.potentialXPathMatch(container, ds, target)) ) tw : SyncWire ( eval(functions.connects(tw, source, target)) ) condition : CompositeCondition ( eContainer == ds ) cwt : ConditionWire ( from == condition, to == tw ) not ( #tw_cw : ConditionWire ( from == condition, to == tw ) and tw_pw : ParameterWire ( from == ds, to == cwt ) #and #tw_pw2 : ParameterWire ( from == target, to == tw_cw ) ) then # We have a ConditionWire that does not have any parameters: # connect the parameters up to the wire ParameterWire pwt = handler.generatedParameterWire( cwt, cwt, ds, cwt); handler.setName(pwt, "[xpath] from ds 2"); queue.add(pwt, drools); ParameterWire pwt2 = handler.generatedParameterWire( cwt, cwt, target, cwt); handler.setName(pwt2, "[xpath] from target"); queue.add(pwt2, drools); end