use of org.drools.core.rule.TypeDeclaration in project drools by kiegroup.
the class KnowledgeBaseImpl method removeObjectsGeneratedFromResource.
public boolean removeObjectsGeneratedFromResource(Resource resource) {
boolean modified = false;
for (InternalKnowledgePackage pkg : pkgs.values()) {
List<RuleImpl> rulesToBeRemoved = pkg.getRulesGeneratedFromResource(resource);
if (!rulesToBeRemoved.isEmpty()) {
this.reteooBuilder.removeRules(rulesToBeRemoved);
// in order to allow the correct flushing of all outstanding staged tuples
for (RuleImpl rule : rulesToBeRemoved) {
pkg.removeRule(rule);
}
}
List<Function> functionsToBeRemoved = pkg.removeFunctionsGeneratedFromResource(resource);
for (Function function : functionsToBeRemoved) {
internalRemoveFunction(pkg.getName(), function.getName());
}
List<Process> processesToBeRemoved = pkg.removeProcessesGeneratedFromResource(resource);
for (Process process : processesToBeRemoved) {
processes.remove(process.getId());
}
List<TypeDeclaration> removedTypes = pkg.removeTypesGeneratedFromResource(resource);
boolean resourceTypePackageSomethingRemoved = pkg.removeFromResourceTypePackageGeneratedFromResource(resource);
modified |= !rulesToBeRemoved.isEmpty() || !functionsToBeRemoved.isEmpty() || !processesToBeRemoved.isEmpty() || !removedTypes.isEmpty() || resourceTypePackageSomethingRemoved;
}
return modified;
}
use of org.drools.core.rule.TypeDeclaration in project drools by kiegroup.
the class KnowledgeBaseImpl method checkSuperClasses.
private TypeDeclarationCandidate checkSuperClasses(Class<?> clazz) {
TypeDeclaration typeDeclaration = null;
Class<?> current = clazz.getSuperclass();
int score = 0;
while (typeDeclaration == null && current != null) {
score++;
typeDeclaration = this.classTypeDeclaration.get(current.getName());
current = current.getSuperclass();
}
TypeDeclarationCandidate candidate = null;
if (typeDeclaration != null) {
candidate = new TypeDeclarationCandidate();
candidate.candidate = typeDeclaration;
candidate.score = score;
}
return candidate;
}
use of org.drools.core.rule.TypeDeclaration in project drools by kiegroup.
the class KnowledgeBaseImpl method checkInterfaces.
private TypeDeclarationCandidate checkInterfaces(Class<?> clazz, TypeDeclarationCandidate baseline, int level) {
TypeDeclarationCandidate candidate = null;
if (baseline == null || level < baseline.score) {
// search
TypeDeclaration typeDeclaration;
for (Class<?> ifc : clazz.getInterfaces()) {
typeDeclaration = this.classTypeDeclaration.get(ifc.getName());
if (typeDeclaration != null) {
candidate = new TypeDeclarationCandidate();
candidate.candidate = typeDeclaration;
candidate.score = level;
break;
} else {
candidate = checkInterfaces(ifc, baseline, level + 1);
}
}
} else {
candidate = baseline;
}
return candidate;
}
use of org.drools.core.rule.TypeDeclaration in project drools by kiegroup.
the class KnowledgePackageImpl method getFactType.
public FactType getFactType(final String typeName) {
if (typeName == null || (this.name != null && !typeName.startsWith(this.name + "."))) {
return null;
}
// in case the package name is != null, remove the package name from the
// beginning of the type name
String key = this.name == null ? typeName : typeName.substring(this.name.length() + 1);
TypeDeclaration decl = this.typeDeclarations.get(key);
if (decl == null) {
return null;
} else {
if (decl.isDefinition() || decl.isGeneratedFact()) {
return decl.getTypeClassDef();
} else {
throw new UnsupportedOperationException("KieBase.getFactType should only be used to retrieve declared beans. Class " + typeName + " exists outside DRL ");
}
}
}
use of org.drools.core.rule.TypeDeclaration in project drools by kiegroup.
the class MapCore method getTypeDeclaration.
public static TypeDeclaration getTypeDeclaration() {
String[] mcInterfaces = new String[MapCore.class.getInterfaces().length];
int j = 0;
for (Class intf : MapCore.class.getInterfaces()) {
mcInterfaces[j++] = intf.getName();
}
ClassDefinition mcClassDef = new ClassDefinition(MapCore.class.getName(), MapCore.class.getSuperclass().getName(), mcInterfaces);
mcClassDef.setTraitable(true);
mcClassDef.setDefinedClass(MapCore.class);
mcClassDef.setAbstrakt(false);
TypeDeclaration mapCoreType = new TypeDeclaration(MapCore.class.getName());
mapCoreType.setKind(TypeDeclaration.Kind.CLASS);
mapCoreType.setTypeClass(MapCore.class);
mapCoreType.setTypeClassDef(mcClassDef);
return mapCoreType;
}
Aggregations