use of org.drools.verifier.components.Import in project drools by kiegroup.
the class PackageDescrVisitor method visitImports.
private void visitImports(List<ImportDescr> importDescrs) throws IOException, ClassNotFoundException {
HashSet<String> imports = new HashSet<String>();
for (ImportDescr i : importDescrs) {
String fullName = i.getTarget();
String name = fullName.substring(fullName.lastIndexOf(".") + 1);
imports.add(fullName);
Import objectImport = new Import(i, rulePackage);
objectImport.setName(fullName);
objectImport.setShortName(name);
data.add(objectImport);
ObjectType objectType = this.data.getObjectTypeByFullName(fullName);
if (objectType == null) {
objectType = new ObjectType(i);
}
objectType.setName(name);
objectType.setFullName(fullName);
data.add(objectType);
}
PackageHeaderLoader packageHeaderLoader = new PackageHeaderLoader(imports, jars);
for (String factTypeName : packageHeaderLoader.getClassNames()) {
String name = factTypeName.substring(factTypeName.lastIndexOf(".") + 1);
Collection<String> fieldNames = packageHeaderLoader.getFieldNames(factTypeName);
for (String fieldName : fieldNames) {
ObjectType objectType = this.data.getObjectTypeByObjectTypeNameAndPackageName(name, rulePackage.getName());
Field field = data.getFieldByObjectTypeAndFieldName(objectType.getFullName(), fieldName);
if (field == null) {
field = ObjectTypeFactory.createField(objectType.getDescr(), fieldName, objectType);
field.setFieldType(packageHeaderLoader.getFieldType(objectType.getName(), fieldName));
data.add(field);
}
}
}
}
use of org.drools.verifier.components.Import in project drools by kiegroup.
the class PatternDescrVisitor method visitPatternDescr.
private Pattern visitPatternDescr(PatternDescr descr, VerifierComponent parent, int orderNumber) throws UnknownDescriptionException {
objectType = data.getObjectTypeByFullName(descr.getObjectType());
if (objectType == null) {
Import objectImport = data.getImportByName(descr.getObjectType());
if (objectImport != null) {
objectType = ObjectTypeFactory.createObjectType(descr, objectImport);
} else {
objectType = ObjectTypeFactory.createObjectType(descr, descr.getObjectType());
}
data.add(objectType);
}
pattern = new Pattern(descr, rule);
if (parent != null) {
pattern.setParentPath(parent.getPath());
pattern.setParentType(parent.getVerifierComponentType());
}
pattern.setObjectTypePath(objectType.getPath());
pattern.setName(objectType.getName());
pattern.setPatternNot(solvers.getRuleSolver().isChildNot());
pattern.setPatternExists(solvers.getRuleSolver().isExists());
pattern.setPatternForall(solvers.getRuleSolver().isForall());
pattern.setOrderNumber(orderNumber);
if (descr.getIdentifier() != null) {
PatternVariable patternVariable = new PatternVariable(rule);
patternVariable.setName(descr.getIdentifier());
patternVariable.setParentPath(pattern.getPath());
patternVariable.setParentType(pattern.getVerifierComponentType());
data.add(patternVariable);
}
// visit source.
if (descr.getSource() != null) {
visit(descr.getSource());
} else {
if (workingMemory == null) {
workingMemory = new WorkingMemory();
data.add(workingMemory);
}
pattern.setSourcePath(workingMemory.getPath());
pattern.setSourceType(workingMemory.getVerifierComponentType());
}
solvers.startPatternSolver(pattern);
visit(descr.getConstraint());
solvers.endPatternSolver();
data.add(pattern);
return pattern;
}
use of org.drools.verifier.components.Import in project drools by kiegroup.
the class TypeDeclarationDescrVisitor method visit.
public void visit(List<TypeDeclarationDescr> typeDeclarationDescrs) {
for (TypeDeclarationDescr typeDeclaration : typeDeclarationDescrs) {
Import objectImport = data.getImportByName(typeDeclaration.getTypeName());
String objectTypeName;
if (objectImport == null) {
objectTypeName = typeDeclaration.getTypeName();
} else {
objectTypeName = objectImport.getName();
}
ObjectType objectType = this.data.getObjectTypeByFullName(objectTypeName);
if (objectType == null) {
objectType = new ObjectType(typeDeclaration);
objectType.setName(typeDeclaration.getTypeName());
objectType.setFullName(typeDeclaration.getTypeName());
data.add(objectType);
}
for (String fieldName : typeDeclaration.getFields().keySet()) {
Field field = data.getFieldByObjectTypeAndFieldName(objectType.getFullName(), fieldName);
if (field == null) {
field = ObjectTypeFactory.createField(typeDeclaration.getFields().get(fieldName), fieldName, objectType);
field.setFieldType(typeDeclaration.getFields().get(fieldName).getPattern().getObjectType());
data.add(field);
}
}
for (AnnotationDescr annDescr : typeDeclaration.getAnnotations()) {
Map<String, Object> values = typeDeclaration.getAnnotation(annDescr.getName()).getValueMap();
for (String value : values.keySet()) {
objectType.getMetadata().put(annDescr.getName(), value);
}
}
}
}
use of org.drools.verifier.components.Import in project drools by kiegroup.
the class FieldConstraintDescrVisitor method visit.
/**
* End
*
* @param descr
*/
private void visit(QualifiedIdentifierRestrictionDescr descr) {
String text = descr.getText();
String base = text.substring(0, text.indexOf("."));
String fieldName = text.substring(text.indexOf("."));
Variable patternVariable = data.getVariableByRuleAndVariableName(pattern.getRuleName(), base);
if (patternVariable != null) {
QualifiedIdentifierRestriction restriction = new QualifiedIdentifierRestriction(pattern);
restriction.setPatternIsNot(pattern.isPatternNot());
restriction.setFieldPath(field.getPath());
restriction.setOperator(Operator.determineOperator(descr.getEvaluator(), descr.isNegated()));
restriction.setVariablePath(patternVariable.getPath());
restriction.setVariableName(base);
restriction.setVariablePath(fieldName);
restriction.setOrderNumber(orderNumber);
restriction.setParentPath(pattern.getPath());
restriction.setParentType(pattern.getVerifierComponentType());
// Set field value, if it is not set.
field.setFieldType(Field.VARIABLE);
data.add(restriction);
solvers.addPatternComponent(restriction);
} else {
EnumField enumField = (EnumField) data.getFieldByObjectTypeAndFieldName(base, fieldName);
if (enumField == null) {
ObjectType objectType = data.getObjectTypeByFullName(base);
if (objectType == null) {
Import objectImport = data.getImportByName(base);
if (objectImport != null) {
objectType = ObjectTypeFactory.createObjectType(descr, objectImport);
} else {
objectType = ObjectTypeFactory.createObjectType(descr, base);
}
data.add(objectType);
}
enumField = new EnumField(descr);
enumField.setObjectTypePath(objectType.getPath());
enumField.setObjectTypeName(objectType.getName());
enumField.setName(fieldName);
objectType.getFields().add(enumField);
data.add(enumField);
}
EnumRestriction restriction = new EnumRestriction(pattern);
restriction.setPatternIsNot(pattern.isPatternNot());
restriction.setFieldPath(field.getPath());
restriction.setOperator(Operator.determineOperator(descr.getEvaluator(), descr.isNegated()));
restriction.setEnumBasePath(enumField.getPath());
restriction.setEnumBase(base);
restriction.setEnumName(fieldName);
restriction.setOrderNumber(orderNumber);
restriction.setParentPath(pattern.getPath());
restriction.setParentType(pattern.getVerifierComponentType());
// Set field value, if it is not set.
field.setFieldType(Field.ENUM);
data.add(restriction);
solvers.addPatternComponent(restriction);
}
}
Aggregations