Package org.drools.spi

Examples of org.drools.spi.Constraint


            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 ( resolved != null && resolved != decl[i] ) {
                        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


            final Object constr = it.next();
            if ( constr instanceof Declaration ) {
                final Declaration decl = (Declaration) constr;
                clone.addDeclaration( decl.getIdentifier() ).setReadAccessor( 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

            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() );
                        }
                    }                   
                   
                    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 ( object instanceof Declaration ) {
                // nothing to be done
                continue;
            }

            final Constraint constraint = (Constraint) object;
            if ( constraint.getType().equals( Constraint.ConstraintType.ALPHA ) ) {
                alphaConstraints.add( constraint );
            } else if ( constraint.getType().equals( Constraint.ConstraintType.BETA ) ) {
                betaConstraints.add( 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

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

            final Constraint constraint = (Constraint) object;
            if ( constraint.getType().equals( Constraint.ConstraintType.ALPHA ) ) {
                alphaConstraints.add( constraint );
            } else if ( constraint.getType().equals( Constraint.ConstraintType.BETA ) ) {
                utils.checkUnboundDeclarations( context,
                                                constraint.getRequiredDeclarations() );
                betaConstraints.add( constraint );
            } else {
                throw new RuntimeDroolsException( "Unknown constraint type: "+constraint.getType()+". This is a bug. Please contact development team.");
            }
        }
    }
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 VariableConstraint variableConstraint = (VariableConstraint) constraint;
                final FieldIndex index = new FieldIndex( variableConstraint.getFieldExtractor(),
                                                         variableConstraint.getRequiredDeclarations()[0],
                                                         variableConstraint.getEvaluator() );
                list.add( index );
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( decl[i].getIdentifier() );
                    if ( resolved != null && resolved != decl[i] ) {
                        constraint.replaceDeclaration( decl[i],
                                                       resolved );
                    }
                }
            }
        } else if ( element instanceof EvalCondition ) {
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

            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

        if ( this.indexed >= 0 ) {
            LinkedListEntry entry = (LinkedListEntry) this.constraints.getFirst();
            final List<FieldIndex> list = new ArrayList<FieldIndex>();

            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

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.