use of org.drools.core.rule.TypeDeclaration in project drools by kiegroup.
the class TypeDeclarationCache method createTypeDeclaration.
private TypeDeclaration createTypeDeclaration(Class<?> cls) {
TypeDeclaration typeDeclaration = getExistingTypeDeclaration(cls);
if (typeDeclaration == null) {
typeDeclaration = createTypeDeclarationForBean(cls);
}
initTypeDeclaration(cls, typeDeclaration);
return typeDeclaration;
}
use of org.drools.core.rule.TypeDeclaration in project drools by kiegroup.
the class TypeDeclarationConfigurator method finalize.
public void finalize(TypeDeclaration type, AbstractClassTypeDeclarationDescr typeDescr, PackageRegistry pkgRegistry, Map<String, PackageRegistry> pkgRegistryMap, ClassHierarchyManager hierarchyManager) {
// prefer definitions where possible
if (type.getNature() == TypeDeclaration.Nature.DEFINITION) {
hierarchyManager.addDeclarationToPackagePreservingOrder(type, typeDescr, pkgRegistry.getPackage(), pkgRegistryMap);
} else {
TypeDeclaration oldType = pkgRegistry.getPackage().getTypeDeclaration(type.getTypeName());
if (oldType == null) {
pkgRegistry.getPackage().addTypeDeclaration(type);
} else {
if (type.getRole() == Role.Type.EVENT) {
oldType.setRole(Role.Type.EVENT);
if (type.getDurationAttribute() != null) {
oldType.setDurationAttribute(type.getDurationAttribute());
oldType.setDurationExtractor(type.getDurationExtractor());
}
if (type.getTimestampAttribute() != null) {
oldType.setTimestampAttribute(type.getTimestampAttribute());
oldType.setTimestampExtractor(type.getTimestampExtractor());
}
if (type.getExpirationOffset() >= 0) {
oldType.setExpirationOffset(type.getExpirationOffset());
oldType.setExpirationType(type.getExpirationPolicy());
}
}
if (type.isPropertyReactive()) {
oldType.setPropertyReactive(true);
}
}
}
}
use of org.drools.core.rule.TypeDeclaration in project drools by kiegroup.
the class TypeDeclarationFactory method processTypeDeclaration.
public TypeDeclaration processTypeDeclaration(PackageRegistry pkgRegistry, AbstractClassTypeDeclarationDescr typeDescr) {
TypeDeclaration type = kbuilder.getTypeBuilder().getExistingTypeDeclaration(typeDescr.getFullTypeName());
if (type == null) {
type = new TypeDeclaration(typeDescr.getTypeName());
type.setResource(typeDescr.getResource());
// if is not new, search the already existing declaration and
// compare them o see if they are at least compatibles
// check whether it is necessary to build the class or not
Class<?> existingClass = TypeDeclarationUtils.getExistingDeclarationClass(typeDescr, pkgRegistry);
type.setTypeClass(existingClass);
type.setNovel(existingClass == null);
type.setNature(existingClass == null ? TypeDeclaration.Nature.DEFINITION : TypeDeclaration.Nature.DECLARATION);
}
processTypeAnnotations(typeDescr, type);
return type;
}
use of org.drools.core.rule.TypeDeclaration in project drools by kiegroup.
the class TypeDeclarationNameResolver method resolveName.
private String resolveName(String type, AbstractClassTypeDeclarationDescr typeDescr, PackageDescr packageDescr, TypeResolver typeResolver, List<TypeDefinition> unresolvedTypes, boolean forceResolution) {
boolean qualified = TypeDeclarationUtils.isQualified(type);
if (!qualified) {
type = TypeDeclarationUtils.lookupSimpleNameByImports(type, typeDescr, packageDescr, kbuilder.getRootClassLoader());
}
// if not qualified yet, it has to be resolved
// DROOLS-677 : if qualified, it may be a partial name (e.g. an inner class)
type = TypeDeclarationUtils.resolveType(type, packageDescr, kbuilder.getPackageRegistry(packageDescr.getNamespace()));
qualified = TypeDeclarationUtils.isQualified(type);
if (!qualified) {
try {
Class klass = typeResolver.resolveType(type, TypeResolver.EXCLUDE_ANNOTATION_CLASS_FILTER);
type = klass.getCanonicalName();
return type;
} catch (ClassNotFoundException e) {
// e.printStackTrace();
}
} else {
type = TypeDeclarationUtils.typeName2ClassName(type, kbuilder.getRootClassLoader());
qualified = TypeDeclarationUtils.isQualified(type);
}
if (forceResolution && !qualified) {
TypeDeclaration temp = new TypeDeclaration(type);
temp.setTypeClassName(type);
unresolvedTypes.add(new TypeDefinition(temp, null));
}
return qualified ? type : null;
}
use of org.drools.core.rule.TypeDeclaration in project drools by kiegroup.
the class KnowledgeBuilderTest method testRepeatedDeclarationInMultiplePackages.
@Test
public void testRepeatedDeclarationInMultiplePackages() {
String str = "package org.drools.test1;\n" + "import org.drools.compiler.Cheese;\n" + "" + "rule R\n" + "when Cheese() then end \n" + "";
String str2 = "package org.drools.test2;\n" + "import org.drools.compiler.Cheese;\n" + "" + "rule S\n" + "when Cheese() then end \n" + "";
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newByteArrayResource(str.getBytes()), ResourceType.DRL);
kbuilder.add(ResourceFactory.newByteArrayResource(str2.getBytes()), ResourceType.DRL);
assertEquals(3, kbuilder.getKnowledgePackages().size());
for (KiePackage kp : kbuilder.getKnowledgePackages()) {
KnowledgePackageImpl kpi = (KnowledgePackageImpl) kp;
TypeDeclaration cheez = kpi.getTypeDeclaration("Cheese");
if ("org.drools.compiler".equals(kpi.getName())) {
assertNotNull(cheez);
} else {
assertNull(cheez);
}
}
}
Aggregations