process.addNode(startNode);
EndNode endNode = new EndNode();
endNode.setName("EndNode");
endNode.setId(2);
process.addNode(endNode);
ForEachNode forEachNode = new ForEachNode();
forEachNode.setName("ForEach");
forEachNode.setId(3);
forEachNode.setCollectionExpression("persons");
personDataType = new ObjectDataType();
personDataType.setClassName("org.drools.Person");
process.addNode(forEachNode);
new ConnectionImpl(
startNode, Node.CONNECTION_DEFAULT_TYPE,
forEachNode, Node.CONNECTION_DEFAULT_TYPE
);
new ConnectionImpl(
forEachNode, Node.CONNECTION_DEFAULT_TYPE,
endNode, Node.CONNECTION_DEFAULT_TYPE
);
final List<String> myList = new ArrayList<String>();
ActionNode actionNode = new ActionNode();
actionNode.setName("Print child");
DroolsAction action = new DroolsConsequenceAction("java", null);
action.setMetaData("Action", new Action() {
public void execute(KnowledgeHelper knowledgeHelper, WorkingMemory workingMemory, ProcessContext context) throws Exception {
System.out.println("Executed action for child " + ((Person) context.getVariable("child")).getName());
myList.add("Executed action");
}
});
actionNode.setAction(action);
forEachNode.addNode(actionNode);
forEachNode.linkIncomingConnections(
Node.CONNECTION_DEFAULT_TYPE,
actionNode.getId(), Node.CONNECTION_DEFAULT_TYPE);
forEachNode.linkOutgoingConnections(
actionNode.getId(), Node.CONNECTION_DEFAULT_TYPE,
Node.CONNECTION_DEFAULT_TYPE);
forEachNode.setVariable("child", personDataType);
AbstractRuleBase ruleBase = (AbstractRuleBase) RuleBaseFactory.newRuleBase();
ruleBase.addProcess(process);
InternalWorkingMemory workingMemory = new ReteooWorkingMemory(1, ruleBase);
Map<String, Object> parameters = new HashMap<String, Object>();