Пример #1
0
  /* (non-Javadoc)
   * @see org.kie.reteoo.builder.ReteooComponentBuilder#build(org.kie.reteoo.builder.BuildContext, org.kie.reteoo.builder.BuildUtils, org.kie.rule.RuleConditionElement)
   */
  public void build(
      final BuildContext context, final BuildUtils utils, final RuleConditionElement rce) {
    final From from = (From) rce;
    context.pushRuleComponent(from);

    @SuppressWarnings("unchecked")
    BetaConstraints betaConstraints =
        utils.createBetaNodeConstraint(
            context, (List<BetaNodeFieldConstraint>) context.getBetaconstraints(), true);

    context.setTupleSource(
        (LeftTupleSource)
            utils.attachNode(
                context,
                context
                    .getComponentFactory()
                    .getNodeFactoryService()
                    .buildFromNode(
                        context.getNextId(),
                        from.getDataProvider(),
                        context.getTupleSource(),
                        context
                            .getAlphaConstraints()
                            .toArray(
                                new AlphaNodeFieldConstraint[context.getAlphaConstraints().size()]),
                        betaConstraints,
                        context.isTupleMemoryEnabled(),
                        context,
                        from)));
    context.setAlphaConstraints(null);
    context.setBetaconstraints(null);
    context.popRuleComponent();
  }
Пример #2
0
  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();
  }