Package org.drools.factmodel

Examples of org.drools.factmodel.FieldDefinition


        aliases = new HashMap<String, FieldDefinition>();
        for ( FieldDefinition tfld : trait.getFieldsDefinitions() ) {
            if ( tfld.hasAlias() ) {
                String alias = tfld.getAlias();
                FieldDefinition coreField = core.getField( alias );
                if ( coreField != null ) {
                    aliases.put( tfld.getName(), coreField );
                }
            }
        }
View Full Code Here


    private void bindAccessors( Class<T> proxyClass, ClassDefinition tdef, ClassDefinition cdef, long mask ) {
        int j = 0;
        for ( FieldDefinition traitField : tdef.getFieldsDefinitions() ) {
            boolean isSoftField = TraitRegistry.isSoftField( traitField, j++, mask );
            if ( ! isSoftField ) {
                FieldDefinition field = cdef.getField( traitField.resolveAlias( cdef ) );
                Field staticField;
                try {
                    staticField = proxyClass.getField( traitField.getName() + "_reader" );
                    staticField.set( null, field.getFieldAccessor().getReadAccessor() );

                    staticField = proxyClass.getField( traitField.getName() + "_writer" );
                    staticField.set( null, field.getFieldAccessor().getWriteAccessor() );
                } catch (NoSuchFieldException e) {
                    e.printStackTrace()//To change body of catch statement use File | Settings | File Templates.
                } catch (IllegalAccessException e) {
                    e.printStackTrace()//To change body of catch statement use File | Settings | File Templates.
                }
View Full Code Here

        def.setDefinedClass( wrapperClass );

        Map<String, Field> fields = inspector.getFieldTypesField();
        for ( Field f : fields.values() ) {
            if ( f != null ) {
                FieldDefinition fld = new FieldDefinition();
                fld.setName( f.getName() );
                fld.setTypeName( f.getType().getName() );
                fld.setInherited( true );
                ClassFieldAccessor accessor = store.getAccessor( def.getDefinedClass().getName(),
                        fld.getName() );
                fld.setReadWriteAccessor( accessor );

                def.addField( fld );
            }
        }
View Full Code Here

        }

        int j = 0;
        long bitmask = 0;
        for ( FactField field : traitDef.getFields() ) {
            FieldDefinition fdef = (FieldDefinition) field;
            boolean isAliased = fdef.hasAlias();
            String alias = ((FieldDefinition) field).resolveAlias( traitableDef );
           
            FieldDefinition concreteField = traitableDef.getField( alias );
            Class concreteType = concreteField != null ? concreteField.getType() : null;
            Class virtualType = field.getType();

            if ( concreteType != null
                    && concreteType.isAssignableFrom( virtualType ) ) {
                bitmask |= 1 << j;
View Full Code Here

        int j = 0;
        BitSet bitmask = new BitSet( traitDef.getFields().size() );
        for ( FactField field : traitDef.getFields() ) {
            String alias = ((FieldDefinition) field).resolveAlias();

            FieldDefinition concreteField = traitableDef.getFieldByAlias( alias );

            if ( concreteField != null ) {
                if ( ! traitableDef.isFullTraiting() && ! concreteField.getType().isAssignableFrom( field.getType() ) ) {
                    throw new UnsupportedOperationException( " Unable to apply trait " + trait + " to class " + traitable + " :" +
                                                             " trait field " + field.getName() + ":" + ( (FieldDefinition) field ).getTypeName() + " is incompatible with" +
                                                             " concrete hard field " + concreteField.getName() + ":" + concreteField.getTypeName() + ". Consider enabling logical traiting" +
                                                             " mode using @Traitable( logical = true )" );
                }

                bitmask.set( j );
            }
View Full Code Here

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

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

            // TODO: WTH is this??????
            DRLLexer lex = new DRLLexer( new ANTLRStringStream( descr.getExpression() ) );
            boolean isSimpleIdentifier = false;
            try {
                lex.mID();
                isSimpleIdentifier = lex.getCharIndex() >= descr.getExpression().length();
            } catch ( RecognitionException e ) {

            }

            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

                }

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

                    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

        // Fields are SORTED in the process
        if ( typeDescr.getFields().size() > 0 ) {
            PriorityQueue<FieldDefinition> fieldDefs = sortFields( typeDescr.getFields(),
                                                                   pkgRegistry );
            while ( fieldDefs.size() > 0 ) {
                FieldDefinition fld = fieldDefs.poll();
                def.addField( fld );
            }
        }

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

            String fullFieldType;
            try {
                fullFieldType = pkgRegistry.getTypeResolver().resolveType( field.getPattern().getObjectType() ).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( "Annotated field " + field.getFieldName() + "  - undefined property in @annotation " + annotationName + ": " + nsme.getMessage() + ";",
                                                                        field.getLine() ) );
                        }
                    }
View Full Code Here

TOP

Related Classes of org.drools.factmodel.FieldDefinition

Copyright © 2018 www.massapicom. 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.