}
BetaConstraints betaSourceConstraints;
switch ( list.size() ) {
case 0:
betaSourceConstraints = new EmptyBetaConstraints();
break;
case 1:
betaSourceConstraints = new SingleBetaConstraints( list.get(0),
buildContext.getRuleBase().getConfiguration() );
break;
case 2:
betaSourceConstraints = new DoubleBetaConstraints( list.toArray( new BetaNodeFieldConstraint[2] ),
buildContext.getRuleBase().getConfiguration() );
break;
case 3:
betaSourceConstraints = new TripleBetaConstraints( list.toArray( new BetaNodeFieldConstraint[2] ),
buildContext.getRuleBase().getConfiguration() );
break;
case 4:
betaSourceConstraints = new QuadroupleBetaConstraints( list.toArray( new BetaNodeFieldConstraint[2] ),
buildContext.getRuleBase().getConfiguration() );
break;
default:
betaSourceConstraints = new DefaultBetaConstraints( list.toArray( new BetaNodeFieldConstraint[2] ),
buildContext.getRuleBase().getConfiguration() );
break;
}
MVELDialectRuntimeData data = (MVELDialectRuntimeData) buildContext.getRuleBase().getPackage( buildContext.getRule().getPackageName() ).getDialectRuntimeRegistry().getDialectData( "mvel" );
data.onAdd( null, ((InternalRuleBase) buildContext.getRuleBase()).getRootClassLoader() );
//MvelD data = (MVELDialectRuntimeData) buildContext.getRuleBase().getPackage( buildContext.getRule().getName() ).getDialectRuntimeRegistry().getDialectData( "mvel" );
NodeTestCase testCase = (NodeTestCase) context.get( "TestCase" );
try {
for ( String imp : testCase.getImports() ) {
if ( imp.endsWith( ".*" ) ) {
data.addPackageImport( imp.substring( 0,
imp.lastIndexOf( '.' ) ) );
} else {
//classImports.add( imp );
cls = data.getRootClassLoader().loadClass( imp ) ;
data.addImport( cls.getSimpleName(), cls);
}
}
} catch (Exception e) {
throw new RuntimeException("Unable to load class",e );
}
Declaration decl = (Declaration) context.get( expr );
// build an external function executor
MVELCompilationUnit compilationUnit = new MVELCompilationUnit( name,
expr,
new String[]{}, // global identifiers
new EvaluatorWrapper[]{}, // operator identifiers
new Declaration[]{}, // previous declarations
new Declaration[]{decl}, // local declarations
new String[]{}, // other identifiers
new String[]{"this", "drools", "kcontext", "rule", decl.getIdentifier()}, // input identifiers
new String[]{Object.class.getName(), KnowledgeHelper.class.getName(), KnowledgeHelper.class.getName(), Rule.class.getName(), decl.getValueType().getClassType().getName()}, // input types
4,
false );
AccumulateFunction accFunction = new SumAccumulateFunction();
Accumulator accumulator = new MVELAccumulatorFunctionExecutor( compilationUnit,
accFunction );
((MVELCompileable) accumulator).compile( data );
Accumulate accumulate = new Accumulate( sourcePattern,
new Declaration[]{}, // required declaration
new Declaration[]{}, // inner declarations
new Accumulator[]{accumulator},
false );
AccumulateNode accNode = new AccumulateNode( buildContext.getNextId(),
leftTupleSource,
rightObjectSource,
alphaResultConstraint,
betaSourceConstraints,
new EmptyBetaConstraints(),
new Behavior[]{},
accumulate,
false,
buildContext );