for ( AccumulateFunctionCallDescr fc : funcCalls ) { AccumulateFunction function = context.getConfiguration().getAccumulateFunction( fc.getFunction() ); if ( function == null ) { context.addError( new DescrBuildError( accumDescr, context.getRuleDescr(), null, "Unknown accumulate function: '" + fc.getFunction() + "' on rule '" + context.getRuleDescr().getName() + "'. All accumulate functions must be registered before building a resource." ) ); return null; if ( fc.getBind() != null ) { if ( pattern.getDeclaration( fc.getBind() ) != null ) { context.addError(new DescrBuildError(context.getParentDescr(), accumDescr, null, "Duplicate declaration for variable '" + fc.getBind() + "' in the rule '" + context.getRule().getName() + "'")); } else { createResultBind( pattern, fc.getParams().length > 0 ? fc.getParams()[0] : "\"\"", new BoundIdentifiers( declCls, context.getPackageBuilder().getGlobals() ) );
for ( AccumulateFunctionCallDescr func : functions ) { AccumulateFunction function = context.getConfiguration().getAccumulateFunction( func.getFunction() ); if ( function == null ) { context.addError( new DescrBuildError( accumDescr, context.getRuleDescr(), null, "Unknown accumulate function: '" + func.getFunction() + "' on rule '" + context.getRuleDescr().getName() + "'. All accumulate functions must be registered before building a resource." ) ); return null; if ( func.getBind() != null ) { if ( pattern.getDeclaration( func.getBind() ) != null ) { context.addError(new DescrBuildError(context.getParentDescr(), accumDescr, null, "Duplicate declaration for variable '" + func.getBind() + "' in the rule '" + context.getRule().getName() + "'")); } else { createResultBind( pattern, func.getParams().length > 0 ? func.getParams()[0] : "\"\"", boundIds ); MVELCompilationUnit unit = dialect.getMVELCompilationUnit( func.getParams().length > 0 ? func.getParams()[0] : "\"\"", analysis, getUsedDeclarations( decls,
private JavaAccumulatorFunctionExecutor generateFunctionCallCodeTemplate( final RuleBuildContext context, final AccumulateDescr accumDescr, final Declaration[] sourceDeclArr, AccumulateFunctionCallDescr fc, AccumulateFunction function, final BoundIdentifiers usedIdentifiers, final Declaration[] previousDeclarations, final boolean readLocalsFromTuple ) { final String className = "accumulateExpression" + context.getNextId(); final Map<String, Object> map = createVariableContext( className, fc.getParams().length > 0 ? fc.getParams()[0] : "\"\"", context, previousDeclarations, sourceDeclArr, usedIdentifiers.getGlobals() ); map.put( "readLocalsFromTuple", readLocalsFromTuple ? Boolean.TRUE : Boolean.FALSE ); JavaAccumulatorFunctionExecutor accumulator = new JavaAccumulatorFunctionExecutor( function ); generateTemplates("returnValueMethod", "returnValueInvoker", context, className, map, accumulator, accumDescr); return accumulator; }
public void visitAccumulateDescr(final AccumulateDescr descr) { String tmpstr = new String(); tmpstr += this.template + " <from> <accumulate> "; if ( descr.isSinglePattern() ) { visitPatternDescr( descr.getInputPattern() ); } else { this.patternContext = false; visit( descr.getInput() ); } tmpstr += this.template; if ( descr.isExternalFunction() ) { AccumulateFunctionCallDescr func = descr.getFunctions().get( 0 ); tmpstr += "<external-function evaluator=\"" + func.getFunction() + "\" expression=\"" + func.getParams()[0] + "\"/>"; } else tmpstr += "<init>" + descr.getInitCode() + "</init><action>" + descr.getActionCode() + "</action><result>" + descr.getResultCode() + "</result>"; this.template = tmpstr + " </accumulate> </from> "; }
private void createResultBind( final Pattern pattern, int index, InternalReadAccessor arrayReader, AccumulateFunctionCallDescr fc, AccumulateFunction function ) { // bind function result on the result pattern Declaration declr = pattern.addDeclaration( fc.getBind() ); Class< ? > type = function instanceof TypedAccumulateFunction ? ((TypedAccumulateFunction) function).getResultType() : Object.class; // this bit is different, notice its the ArrayElementReader that we wire up to, not the declaration. ArrayElementReader reader = new ArrayElementReader( arrayReader, index, type ); declr.setReadAccessor( reader ); }
private void createResultBind( final Pattern pattern, int index, InternalReadAccessor arrayReader, AccumulateFunctionCallDescr fc, AccumulateFunction function ) { // bind function result on the result pattern Declaration declr = pattern.addDeclaration( fc.getBind() ); Class< ? > type = function instanceof TypedAccumulateFunction ? ((TypedAccumulateFunction) function).getResultType() : Object.class; // this bit is different, notice its the ArrayElementReader that we wire up to, not the declaration. ArrayElementReader reader = new ArrayElementReader( arrayReader, index, type ); declr.setReadAccessor( reader ); }
public void addFunction( String function, String bind, String[] params ) { addFunction( new AccumulateFunctionCallDescr( function, bind, params ) ); }