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();
}
Aggregations