*/
public RuleConditionElement build(final RuleBuildContext context,
final BaseDescr descr,
final Pattern prefixPattern) {
// it must be an EvalDescr
final EvalDescr evalDescr = (EvalDescr) descr;
try {
MVELDialect dialect = (MVELDialect) context.getDialect( context.getDialect().getId() );
Dialect.AnalysisResult analysis = context.getDialect().analyzeExpression( context,
evalDescr,
evalDescr.getContent(),
new Set[]{context.getDeclarationResolver().getDeclarations(context.getRule()).keySet(), context.getPkg().getGlobals().keySet()} );
Declaration[] previousDeclarations = (Declaration[]) context.getDeclarationResolver().getDeclarations(context.getRule()).values().toArray( new Declaration[context.getDeclarationResolver().getDeclarations(context.getRule()).size()] );
MVELCompilationUnit unit = dialect.getMVELCompilationUnit( (String) evalDescr.getContent(),
analysis,
previousDeclarations,
null,
null,
context );
final EvalCondition eval = new EvalCondition( previousDeclarations );
MVELEvalExpression expr = new MVELEvalExpression( unit,
dialect.getId() );
eval.setEvalExpression( expr );
MVELDialectRuntimeData data = (MVELDialectRuntimeData) context.getPkg().getDialectRuntimeRegistry().getDialectData( context.getDialect().getId() );
data.addCompileable( eval,
expr );
expr.compile( context.getPackageBuilder().getRootClassLoader() );
return eval;
} catch ( final Exception e ) {
context.getErrors().add( new DescrBuildError( context.getParentDescr(),
evalDescr,
e,
"Unable to build expression for 'eval':" + e.getMessage() + " '" + evalDescr.getContent() + "'" ) );
return null;
}
}