Search in sources :

Example 1 with MVELReturnValueExpression

use of org.drools.core.base.mvel.MVELReturnValueExpression in project drools by kiegroup.

the class MVELReturnValueBuilder method build.

public void build(final RuleBuildContext context, final BoundIdentifiers usedIdentifiers, final Declaration[] previousDeclarations, final Declaration[] localDeclarations, final ReturnValueRestriction returnValueRestriction, final ReturnValueRestrictionDescr returnValueRestrictionDescr, final AnalysisResult analysis) {
    boolean typesafe = context.isTypesafe();
    try {
        MVELDialect dialect = (MVELDialect) context.getDialect("mvel");
        context.setTypesafe(((MVELAnalysisResult) analysis).isTypesafe());
        MVELCompilationUnit unit = dialect.getMVELCompilationUnit((String) returnValueRestrictionDescr.getContent(), analysis, previousDeclarations, localDeclarations, null, context, "drools", KnowledgeHelper.class, false, MVELCompilationUnit.Scope.EXPRESSION);
        MVELReturnValueExpression expr = new MVELReturnValueExpression(unit, context.getDialect().getId());
        returnValueRestriction.setReturnValueExpression(expr);
        MVELDialectRuntimeData data = (MVELDialectRuntimeData) context.getPkg().getDialectRuntimeRegistry().getDialectData("mvel");
        data.addCompileable(returnValueRestriction, expr);
        expr.compile(data, context.getRule());
    } catch (final Exception e) {
        DialectUtil.copyErrorLocation(e, context.getRuleDescr());
        context.addError(new DescrBuildError(context.getParentDescr(), context.getRuleDescr(), null, "Unable to build expression for 'returnValue' : " + e.getMessage() + "'" + context.getRuleDescr().getSalience() + "'"));
    } finally {
        context.setTypesafe(typesafe);
    }
}
Also used : MVELDialectRuntimeData(org.drools.core.rule.MVELDialectRuntimeData) MVELReturnValueExpression(org.drools.core.base.mvel.MVELReturnValueExpression) DescrBuildError(org.drools.compiler.compiler.DescrBuildError) MVELCompilationUnit(org.drools.core.base.mvel.MVELCompilationUnit)

Aggregations

DescrBuildError (org.drools.compiler.compiler.DescrBuildError)1 MVELCompilationUnit (org.drools.core.base.mvel.MVELCompilationUnit)1 MVELReturnValueExpression (org.drools.core.base.mvel.MVELReturnValueExpression)1 MVELDialectRuntimeData (org.drools.core.rule.MVELDialectRuntimeData)1