use of org.drools.core.ruleunit.RuleUnitDescriptionLoader in project drools by kiegroup.
the class KnowledgePackageImpl method setClassLoader.
public void setClassLoader(ClassLoader classLoader) {
if (typeResolver != null && typeResolver.getClassLoader() == classLoader) {
return;
}
this.typeResolver = new ClassTypeResolver(new HashSet<>(getImports().keySet()), classLoader, getName());
typeResolver.addImport(getName() + ".*");
for (String implicitImport : getImplicitImports()) {
typeResolver.addImplicitImport(implicitImport);
}
this.ruleUnitDescriptionLoader = new RuleUnitDescriptionLoader(this);
}
use of org.drools.core.ruleunit.RuleUnitDescriptionLoader 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