package org.openiaml.model.drools.rules.conditions #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; # TODO can we put this function into something global? function boolean connects(WireEdge wire, Object a, Object b) { return (wire.getFrom().equals(a) && wire.getTo().equals(b)) || (wire.getFrom().equals(b) && wire.getTo().equals(a)); } # @inference SyncWire,RunInstanceWire,ConditionWire {@model RunInstanceWire RunInstanceWires} with incoming {@model ConditionWire conditions} will be copied to elements created by {@model SyncWire SyncWires}. rule "Connect ConditionWires to RunInstanceWires created by SyncWires" when # we have a sync wire sw : SyncWire(overridden == false) source : ContainsEventTriggers( ) target : ContainsOperations( ) eval(functions.connects(sw, source, target)) # which has a run wire between event and operation (generated) event : EventTrigger( eContainer == source, name=="edit" ) operation : Operation( eContainer == target, name=="update" ) run : RunInstanceWire( eContainer == sw, from == event, to == operation, name == "run" ) # and the sync wire had a condition condition : Condition ( ) sourceCw : ConditionWire( from == condition, to == sw ) # but our run wire doesn't not (ConditionWire (from == condition, to == run )) then # copy the condition ConditionWire cw = handler.generatedConditionWire( sourceCw, sourceCw, condition, run ); handler.setName(cw, "copied condition: " + sourceCw.getId()); queue.add(cw, drools); end # @inference SyncWire,RunInstanceWire,ConditionWire,ParameterWire {@model RunInstanceWire RunInstanceWires} with incoming {@model ConditionWire conditions} with {@model ParameterWire parameters} will be copied to elements created by {@model SyncWire SyncWires}. rule "Connect ParameterWires to ConditionWires connected to RunInstanceWires created by SyncWires" when # we have a syncwire sw : SyncWire(overridden == false) source : ContainsEventTriggers( ) target : ContainsOperations( ) eval(functions.connects(sw, source, target)) # that has created a RunInstanceWire event : EventTrigger( eContainer == source, name=="edit" ) operation : Operation( eContainer == target, name=="update" ) run : RunInstanceWire( eContainer == sw, from == event, to == operation, name == "run" ) # and this SyncWire has a condition condition : Condition ( ) sourceCw : ConditionWire( from == condition, to == sw ) # and the RunInstanceWire has the same condition targetCw : ConditionWire (from == condition, to == run ) # and the SyncWire had a parameter param : WireEdgesSource ( ) paramWire : ParameterWire( from == param, to == sourceCw ) # but this wire does not have it not (ParameterWire (from == param, to == targetCw )) then ParameterWire pw = handler.generatedParameterWire( sourceCw, sourceCw, param, targetCw ); //cw.setName("copied parameter: " + paramWire.getName()); handler.setName(pw, "[conditions] sync from: " + paramWire.getId() + " param=" + ((GeneratedElement) param).getId() + " run=" + run.getId() ); queue.add(pw, drools); end