use of org.drools.modelcompiler.builder.errors.UnknownRuleUnitException in project drools by kiegroup.
the class RuleContext method findUnitDescr.
private void findUnitDescr() {
if (ruleDescr == null) {
return;
}
boolean useNamingConvention = false;
String unitName;
AnnotationDescr unitAnn = ruleDescr.getAnnotation("Unit");
if (unitAnn != null) {
unitName = (String) unitAnn.getValue();
unitName = unitName.substring(0, unitName.length() - ".class".length());
} else if (ruleDescr.getUnit() != null) {
unitName = ruleDescr.getUnit().getTarget();
} else {
if (ruleDescr.getResource() == null) {
return;
}
String drlFile = ruleDescr.getResource().getSourcePath();
if (drlFile != null) {
String drlFileName = drlFile.substring(drlFile.lastIndexOf('/') + 1);
unitName = packageModel.getName() + '.' + drlFileName.substring(0, drlFileName.length() - ".drl".length());
useNamingConvention = true;
} else {
return;
}
}
RuleUnitDescriptionLoader ruleUnitDescriptionLoader = kbuilder.getPackageRegistry(packageModel.getName()).getPackage().getRuleUnitDescriptionLoader();
Optional<RuleUnitDescription> ruDescr = ruleUnitDescriptionLoader.getDescription(unitName);
if (ruDescr.isPresent()) {
ruleUnitDescr = ruDescr.get();
} else if (!useNamingConvention) {
throw new UnknownRuleUnitException(unitName);
}
}
Aggregations