*/
public RuleConditionElement build(final RuleBuildContext context,
final BaseDescr descr,
final Pattern prefixPattern) {
// it must be an EvalDescr
final EvalDescr evalDescr = (EvalDescr) descr;
try {
final DroolsMVELFactory factory = new DroolsMVELFactory( context.getDeclarationResolver().getDeclarations(),
null,
context.getPkg().getGlobals() );
factory.setNextFactory( ((MVELDialect) context.getDialect()).getStaticMethodImportResolverFactory() );
Dialect.AnalysisResult analysis = context.getDialect().analyzeExpression( context,
evalDescr,
evalDescr.getContent() );
final List[] usedIdentifiers = analysis.getBoundIdentifiers();
final Declaration[] declarations = new Declaration[usedIdentifiers[0].size()];
for ( int i = 0, size = usedIdentifiers[0].size(); i < size; i++ ) {
declarations[i] = context.getDeclarationResolver().getDeclaration( (String) usedIdentifiers[0].get( i ) );
}
final EvalCondition eval = new EvalCondition( declarations );
Serializable expr = ((MVELDialect) context.getDialect()).compile( (String) evalDescr.getContent(),
analysis,
null,
null,
context );
eval.setEvalExpression( new MVELEvalExpression( expr,
factory ) );
return eval;
} catch ( final Exception e ) {
context.getErrors().add( new RuleError( context.getRule(),
evalDescr,
e,
"Unable to build expression for 'eval' node '" + evalDescr.getContent() + "'" ) );
return null;
}
}