} else {
// it doesn't exist, so it's an output
declr = pattern.addDeclaration( expr );
// this bit is different, notice its the ArrayElementReader that we wire up to, not the declaration.
ArrayElementReader reader = new ArrayElementReader( arrayReader,
varIndexes.size(),
params[arg.getPosition()].getExtractor().getExtractToClass() );
declr.setReadAccessor( reader );
varIndexes.add( arg.getPosition() );
arguments.set( arg.getPosition(), Variable.variable );
}
} else {
// it's an expression and thus an input
DrlExprParser parser = new DrlExprParser();
ConstraintConnectiveDescr result = parser.parse( expr );
if ( parser.hasErrors() ) {
for ( DroolsParserException error : parser.getErrors() ) {
context.getErrors().add( new DescrBuildError( context.getParentDescr(),
descr,
null,
"Unable to parser pattern expression:\n" + error.getMessage() ) );
}
return null;
}
// if ( !isAtomic( result ) ) {
//
// }
MVELDumper.MVELDumperContext mvelCtx = new MVELDumper.MVELDumperContext();
expr = new MVELDumper().dump( result,
mvelCtx );
arguments.set( arg.getPosition(), MVEL.eval( expr )); // for now we just work with literals
}
}
// now do the slotted, all of which should be done via : bindings
for ( BindingDescr binding : patternDescr.getBindings() ) {
// if left is for existing binding, we need to actual execute as an input var
Declaration declr = context.getDeclarationResolver().getDeclaration( context.getRule(), binding.getVariable() );
if ( declr != null ) {
// check right maps to a slot, otherwise we can't reverse this and should error
int pos = getPos( binding.getExpression().trim(), params );
if ( pos >= 0 ) {
// slot exist, reverse and continue
String slot = binding.getExpression().trim();
String var = binding.getVariable().trim();
binding.setVariable( slot );
binding.setExpression( var );
} else {
// else error, we cannot find the slot to unify against
}
}
// left does not already exist, is it a slot?
int pos = getPos( binding.getVariable(), params );
if ( pos >= 0 ) {
// it's an input on a slot, is the input using bindings?
declr = context.getDeclarationResolver().getDeclaration( context.getRule(), binding.getExpression() );
if ( declr != null ) {
arguments.set( pos, declr );
declrIndexes.add( pos );
requiredDeclarations.add( declr );
} else {
// it must be a literal/expression
// it's an expression and thus an input
DrlExprParser parser = new DrlExprParser();
ConstraintConnectiveDescr result = parser.parse( binding.getExpression() );
if ( parser.hasErrors() ) {
for ( DroolsParserException error : parser.getErrors() ) {
context.getErrors().add( new DescrBuildError( context.getParentDescr(),
descr,
null,
"Unable to parser pattern expression:\n" + error.getMessage() ) );
}
return null;
}
// if ( !isAtomic( result ) ) {
//
// }
MVELDumper.MVELDumperContext mvelCtx = new MVELDumper.MVELDumperContext();
String expr = new MVELDumper().dump( result,
mvelCtx );
Object o = MVEL.eval( expr );
arguments.set( pos, o ); // for now we just work with literals
}
} else {
// this is creating a new output binding
// we know it doesn't exist, as we already checked for left == var
declr = pattern.addDeclaration( binding.getVariable() );
pos = getPos( binding.getExpression(), params );
if ( pos < 0 ) {
// error this must be a binding on a slot
throw new RuntimeException( "named argument does not exist" );
}
// this bit is different, notice its the ArrayElementReader that we wire up to, not the declaration.
ArrayElementReader reader = new ArrayElementReader( arrayReader,
varIndexes.size(),
params[pos].getExtractor().getExtractToClass() );
declr.setReadAccessor( reader );