private void attachPattern( final BuildContext context, final BuildUtils utils, final Pattern pattern) throws InvalidPatternException { // Set pattern offset to the appropriate value pattern.setOffset(context.getCurrentPatternOffset()); final List<Constraint> alphaConstraints = new LinkedList<Constraint>(); final List<Constraint> betaConstraints = new LinkedList<Constraint>(); final List<Behavior> behaviors = new LinkedList<Behavior>(); this.createConstraints(context, utils, pattern, alphaConstraints, betaConstraints); // Create BetaConstraints object context.setBetaconstraints(betaConstraints); // set behaviors list behaviors.addAll(pattern.getBehaviors()); context.setBehaviors(behaviors); if (pattern.getSource() != null) { context.setAlphaConstraints(alphaConstraints); final int currentOffset = context.getCurrentPatternOffset(); PatternSource source = pattern.getSource(); ReteooComponentBuilder builder = utils.getBuilderFor(source); builder.build(context, utils, source); // restoring offset context.setCurrentPatternOffset(currentOffset); } if (pattern.getSource() == null || context.getCurrentEntryPoint() != EntryPoint.DEFAULT) { attachAlphaNodes(context, utils, pattern, alphaConstraints); if (context.getCurrentEntryPoint() != EntryPoint.DEFAULT) { context.setObjectSource( (ObjectSource) utils.attachNode( context, new PropagationQueuingNode( context.getNextId(), context.getObjectSource(), context))); // the entry-point specific network nodes are attached, so, set context to default // entry-point context.setCurrentEntryPoint(EntryPoint.DEFAULT); } } // last thing to do is increment the offset, since if the pattern has a source, // offset must be overriden context.incrementCurrentPatternOffset(); }
public void build(BuildContext context, BuildUtils utils, RuleConditionElement rce) { NamedConsequence namedConsequence = (NamedConsequence) rce; Timer timer = context.getRule().getTimer(); if (timer != null) { ReteooComponentBuilder builder = utils.getBuilderFor(Timer.class); builder.build(context, utils, context.getRule().getTimer()); } RuleTerminalNode terminalNode = buildTerminalNodeForNamedConsequence(context, namedConsequence); terminalNode.attach(context); terminalNode.networkUpdated(new UpdateContext()); // adds the terminal node to the list of nodes created/added by this sub-rule context.getNodes().add(terminalNode); if (timer != null) { context.setTupleSource(context.getTupleSource().getLeftTupleSource()); } context.setTerminated(namedConsequence.isTerminal()); }