use of org.drools.core.base.mvel.ActivationPropertyHandler 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;
}
use of org.drools.core.base.mvel.ActivationPropertyHandler 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();
}
Aggregations