Object tupleObject = leftTuple.get( declr ).getObject();
if ( tupleObject instanceof DroolsQuery ) {
ArrayElementReader reader = (ArrayElementReader) declr.getExtractor();
DroolsQuery q = (DroolsQuery) tupleObject;
Variable v = q.getVariables()[reader.getIndex()];
// is that parameter an output Variable
if ( v != null ) {
if ( !v.isSet() ) {
// it's not set yet, so we need to pass back any unified values
// If the declaration resolves to a variable being passed in, we need to add that to the variable indexes, so it's copied
if ( srcVarIndexes == null ) {
srcVarIndexes = new ArrayList<Integer>();
trgVars = new ArrayList<Variable>();
}
trgVars.add( v ); // this needs to be here, so we can pass the value back
srcVarIndexes.add( declIndexes[i] );
args[declIndexes[i]] = Variable.variable;
continue;
}
}
}
Object o = declr.getValue( workingMemory,
tupleObject );
args[declIndexes[i]] = o;
}
int[] varIndexes = this.queryElement.getVariableIndexes();
if ( srcVarIndexes != null ) {
// we have Variable inputs to handle
// now merge the two, by adding new onto the end of the old
int length = varIndexes.length;
varIndexes = new int[varIndexes.length + srcVarIndexes.size()];
System.arraycopy( this.queryElement.getVariableIndexes(),
0,
varIndexes,
0,
length );
for ( int i = 0; i < srcVarIndexes.size(); i++ ) {
varIndexes[i + length] = srcVarIndexes.get( i );
}
}
UnificationNodeViewChangedEventListener collector = new UnificationNodeViewChangedEventListener( leftTuple,
varIndexes,
this.sink,
this.tupleMemoryEnabled );
DroolsQuery queryObject = new DroolsQuery( this.queryElement.getQueryName(),
args,
collector,
false );
collector.setDroolsQuery( queryObject );