### Eclipse Workspace Patch 1.0 #P drools-core Index: src/main/java/org/drools/base/dataproviders/MVELDataProvider.java =================================================================== --- src/main/java/org/drools/base/dataproviders/MVELDataProvider.java (revision 33579) +++ src/main/java/org/drools/base/dataproviders/MVELDataProvider.java (working copy) @@ -74,6 +74,18 @@ return this.requiredDeclarations; } + public void replaceDeclaration(Declaration declaration, + Declaration resolved) { + for ( int i = 0; i < this.requiredDeclarations.length; i++ ) { + if ( this.requiredDeclarations[i].equals( declaration ) ) { + this.requiredDeclarations[i] = resolved; + } + } + this.unit.replaceDeclaration( declaration, + resolved ); + prototype = unit.getFactory(); + } + public Object createContext() { return this.prototype.clone(); } Index: src/main/java/org/drools/spi/DataProvider.java =================================================================== --- src/main/java/org/drools/spi/DataProvider.java (revision 33579) +++ src/main/java/org/drools/spi/DataProvider.java (working copy) @@ -6,10 +6,13 @@ import org.drools.rule.Declaration; import org.drools.WorkingMemory; -public interface DataProvider extends Serializable, Cloneable { +public interface DataProvider + extends + Serializable, + Cloneable { public Declaration[] getRequiredDeclarations(); - + public Object createContext(); public Iterator getResults(Tuple tuple, @@ -19,4 +22,7 @@ public DataProvider clone(); + public void replaceDeclaration(Declaration declaration, + Declaration resolved); + } Index: src/main/java/org/drools/rule/LogicTransformer.java =================================================================== --- src/main/java/org/drools/rule/LogicTransformer.java (revision 33579) +++ src/main/java/org/drools/rule/LogicTransformer.java (working copy) @@ -24,6 +24,7 @@ import java.util.Stack; import org.drools.spi.Constraint; +import org.drools.spi.DataProvider; import org.drools.spi.DeclarationScopeResolver; /** @@ -183,6 +184,26 @@ resolved ); } } + } else if ( element instanceof From ) { + DataProvider provider = ((From)element).getDataProvider(); + Declaration[] decl = provider.getRequiredDeclarations(); + for ( int i = 0; i < decl.length; i++ ) { + Declaration resolved = resolver.getDeclaration(null, decl[i].getIdentifier() ); + if ( resolved != null && resolved != decl[i] ) { + provider.replaceDeclaration( decl[i], + resolved ); + } else if( resolved == null ) { + // it is probably an implicit declaration, so find the corresponding pattern + Pattern old = decl[i].getPattern(); + Pattern current = resolver.findPatternByIndex( old.getIndex() ); + if ( current != null && old != current ) { + resolved = new Declaration( decl[i].getIdentifier(), + decl[i].getExtractor(), + current ); + provider.replaceDeclaration( decl[i], resolved ); + } + } + } } else { contextStack.push( element ); for ( Iterator it = element.getNestedElements().iterator(); it.hasNext(); ) { Index: src/main/java/org/drools/rule/Collect.java =================================================================== --- src/main/java/org/drools/rule/Collect.java (revision 33579) +++ src/main/java/org/drools/rule/Collect.java (working copy) @@ -69,8 +69,18 @@ } public Object clone() { - return new Collect( this.sourcePattern, - this.resultPattern ); + PatternSource source = this.resultPattern.getSource(); + if ( source == this ) { + this.resultPattern.setSource( null ); + } + Pattern clonedResultPattern = (Pattern) this.resultPattern.clone(); + + Collect collect = new Collect( (Pattern) this.sourcePattern.clone(), + clonedResultPattern ); + if ( source == this ) { + collect.getResultPattern().setSource( collect ); + } + return collect; } public Pattern getResultPattern() { Index: src/test/java/org/drools/reteoo/FromNodeTest.java =================================================================== --- src/test/java/org/drools/reteoo/FromNodeTest.java (revision 33579) +++ src/test/java/org/drools/reteoo/FromNodeTest.java (working copy) @@ -348,6 +348,10 @@ return null; } + public void replaceDeclaration(Declaration declaration, + Declaration resolved) { + } + public MockDataProvider(final Collection collection) { this.collection = collection; }