Search in sources :

Example 1 with PredicateDescr

use of org.drools.compiler.lang.descr.PredicateDescr in project drools by kiegroup.

the class MVELConstraintBuilder method buildCompilationUnit.

public MVELCompilationUnit buildCompilationUnit(RuleBuildContext context, Pattern pattern, String expression, Map<String, OperatorDescr> aliases) {
    Dialect dialect = context.getDialect();
    context.setDialect(context.getDialect("mvel"));
    try {
        PredicateDescr predicateDescr = new PredicateDescr(context.getRuleDescr().getResource(), expression);
        AnalysisResult analysis = buildAnalysis(context, pattern, predicateDescr, aliases);
        if (analysis == null) {
            // something bad happened
            return null;
        }
        Declaration[][] usedDeclarations = getUsedDeclarations(context, pattern, analysis);
        return buildCompilationUnit(context, usedDeclarations[0], usedDeclarations[1], predicateDescr, analysis);
    } finally {
        context.setDialect(dialect);
    }
}
Also used : MVELDialect(org.drools.compiler.rule.builder.dialect.mvel.MVELDialect) Dialect(org.drools.compiler.compiler.Dialect) PredicateDescr(org.drools.compiler.lang.descr.PredicateDescr) MVELAnalysisResult(org.drools.compiler.rule.builder.dialect.mvel.MVELAnalysisResult) AnalysisResult(org.drools.compiler.compiler.AnalysisResult)

Example 2 with PredicateDescr

use of org.drools.compiler.lang.descr.PredicateDescr in project drools by kiegroup.

the class PatternBuilder method processAtomicExpression.

protected Constraint processAtomicExpression(RuleBuildContext context, Pattern pattern, BaseDescr d, String expr, Map<String, OperatorDescr> aliases) {
    if (d instanceof AtomicExprDescr) {
        Matcher m = evalRegexp.matcher(((AtomicExprDescr) d).getExpression());
        if (m.find()) {
            // MVELDumper already stripped the eval
            // this will build the eval using the specified dialect
            PredicateDescr pdescr = new PredicateDescr(context.getRuleDescr().getResource(), expr);
            pdescr.copyLocation(d);
            return buildEval(context, pattern, pdescr, aliases, expr, true);
        }
    }
    return null;
}
Also used : Matcher(java.util.regex.Matcher) AtomicExprDescr(org.drools.compiler.lang.descr.AtomicExprDescr) PredicateDescr(org.drools.compiler.lang.descr.PredicateDescr)

Example 3 with PredicateDescr

use of org.drools.compiler.lang.descr.PredicateDescr in project drools by kiegroup.

the class PatternBuilder method createAndBuildPredicate.

protected Constraint createAndBuildPredicate(RuleBuildContext context, Pattern pattern, BaseDescr base, String expr, Map<String, OperatorDescr> aliases) {
    Dialect dialect = context.getDialect();
    MVELDialect mvelDialect = (MVELDialect) context.getDialect("mvel");
    context.setDialect(mvelDialect);
    PredicateDescr pdescr = new PredicateDescr(context.getRuleDescr().getResource(), expr);
    pdescr.copyParameters(base);
    pdescr.copyLocation(base);
    Constraint evalConstraint = buildEval(context, pattern, pdescr, aliases, expr, false);
    // fall back to original dialect
    context.setDialect(dialect);
    return evalConstraint;
}
Also used : XpathConstraint(org.drools.core.rule.constraint.XpathConstraint) NegConstraint(org.drools.core.rule.constraint.NegConstraint) Constraint(org.drools.core.spi.Constraint) MvelConstraint(org.drools.core.rule.constraint.MvelConstraint) EvaluatorConstraint(org.drools.core.rule.constraint.EvaluatorConstraint) PredicateConstraint(org.drools.core.rule.PredicateConstraint) Dialect(org.drools.compiler.compiler.Dialect) MVELDialect(org.drools.compiler.rule.builder.dialect.mvel.MVELDialect) JavaDialect(org.drools.compiler.rule.builder.dialect.java.JavaDialect) MVELDialect(org.drools.compiler.rule.builder.dialect.mvel.MVELDialect) PredicateDescr(org.drools.compiler.lang.descr.PredicateDescr)

Example 4 with PredicateDescr

use of org.drools.compiler.lang.descr.PredicateDescr in project drools by kiegroup.

the class AbstractASMEvalBuilder method build.

public RuleConditionElement build(RuleBuildContext context, BaseDescr descr, Pattern prefixPattern) {
    if (prefixPattern == null) {
        return build(context, descr);
    }
    EvalDescr evalDescr = (EvalDescr) descr;
    PredicateDescr predicateDescr = new PredicateDescr(context.getRuleDescr().getResource(), evalDescr.getContent());
    AnalysisResult analysis = buildAnalysis(context, prefixPattern, predicateDescr, null);
    Declaration[] declarations = getUsedDeclarations(context, prefixPattern, analysis);
    return buildEval(context, evalDescr, analysis, declarations);
}
Also used : EvalDescr(org.drools.compiler.lang.descr.EvalDescr) Declaration(org.drools.core.rule.Declaration) PredicateDescr(org.drools.compiler.lang.descr.PredicateDescr) AnalysisResult(org.drools.compiler.compiler.AnalysisResult)

Aggregations

PredicateDescr (org.drools.compiler.lang.descr.PredicateDescr)4 AnalysisResult (org.drools.compiler.compiler.AnalysisResult)2 Dialect (org.drools.compiler.compiler.Dialect)2 MVELDialect (org.drools.compiler.rule.builder.dialect.mvel.MVELDialect)2 Matcher (java.util.regex.Matcher)1 AtomicExprDescr (org.drools.compiler.lang.descr.AtomicExprDescr)1 EvalDescr (org.drools.compiler.lang.descr.EvalDescr)1 JavaDialect (org.drools.compiler.rule.builder.dialect.java.JavaDialect)1 MVELAnalysisResult (org.drools.compiler.rule.builder.dialect.mvel.MVELAnalysisResult)1 Declaration (org.drools.core.rule.Declaration)1 PredicateConstraint (org.drools.core.rule.PredicateConstraint)1 EvaluatorConstraint (org.drools.core.rule.constraint.EvaluatorConstraint)1 MvelConstraint (org.drools.core.rule.constraint.MvelConstraint)1 NegConstraint (org.drools.core.rule.constraint.NegConstraint)1 XpathConstraint (org.drools.core.rule.constraint.XpathConstraint)1 Constraint (org.drools.core.spi.Constraint)1