Package org.drools.spi

Examples of org.drools.spi.Constraint


    public long getListenedPropertyMask(List<String> settableProperties) {
        long mask = 0L;
        LinkedListEntry entry = (LinkedListEntry) constraints.getFirst();
        while ( entry != null ) {
            final Constraint constraint = (Constraint) entry.getObject();
            entry = (LinkedListEntry) entry.getNext();
            if (constraint instanceof MvelConstraint) {
                mask |= ((MvelConstraint)constraint).getListenedPropertyMask(settableProperties);
            } else {
                return Long.MAX_VALUE;
View Full Code Here


            for ( Iterator it = pattern.getConstraints().iterator(); it.hasNext(); ) {
                Object next = it.next();
                if ( next instanceof Declaration ) {
                    continue;
                }
                Constraint constraint = (Constraint) next;
                Declaration[] decl = constraint.getRequiredDeclarations();
                for ( int i = 0; i < decl.length; i++ ) {
                    Declaration resolved = resolver.getDeclaration( null,
                                                                    decl[i].getIdentifier() );
                   
                    if ( constraint instanceof VariableConstraint && ((VariableConstraint)constraint).getRestriction() instanceof UnificationRestriction ) {
                        UnificationRestriction restriction = ( UnificationRestriction ) ((VariableConstraint)constraint).getRestriction();
                        if( ClassObjectType.DroolsQuery_ObjectType.isAssignableFrom( resolved.getPattern().getObjectType() ) ) {
                            // if the resolved still points to DroolsQuery, we know this is the first unification pattern, so redeclare it as the visible Declaration
                            Declaration redeclaredDeclr = new Declaration(resolved.getIdentifier(), restriction.getVariableRestriction().getReadAccessor(), pattern, false );
                            pattern.addDeclarationredeclaredDeclr );
                        } else if ( resolved.getPattern() != pattern ) {
                            // It's a subsequent unification, so it should be able to use the redeclared Declaration as a normal VariableRestriction.
                            // but only rewrite if the resolved declaration is not for current pattern (this occurs if LogicTransformer is applied twice
                            // to the same tree that has already been rewritten before.
                            ((VariableConstraint)constraint).setRestriction( restriction.getVariableRestriction() );
                        }
                    } else if (constraint instanceof MvelConstraint && ((MvelConstraint)constraint).isUnification()) {
                        if( ClassObjectType.DroolsQuery_ObjectType.isAssignableFrom( resolved.getPattern().getObjectType() ) ) {
                            Declaration redeclaredDeclr = new Declaration(resolved.getIdentifier(), ((MvelConstraint)constraint).getFieldExtractor(), pattern, false );
                            pattern.addDeclaration(redeclaredDeclr);
                        } else {
                            ((MvelConstraint)constraint).unsetUnification();
                        }
                    }
                   
                    if ( resolved != null && resolved != decl[i] && resolved.getPattern() != pattern ) {
                        constraint.replaceDeclaration( decl[i],
                                                       resolved );
                    } else if ( resolved == null ) {
                        // it is probably an implicit declaration, so find the corresponding pattern
                        Pattern old = decl[i].getPattern();
                        Pattern current = resolver.findPatternByIndex( old.getIndex() );
                        if ( current != null && old != current ) {
                            resolved = new Declaration( decl[i].getIdentifier(),
                                                        decl[i].getExtractor(),
                                                        current );
                            constraint.replaceDeclaration( decl[i],
                                                           resolved );
                        }
                    }
                }
            }
View Full Code Here

        if ( restriction == null ) {
            // error was already logged during restriction creation failure
            return;
        }

        Constraint constraint = null;
        if ( restriction instanceof AbstractCompositeRestriction ) {
            constraint = new MultiRestrictionFieldConstraint( extractor,
                                                              restriction );
        } else if ( restriction instanceof LiteralRestriction ) {
            constraint = new LiteralConstraint( extractor,
View Full Code Here

        }

        String expression = expressionBuilder.toString();
        MVELCompilationUnit compilationUnit = getConstraintBuilder( context ).buildCompilationUnit(context, pattern, expression, mvelCtx.getAliases());

        Constraint combinedConstraint = getConstraintBuilder( context ).buildMvelConstraint( packageName,
                                                                                             expression,
                                                                                             declarations.toArray(new Declaration[declarations.size()]),
                                                                                             compilationUnit,
                                                                                             IndexUtil.ConstraintType.UNKNOWN,
                                                                                             null, null, false );
View Full Code Here

        LiteralRestrictionDescr restrictionDescr = buildLiteralRestrictionDescr(context, relDescr, value2, operator, isConstant);

        if (restrictionDescr != null) {
            FieldValue field = getFieldValue(context, vtype, restrictionDescr);
            if (field != null) {
                Constraint constraint = getConstraintBuilder( context ).buildLiteralConstraint(context, pattern, vtype, field, expr, value1, operator, value2, extractor, restrictionDescr);
                if (constraint != null) {
                    pattern.addConstraint(constraint);
                    return true;
                }
            }
View Full Code Here

            boolean isDynamic = requiredOperators.length > 0 ||
                    ClassObjectType.Activation_ObjectType.isAssignableFrom( pattern.getObjectType()) ||
                    (!((ClassObjectType)pattern.getObjectType()).getClassType().isArray() &&
                    !context.getPackageBuilder().getTypeDeclaration(((ClassObjectType)pattern.getObjectType()).getClassType()).isTypesafe());

            Constraint constraint = getConstraintBuilder( context ).buildMvelConstraint( context.getPkg().getName(), expr, mvelDeclarations, compilationUnit, isDynamic );
            pattern.addConstraint( constraint );
        }
    }
View Full Code Here

        if ( restriction == null ) {
            // error was already logged during restriction creation failure
            return;
        }

        Constraint constraint = null;
        if ( restriction instanceof AbstractCompositeRestriction ) {
            constraint = new MultiRestrictionFieldConstraint( extractor,
                                                              restriction );
        } else if ( restriction instanceof LiteralRestriction ) {
            constraint = new LiteralConstraint( extractor,
View Full Code Here

                addedDeclaration.setBindingName( decl.getBindingName() );
            }
        }

        for ( Constraint constr : this.constraints ) {
            Constraint constraint = constr.clone();

            // we must update pattern references in cloned declarations
            Declaration[] oldDecl = constr.getRequiredDeclarations();
            Declaration[] newDecl = constraint.getRequiredDeclarations();
            for ( int i = 0; i < newDecl.length; i++ ) {
                if ( newDecl[i].getPattern() == this ) {
                    newDecl[i].setPattern( clone );
                    // we still need to call replace because there might be nested declarations to replace
                    constraint.replaceDeclaration( oldDecl[i],
                                                   newDecl[i] );
                }
            }

            clone.addConstraint(constraint);
View Full Code Here

        LiteralRestrictionDescr restrictionDescr = buildLiteralRestrictionDescr(context, relDescr, value2, operator, isConstant);

        if (restrictionDescr != null) {
            FieldValue field = getFieldValue(context, vtype, restrictionDescr);
            if (field != null) {
                Constraint constraint = buildLiteralConstraint(context, pattern, vtype, field, expr, value1, operator, value2, extractor, restrictionDescr);
                if (constraint != null) {
                    pattern.addConstraint(constraint);
                    return true;
                }
            }
View Full Code Here

            boolean isDynamic = requiredOperators.length > 0 ||
                    ClassObjectType.Activation_ObjectType.isAssignableFrom( pattern.getObjectType()) ||
                    (!((ClassObjectType)pattern.getObjectType()).getClassType().isArray() &&
                    !context.getPackageBuilder().getTypeDeclaration(((ClassObjectType)pattern.getObjectType()).getClassType()).isTypesafe());

            Constraint constraint = new MvelConstraint(context.getPkg().getName(), expr, mvelDeclarations, compilationUnit, isDynamic);
            pattern.addConstraint( constraint );
        }
    }
View Full Code Here

TOP

Related Classes of org.drools.spi.Constraint

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.