use of org.kie.api.definition.rule.Watch in project drools by kiegroup.
the class PatternBuilder method processListenedPropertiesAnnotation.
protected void processListenedPropertiesAnnotation(RuleBuildContext context, PatternDescr patternDescr, Pattern pattern) {
String watchedValues = null;
try {
Watch watch = getTypedAnnotation(patternDescr, Watch.class);
watchedValues = watch == null ? null : watch.value();
} catch (Exception e) {
registerDescrBuildError(context, patternDescr, e.getMessage());
}
if (watchedValues == null) {
return;
}
Collection<String> settableProperties = getSettableProperties(context, patternDescr, pattern);
List<String> listenedProperties = new ArrayList<>();
for (String propertyName : watchedValues.split(",")) {
propertyName = propertyName.trim();
if (propertyName.equals("*") || propertyName.equals("!*")) {
if (listenedProperties.contains("*") || listenedProperties.contains("!*")) {
registerDescrBuildError(context, patternDescr, "Duplicate usage of wildcard * in @" + Watch.class.getSimpleName() + " annotation");
} else {
listenedProperties.add(propertyName);
}
continue;
}
boolean isNegative = propertyName.startsWith("!");
propertyName = isNegative ? propertyName.substring(1).trim() : propertyName;
if (settableProperties != null && !settableProperties.contains(propertyName)) {
registerDescrBuildError(context, patternDescr, "Unknown property " + propertyName + " in @" + Watch.class.getSimpleName() + " annotation");
} else if (listenedProperties.contains(propertyName) || listenedProperties.contains("!" + propertyName)) {
registerDescrBuildError(context, patternDescr, "Duplicate property " + propertyName + " in @" + Watch.class.getSimpleName() + " annotation");
} else {
listenedProperties.add(isNegative ? "!" + propertyName : propertyName);
}
}
pattern.addWatchedProperties(listenedProperties);
}
Aggregations