Search in sources :

Example 1 with Field

use of org.drools.verifier.components.Field in project drools by kiegroup.

the class ExprConstraintDescrVisitor method createField.

private void createField(RelationalExprDescr descr, String fieldName) {
    field = new Field(pattern.getDescr());
    field.setName(fieldName);
    field.setObjectTypePath(pattern.getObjectTypePath());
    field.setObjectTypeName(pattern.getName());
    data.add(field);
}
Also used : Field(org.drools.verifier.components.Field)

Example 2 with Field

use of org.drools.verifier.components.Field in project drools by kiegroup.

the class ExprConstraintDescrVisitor method visit.

private void visit(BindingDescr descr) {
    Field field = new Field(descr);
    field.setName(descr.getExpression());
    field.setObjectTypeName(pattern.getName());
    field.setObjectTypePath(pattern.getObjectTypePath());
    data.add(field);
    FieldVariable fieldVariable = new FieldVariable(pattern);
    fieldVariable.setParentPath(field.getPath());
    fieldVariable.setName(descr.getVariable());
    fieldVariable.setOrderNumber(orderNumber.next());
    data.add(fieldVariable);
}
Also used : Field(org.drools.verifier.components.Field) FieldVariable(org.drools.verifier.components.FieldVariable)

Example 3 with Field

use of org.drools.verifier.components.Field 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);
            }
        }
    }
}
Also used : PackageHeaderLoader(org.drools.verifier.jarloader.PackageHeaderLoader) ObjectType(org.drools.verifier.components.ObjectType) Field(org.drools.verifier.components.Field) Import(org.drools.verifier.components.Import) ImportDescr(org.drools.compiler.lang.descr.ImportDescr) HashSet(java.util.HashSet)

Example 4 with Field

use of org.drools.verifier.components.Field in project drools by kiegroup.

the class PatternDescrVisitor method visitBindingDescr.

/**
 * End
 *
 * @param descr
 */
private void visitBindingDescr(BindingDescr descr) {
    Field field = new Field(descr);
    field.setName(descr.getExpression());
    field.setObjectTypeName(objectType.getName());
    field.setObjectTypePath(objectType.getPath());
    data.add(field);
    FieldVariable fieldVariable = new FieldVariable(pattern);
    fieldVariable.setParentPath(field.getPath());
    fieldVariable.setName(descr.getVariable());
    fieldVariable.setOrderNumber(orderNumber.next());
    data.add(fieldVariable);
}
Also used : Field(org.drools.verifier.components.Field) FieldVariable(org.drools.verifier.components.FieldVariable)

Example 5 with Field

use of org.drools.verifier.components.Field 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);
            }
        }
    }
}
Also used : ObjectType(org.drools.verifier.components.ObjectType) Field(org.drools.verifier.components.Field) Import(org.drools.verifier.components.Import) TypeDeclarationDescr(org.drools.compiler.lang.descr.TypeDeclarationDescr) AnnotationDescr(org.drools.compiler.lang.descr.AnnotationDescr)

Aggregations

Field (org.drools.verifier.components.Field)14 ObjectType (org.drools.verifier.components.ObjectType)7 VerifierReport (org.drools.verifier.data.VerifierReport)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 JarInputStream (java.util.jar.JarInputStream)2 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)2 ClassPathResource (org.drools.core.io.impl.ClassPathResource)2 VerifierBuilder (org.drools.verifier.builder.VerifierBuilder)2 EnumField (org.drools.verifier.components.EnumField)2 FieldVariable (org.drools.verifier.components.FieldVariable)2 Import (org.drools.verifier.components.Import)2 VerifierRule (org.drools.verifier.components.VerifierRule)2 FileOutputStream (java.io.FileOutputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 AnnotationDescr (org.drools.compiler.lang.descr.AnnotationDescr)1