Search in sources :

Example 1 with PatternExprImpl

use of org.drools.model.PatternDSL.PatternExprImpl in project drools by kiegroup.

the class ViewPatternBuilder method ruleItem2Condition.

private static Condition ruleItem2Condition(RuleItem ruleItem) {
    if (ruleItem instanceof PatternDefImpl) {
        PatternDefImpl<?> patternDef = (PatternDefImpl) ruleItem;
        PatternImpl pattern = new PatternImpl(patternDef.getFirstVariable());
        for (PatternItem patternItem : patternDef.getItems()) {
            if (patternItem instanceof PatternExprImpl) {
                pattern.addConstraint(((PatternExprImpl) patternItem).asConstraint(patternDef));
            } else if (patternItem instanceof PatternBindingImpl) {
                pattern.addBinding(((PatternBindingImpl) patternItem).asBinding(patternDef));
            }
        }
        pattern.addWatchedProps(patternDef.getWatch());
        return pattern;
    }
    if (ruleItem instanceof FixedValueItem) {
        return new EvalImpl(((FixedValueItem) ruleItem).isValue());
    }
    if (ruleItem instanceof QueryCallViewItem) {
        return new QueryCallPattern((QueryCallViewItem) ruleItem);
    }
    if (ruleItem instanceof CombinedExprViewItem) {
        CombinedExprViewItem combined = (CombinedExprViewItem) ruleItem;
        List<Condition> conditions = new ArrayList<>();
        for (ViewItem expr : combined.getExpressions()) {
            conditions.add(ruleItem2Condition(expr));
        }
        return new CompositePatterns(combined.getType(), conditions);
    }
    if (ruleItem instanceof ExistentialExprViewItem) {
        ExistentialExprViewItem existential = (ExistentialExprViewItem) ruleItem;
        return new ExistentialPatternImpl(ruleItem2Condition(existential.getExpression()), existential.getType());
    }
    if (ruleItem instanceof AccumulateExprViewItem) {
        AccumulateExprViewItem acc = (AccumulateExprViewItem) ruleItem;
        return new AccumulatePatternImpl(ruleItem2Condition(acc.getExpr()), acc.getAccumulateFunctions());
    }
    if (ruleItem instanceof ExprViewItem) {
        return new EvalImpl(createConstraint((ExprViewItem) ruleItem));
    }
    throw new UnsupportedOperationException("Unknown " + ruleItem);
}
Also used : Condition(org.drools.model.Condition) AccumulatePatternImpl(org.drools.model.patterns.AccumulatePatternImpl) ExistentialExprViewItem(org.drools.model.view.ExistentialExprViewItem) AccumulateExprViewItem(org.drools.model.view.AccumulateExprViewItem) CombinedExprViewItem(org.drools.model.view.CombinedExprViewItem) ExprViewItem(org.drools.model.view.ExprViewItem) ExistentialExprViewItem(org.drools.model.view.ExistentialExprViewItem) QueryCallViewItem(org.drools.model.view.QueryCallViewItem) ViewItem(org.drools.model.view.ViewItem) AccumulateExprViewItem(org.drools.model.view.AccumulateExprViewItem) CombinedExprViewItem(org.drools.model.view.CombinedExprViewItem) ExprViewItem(org.drools.model.view.ExprViewItem) CombinedExprViewItem(org.drools.model.view.CombinedExprViewItem) ExistentialPatternImpl(org.drools.model.patterns.ExistentialPatternImpl) PatternItem(org.drools.model.PatternDSL.PatternItem) ArrayList(java.util.ArrayList) FixedValueItem(org.drools.model.view.FixedValueItem) PatternExprImpl(org.drools.model.PatternDSL.PatternExprImpl) CompositePatterns(org.drools.model.patterns.CompositePatterns) PatternImpl(org.drools.model.patterns.PatternImpl) ExistentialPatternImpl(org.drools.model.patterns.ExistentialPatternImpl) AccumulatePatternImpl(org.drools.model.patterns.AccumulatePatternImpl) AccumulateExprViewItem(org.drools.model.view.AccumulateExprViewItem) EvalImpl(org.drools.model.patterns.EvalImpl) QueryCallViewItem(org.drools.model.view.QueryCallViewItem) QueryCallPattern(org.drools.model.patterns.QueryCallPattern) ExistentialExprViewItem(org.drools.model.view.ExistentialExprViewItem) PatternBindingImpl(org.drools.model.PatternDSL.PatternBindingImpl) PatternDefImpl(org.drools.model.PatternDSL.PatternDefImpl)

Aggregations

ArrayList (java.util.ArrayList)1 Condition (org.drools.model.Condition)1 PatternBindingImpl (org.drools.model.PatternDSL.PatternBindingImpl)1 PatternDefImpl (org.drools.model.PatternDSL.PatternDefImpl)1 PatternExprImpl (org.drools.model.PatternDSL.PatternExprImpl)1 PatternItem (org.drools.model.PatternDSL.PatternItem)1 AccumulatePatternImpl (org.drools.model.patterns.AccumulatePatternImpl)1 CompositePatterns (org.drools.model.patterns.CompositePatterns)1 EvalImpl (org.drools.model.patterns.EvalImpl)1 ExistentialPatternImpl (org.drools.model.patterns.ExistentialPatternImpl)1 PatternImpl (org.drools.model.patterns.PatternImpl)1 QueryCallPattern (org.drools.model.patterns.QueryCallPattern)1 AccumulateExprViewItem (org.drools.model.view.AccumulateExprViewItem)1 CombinedExprViewItem (org.drools.model.view.CombinedExprViewItem)1 ExistentialExprViewItem (org.drools.model.view.ExistentialExprViewItem)1 ExprViewItem (org.drools.model.view.ExprViewItem)1 FixedValueItem (org.drools.model.view.FixedValueItem)1 QueryCallViewItem (org.drools.model.view.QueryCallViewItem)1 ViewItem (org.drools.model.view.ViewItem)1