final BaseDescr descr,
final Pattern prefixPattern) {
final FromDescr fromDescr = (FromDescr) descr;
final MVELExprDescr expr = (MVELExprDescr) fromDescr.getDataSource();
From from = null;
try {
// This builder is re-usable in other dialects, so specify by name
MVELDialect dialect = (MVELDialect) context.getDialect( "mvel" );
Map<String, Declaration> decls = context.getDeclarationResolver().getDeclarations(context.getRule());
String text = (String) expr.getText();
AnalysisResult analysis = dialect.analyzeExpression( context,
descr,
text,
new BoundIdentifiers(context.getDeclarationResolver().getDeclarationClasses( decls ),
context.getPackageBuilder().getGlobals() ) );
if ( analysis == null ) {
// something bad happened
return null;
}
final BoundIdentifiers usedIdentifiers = analysis.getBoundIdentifiers();
final Declaration[] declarations = new Declaration[usedIdentifiers.getDeclarations().size()];
String[] declrStr = new String[declarations.length];
int j = 0;
for (String str : usedIdentifiers.getDeclarations().keySet() ) {
declrStr[j] = str;
declarations[j++] = decls.get( str );
}
Arrays.sort( declarations, SortDeclarations.instance );
MVELCompilationUnit unit = dialect.getMVELCompilationUnit( text,
analysis,
declarations,
null,
null,
context,
"drools",
KnowledgeHelper.class );
MVELDataProvider dataProvider = new MVELDataProvider( unit,
context.getDialect().getId() );
from = new From( dataProvider );
MVELDialectRuntimeData data = (MVELDialectRuntimeData) context.getPkg().getDialectRuntimeRegistry().getDialectData( dialect.getId() );
data.addCompileable( from,
dataProvider );