Search in sources :

Example 1 with PatternSource

use of org.drools.core.rule.PatternSource in project drools by kiegroup.

the class PatternBuilder method attachPattern.

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());
    // this is needed for Activation patterns, to allow declarations and annotations to be used like field constraints
    if (ClassObjectType.Match_ObjectType.isAssignableFrom(pattern.getObjectType())) {
        PropertyHandler handler = PropertyHandlerFactory.getPropertyHandler(AgendaItemImpl.class);
        if (handler == null) {
            PropertyHandlerFactoryFixer.getPropertyHandlerClass().put(AgendaItemImpl.class, new ActivationPropertyHandler());
        }
    }
    Constraints constraints = createConstraints(context, pattern);
    // Create BetaConstraints object
    context.setBetaconstraints(constraints.betaConstraints);
    if (pattern.getSource() != null) {
        context.setAlphaConstraints(constraints.alphaConstraints);
        final int currentOffset = context.getCurrentPatternOffset();
        PatternSource source = pattern.getSource();
        ReteooComponentBuilder builder = utils.getBuilderFor(source);
        if (builder == null) {
            throw new RuntimeException("Unknown pattern source type: " + source.getClass() + " for source " + source + " on pattern " + pattern);
        }
        builder.build(context, utils, source);
        // restoring offset
        context.setCurrentPatternOffset(currentOffset);
    } else {
        // default entry point
        PatternSource source = EntryPointId.DEFAULT;
        ReteooComponentBuilder builder = utils.getBuilderFor(source);
        builder.build(context, utils, source);
    }
    buildBehaviors(context, utils, pattern, constraints);
    if (context.getObjectSource() != null) {
        attachAlphaNodes(context, utils, pattern, constraints.alphaConstraints);
    }
    buildXpathConstraints(context, utils, pattern, constraints);
    // last thing to do is increment the offset, since if the pattern has a source,
    // offset must be overriden
    context.incrementCurrentPatternOffset();
}
Also used : ActivationPropertyHandler(org.drools.core.base.mvel.ActivationPropertyHandler) PropertyHandler(org.mvel2.integration.PropertyHandler) PatternSource(org.drools.core.rule.PatternSource) ActivationPropertyHandler(org.drools.core.base.mvel.ActivationPropertyHandler) InstanceNotEqualsConstraint(org.drools.core.common.InstanceNotEqualsConstraint) BetaNodeFieldConstraint(org.drools.core.spi.BetaNodeFieldConstraint) IntervalProviderConstraint(org.drools.core.rule.IntervalProviderConstraint) XpathConstraint(org.drools.core.rule.constraint.XpathConstraint) AlphaNodeFieldConstraint(org.drools.core.spi.AlphaNodeFieldConstraint) Constraint(org.drools.core.spi.Constraint)

Aggregations

ActivationPropertyHandler (org.drools.core.base.mvel.ActivationPropertyHandler)1 InstanceNotEqualsConstraint (org.drools.core.common.InstanceNotEqualsConstraint)1 IntervalProviderConstraint (org.drools.core.rule.IntervalProviderConstraint)1 PatternSource (org.drools.core.rule.PatternSource)1 XpathConstraint (org.drools.core.rule.constraint.XpathConstraint)1 AlphaNodeFieldConstraint (org.drools.core.spi.AlphaNodeFieldConstraint)1 BetaNodeFieldConstraint (org.drools.core.spi.BetaNodeFieldConstraint)1 Constraint (org.drools.core.spi.Constraint)1 PropertyHandler (org.mvel2.integration.PropertyHandler)1