Package org.drools.spi

Examples of org.drools.spi.Constraint$ConstraintType


        //  column3 : Column(name == "column3")
        //  exists StringCell(row == r, column == column3, value == "xyz")
        assertEquals(7, lhs.getChildren().size());
        org.drools.rule.Pattern pattern = (org.drools.rule.Pattern) lhs.getChildren().get(1);
        assertEquals(1, pattern.getConstraints().size());
        Constraint constraint = pattern.getConstraints().get(0);
        GroupElement exists = (GroupElement) lhs.getChildren().get(2);
        pattern = (org.drools.rule.Pattern) exists.getChildren().get(0);
        assertEquals(3, pattern.getConstraints().size());
        IndexableConstraint vconstraint = (IndexableConstraint)pattern.getConstraints().get(1);
        assertEquals(Column.class, vconstraint.getFieldIndex().getExtractor().getExtractToClass());
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, vtype, field, expr, value1, operator, value2, extractor, restrictionDescr);
                if (constraint != null) {
                    pattern.addConstraint(constraint);
                    return true;
                }
            }
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 ( this.indexed >= 0 ) {
            LinkedListEntry entry = (LinkedListEntry) this.constraints.getFirst();
            final List list = new ArrayList();

            for ( int pos = 0; pos <= this.indexed; pos++ ) {
                final Constraint constraint = (Constraint) entry.getObject();
                final IndexableConstraint indexableConstraint = (IndexableConstraint) constraint;
                final FieldIndex index = indexableConstraint.getFieldIndex();
                list.add( index );
                entry = (LinkedListEntry) entry.getNext();
            }
View Full Code Here

            if ( object instanceof Declaration ) {
                // nothing to be done
                continue;
            }

            final Constraint constraint = (Constraint) object;
            if ( constraint.getType().equals( Constraint.ConstraintType.ALPHA ) ) {
                alphaConstraints.add( (AlphaNodeFieldConstraint) constraint );
            } else if ( constraint.getType().equals( Constraint.ConstraintType.BETA ) ) {
                betaConstraints.add( (BetaNodeFieldConstraint) constraint );
                if ( isNegative && context.getRuleBase().getConfiguration().getEventProcessingMode() == EventProcessingOption.STREAM && pattern.getObjectType().isEvent() && constraint.isTemporal() ) {
                    checkDelaying( context,
                                   constraint );
                }
            } else {
                throw new RuntimeDroolsException( "Unknown constraint type: " + constraint.getType() + ". This is a bug. Please contact development team." );
            }
        }
    }
View Full Code Here

        builder1.addPackage( packageDescr1 );
        if ( builder1.hasErrors() ) {
            fail( builder1.getErrors().toString() );
        }
        final Pattern pattern1 = (Pattern) builder1.getPackage().getRules()[0].getLhs().getChildren().get( 0 );
        final Constraint returnValue1 = pattern1.getConstraints().get( 0 );

        final PackageBuilder builder2 = new PackageBuilder();
        final PackageDescr packageDescr2 = new PackageDescr( "package2" );
        createReturnValueRule( packageDescr2,
                               " x + y " );
        builder2.addPackage( packageDescr2 );
        final Pattern pattern2 = (Pattern) builder2.getPackage().getRules()[0].getLhs().getChildren().get( 0 );
        final Constraint returnValue2 = pattern2.getConstraints().get( 0 );

        final PackageBuilder builder3 = new PackageBuilder();
        final PackageDescr packageDescr3 = new PackageDescr( "package3" );
        createReturnValueRule( packageDescr3,
                               " x - y " );
        builder3.addPackage( packageDescr3 );
        final Pattern pattern3 = (Pattern) builder3.getPackage().getRules()[0].getLhs().getChildren().get( 0 );
        final Constraint returnValue3 = pattern3.getConstraints().get( 0 );

        assertEquals( returnValue1,
                      returnValue2 );
        assertFalse( returnValue1.equals( returnValue3 ) );
        assertFalse( returnValue2.equals( returnValue3 ) );
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,
                                                (LiteralRestriction) restriction );
            registerReadAccessor( context,
                                  pattern.getObjectType(),
                                  fieldName,
                                  (LiteralConstraint) constraint );
            registerReadAccessor( context,
                                  pattern.getObjectType(),
                                  fieldName,
                                  (LiteralRestriction) restriction );
        } else if ( restriction instanceof VariableRestriction ||  restriction instanceof UnificationRestriction ) {
            constraint = new VariableConstraint( extractor,
                                                 restriction );
            registerReadAccessor( context,
                                  pattern.getObjectType(),
                                  fieldName,
                                  (AcceptsReadAccessor) restriction );
            registerReadAccessor( context,
                                  pattern.getObjectType(),
                                  fieldName,
                                  (AcceptsReadAccessor) restriction );
        } else if ( restriction instanceof ReturnValueRestriction ) {
            constraint = new ReturnValueConstraint( extractor,
                                                    (ReturnValueRestriction) restriction );
            registerReadAccessor( context,
                                  pattern.getObjectType(),
                                  fieldName,
                                  (ReturnValueConstraint) constraint );
            registerReadAccessor( context,
                                  pattern.getObjectType(),
                                  fieldName,
                                  (ReturnValueRestriction) restriction );
        } else {
            context.getErrors().add( new DescrBuildError( context.getParentDescr(),
                                                          fieldConstraintDescr,
                                                          null,
                                                          "This is a bug: Unkown restriction type '" + restriction.getClass() + "' for pattern '" + pattern.getObjectType().toString() + "' in rule '" + context.getRule().getName() + "'" ) );
        }

        if ( container == null ) {
            pattern.addConstraint( constraint );
        } else {
            if ( constraint.getType().equals( Constraint.ConstraintType.UNKNOWN ) ) {
                this.setConstraintType( pattern,
                                        (MutableTypeConstraint) constraint );
            }
            container.addConstraint( constraint );
        }
View Full Code Here

        Rule rule2 = ((KnowledgePackageImp)pkg2).pkg.getRule( "rule1" );
        Rule rule3 = ((KnowledgePackageImp)pkg3).pkg.getRule( "rule1" );
       
        // test return value
        Pattern p1 = ( Pattern ) rule1.getLhs().getChildren().get( 0 );
        Constraint rvc1 = p1.getConstraints().get( 0 );
       
        Pattern p2 = ( Pattern ) rule2.getLhs().getChildren().get( 0 );       
        Constraint rvc2 = p2.getConstraints().get( 0 );
       
        assertNotSame( rvc1, rvc2 );
        assertEquals( rvc1, rvc2 );
       
        Pattern p3 = ( Pattern ) rule3.getLhs().getChildren().get( 0 );
        Constraint rvc3 = p3.getConstraints().get( 0 );
       
        assertNotSame( rvc1, rvc3 );
        assertThat(rvc1, not( equalTo( rvc3 ) ) );
       
        // test inline eval
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,
                                                (LiteralRestriction) restriction );
            registerReadAccessor( context,
                                  pattern.getObjectType(),
                                  fieldName,
                                  ( LiteralConstraint ) constraint );           
            registerReadAccessor( context,
                                  pattern.getObjectType(),
                                  fieldName,
                                  (LiteralRestriction) restriction );
        } else if ( restriction instanceof VariableRestriction ) {
            constraint = new VariableConstraint( extractor,
                                                 (VariableRestriction) restriction );
            registerReadAccessor( context,
                                  pattern.getObjectType(),
                                  fieldName,
                                  (VariableRestriction) restriction );           
            registerReadAccessor( context,
                                  pattern.getObjectType(),
                                  fieldName,
                                  (VariableRestriction) restriction );
        } else if ( restriction instanceof ReturnValueRestriction ) {
            constraint = new ReturnValueConstraint( extractor,
                                                    (ReturnValueRestriction) restriction );
            registerReadAccessor( context,
                                  pattern.getObjectType(),
                                  fieldName,
                                  (ReturnValueConstraint) constraint );           
            registerReadAccessor( context,
                                  pattern.getObjectType(),
                                  fieldName,
                                  (ReturnValueRestriction) restriction );
        } else {
            context.getErrors().add( new DescrBuildError( context.getParentDescr(),
                                                          fieldConstraintDescr,
                                                          null,
                                                          "This is a bug: Unkown restriction type '" + restriction.getClass() + "' for pattern '" + pattern.getObjectType().toString() + "' in rule '" + context.getRule().getName() + "'" ) );
        }

        if ( container == null ) {
            pattern.addConstraint( constraint );
        } else {
            if ( constraint.getType().equals( Constraint.ConstraintType.UNKNOWN ) ) {
                this.setConstraintType( pattern,
                                        (MutableTypeConstraint) constraint );
            }
            container.addConstraint( constraint );
        }
View Full Code Here

            if ( constr instanceof Declaration ) {
                final Declaration decl = (Declaration) constr;
                clone.addDeclaration( decl.getIdentifier(),
                                      decl.getExtractor() );
            } else {
                Constraint constraint = (Constraint) ((Constraint) constr).clone();
               
                // we must update pattern references in cloned declarations
                Declaration[] oldDecl = ((Constraint) 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

TOP

Related Classes of org.drools.spi.Constraint$ConstraintType

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.