public RuleConditionElement build( final RuleBuildContext context,
final BaseDescr descr,
final Pattern prefixPattern ) {
boolean typesafe = context.isTypesafe();
try {
final AccumulateDescr accumDescr = (AccumulateDescr) descr;
if ( !accumDescr.hasValidInput() ) {
return null;
}
final RuleConditionBuilder builder = (RuleConditionBuilder) context.getDialect().getBuilder( accumDescr.getInput().getClass() );
// create source CE
final RuleConditionElement source = builder.build( context,
accumDescr.getInput() );
if ( source == null ) {
return null;
}
MVELDialect dialect = (MVELDialect) context.getDialect();
Map<String, Declaration> decls = context.getDeclarationResolver().getDeclarations( context.getRule() );
Map<String, Declaration> sourceOuterDeclr = source.getOuterDeclarations();
Map<String, Declaration> mergedDecl = new HashMap( decls );
mergedDecl.putAll( sourceOuterDeclr );
Map<String, Class< ? >> declarationClasses = context.getDeclarationResolver().getDeclarationClasses( decls );
declarationClasses.putAll( context.getDeclarationResolver().getDeclarationClasses( sourceOuterDeclr ) );
BoundIdentifiers boundIds = new BoundIdentifiers( declarationClasses,
context.getKnowledgeBuilder().getGlobals() );
boundIds.setDeclarations( mergedDecl );
Accumulator[] accumulators = null;
final boolean readLocalsFromTuple = PackageBuilderUtil.isReadLocalsFromTuple(accumDescr, source);
if ( accumDescr.isExternalFunction() ) {
// uses accumulate functions
accumulators = buildExternalFunctions( context,
accumDescr,
dialect,
decls,
sourceOuterDeclr,
boundIds,
readLocalsFromTuple );
} else {
// it is a custom accumulate
accumulators = buildCustomAccumulate( context,
accumDescr,
source,
dialect,
decls,
sourceOuterDeclr,
boundIds,
readLocalsFromTuple );
}
MVELDialectRuntimeData data = (MVELDialectRuntimeData) context.getPkg().getDialectRuntimeRegistry().getDialectData( "mvel" );
Accumulate accumulate = null;
if (accumDescr.isMultiFunction()) {
accumulate = new MultiAccumulate( source,
null,
accumulators );
int index = 0;
for ( Accumulator accumulator : accumulators ) {