Search in sources :

Example 1 with PropertyHandlerFactory.getPropertyHandler

use of org.mvel2.integration.PropertyHandlerFactory.getPropertyHandler in project drools by kiegroup.

the class PatternBuilder method buildPattern.

private Pattern buildPattern(RuleBuildContext context, PatternDescr patternDescr, ObjectType objectType) {
    String patternIdentifier = patternDescr.getIdentifier();
    boolean duplicateBindings = patternIdentifier != null && objectType instanceof ClassObjectType && context.getDeclarationResolver().isDuplicated(context.getRule(), patternIdentifier, objectType.getClassName());
    Pattern pattern;
    if (!StringUtils.isEmpty(patternIdentifier) && !duplicateBindings) {
        pattern = new Pattern(context.getNextPatternId(), // offset is 0 by default
        0, objectType, patternIdentifier, patternDescr.isInternalFact(context));
        if (objectType instanceof ClassObjectType) {
            // make sure PatternExtractor is wired up to correct ClassObjectType and set as a target for rewiring
            context.getPkg().getClassFieldAccessorStore().wireObjectType(objectType, (AcceptsClassObjectType) pattern.getDeclaration().getExtractor());
        }
    } else {
        pattern = new Pattern(context.getNextPatternId(), // offset is 0 by default
        0, objectType, null);
    }
    pattern.setPassive(patternDescr.isPassive(context));
    if (ClassObjectType.Match_ObjectType.isAssignableFrom(pattern.getObjectType())) {
        PropertyHandler handler = PropertyHandlerFactory.getPropertyHandler(RuleTerminalNodeLeftTuple.class);
        if (handler == null) {
            PropertyHandlerFactoryFixer.getPropertyHandlerClass().put(RuleTerminalNodeLeftTuple.class, new ActivationPropertyHandler());
        }
    }
    // adding the newly created pattern to the build stack this is necessary in case of local declaration usage
    context.getDeclarationResolver().pushOnBuildStack(pattern);
    if (duplicateBindings) {
        processDuplicateBindings(patternDescr.isUnification(), patternDescr, pattern, patternDescr, "this", patternDescr.getIdentifier(), context);
    }
    return pattern;
}
Also used : Pattern(org.drools.core.rule.Pattern) AcceptsClassObjectType(org.drools.core.spi.AcceptsClassObjectType) ClassObjectType(org.drools.core.base.ClassObjectType) ActivationPropertyHandler(org.drools.core.base.mvel.ActivationPropertyHandler) PropertyHandler(org.mvel2.integration.PropertyHandler) ActivationPropertyHandler(org.drools.core.base.mvel.ActivationPropertyHandler)

Example 2 with PropertyHandlerFactory.getPropertyHandler

use of org.mvel2.integration.PropertyHandlerFactory.getPropertyHandler 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)2 PropertyHandler (org.mvel2.integration.PropertyHandler)2 ClassObjectType (org.drools.core.base.ClassObjectType)1 InstanceNotEqualsConstraint (org.drools.core.common.InstanceNotEqualsConstraint)1 IntervalProviderConstraint (org.drools.core.rule.IntervalProviderConstraint)1 Pattern (org.drools.core.rule.Pattern)1 PatternSource (org.drools.core.rule.PatternSource)1 XpathConstraint (org.drools.core.rule.constraint.XpathConstraint)1 AcceptsClassObjectType (org.drools.core.spi.AcceptsClassObjectType)1 AlphaNodeFieldConstraint (org.drools.core.spi.AlphaNodeFieldConstraint)1 BetaNodeFieldConstraint (org.drools.core.spi.BetaNodeFieldConstraint)1 Constraint (org.drools.core.spi.Constraint)1