Examples of FieldDefinition


Examples of org.drools.core.factmodel.FieldDefinition

                        null,
                        "Unable to find @positional field " + descr.getPosition() + " for class " + tDecl.getTypeName() + "\n"));
                return;
            }

            FieldDefinition field = clsDef.getField( descr.getPosition() );
            if ( field == null ) {
                context.addError(new DescrBuildError(context.getParentDescr(),
                        descr,
                        null,
                        "Unable to find @positional field " + descr.getPosition() + " for class " + tDecl.getTypeName() + "\n"));
                return;
            }

            String expr = descr.getExpression();
            boolean isSimpleIdentifier = isIdentifier(expr);

            if ( isSimpleIdentifier ) {
                // create a binding
                BindingDescr binder = new BindingDescr();
                binder.setUnification( true );
                binder.setExpression( field.getName() );
                binder.setVariable( descr.getExpression() );
                buildRuleBindings( context,
                                   patternDescr,
                                   pattern,
                                   binder );
            } else {
                // create a constraint
                build( context,
                       patternDescr,
                       pattern,
                       descr,
                       field.getName() + " == " + descr.getExpression() );
            }
        }
    }
View Full Code Here

Examples of org.drools.core.factmodel.FieldDefinition

        }

        for (Field fld : fields) {
            Position pos = fld.getAnnotation(Position.class);
            if (pos != null) {
                FieldDefinition fldDef = clsDef.getField(fld.getName());
                if (fldDef == null) {
                    fldDef = new FieldDefinition(fld.getName(), fld.getType().getName());
                }
                fldDef.setIndex(pos.value());
                orderedFields.set(pos.value(), fldDef);
            }
        }
        for (FieldDefinition fld : orderedFields) {
            if (fld != null) {
View Full Code Here

Examples of org.drools.core.factmodel.FieldDefinition

                    continue;
                }
                if (!inspector.isNonGetter(fieldName) && setters.keySet().contains(fieldName)) {

                    Class ret = methods.get(fieldName).getReturnType();
                    FieldDefinition field = new FieldDefinition();
                    field.setName(fieldName);
                    field.setTypeName(ret.getName());
                    field.setIndex(j++);
                    type.getTypeClassDef().addField(field);
                }
            }

            Set<String> interfaces = new HashSet<String>();
View Full Code Here

Examples of org.drools.core.factmodel.FieldDefinition

        if (!typeDescr.getFields().isEmpty()) {
            PriorityQueue<FieldDefinition> fieldDefs = sortFields(typeDescr.getFields(),
                    pkgRegistry);
            int n = fieldDefs.size();
            for (int k = 0; k < n; k++) {
                FieldDefinition fld = fieldDefs.poll();
                if (unresolvedTypeDefinitions != null) {
                    for (TypeDefinition typeDef : unresolvedTypeDefinitions) {
                        if (fld.getTypeName().equals(typeDef.getTypeClassName())) {
                            fld.setRecursive(true);
                            break;
                        }
                    }
                }
                fld.setIndex(k);
                def.addField(fld);
            }
        }

        // check whether it is necessary to build the class or not
View Full Code Here

Examples of org.drools.core.factmodel.FieldDefinition

                    typeNameKey = typeName.substring( 0, arrayIndex );
                }

                String fullFieldType = generatedTypes.contains( typeNameKey ) ? BuildUtils.resolveDeclaredType( typeName ) : pkgRegistry.getTypeResolver().resolveType(typeName).getName();

                FieldDefinition fieldDef = new FieldDefinition(field.getFieldName(),
                        fullFieldType);
                // field is marked as PK
                boolean isKey = field.getAnnotation(TypeDeclaration.ATTR_KEY) != null;
                fieldDef.setKey(isKey);

                fieldDef.setDeclIndex(field.getIndex());
                if (field.getIndex() < 0) {
                    int freePos = occupiedPositions.nextClearBit(0);
                    if (freePos < maxDeclaredPos) {
                        occupiedPositions.set(freePos);
                    } else {
                        freePos = maxDeclaredPos + 1;
                    }
                    fieldDef.setPriority(freePos * 256 + curr++);
                } else {
                    fieldDef.setPriority(field.getIndex() * 256 + curr++);
                }
                fieldDef.setInherited(field.isInherited());
                fieldDef.setInitExpr(field.getInitExpr());

                for (String annotationName : field.getAnnotationNames()) {
                    Class annotation = resolveAnnotation(annotationName,
                            pkgRegistry.getTypeResolver());
                    if (annotation != null && annotation.isAnnotation() ) {
                        try {
                            AnnotationDefinition annotationDefinition = AnnotationDefinition.build(annotation,
                                    field.getAnnotations().get(annotationName).getValueMap(),
                                    pkgRegistry.getTypeResolver());
                            fieldDef.addAnnotation(annotationDefinition);
                        } catch (NoSuchMethodException nsme) {
                            this.results.add(new TypeDeclarationError(field,
                                    "Annotated field " + field.getFieldName() +
                                            "  - undefined property in @annotation " +
                                            annotationName + ": " + nsme.getMessage() + ";"));
                        }
                    }
                    if (annotation == null || annotation == Key.class || annotation == Position.class) {
                        fieldDef.addMetaData(annotationName, field.getAnnotation(annotationName).getSingleValue());
                    }
                }

                queue.add(fieldDef);
            } catch (ClassNotFoundException cnfe) {
View Full Code Here

Examples of org.drools.core.factmodel.FieldDefinition

            return;
        }

        //add the missing fields (if any) to newDeclaration
        for (FieldDefinition oldFactField : oldDeclaration.getTypeClassDef().getFieldsDefinitions()) {
            FieldDefinition newFactField = newDeclaration.getTypeClassDef().getField(oldFactField.getName());
            if (newFactField == null) {
                newDeclaration.getTypeClassDef().addField(oldFactField);
            }
        }
View Full Code Here

Examples of org.drools.core.factmodel.FieldDefinition

                    continue;
                }
                if ( !inspector.isNonGetter( fieldName ) && setters.keySet().contains( fieldName ) ) {

                    Class ret = methods.get( fieldName ).getReturnType();
                    FieldDefinition field = new FieldDefinition();
                    field.setName( fieldName );
                    field.setTypeName( ret.getName() );
                    field.setIndex( j++ );
                    type.getTypeClassDef().addField( field );
                }
            }

            Set<String> interfaces = new HashSet<String>();
View Full Code Here

Examples of org.drools.core.factmodel.FieldDefinition

        // Fields are SORTED in the process
        if ( !typeDescr.getFields().isEmpty() ) {
            PriorityQueue<FieldDefinition> fieldDefs = sortFields( typeDescr.getFields(),
                                                                   pkgRegistry );
            while ( !fieldDefs.isEmpty() ) {
                FieldDefinition fld = fieldDefs.poll();
                if ( unresolvedTypeDefinitions != null ) {
                    for ( TypeDefinition typeDef : unresolvedTypeDefinitions ) {
                        if ( fld.getTypeName().equals( typeDef.getTypeClassName() ) ) {
                            fld.setRecursive( true );
                            break;
                        }
                    }
                }
                def.addField( fld );
View Full Code Here

Examples of org.drools.core.factmodel.FieldDefinition

            try {
                String typeName = field.getPattern().getObjectType();
                String fullFieldType = generatedTypes.contains( typeName ) ? typeName : pkgRegistry.getTypeResolver().resolveType( typeName ).getName();

                FieldDefinition fieldDef = new FieldDefinition( field.getFieldName(),
                                                                fullFieldType );
                // field is marked as PK
                boolean isKey = field.getAnnotation( TypeDeclaration.ATTR_KEY ) != null;
                fieldDef.setKey( isKey );

                fieldDef.setIndex( field.getIndex() );
                fieldDef.setInherited( field.isInherited() );
                fieldDef.setInitExpr( field.getInitExpr() );

                for ( String annotationName : field.getAnnotationNames() ) {
                    Class annotation = resolveAnnotation( annotationName,
                                                          pkgRegistry.getTypeResolver() );
                    if ( annotation != null ) {
                        try {
                            AnnotationDefinition annotationDefinition = AnnotationDefinition.build( annotation,
                                                                                                    field.getAnnotations().get( annotationName ).getValueMap(),
                                                                                                    pkgRegistry.getTypeResolver() );
                            fieldDef.addAnnotation( annotationDefinition );
                        } catch ( NoSuchMethodException nsme ) {
                            this.results.add( new TypeDeclarationError( field,
                                                                        "Annotated field " + field.getFieldName() +
                                                                                "  - undefined property in @annotation " +
                                                                                annotationName + ": " + nsme.getMessage() + ";" ) );
                        }
                    }
                    if (annotation == null || annotation == Key.class || annotation == Position.class) {
                        fieldDef.addMetaData( annotationName, field.getAnnotation( annotationName ).getSingleValue() );
                    }
                }

                queue.add( fieldDef );
            } catch ( ClassNotFoundException cnfe ) {
View Full Code Here

Examples of org.drools.core.factmodel.FieldDefinition

            return;
        }

        //add the missing fields (if any) to newDeclaration
        for ( FieldDefinition oldFactField : oldDeclaration.getTypeClassDef().getFieldsDefinitions() ) {
            FieldDefinition newFactField = newDeclaration.getTypeClassDef().getField( oldFactField.getName() );
            if ( newFactField == null ) {
                newDeclaration.getTypeClassDef().addField( oldFactField );
            }
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.