[jboss-svn-commits] JBL Code SVN: r32524 - in labs/jbossrules/trunk: drools-compiler/src/test/java/org/drools/integrationtests and 10 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Apr 12 17:37:45 EDT 2010


Author: tirelli
Date: 2010-04-12 17:37:43 -0400 (Mon, 12 Apr 2010)
New Revision: 32524

Added:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/CollectAccumulator.java
Removed:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/core/util/debug/CollectNodeVisitor.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CollectNode.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CollectNodeTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/test/dsl/CollectNodeStep.java
   labs/jbossrules/trunk/drools-core/src/test/resources/org/drools/reteoo/test/CollectNodeAssertRetractTest.nodeTestCase
Modified:
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/java/JavaAccumulateBuilder.java
   labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/FirstOrderLogicTest.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/JavaAccumulatorFunctionExecutor.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/core/util/debug/SessionInspector.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/impl/InputMarshaller.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/impl/OutputMarshaller.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/BetaNode.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/NodeTypeEnums.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/CollectBuilder.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Collect.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Pattern.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/test/ReteDslTestEngine.java
Log:
JBRULES-2339: JBRULES-2340: eliminating code duplication for Collect and CollectNode

Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/java/JavaAccumulateBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/java/JavaAccumulateBuilder.java	2010-04-12 20:12:05 UTC (rev 32523)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/java/JavaAccumulateBuilder.java	2010-04-12 21:37:43 UTC (rev 32524)
@@ -82,13 +82,14 @@
             final JavaAnalysisResult analysis = (JavaAnalysisResult) context.getDialect().analyzeBlock( context,
                                                                                                         accumDescr,
                                                                                                         accumDescr.getExpression(),
-                                                                                                        new Map[]{context.getDeclarationResolver().getDeclarationClasses(context.getRule()), context.getPackageBuilder().getGlobals()} );
+                                                                                                        new Map[]{context.getDeclarationResolver().getDeclarationClasses( context.getRule() ), context.getPackageBuilder().getGlobals()} );
 
             final List[] usedIdentifiers = analysis.getBoundIdentifiers();
 
             final List<Declaration> tupleDeclarations = new ArrayList<Declaration>();
             for ( int i = 0, size = usedIdentifiers[0].size(); i < size; i++ ) {
-                tupleDeclarations.add( context.getDeclarationResolver().getDeclaration(context.getRule(), (String) usedIdentifiers[0].get( i ) ) );
+                tupleDeclarations.add( context.getDeclarationResolver().getDeclaration( context.getRule(),
+                                                                                        (String) usedIdentifiers[0].get( i ) ) );
             }
 
             final Declaration[] previousDeclarations = tupleDeclarations.toArray( new Declaration[tupleDeclarations.size()] );
@@ -98,12 +99,13 @@
             final String className = "accumulateExpression" + context.getNextId();
 
             final Map<String, Object> map = createVariableContext( className,
-                                                   (String) accumDescr.getExpression(),
-                                                   context,
-                                                   previousDeclarations,
-                                                   sourceDeclArr,
-                                                   requiredGlobals );
-            map.put( "readLocalsFromTuple", accumDescr.isMultiPattern() ? Boolean.TRUE : Boolean.FALSE );
+                                                                   (String) accumDescr.getExpression(),
+                                                                   context,
+                                                                   previousDeclarations,
+                                                                   sourceDeclArr,
+                                                                   requiredGlobals );
+            map.put( "readLocalsFromTuple",
+                     accumDescr.isMultiPattern() ? Boolean.TRUE : Boolean.FALSE );
 
             AccumulateFunction function = context.getConfiguration().getAccumulateFunction( accumDescr.getFunctionIdentifier() );
 
@@ -126,7 +128,7 @@
             final String className = "Accumulate" + context.getNextId();
             accumDescr.setClassName( className );
 
-            Map<String,Class<?>>[] available = new Map[]{context.getDeclarationResolver().getDeclarationClasses(context.getRule()), context.getPackageBuilder().getGlobals()};
+            Map<String, Class< ? >>[] available = new Map[]{context.getDeclarationResolver().getDeclarationClasses( context.getRule() ), context.getPackageBuilder().getGlobals()};
             final JavaAnalysisResult initCodeAnalysis = (JavaAnalysisResult) context.getDialect().analyzeBlock( context,
                                                                                                                 accumDescr,
                                                                                                                 accumDescr.getInitCode(),
@@ -159,19 +161,20 @@
 
             final Declaration[] declarations = new Declaration[requiredDeclarations.size()];
             int i = 0;
-            for( Iterator<String> it = requiredDeclarations.iterator(); it.hasNext(); i++ ) {
-                declarations[i] = context.getDeclarationResolver().getDeclaration(context.getRule(), it.next() );
+            for ( Iterator<String> it = requiredDeclarations.iterator(); it.hasNext(); i++ ) {
+                declarations[i] = context.getDeclarationResolver().getDeclaration( context.getRule(),
+                                                                                   it.next() );
             }
             final Declaration[] sourceDeclArr = (Declaration[]) source.getOuterDeclarations().values().toArray( new Declaration[0] );
 
             final String[] globals = requiredGlobals.toArray( new String[requiredGlobals.size()] );
 
             final Map<String, Object> map = createVariableContext( className,
-                                                   null,
-                                                   context,
-                                                   declarations,
-                                                   null,
-                                                   globals );
+                                                                   null,
+                                                                   context,
+                                                                   declarations,
+                                                                   null,
+                                                                   globals );
 
             map.put( "className",
                      accumDescr.getClassName() );

Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/FirstOrderLogicTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/FirstOrderLogicTest.java	2010-04-12 20:12:05 UTC (rev 32523)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/FirstOrderLogicTest.java	2010-04-12 21:37:43 UTC (rev 32524)
@@ -17,7 +17,6 @@
 import org.drools.ClockType;
 import org.drools.FactHandle;
 import org.drools.KnowledgeBase;
-import org.drools.KnowledgeBaseConfiguration;
 import org.drools.KnowledgeBaseFactory;
 import org.drools.Order;
 import org.drools.OrderItem;
@@ -37,7 +36,6 @@
 import org.drools.compiler.DrlParser;
 import org.drools.compiler.DroolsParserException;
 import org.drools.compiler.PackageBuilder;
-import org.drools.integrationtests.eventgenerator.PseudoSessionClock;
 import org.drools.io.ResourceFactory;
 import org.drools.lang.descr.PackageDescr;
 import org.drools.rule.Package;

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/CollectAccumulator.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/CollectAccumulator.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/CollectAccumulator.java	2010-04-12 21:37:43 UTC (rev 32524)
@@ -0,0 +1,143 @@
+/*
+ * Copyright 2007 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Created on Jun 20, 2007
+ */
+package org.drools.base.accumulators;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.io.Serializable;
+import java.util.Collection;
+
+import org.drools.WorkingMemory;
+import org.drools.common.InternalFactHandle;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.rule.Collect;
+import org.drools.rule.Declaration;
+import org.drools.spi.Accumulator;
+import org.drools.spi.Tuple;
+
+/**
+ * An accumulator to execute "collect" CEs
+ *
+ * @author etirelli
+ */
+public class CollectAccumulator
+    implements
+    Accumulator,
+    Externalizable {
+
+    private static final long                          serialVersionUID = 400L;
+    private Collect collect;
+
+    public CollectAccumulator() {
+    }
+
+    public CollectAccumulator( final Collect collect ) {
+        this.collect = collect;
+    }
+
+    public void readExternal(ObjectInput in) throws IOException,
+                                            ClassNotFoundException {
+        this.collect = (Collect) in.readObject();
+    }
+
+    public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeObject( this.collect );
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.spi.Accumulator#createContext()
+     */
+    public Serializable createContext() {
+        return new CollectContext();
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.spi.Accumulator#init(java.lang.Object, org.drools.spi.Tuple, org.drools.rule.Declaration[], org.drools.WorkingMemory)
+     */
+    public void init(Object workingMemoryContext,
+                     Object context,
+                     Tuple leftTuple,
+                     Declaration[] declarations,
+                     WorkingMemory workingMemory) throws Exception {
+        ((CollectContext) context).result = this.collect.instantiateResultObject( (InternalWorkingMemory) workingMemory );
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.spi.Accumulator#accumulate(java.lang.Object, org.drools.spi.Tuple, org.drools.common.InternalFactHandle, org.drools.rule.Declaration[], org.drools.rule.Declaration[], org.drools.WorkingMemory)
+     */
+    public void accumulate(Object workingMemoryContext,
+                           Object context,
+                           Tuple leftTuple,
+                           InternalFactHandle handle,
+                           Declaration[] declarations,
+                           Declaration[] innerDeclarations,
+                           WorkingMemory workingMemory) throws Exception {
+        ((CollectContext) context).result.add( handle.getObject() );
+    }
+
+    public void reverse(Object workingMemoryContext,
+                        Object context,
+                        Tuple leftTuple,
+                        InternalFactHandle handle,
+                        Declaration[] declarations,
+                        Declaration[] innerDeclarations,
+                        WorkingMemory workingMemory) throws Exception {
+        ((CollectContext) context).result.remove( handle.getObject() );
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.spi.Accumulator#getResult(java.lang.Object, org.drools.spi.Tuple, org.drools.rule.Declaration[], org.drools.WorkingMemory)
+     */
+    public Object getResult(Object workingMemoryContext,
+                            Object context,
+                            Tuple leftTuple,
+                            Declaration[] declarations,
+                            WorkingMemory workingMemory) throws Exception {
+        return ((CollectContext) context).result;
+    }
+
+    public boolean supportsReverse() {
+        return true;
+    }
+
+    public Object createWorkingMemoryContext() {
+        // no working memory context needed
+        return null;
+    }
+
+    private static class CollectContext
+        implements
+        Externalizable {
+        public Collection<Object> result;
+        
+        public CollectContext() {}
+
+        @SuppressWarnings("unchecked")
+        public void readExternal(ObjectInput in) throws IOException,
+                                                ClassNotFoundException {
+            result = (Collection<Object>) in.readObject();
+        }
+
+        public void writeExternal(ObjectOutput out) throws IOException {
+            out.writeObject( result );
+        }
+    }
+
+}

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/JavaAccumulatorFunctionExecutor.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/JavaAccumulatorFunctionExecutor.java	2010-04-12 20:12:05 UTC (rev 32523)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/JavaAccumulatorFunctionExecutor.java	2010-04-12 21:37:43 UTC (rev 32524)
@@ -35,7 +35,7 @@
 import org.drools.spi.Wireable;
 
 /**
- * An MVEL accumulator function executor implementation
+ * A Java accumulator function executor implementation
  *
  * @author etirelli
  */
@@ -175,6 +175,7 @@
         public JavaAccumulatorFunctionContext() {
         }
 
+        @SuppressWarnings("unchecked")
         public void readExternal(ObjectInput in) throws IOException,
                                                 ClassNotFoundException {
             context = (Externalizable) in.readObject();

Deleted: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/core/util/debug/CollectNodeVisitor.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/core/util/debug/CollectNodeVisitor.java	2010-04-12 20:12:05 UTC (rev 32523)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/core/util/debug/CollectNodeVisitor.java	2010-04-12 21:37:43 UTC (rev 32524)
@@ -1,36 +0,0 @@
-package org.drools.core.util.debug;
-
-import java.util.Stack;
-
-import org.drools.common.NetworkNode;
-import org.drools.reteoo.CollectNode;
-import org.drools.reteoo.CollectNode.CollectMemory;
-
-public class CollectNodeVisitor extends AbstractNetworkNodeVisitor {
-    
-    public static final CollectNodeVisitor INSTANCE = new CollectNodeVisitor();
-    
-    protected CollectNodeVisitor() {
-    }
-
-    @Override
-    protected void doVisit(NetworkNode node,
-                           Stack<NetworkNode> nodeStack,
-                           StatefulKnowledgeSessionInfo info) {
-        CollectNode an = (CollectNode) node;
-        DefaultNodeInfo ni = (DefaultNodeInfo) info.getNodeInfo( node );
-        final CollectMemory memory = (CollectMemory) info.getSession().getNodeMemory( an );
-        
-        ni.setMemoryEnabled( true );
-        
-        if( an.isObjectMemoryEnabled() ) {
-            ni.setFactMemorySize( memory.betaMemory.getRightTupleMemory().size() );
-        }
-        if( an.isLeftTupleMemoryEnabled() ) {
-            ni.setTupleMemorySize( memory.betaMemory.getLeftTupleMemory().size() );
-            ni.setCreatedFactHandles( memory.betaMemory.getCreatedHandles().size() );
-        }
-
-    }
-
-}

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/core/util/debug/SessionInspector.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/core/util/debug/SessionInspector.java	2010-04-12 20:12:05 UTC (rev 32523)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/core/util/debug/SessionInspector.java	2010-04-12 21:37:43 UTC (rev 32524)
@@ -26,7 +26,6 @@
 import org.drools.impl.StatefulKnowledgeSessionImpl;
 import org.drools.reteoo.AccumulateNode;
 import org.drools.reteoo.AlphaNode;
-import org.drools.reteoo.CollectNode;
 import org.drools.reteoo.EntryPointNode;
 import org.drools.reteoo.EvalConditionNode;
 import org.drools.reteoo.ExistsNode;
@@ -93,8 +92,6 @@
                            BetaNodeVisitor.INSTANCE );
         this.visitors.put( AccumulateNode.class,
                            AccumulateNodeVisitor.INSTANCE );
-        this.visitors.put( CollectNode.class,
-                           CollectNodeVisitor.INSTANCE );
         this.visitors.put( EvalConditionNode.class,
                            EvalConditionNodeVisitor.INSTANCE );
         this.visitors.put( FromNode.class,

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/impl/InputMarshaller.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/impl/InputMarshaller.java	2010-04-12 20:12:05 UTC (rev 32523)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/impl/InputMarshaller.java	2010-04-12 21:37:43 UTC (rev 32524)
@@ -3,10 +3,7 @@
 import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.Serializable;
-import java.util.ArrayList;
 import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 import java.util.Queue;
 
@@ -33,20 +30,14 @@
 import org.drools.core.util.ObjectHashSet;
 import org.drools.impl.EnvironmentFactory;
 import org.drools.marshalling.ObjectMarshallingStrategy;
-import org.drools.process.core.context.swimlane.SwimlaneContext;
-import org.drools.process.core.context.variable.VariableScope;
-import org.drools.process.instance.ProcessInstance;
 import org.drools.process.instance.WorkItem;
 import org.drools.process.instance.WorkItemManager;
-import org.drools.process.instance.context.swimlane.SwimlaneContextInstance;
-import org.drools.process.instance.context.variable.VariableScopeInstance;
 import org.drools.process.instance.impl.WorkItemImpl;
 import org.drools.process.instance.timer.TimerInstance;
 import org.drools.process.instance.timer.TimerManager;
 import org.drools.reteoo.BetaMemory;
 import org.drools.reteoo.BetaNode;
 import org.drools.reteoo.EntryPointNode;
-import org.drools.reteoo.EvalConditionNode;
 import org.drools.reteoo.InitialFactHandle;
 import org.drools.reteoo.InitialFactHandleDummyObject;
 import org.drools.reteoo.LeftTuple;
@@ -60,33 +51,17 @@
 import org.drools.reteoo.RuleTerminalNode;
 import org.drools.reteoo.AccumulateNode.AccumulateContext;
 import org.drools.reteoo.AccumulateNode.AccumulateMemory;
-import org.drools.reteoo.CollectNode.CollectContext;
-import org.drools.reteoo.CollectNode.CollectMemory;
-import org.drools.reteoo.EvalConditionNode.EvalMemory;
 import org.drools.rule.EntryPoint;
 import org.drools.rule.GroupElement;
 import org.drools.rule.Package;
 import org.drools.rule.Rule;
-import org.drools.ruleflow.instance.RuleFlowProcessInstance;
 import org.drools.runtime.Environment;
-import org.drools.runtime.process.NodeInstance;
-import org.drools.runtime.process.NodeInstanceContainer;
 import org.drools.spi.Activation;
 import org.drools.spi.AgendaGroup;
 import org.drools.spi.FactHandleFactory;
 import org.drools.spi.ObjectType;
 import org.drools.spi.PropagationContext;
 import org.drools.spi.RuleFlowGroup;
-import org.drools.workflow.instance.impl.NodeInstanceImpl;
-import org.drools.workflow.instance.node.CompositeContextNodeInstance;
-import org.drools.workflow.instance.node.ForEachNodeInstance;
-import org.drools.workflow.instance.node.HumanTaskNodeInstance;
-import org.drools.workflow.instance.node.JoinInstance;
-import org.drools.workflow.instance.node.MilestoneNodeInstance;
-import org.drools.workflow.instance.node.RuleSetNodeInstance;
-import org.drools.workflow.instance.node.SubProcessNodeInstance;
-import org.drools.workflow.instance.node.TimerNodeInstance;
-import org.drools.workflow.instance.node.WorkItemNodeInstance;
 
 public class InputMarshaller {
     /**
@@ -404,10 +379,6 @@
                 memory = ((AccumulateMemory) context.wm.getNodeMemory( (BetaNode) sink )).betaMemory;
                 break;
             }
-            case NodeTypeEnums.CollectNode : {
-                memory = ((CollectMemory) context.wm.getNodeMemory( (BetaNode) sink )).betaMemory;
-                break;
-            }
             default : {
                 memory = (BetaMemory) context.wm.getNodeMemory( (BetaNode) sink );
                 break;
@@ -577,56 +548,6 @@
                 }
                 break;
             }
-            case NodeTypeEnums.CollectNode : {
-                // accumulate nodes generate new facts on-demand and need special procedures when de-serializing from persistent storage
-                CollectMemory memory = (CollectMemory) context.wm.getNodeMemory( (BetaNode) sink );
-                memory.betaMemory.getLeftTupleMemory().add( parentLeftTuple );
-
-                CollectContext colctx = new CollectContext();
-                memory.betaMemory.getCreatedHandles().put( parentLeftTuple,
-                                                           colctx,
-                                                           false );
-                // first we de-serialize the generated fact handle
-                InternalFactHandle handle = readFactHandle( context );
-                colctx.resultTuple = new RightTuple( handle,
-                                                     (RightTupleSink) sink );
-
-                // then we de-serialize the boolean propagated flag
-                colctx.propagated = stream.readBoolean();
-
-                // then we de-serialize all the propagated tuples
-                short head = -1;
-                while ( (head = stream.readShort()) != PersisterEnums.END ) {
-                    switch ( head ) {
-                        case PersisterEnums.RIGHT_TUPLE : {
-                            int factHandleId = stream.readInt();
-                            RightTupleKey key = new RightTupleKey( factHandleId,
-                                                                   sink );
-                            RightTuple rightTuple = context.rightTuples.get( key );
-                            // just wiring up the match record
-                            new LeftTuple( parentLeftTuple,
-                                           rightTuple,
-                                           sink,
-                                           true );
-                            break;
-                        }
-                        case PersisterEnums.LEFT_TUPLE : {
-                            LeftTupleSink childSink = (LeftTupleSink) sinks.get( stream.readInt() );
-                            LeftTuple childLeftTuple = new LeftTuple( parentLeftTuple,
-                                                                      colctx.resultTuple,
-                                                                      childSink,
-                                                                      true );
-                            readLeftTuple( childLeftTuple,
-                                           context );
-                            break;
-                        }
-                        default : {
-                            throw new RuntimeDroolsException( "Marshalling error. This is a bug. Please contact the development team." );
-                        }
-                    }
-                }
-                break;
-            }
             case NodeTypeEnums.RightInputAdaterNode : {
                 // RIANs generate new fact handles on-demand to wrap tuples and need special procedures when de-serializing from persistent storage
                 ObjectHashMap memory = (ObjectHashMap) context.wm.getNodeMemory( (NodeMemory) sink );

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/impl/OutputMarshaller.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/impl/OutputMarshaller.java	2010-04-12 20:12:05 UTC (rev 32523)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/impl/OutputMarshaller.java	2010-04-12 21:37:43 UTC (rev 32524)
@@ -45,8 +45,6 @@
 import org.drools.reteoo.RuleTerminalNode;
 import org.drools.reteoo.AccumulateNode.AccumulateContext;
 import org.drools.reteoo.AccumulateNode.AccumulateMemory;
-import org.drools.reteoo.CollectNode.CollectContext;
-import org.drools.reteoo.CollectNode.CollectMemory;
 import org.drools.rule.EntryPoint;
 import org.drools.rule.Rule;
 import org.drools.runtime.process.WorkItem;
@@ -521,40 +519,6 @@
 //                context.out.println( "AccumulateNode   ---   END" );
                 break;
             }
-            case NodeTypeEnums.CollectNode : {
-//                context.out.println( "CollectNode" );
-                // collect nodes generate new facts on-demand and need special procedures when serializing to persistent storage
-                CollectMemory memory = (CollectMemory) context.wm.getNodeMemory( (BetaNode) sink );
-                CollectContext colctx = (CollectContext) memory.betaMemory.getCreatedHandles().get( leftTuple );
-                // first we serialize the generated fact handle
-                writeFactHandle( context,
-                                 stream,
-                                 context.objectMarshallingStrategyStore,
-                                 colctx.resultTuple.getFactHandle() );
-                // then we serialize the boolean propagated flag
-                stream.writeBoolean( colctx.propagated );
-
-                // then we serialize all the propagated tuples
-                for ( LeftTuple childLeftTuple = leftTuple.firstChild; childLeftTuple != null; childLeftTuple = (LeftTuple) childLeftTuple.getLeftParentNext() ) {
-                    if( leftTuple.getLeftTupleSink().getId() == childLeftTuple.getLeftTupleSink().getId()) {
-                        // this is a matching record, so, associate the right tuples
-//                        context.out.println( "RightTuple(match) int:" + childLeftTuple.getLeftTupleSink().getId() + " int:" + childLeftTuple.getRightParent().getFactHandle().getId() );
-                        stream.writeShort( PersisterEnums.RIGHT_TUPLE );
-                        stream.writeInt( childLeftTuple.getRightParent().getFactHandle().getId() );
-                    } else {
-                        // this is a propagation record
-//                        context.out.println( "RightTuple(propagation) int:" + childLeftTuple.getLeftTupleSink().getId() + " int:" + childLeftTuple.getRightParent().getFactHandle().getId() );
-                        stream.writeShort( PersisterEnums.LEFT_TUPLE );
-                        stream.writeInt( childLeftTuple.getLeftTupleSink().getId() );
-                        writeLeftTuple( childLeftTuple,
-                                        context,
-                                        recurse );
-                    }
-                }
-                stream.writeShort( PersisterEnums.END );
-//                context.out.println( "CollectNode   ---   END" );
-                break;
-            }
             case NodeTypeEnums.RightInputAdaterNode : {
 //                context.out.println( "RightInputAdapterNode" );
                 // RIANs generate new fact handles on-demand to wrap tuples and need special procedures when serializing to persistent storage

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/BetaNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/BetaNode.java	2010-04-12 20:12:05 UTC (rev 32523)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/BetaNode.java	2010-04-12 21:37:43 UTC (rev 32524)
@@ -34,7 +34,6 @@
 import org.drools.core.util.LinkedList;
 import org.drools.core.util.LinkedListEntry;
 import org.drools.reteoo.AccumulateNode.AccumulateMemory;
-import org.drools.reteoo.CollectNode.CollectMemory;
 import org.drools.rule.Behavior;
 import org.drools.rule.BehaviorManager;
 import org.drools.spi.BetaNodeFieldConstraint;
@@ -236,11 +235,9 @@
                 BetaMemory memory = null;
                 Object object = workingMemories[i].getNodeMemory( this );
                 
-                // handle special cases for Collect and Accumulate to make sure they tidy up their specific data
+                // handle special cases for Accumulate to make sure they tidy up their specific data
                 // like destroying the local FactHandles
-                if ( object instanceof CollectMemory ) {
-                    memory = (( CollectMemory )object).betaMemory;
-                } else if ( object instanceof AccumulateMemory ) {
+                if ( object instanceof AccumulateMemory ) {
                     memory = (( AccumulateMemory )object).betaMemory;
                 } else {
                     memory = ( BetaMemory ) object;
@@ -263,11 +260,9 @@
                     leftTuple.unlinkFromRightParent();
                 }
 
-                // handle special cases for Collect and Accumulate to make sure they tidy up their specific data
+                // handle special cases for Accumulate to make sure they tidy up their specific data
                 // like destroying the local FactHandles
-                if ( object instanceof CollectMemory ) {
-                    ((CollectNode) this).doRemove( workingMemories[i], ( CollectMemory ) object );
-                } else if ( object instanceof AccumulateMemory ) {
+                if ( object instanceof AccumulateMemory ) {
                     ((AccumulateNode) this).doRemove( workingMemories[i], ( AccumulateMemory ) object );
                 }
 

Deleted: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CollectNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CollectNode.java	2010-04-12 20:12:05 UTC (rev 32523)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CollectNode.java	2010-04-12 21:37:43 UTC (rev 32524)
@@ -1,915 +0,0 @@
-/*
- * Copyright 2005 JBoss Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.drools.reteoo;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-
-import org.drools.RuleBaseConfiguration;
-import org.drools.common.BetaConstraints;
-import org.drools.common.InternalFactHandle;
-import org.drools.common.InternalWorkingMemory;
-import org.drools.common.PropagationContextImpl;
-import org.drools.core.util.ArrayUtils;
-import org.drools.core.util.Iterator;
-import org.drools.core.util.ObjectHashMap.ObjectEntry;
-import org.drools.reteoo.builder.BuildContext;
-import org.drools.rule.Behavior;
-import org.drools.rule.Collect;
-import org.drools.rule.ContextEntry;
-import org.drools.rule.Declaration;
-import org.drools.rule.Pattern;
-import org.drools.spi.AlphaNodeFieldConstraint;
-import org.drools.spi.BetaNodeFieldConstraint;
-import org.drools.spi.PropagationContext;
-
-/**
- * @author etirelli
- *
- */
-public class CollectNode extends BetaNode {
-    private static final long          serialVersionUID = 400L;
-
-    private Collect                    collect;
-    private AlphaNodeFieldConstraint[] resultConstraints;
-    private BetaConstraints            resultsBinder;
-    private boolean                    unwrapRightObject;
-    private Pattern[]                  requiredPatterns;
-
-    public CollectNode() {
-    }
-
-    /**
-     * Constructor.
-     *
-     * @param id
-     *            The id for the node
-     * @param leftInput
-     *            The left input <code>TupleSource</code>.
-     * @param rightInput
-     *            The right input <code>ObjectSource</code>.
-     * @param resultConstraints
-     *            The alpha constraints to be applied to the resulting collection
-     *            The beta binder to be applied to the source facts
-     * @param resultsBinder
-     *            The beta binder to be applied to the resulting collection
-     * @param collect
-     *            The collect conditional element
-     */
-    public CollectNode(final int id,
-                       final LeftTupleSource leftInput,
-                       final ObjectSource rightInput,
-                       final AlphaNodeFieldConstraint[] resultConstraints,
-                       final BetaConstraints sourceBinder,
-                       final BetaConstraints resultsBinder,
-                       final Behavior[] behaviors,
-                       final Collect collect,
-                       final boolean unwrapRight,
-                       final BuildContext context) {
-        super( id,
-               context.getPartitionId(),
-               context.getRuleBase().getConfiguration().isMultithreadEvaluation(),
-               leftInput,
-               rightInput,
-               sourceBinder,
-               behaviors );
-        this.resultsBinder = resultsBinder;
-        this.resultConstraints = resultConstraints;
-        this.collect = collect;
-        this.unwrapRightObject = unwrapRight;
-        this.tupleMemoryEnabled = context.isTupleMemoryEnabled();
-
-        List<Declaration> declrs = new ArrayList<Declaration>();
-        int maxIndex = 0;
-        for ( BetaNodeFieldConstraint constraint : getConstraints() ) {
-            for ( Declaration declr : constraint.getRequiredDeclarations() ) {
-                if ( declr.getPattern().getOffset() > maxIndex ) {
-                    maxIndex = declr.getPattern().getOffset();
-                }
-                declrs.add( declr );
-            }
-        }
-        requiredPatterns = new Pattern[maxIndex + 1];
-        for ( Declaration declr : declrs ) {
-            requiredPatterns[declr.getPattern().getOffset()] = declr.getPattern();
-        }
-    }
-
-    public void readExternal(ObjectInput in) throws IOException,
-                                            ClassNotFoundException {
-        super.readExternal( in );
-        collect = (Collect) in.readObject();
-        resultConstraints = (AlphaNodeFieldConstraint[]) in.readObject();
-        resultsBinder = (BetaConstraints) in.readObject();
-        unwrapRightObject = in.readBoolean();
-    }
-
-    public void writeExternal(ObjectOutput out) throws IOException {
-        super.writeExternal( out );
-        out.writeObject( collect );
-        out.writeObject( resultConstraints );
-        out.writeObject( resultsBinder );
-        out.writeBoolean( unwrapRightObject );
-    }
-
-    /**
-     * @inheritDoc
-     *
-     *  When a new tuple is asserted into a CollectNode, do this:
-     *
-     *  1. Select all matching objects from right memory
-     *  2. Add them to the resulting collection object
-     *  3. Apply resultConstraints and resultsBinder to the resulting collection
-     *  4. In case all of them evaluates to true do the following:
-     *  4.1. Create a new InternalFactHandle for the resulting collection and add it to the tuple
-     *  4.2. Propagate the tuple
-     *
-     */
-    @SuppressWarnings("unchecked")
-    public void assertLeftTuple(final LeftTuple leftTuple,
-                                final PropagationContext context,
-                                final InternalWorkingMemory workingMemory) {
-
-        final CollectMemory memory = (CollectMemory) workingMemory.getNodeMemory( this );
-
-        final Collection<Object> result = (Collection<Object>) this.collect.instantiateResultObject( workingMemory );
-        final InternalFactHandle resultHandle = workingMemory.getFactHandleFactory().newFactHandle( result,
-                                                                                                    workingMemory.getObjectTypeConfigurationRegistry().getObjectTypeConf( context.getEntryPoint(),
-                                                                                                                                                                          result ),
-                                                                                                    workingMemory );
-
-        final CollectContext colctx = new CollectContext();
-        colctx.resultTuple = new RightTuple( resultHandle,
-                                             this );
-
-        // do not add tuple and result to the memory in sequential mode
-        if ( this.tupleMemoryEnabled ) {
-            memory.betaMemory.getLeftTupleMemory().add( leftTuple );
-            memory.betaMemory.getCreatedHandles().put( leftTuple,
-                                                       colctx,
-                                                       false );
-        }
-
-        this.constraints.updateFromTuple( memory.betaMemory.getContext(),
-                                          workingMemory,
-                                          leftTuple );
-
-        for ( RightTuple rightTuple = memory.betaMemory.getRightTupleMemory().getFirst( leftTuple ); rightTuple != null; rightTuple = (RightTuple) rightTuple.getNext() ) {
-            InternalFactHandle handle = rightTuple.getFactHandle();
-            if ( this.constraints.isAllowedCachedLeft( memory.betaMemory.getContext(),
-                                                       handle ) ) {
-                addMatch( leftTuple,
-                          rightTuple,
-                          null,
-                          null,
-                          colctx );
-            }
-        }
-
-        this.constraints.resetTuple( memory.betaMemory.getContext() );
-
-        evaluateResultConstraints( ActivitySource.LEFT,
-                                   leftTuple,
-                                   context,
-                                   workingMemory,
-                                   memory,
-                                   colctx );
-    }
-
-    /**
-     * @inheritDoc
-     * 
-     * When retracting the left tuple, clear all matches from the right tuples
-     * and if previously propagated as an assert, propagate a retract
-     */
-    public void retractLeftTuple(final LeftTuple leftTuple,
-                                 final PropagationContext context,
-                                 final InternalWorkingMemory workingMemory) {
-
-        final CollectMemory memory = (CollectMemory) workingMemory.getNodeMemory( this );
-        memory.betaMemory.getLeftTupleMemory().remove( leftTuple );
-        final CollectContext colctx = (CollectContext) memory.betaMemory.getCreatedHandles().remove( leftTuple );
-
-        removePreviousMatchesForLeftTuple( leftTuple,
-                                           colctx );
-
-        if ( colctx.propagated ) {
-            // if tuple was previously propagated, retract it
-            this.sink.propagateRetractLeftTupleDestroyRightTuple( leftTuple,
-                                                                  context,
-                                                                  workingMemory );
-        } else {
-            // if not propagated, just destroy the result fact handle
-            workingMemory.getFactHandleFactory().destroyFactHandle( colctx.resultTuple.getFactHandle() );
-
-        }
-    }
-
-    /**
-     * @inheritDoc
-     *
-     *  When a new object is asserted into a CollectNode, do this:
-     *
-     *  1. Select all matching tuples from left memory
-     *  2. For each matching tuple, add the new match and evaluate the result constraints
-     *
-     */
-    public void assertObject(final InternalFactHandle factHandle,
-                             final PropagationContext context,
-                             final InternalWorkingMemory workingMemory) {
-
-        final CollectMemory memory = (CollectMemory) workingMemory.getNodeMemory( this );
-        final RightTuple rightTuple = new RightTuple( factHandle,
-                                                      this );
-
-        if ( !behavior.assertRightTuple( memory.betaMemory.getBehaviorContext(),
-                                         rightTuple,
-                                         workingMemory ) ) {
-            // destroy right tuple
-            rightTuple.unlinkFromRightParent();
-            return;
-        }
-
-        memory.betaMemory.getRightTupleMemory().add( rightTuple );
-
-        if ( !this.tupleMemoryEnabled ) {
-            // do nothing here, as we know there are no left tuples at this stage in sequential mode.
-            return;
-        }
-
-        this.constraints.updateFromFactHandle( memory.betaMemory.getContext(),
-                                               workingMemory,
-                                               factHandle );
-
-        for ( LeftTuple leftTuple = memory.betaMemory.getLeftTupleMemory().getFirst( rightTuple ); leftTuple != null; leftTuple = (LeftTuple) leftTuple.getNext() ) {
-            if ( this.constraints.isAllowedCachedRight( memory.betaMemory.getContext(),
-                                                        leftTuple ) ) {
-                final CollectContext colctx = (CollectContext) memory.betaMemory.getCreatedHandles().get( leftTuple );
-                addMatch( leftTuple,
-                          rightTuple,
-                          null,
-                          null,
-                          colctx );
-                evaluateResultConstraints( ActivitySource.RIGHT,
-                                           leftTuple,
-                                           context,
-                                           workingMemory,
-                                           memory,
-                                           colctx );
-            }
-        }
-
-        this.constraints.resetFactHandle( memory.betaMemory.getContext() );
-    }
-
-    /**
-     *  @inheritDoc
-     *
-     *  If an object is retract, call modify tuple for each
-     *  tuple match.
-     */
-    public void retractRightTuple(final RightTuple rightTuple,
-                                  final PropagationContext context,
-                                  final InternalWorkingMemory workingMemory) {
-
-        final CollectMemory memory = (CollectMemory) workingMemory.getNodeMemory( this );
-
-        final InternalFactHandle origin = (InternalFactHandle) context.getFactHandleOrigin();
-        if ( context.getType() == PropagationContext.EXPIRATION ) {
-            ((PropagationContextImpl) context).setFactHandle( null );
-        }
-
-        behavior.retractRightTuple( memory.betaMemory.getBehaviorContext(),
-                                    rightTuple,
-                                    workingMemory );
-        memory.betaMemory.getRightTupleMemory().remove( rightTuple );
-
-        removePreviousMatchesForRightTuple( rightTuple,
-                                            context,
-                                            workingMemory,
-                                            memory,
-                                            rightTuple.firstChild );
-
-        if ( context.getType() == PropagationContext.EXPIRATION ) {
-            ((PropagationContextImpl) context).setFactHandle( origin );
-        }
-
-    }
-
-    public void modifyLeftTuple(LeftTuple leftTuple,
-                                PropagationContext context,
-                                InternalWorkingMemory workingMemory) {
-        final CollectMemory memory = (CollectMemory) workingMemory.getNodeMemory( this );
-        final CollectContext colctx = (CollectContext) memory.betaMemory.getCreatedHandles().get( leftTuple );
-
-        // Add and remove to make sure we are in the right bucket and at the end
-        // this is needed to fix for indexing and deterministic iteration
-        memory.betaMemory.getLeftTupleMemory().remove( leftTuple );
-        memory.betaMemory.getLeftTupleMemory().add( leftTuple );
-
-        this.constraints.updateFromTuple( memory.betaMemory.getContext(),
-                                          workingMemory,
-                                          leftTuple );
-        LeftTuple childLeftTuple = getFirstMatch( leftTuple,
-                                                  colctx,
-                                                  false );
-
-        RightTupleMemory rightMemory = memory.betaMemory.getRightTupleMemory();
-
-        RightTuple rightTuple = rightMemory.getFirst( leftTuple );
-
-        // first check our index (for indexed nodes only) hasn't changed and we are returning the same bucket
-        if ( childLeftTuple != null && rightMemory.isIndexed() && rightTuple != rightMemory.getFirst( childLeftTuple.getRightParent() ) ) {
-            // our index has changed, so delete all the previous matchings
-
-            removePreviousMatchesForLeftTuple( leftTuple,
-                                               colctx );
-
-            childLeftTuple = null; // null so the next check will attempt matches for new bucket
-        }
-
-        // we can't do anything if RightTupleMemory is empty
-        if ( rightTuple != null ) {
-            if ( childLeftTuple == null ) {
-                // either we are indexed and changed buckets or
-                // we had no children before, but there is a bucket to potentially match, so try as normal assert
-                for ( ; rightTuple != null; rightTuple = (RightTuple) rightTuple.getNext() ) {
-                    final InternalFactHandle handle = rightTuple.getFactHandle();
-                    if ( this.constraints.isAllowedCachedLeft( memory.betaMemory.getContext(),
-                                                               handle ) ) {
-                        // add a new match
-                        addMatch( leftTuple,
-                                  rightTuple,
-                                  null,
-                                  null,
-                                  colctx );
-
-                    }
-                }
-            } else {
-                // in the same bucket, so iterate and compare
-                for ( ; rightTuple != null; rightTuple = (RightTuple) rightTuple.getNext() ) {
-                    final InternalFactHandle handle = rightTuple.getFactHandle();
-
-                    if ( this.constraints.isAllowedCachedLeft( memory.betaMemory.getContext(),
-                                                               handle ) ) {
-                        if ( childLeftTuple == null || childLeftTuple.getRightParent() != rightTuple ) {
-                            // add a new match
-                            addMatch( leftTuple,
-                                      rightTuple,
-                                      childLeftTuple,
-                                      null,
-                                      colctx );
-                        } else {
-                            // we must re-add this to ensure deterministic iteration
-                            LeftTuple temp = childLeftTuple.getLeftParentNext();
-                            childLeftTuple.reAddRight();
-                            childLeftTuple = temp;
-                        }
-                    } else if ( childLeftTuple != null && childLeftTuple.getRightParent() == rightTuple ) {
-                        LeftTuple temp = childLeftTuple.getLeftParentNext();
-                        // remove the match
-                        removeMatch( rightTuple,
-                                     childLeftTuple,
-                                     colctx );
-                        childLeftTuple = temp;
-                    }
-                    // else do nothing, was false before and false now.
-                }
-            }
-        }
-
-        this.constraints.resetTuple( memory.betaMemory.getContext() );
-        evaluateResultConstraints( ActivitySource.LEFT,
-                                   leftTuple,
-                                   context,
-                                   workingMemory,
-                                   memory,
-                                   colctx );
-    }
-
-    public void modifyRightTuple(RightTuple rightTuple,
-                                 PropagationContext context,
-                                 InternalWorkingMemory workingMemory) {
-        final CollectMemory memory = (CollectMemory) workingMemory.getNodeMemory( this );
-
-        // Add and remove to make sure we are in the right bucket and at the end
-        // this is needed to fix for indexing and deterministic iteration
-        memory.betaMemory.getRightTupleMemory().remove( rightTuple );
-        memory.betaMemory.getRightTupleMemory().add( rightTuple );
-        
-        if ( !this.tupleMemoryEnabled ) {
-            // do nothing here, as we know there are no left tuples at this stage in sequential mode.
-            return;
-        }        
-
-        // WTD here
-        //                if ( !behavior.assertRightTuple( memory.getBehaviorContext(),
-        //                                                 rightTuple,
-        //                                                 workingMemory ) ) {
-        //                    // destroy right tuple
-        //                    rightTuple.unlinkFromRightParent();
-        //                    return;
-        //                }
-
-        LeftTuple childLeftTuple = rightTuple.firstChild;
-
-        LeftTupleMemory leftMemory = memory.betaMemory.getLeftTupleMemory();
-
-        LeftTuple leftTuple = leftMemory.getFirst( rightTuple );
-
-        this.constraints.updateFromFactHandle( memory.betaMemory.getContext(),
-                                               workingMemory,
-                                               rightTuple.getFactHandle() );
-
-        // first check our index (for indexed nodes only) hasn't changed and we are returning the same bucket
-        if ( childLeftTuple != null && leftMemory.isIndexed() && leftTuple != leftMemory.getFirst( childLeftTuple.getLeftParent() ) ) {
-            // our index has changed, so delete all the previous matches
-            removePreviousMatchesForRightTuple( rightTuple,
-                                                context,
-                                                workingMemory,
-                                                memory,
-                                                childLeftTuple );
-            childLeftTuple = null; // null so the next check will attempt matches for new bucket
-        }
-
-        // if LeftTupleMemory is empty, there are no matches to modify
-        if ( leftTuple != null ) {
-            if ( childLeftTuple == null ) {
-                // either we are indexed and changed buckets or
-                // we had no children before, but there is a bucket to potentially match, so try as normal assert
-                for ( ; leftTuple != null; leftTuple = (LeftTuple) leftTuple.getNext() ) {
-                    if ( this.constraints.isAllowedCachedRight( memory.betaMemory.getContext(),
-                                                                leftTuple ) ) {
-                        final CollectContext colctx = (CollectContext) memory.betaMemory.getCreatedHandles().get( leftTuple );
-                        // add a new match
-                        addMatch( leftTuple,
-                                  rightTuple,
-                                  null,
-                                  null,
-                                  colctx );
-                        evaluateResultConstraints( ActivitySource.RIGHT,
-                                                   leftTuple,
-                                                   context,
-                                                   workingMemory,
-                                                   memory,
-                                                   colctx );
-                    }
-                }
-            } else {
-                // in the same bucket, so iterate and compare
-                for ( ; leftTuple != null; leftTuple = (LeftTuple) leftTuple.getNext() ) {
-                    if ( this.constraints.isAllowedCachedRight( memory.betaMemory.getContext(),
-                                                                leftTuple ) ) {
-                        final CollectContext colctx = (CollectContext) memory.betaMemory.getCreatedHandles().get( leftTuple );
-                        LeftTuple temp = null;
-                        if ( childLeftTuple != null && childLeftTuple.getLeftParent() == leftTuple ) {
-                            // we must re-add this to ensure deterministic iteration
-                            temp = childLeftTuple.getRightParentNext();
-                            childLeftTuple.reAddLeft();
-                            removeMatch( rightTuple,
-                                         childLeftTuple,
-                                         colctx );
-                        }
-                        // add a new match
-                        addMatch( leftTuple,
-                                  rightTuple,
-                                  null,
-                                  childLeftTuple,
-                                  colctx );
-                        if( temp != null ) {
-                            childLeftTuple = temp;
-                        }
-                        evaluateResultConstraints( ActivitySource.RIGHT,
-                                                   leftTuple,
-                                                   context,
-                                                   workingMemory,
-                                                   memory,
-                                                   colctx );
-                    } else if ( childLeftTuple != null && childLeftTuple.getLeftParent() == leftTuple ) {
-
-                        LeftTuple temp = childLeftTuple.getRightParentNext();
-                        final CollectContext colctx = (CollectContext) memory.betaMemory.getCreatedHandles().get( leftTuple );
-                        // remove the match
-                        removeMatch( rightTuple,
-                                     childLeftTuple,
-                                     colctx );
-                        evaluateResultConstraints( ActivitySource.RIGHT,
-                                                   leftTuple,
-                                                   context,
-                                                   workingMemory,
-                                                   memory,
-                                                   colctx );
-
-                        childLeftTuple = temp;
-                    }
-                    // else do nothing, was false before and false now.
-                }
-            }
-        }
-
-        this.constraints.resetFactHandle( memory.betaMemory.getContext() );
-    }
-
-    /**
-     * Evaluate result constraints and propagate tuple if it evaluates to true
-     * 
-     * @param leftTuple
-     * @param context
-     * @param workingMemory
-     * @param memory
-     * @param colctx
-     */
-    private void evaluateResultConstraints(final ActivitySource source,
-                                           final LeftTuple leftTuple,
-                                           final PropagationContext context,
-                                           final InternalWorkingMemory workingMemory,
-                                           final CollectMemory memory,
-                                           final CollectContext colctx) {
-        // First alpha node filters
-        boolean isAllowed = true;
-        for ( int i = 0, length = this.resultConstraints.length; i < length; i++ ) {
-            if ( !this.resultConstraints[i].isAllowed( colctx.resultTuple.getFactHandle(),
-                                                       workingMemory,
-                                                       memory.alphaContexts[i] ) ) {
-                isAllowed = false;
-                break;
-            }
-        }
-        if ( isAllowed ) {
-            this.resultsBinder.updateFromTuple( memory.resultsContext,
-                                                workingMemory,
-                                                leftTuple );
-            if ( !this.resultsBinder.isAllowedCachedLeft( memory.resultsContext,
-                                                          colctx.resultTuple.getFactHandle() ) ) {
-                isAllowed = false;
-            }
-
-            this.resultsBinder.resetTuple( memory.resultsContext );
-        }
-
-        if ( colctx.propagated == true ) {
-            // temporarily break the linked list to avoid wrong interactions
-            LeftTuple[] matchings = splitList( leftTuple,
-                                               colctx,
-                                               false );
-
-            if ( isAllowed ) {
-                // modify 
-                if ( ActivitySource.LEFT.equals( source ) ) {
-                    this.sink.propagateModifyChildLeftTuple( leftTuple.firstChild,
-                                                             leftTuple,
-                                                             context,
-                                                             workingMemory,
-                                                             this.tupleMemoryEnabled );
-                } else {
-                    this.sink.propagateModifyChildLeftTuple( leftTuple.firstChild,
-                                                             colctx.resultTuple,
-                                                             context,
-                                                             workingMemory,
-                                                             this.tupleMemoryEnabled );
-                }
-            } else {
-                // retract
-                this.sink.propagateRetractLeftTuple( leftTuple,
-                                                     context,
-                                                     workingMemory );
-                colctx.propagated = false;
-            }
-            // restore the matchings list
-            restoreList( leftTuple,
-                         matchings );
-        } else if ( isAllowed ) {
-            // temporarily break the linked list to avoid wrong interactions
-            LeftTuple[] matchings = splitList( leftTuple,
-                                               colctx,
-                                               false );
-
-            // assert
-            this.sink.propagateAssertLeftTuple( leftTuple,
-                                                colctx.resultTuple,
-                                                null,
-                                                null,
-                                                context,
-                                                workingMemory,
-                                                this.tupleMemoryEnabled );
-            colctx.propagated = true;
-            // restore the matchings list
-            restoreList( leftTuple,
-                         matchings );
-        }
-    }
-
-    /**
-     * Skips the propagated tuple handles and return the first handle
-     * in the list that correspond to a match
-     * 
-     * @param leftTuple
-     * @param colctx
-     * @return
-     */
-    private LeftTuple getFirstMatch(final LeftTuple leftTuple,
-                                    final CollectContext colctx,
-                                    final boolean isUpdatingSink) {
-        // unlink all right matches 
-        LeftTuple child = leftTuple.firstChild;
-
-        if ( colctx.propagated ) {
-            // To do that, we need to skip the first N children that are in fact
-            // the propagated tuples
-            int target = isUpdatingSink ? this.sink.size() - 1 : this.sink.size();
-            for ( int i = 0; i < target; i++ ) {
-                child = child.getLeftParentNext();
-            }
-        }
-        return child;
-    }
-
-    public void updateSink(final LeftTupleSink sink,
-                           final PropagationContext context,
-                           final InternalWorkingMemory workingMemory) {
-        final CollectMemory memory = (CollectMemory) workingMemory.getNodeMemory( this );
-
-        final Iterator tupleIter = memory.betaMemory.getLeftTupleMemory().iterator();
-        for ( LeftTuple leftTuple = (LeftTuple) tupleIter.next(); leftTuple != null; leftTuple = (LeftTuple) tupleIter.next() ) {
-            CollectContext colctx = (CollectContext) memory.betaMemory.getCreatedHandles().get( leftTuple );
-            if ( colctx.propagated ) {
-                // temporarily break the linked list to avoid wrong interactions
-                LeftTuple[] matchings = splitList( leftTuple,
-                                                   colctx,
-                                                   true );
-                sink.assertLeftTuple( new LeftTuple( leftTuple,
-                                                     colctx.resultTuple,
-                                                     null,
-                                                     null,
-                                                     sink,
-                                                     this.tupleMemoryEnabled ),
-                                      context,
-                                      workingMemory );
-                restoreList( leftTuple,
-                             matchings );
-            }
-        }
-    }
-
-    protected void doRemove(final InternalWorkingMemory workingMemory,
-                            final CollectMemory memory) {
-        Iterator it = memory.betaMemory.getCreatedHandles().iterator();
-        for ( ObjectEntry entry = (ObjectEntry) it.next(); entry != null; entry = (ObjectEntry) it.next() ) {
-            CollectContext ctx = (CollectContext) entry.getValue();
-            workingMemory.getFactHandleFactory().destroyFactHandle( ctx.resultTuple.getFactHandle() );
-        }
-    }
-
-    public short getType() {
-        return NodeTypeEnums.CollectNode;
-    }
-
-    /**
-     * Creates a BetaMemory for the BetaNode's memory.
-     */
-    public Object createMemory(final RuleBaseConfiguration config) {
-        CollectMemory memory = new CollectMemory();
-        memory.betaMemory = this.constraints.createBetaMemory( config );
-        memory.resultsContext = this.resultsBinder.createContext();
-        memory.alphaContexts = new ContextEntry[this.resultConstraints.length];
-        for ( int i = 0; i < this.resultConstraints.length; i++ ) {
-            memory.alphaContexts[i] = this.resultConstraints[i].createContextEntry();
-        }
-        memory.betaMemory.setBehaviorContext( this.behavior.createBehaviorContext() );
-        return memory;
-    }
-
-    /**
-     * Adds a match between left and right tuple
-     * 
-     * @param leftTuple
-     * @param rightTuple
-     * @param colctx
-     */
-    @SuppressWarnings("unchecked")
-    private void addMatch(final LeftTuple leftTuple,
-                          final RightTuple rightTuple,
-                          final LeftTuple currentLeftChild,
-                          final LeftTuple currentRightChild,
-                          final CollectContext colctx) {
-        InternalFactHandle handle = rightTuple.getFactHandle();
-        if ( this.unwrapRightObject ) {
-            handle = ((LeftTuple) handle.getObject()).getLastHandle();
-        }
-        ((Collection<Object>) colctx.resultTuple.getFactHandle().getObject()).add( handle.getObject() );
-
-        // in sequential mode, we don't need to keep record of matched tuples
-        if ( this.tupleMemoryEnabled ) {
-            // linking left and right by creating a new left tuple
-            new LeftTuple( leftTuple,
-                           rightTuple,
-                           currentLeftChild,
-                           currentRightChild,
-                           this,
-                           this.tupleMemoryEnabled );
-        }
-    }
-
-    /**
-     * Removes a match between left and right tuple
-     *
-     * @param rightTuple
-     * @param match
-     * @param result
-     */
-    @SuppressWarnings("unchecked")
-    public void removeMatch(final RightTuple rightTuple,
-                            final LeftTuple match,
-                            final CollectContext colctx) {
-        if ( match != null ) {
-            // removing link between left and right
-            match.unlinkFromLeftParent();
-            match.unlinkFromRightParent();
-        }
-
-        // if there is a subnetwork, we need to unwrap the object from inside the tuple
-        InternalFactHandle handle = rightTuple.getFactHandle();
-        if ( this.unwrapRightObject ) {
-            handle = ((LeftTuple) handle.getObject()).getLastHandle();
-        }
-
-        ((Collection<Object>) colctx.resultTuple.getFactHandle().getObject()).remove( handle.getObject() );
-    }
-
-    @SuppressWarnings("unchecked")
-    private void removePreviousMatchesForLeftTuple(final LeftTuple leftTuple,
-                                                   final CollectContext colctx) {
-        // It is cheaper to simply wipe out the matchings from the end of the list than
-        // going through element by element doing proper removal
-
-        // so we just split the list keeping the head 
-        LeftTuple[] matchings = splitList( leftTuple,
-                                           colctx,
-                                           false );
-        for ( LeftTuple match = matchings[0]; match != null; match = match.getLeftParentNext() ) {
-            // no need to unlink from the left parent as the left parent is being wiped out
-            match.unlinkFromRightParent();
-        }
-        // since there are no more matches, we need to clear the result collection
-        ((Collection<Object>) colctx.resultTuple.getFactHandle().getObject()).clear();
-
-    }
-
-    private void removePreviousMatchesForRightTuple(RightTuple rightTuple,
-                                                    PropagationContext context,
-                                                    InternalWorkingMemory workingMemory,
-                                                    final CollectMemory memory,
-                                                    LeftTuple firstChild) {
-        for ( LeftTuple match = firstChild; match != null; ) {
-            final LeftTuple tmp = match.getRightParentNext();
-            final LeftTuple parent = match.getLeftParent();
-            final CollectContext colctx = (CollectContext) memory.betaMemory.getCreatedHandles().get( parent );
-            removeMatch( rightTuple,
-                         match,
-                         colctx );
-            evaluateResultConstraints( ActivitySource.RIGHT,
-                                       parent,
-                                       context,
-                                       workingMemory,
-                                       memory,
-                                       colctx );
-            match = tmp;
-        }
-    }
-
-    protected LeftTuple[] splitList(final LeftTuple parent,
-                                    final CollectContext colctx,
-                                    final boolean isUpdatingSink) {
-        LeftTuple[] matchings = new LeftTuple[2];
-
-        // save the matchings list
-        matchings[0] = getFirstMatch( parent,
-                                      colctx,
-                                      isUpdatingSink );
-        matchings[1] = matchings[0] != null ? parent.lastChild : null;
-
-        // update the tuple for the actual propagations
-        if ( matchings[0] != null ) {
-            if ( parent.firstChild == matchings[0] ) {
-                parent.firstChild = null;
-            }
-            parent.lastChild = matchings[0].getLeftParentPrevious();
-            if ( parent.lastChild != null ) {
-                parent.lastChild.setLeftParentNext( null );
-                matchings[0].setLeftParentPrevious( null );
-            }
-        }
-
-        return matchings;
-    }
-
-    private void restoreList(final LeftTuple parent,
-                             final LeftTuple[] matchings) {
-        // concatenate matchings list at the end of the children list
-        if ( parent.firstChild == null ) {
-            parent.firstChild = matchings[0];
-            parent.lastChild = matchings[1];
-        } else if ( matchings[0] != null ) {
-            parent.lastChild.setLeftParentNext( matchings[0] );
-            matchings[0].setLeftParentPrevious( parent.lastChild );
-            parent.lastChild = matchings[1];
-        }
-    }
-
-    /* (non-Javadoc)
-     * @see org.drools.reteoo.BaseNode#hashCode()
-     */
-    public int hashCode() {
-        return this.leftInput.hashCode() ^ this.rightInput.hashCode() ^ this.collect.hashCode() ^ this.resultsBinder.hashCode() ^ ArrayUtils.hashCode( this.resultConstraints );
-    }
-
-    /* (non-Javadoc)
-     * @see java.lang.Object#equals(java.lang.Object)
-     */
-    public boolean equals(final Object object) {
-        if ( this == object ) {
-            return true;
-        }
-
-        if ( object == null || !(object instanceof CollectNode) ) {
-            return false;
-        }
-
-        final CollectNode other = (CollectNode) object;
-
-        if ( this.getClass() != other.getClass() || (!this.leftInput.equals( other.leftInput )) || (!this.rightInput.equals( other.rightInput )) || (!this.constraints.equals( other.constraints )) ) {
-            return false;
-        }
-
-        return this.collect.equals( other.collect ) && resultsBinder.equals( other.resultsBinder ) && Arrays.equals( this.resultConstraints,
-                                                                                                                     other.resultConstraints );
-    }
-
-    public static class CollectMemory
-        implements
-        Externalizable {
-        private static final long serialVersionUID = 400L;
-        public BetaMemory         betaMemory;
-        public ContextEntry[]     resultsContext;
-        public ContextEntry[]     alphaContexts;
-
-        public void readExternal(ObjectInput in) throws IOException,
-                                                ClassNotFoundException {
-            betaMemory = (BetaMemory) in.readObject();
-            resultsContext = (ContextEntry[]) in.readObject();
-            alphaContexts = (ContextEntry[]) in.readObject();
-        }
-
-        public void writeExternal(ObjectOutput out) throws IOException {
-            out.writeObject( betaMemory );
-            out.writeObject( resultsContext );
-            out.writeObject( alphaContexts );
-        }
-    }
-
-    public static class CollectContext
-        implements
-        Externalizable {
-        private static final long serialVersionUID = -3076306175989410574L;
-        public RightTuple         resultTuple;
-        public boolean            propagated;
-
-        public void readExternal(ObjectInput in) throws IOException,
-                                                ClassNotFoundException {
-            resultTuple = (RightTuple) in.readObject();
-            propagated = in.readBoolean();
-        }
-
-        public void writeExternal(ObjectOutput out) throws IOException {
-            out.writeObject( resultTuple );
-            out.writeBoolean( propagated );
-        }
-
-    }
-
-    private static enum ActivitySource {
-        LEFT, RIGHT
-    }
-
-}

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/NodeTypeEnums.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/NodeTypeEnums.java	2010-04-12 20:12:05 UTC (rev 32523)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/NodeTypeEnums.java	2010-04-12 21:37:43 UTC (rev 32524)
@@ -6,7 +6,7 @@
     public static final short ExistsNode           = 2;
     public static final short EvalConditionNode    = 3;
     public static final short FromNode             = 4;
-    public static final short CollectNode          = 5;
+    //public static final short CollectNode          = 5;   // no longer used, since accumulate nodes execute collect logic now
     public static final short AccumulateNode       = 6;
     public static final short RightInputAdaterNode = 7;
     public static final short QueryTerminalNode    = 8;

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java	2010-04-12 20:12:05 UTC (rev 32523)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java	2010-04-12 21:37:43 UTC (rev 32524)
@@ -409,7 +409,7 @@
         // If we have no alpha or beta node with constraints on this ObjectType, we can just skip modifies
         boolean hasConstraints = false;
         for ( int i = 0; i < sinks.length && !hasConstraints; i++ ) {
-            if ( sinks[i] instanceof AlphaNode || sinks[i] instanceof AccumulateNode || sinks[i] instanceof CollectNode || sinks[i] instanceof FromNode ) {
+            if ( sinks[i] instanceof AlphaNode || sinks[i] instanceof AccumulateNode || sinks[i] instanceof FromNode ) {
                 hasConstraints = true;
             } else if ( sinks[i] instanceof BetaNode && ((BetaNode) sinks[i]).getConstraints().length > 0 ) {
                 hasConstraints = rootCall || this.usesDeclaration( ((BetaNode) sinks[i]).getConstraints() );

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/CollectBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/CollectBuilder.java	2010-04-12 20:12:05 UTC (rev 32523)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/CollectBuilder.java	2010-04-12 21:37:43 UTC (rev 32524)
@@ -20,14 +20,17 @@
 import java.util.Collections;
 import java.util.List;
 
+import org.drools.base.accumulators.CollectAccumulator;
 import org.drools.common.BetaConstraints;
 import org.drools.common.TupleStartEqualsConstraint;
-import org.drools.reteoo.CollectNode;
+import org.drools.reteoo.AccumulateNode;
 import org.drools.reteoo.LeftTupleSource;
 import org.drools.reteoo.ObjectSource;
 import org.drools.reteoo.RightInputAdapterNode;
+import org.drools.rule.Accumulate;
 import org.drools.rule.Behavior;
 import org.drools.rule.Collect;
+import org.drools.rule.Declaration;
 import org.drools.rule.Pattern;
 import org.drools.rule.RuleConditionElement;
 import org.drools.spi.AlphaNodeFieldConstraint;
@@ -55,15 +58,15 @@
         final List resultBehaviors = context.getBehaviors();
 
         final Pattern sourcePattern = collect.getSourcePattern();
-        final Pattern resultPattern = collect.getResultPattern();      
-        
+        final Pattern resultPattern = collect.getResultPattern();
+
         // get builder for the pattern
         final ReteooComponentBuilder builder = utils.getBuilderFor( sourcePattern );
 
         // save tuple source and pattern offset for later if needed
         final LeftTupleSource tupleSource = context.getTupleSource();
         final int currentPatternIndex = context.getCurrentPatternOffset();
-        
+
         // builds the source pattern
         builder.build( context,
                        utils,
@@ -88,27 +91,36 @@
             context.setBetaconstraints( betaConstraints );
             existSubNetwort = true;
         }
-        
-        BetaConstraints binder = utils.createBetaNodeConstraint( context, context.getBetaconstraints(), false );
+
+        BetaConstraints binder = utils.createBetaNodeConstraint( context,
+                                                                 context.getBetaconstraints(),
+                                                                 false );
         // indexing for the results should be always disabled
-        BetaConstraints resultBinder = utils.createBetaNodeConstraint( context, resultBetaConstraints, true );
-        
+        BetaConstraints resultBinder = utils.createBetaNodeConstraint( context,
+                                                                       resultBetaConstraints,
+                                                                       true );
+
         Behavior[] behaviors = Behavior.EMPTY_BEHAVIOR_LIST;
-        if( ! context.getBehaviors().isEmpty() ) {
-            behaviors = (Behavior[]) context.getBehaviors().toArray( new Behavior[ context.getBehaviors().size() ]);
+        if ( !context.getBehaviors().isEmpty() ) {
+            behaviors = (Behavior[]) context.getBehaviors().toArray( new Behavior[context.getBehaviors().size()] );
         }
 
+        CollectAccumulator accumulator = new CollectAccumulator( collect );
+        Accumulate accumulate = new Accumulate( sourcePattern,
+                                                sourcePattern.getRequiredDeclarations(),
+                                                (Declaration[]) collect.getInnerDeclarations().values().toArray( new Declaration[0] ),
+                                                accumulator );
         context.setTupleSource( (LeftTupleSource) utils.attachNode( context,
-                                                                new CollectNode( context.getNextId(),
-                                                                                 context.getTupleSource(),
-                                                                                 context.getObjectSource(),
-                                                                                 (AlphaNodeFieldConstraint[]) resultAlphaConstraints.toArray( new AlphaNodeFieldConstraint[resultAlphaConstraints.size()] ),
-                                                                                 binder, // source binder
-                                                                                 resultBinder,
-                                                                                 behaviors,
-                                                                                 collect,
-                                                                                 existSubNetwort,
-                                                                                 context ) ) );
+                                                                    new AccumulateNode( context.getNextId(),
+                                                                                        context.getTupleSource(),
+                                                                                        context.getObjectSource(),
+                                                                                        (AlphaNodeFieldConstraint[]) resultAlphaConstraints.toArray( new AlphaNodeFieldConstraint[resultAlphaConstraints.size()] ),
+                                                                                        binder, // source binder
+                                                                                        resultBinder,
+                                                                                        behaviors,
+                                                                                        accumulate,
+                                                                                        existSubNetwort,
+                                                                                        context ) ) );
         // source pattern was bound, so nulling context
         context.setObjectSource( null );
         context.setCurrentPatternOffset( currentPatternIndex );

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Collect.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Collect.java	2010-04-12 20:12:05 UTC (rev 32523)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Collect.java	2010-04-12 21:37:43 UTC (rev 32524)
@@ -40,13 +40,13 @@
     implements
     PatternSource {
 
-    private static final long serialVersionUID = 400L;
+    private static final long      serialVersionUID = 400L;
 
-    private Pattern           sourcePattern;
-    private Pattern           resultPattern;
-    
-    private Class             cls;
+    private Pattern                sourcePattern;
+    private Pattern                resultPattern;
 
+    private Class<Collection< Object >> cls;
+
     public Collect() {
     }
 
@@ -57,14 +57,15 @@
         this.resultPattern = resultPattern;
     }
 
-    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        sourcePattern   = (Pattern)in.readObject();
-        resultPattern   = (Pattern)in.readObject();
+    public void readExternal(ObjectInput in) throws IOException,
+                                            ClassNotFoundException {
+        sourcePattern = (Pattern) in.readObject();
+        resultPattern = (Pattern) in.readObject();
     }
 
     public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeObject(sourcePattern);
-        out.writeObject(resultPattern);
+        out.writeObject( sourcePattern );
+        out.writeObject( resultPattern );
     }
 
     public Object clone() {
@@ -80,16 +81,17 @@
         return this.sourcePattern;
     }
 
-    public Collection instantiateResultObject(InternalWorkingMemory wm) throws RuntimeDroolsException {
+    @SuppressWarnings("unchecked")
+    public Collection< Object > instantiateResultObject(InternalWorkingMemory wm) throws RuntimeDroolsException {
         try {
             // Collect can only be used with a Collection implementation, so
             // FactTemplateObject type is not allowed
             if ( this.cls == null ) {
                 ClassObjectType objType = ((ClassObjectType) this.resultPattern.getObjectType());
                 String className = determineResultClassName( objType );
-                this.cls = ((InternalRuleBase)wm.getRuleBase()).getRootClassLoader().loadClass( className );
+                this.cls = (Class<Collection<Object>>) Class.forName( className, true, ((InternalRuleBase) wm.getRuleBase()).getRootClassLoader() );
             }
-            return (Collection) this.cls.newInstance();
+            return this.cls.newInstance();
         } catch ( final ClassCastException cce ) {
             throw new RuntimeDroolsException( "Collect CE requires a Collection implementation as return type",
                                               cce );
@@ -99,9 +101,9 @@
         } catch ( final IllegalAccessException e ) {
             throw new RuntimeDroolsException( "Collect CE requires an accessible constructor for the return type",
                                               e );
-        } catch ( final ClassNotFoundException  e) {
+        } catch ( final ClassNotFoundException e ) {
             throw new RuntimeDroolsException( "Collect CE could not resolve return result class '" + ((ClassObjectType) this.resultPattern.getObjectType()).getClassName() + "'",
-                                              e );            
+                                              e );
         }
     }
 
@@ -118,11 +120,11 @@
      */
     private String determineResultClassName(ClassObjectType objType) {
         String className = objType.getClassName();
-        if( List.class.getName().equals( className ) ) {
+        if ( List.class.getName().equals( className ) ) {
             className = ArrayList.class.getName();
-        } else if( Set.class.getName().equals( className ) ) {
+        } else if ( Set.class.getName().equals( className ) ) {
             className = HashSet.class.getName();
-        } else if( Collection.class.getName().equals( className ) ) {
+        } else if ( Collection.class.getName().equals( className ) ) {
             className = ArrayList.class.getName();
         }
         return className;

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Pattern.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Pattern.java	2010-04-12 20:12:05 UTC (rev 32523)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Pattern.java	2010-04-12 21:37:43 UTC (rev 32524)
@@ -23,9 +23,11 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.drools.base.ClassObjectType;
 import org.drools.spi.AcceptsClassObjectType;
@@ -136,6 +138,23 @@
         this.objectType = objectType;
     }
 
+    public Declaration[] getRequiredDeclarations() {
+        Set<Declaration> decl = new HashSet<Declaration>();
+        Set<String> locals = new HashSet<String>();
+        for( Object constr : this.constraints ) {
+            if( constr instanceof Constraint ) {
+                for( Declaration d : ((Constraint)constr).getRequiredDeclarations() ) {
+                    if( ! locals.contains( d.getIdentifier() ) ) {
+                        decl.add( d );
+                    }
+                }
+            } else {
+                locals.add( ((Declaration)constr).getIdentifier() );
+            }
+        }
+        return decl.toArray( new Declaration[decl.size()] );
+    }
+    
     public Object clone() {
         final String identifier = (this.declaration != null) ? this.declaration.getIdentifier() : null;
         final Pattern clone = new Pattern( this.index,

Deleted: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CollectNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CollectNodeTest.java	2010-04-12 20:12:05 UTC (rev 32523)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CollectNodeTest.java	2010-04-12 21:37:43 UTC (rev 32524)
@@ -1,374 +0,0 @@
-/*
- * Copyright 2005 JBoss Inc
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.drools.reteoo;
-
-import java.util.Collection;
-import java.util.LinkedList;
-
-import junit.framework.Assert;
-
-import org.drools.DroolsTestCase;
-import org.drools.RuleBaseConfiguration;
-import org.drools.RuleBaseFactory;
-import org.drools.base.ClassObjectType;
-import org.drools.common.DefaultFactHandle;
-import org.drools.common.EmptyBetaConstraints;
-import org.drools.common.PropagationContextImpl;
-import org.drools.reteoo.CollectNode.CollectMemory;
-import org.drools.reteoo.builder.BuildContext;
-import org.drools.rule.Behavior;
-import org.drools.rule.Collect;
-import org.drools.rule.Pattern;
-import org.drools.rule.Rule;
-import org.drools.spi.AlphaNodeFieldConstraint;
-import org.drools.spi.ObjectType;
-import org.drools.spi.PropagationContext;
-import org.drools.spi.Tuple;
-
-/**
- * @author etirelli
- *
- */
-public class CollectNodeTest extends DroolsTestCase {
-    Rule                rule;
-    PropagationContext  contextAssert;
-    PropagationContext  contextRetract;
-    ReteooWorkingMemory workingMemory;
-    MockObjectSource    objectSource;
-    MockTupleSource     tupleSource;
-    MockLeftTupleSink   sink;
-    BetaNode            node;
-    CollectMemory       memory;
-    Collect             collect;
-
-    /* (non-Javadoc)
-     * @see junit.framework.TestCase#setUp()
-     */
-    protected void setUp() throws Exception {
-        super.setUp();
-        this.rule = new Rule( "test-rule" );
-        this.contextAssert = new PropagationContextImpl( 0,
-                                                         PropagationContext.ASSERTION,
-                                                         null,
-                                                         null,
-                                                         null );
-        this.contextRetract = new PropagationContextImpl( 0,
-                                                          PropagationContext.RETRACTION,
-                                                          null,
-                                                          null,
-                                                          null );
-
-        ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
-        BuildContext buildContext = new BuildContext( ruleBase,
-                                                      ruleBase.getReteooBuilder().getIdGenerator() );
-
-        this.workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
-
-        this.tupleSource = new MockTupleSource( 4 );
-        this.objectSource = new MockObjectSource( 4 );
-        this.sink = new MockLeftTupleSink();
-
-        final ObjectType srcObjType = new ClassObjectType( String.class );
-        final Pattern sourcePattern = new Pattern( 0,
-                                                   srcObjType );
-        final ObjectType resultObjType = new ClassObjectType( LinkedList.class );
-        final Pattern resultPattern = new Pattern( 1,
-                                                   resultObjType );
-        this.collect = new Collect( sourcePattern,
-                                    resultPattern );
-
-        this.node = new CollectNode( 15,
-                                     this.tupleSource,
-                                     this.objectSource,
-                                     new AlphaNodeFieldConstraint[0],
-                                     EmptyBetaConstraints.getInstance(),
-                                     EmptyBetaConstraints.getInstance(),
-                                     Behavior.EMPTY_BEHAVIOR_LIST,
-                                     this.collect,
-                                     false,
-                                     buildContext );
-
-        this.node.addTupleSink( this.sink );
-
-        this.memory = (CollectMemory) this.workingMemory.getNodeMemory( this.node );
-
-        // check memories are empty
-        assertEquals( 0,
-                      this.memory.betaMemory.getLeftTupleMemory().size() );
-        assertEquals( 0,
-                      this.memory.betaMemory.getRightTupleMemory().size() );
-    }
-
-    /* (non-Javadoc)
-     * @see junit.framework.TestCase#tearDown()
-     */
-    protected void tearDown() throws Exception {
-        super.tearDown();
-    }
-
-    public void testUpdateNewNode() {
-        this.node.updateSink( this.sink,
-                              this.contextAssert,
-                              this.workingMemory );
-        Assert.assertEquals( "No tuple should be propagated",
-                             0,
-                             this.sink.getAsserted().size() );
-
-        this.node.assertLeftTuple( new LeftTuple( this.workingMemory.getFactHandleFactory().newFactHandle( "cheese",
-                                                                                                           null,
-                                                                                                           null ),
-                                                  this.node,
-                                                  true ),
-                                   this.contextAssert,
-                                   this.workingMemory );
-        this.node.assertLeftTuple( new LeftTuple( this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese",
-                                                                                                           null,
-                                                                                                           null ),
-                                                  this.node,
-                                                  true ),
-                                   this.contextAssert,
-                                   this.workingMemory );
-
-        Assert.assertEquals( "Two tuples should have been propagated",
-                             2,
-                             this.sink.getAsserted().size() );
-
-        final MockLeftTupleSink otherSink = new MockLeftTupleSink();
-
-        this.node.addTupleSink( otherSink );
-        this.node.updateSink( otherSink,
-                              this.contextAssert,
-                              this.workingMemory );
-
-        Assert.assertEquals( "Two tuples should have been propagated",
-                             2,
-                             otherSink.getAsserted().size() );
-    }
-
-    public void testAssertTuple() {
-        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese",
-                                                                                                                  null,
-                                                                                                                  null );
-        final LeftTuple tuple0 = new LeftTuple( f0,
-                                                this.node,
-                                                true );
-
-        // assert tuple, should add one to left memory
-        this.node.assertLeftTuple( tuple0,
-                                   this.contextAssert,
-                                   this.workingMemory );
-        // check memories 
-        assertEquals( 1,
-                      this.memory.betaMemory.getLeftTupleMemory().size() );
-        assertEquals( 0,
-                      this.memory.betaMemory.getRightTupleMemory().size() );
-        Assert.assertTrue( "An empty collection should be propagated",
-                           ((Collection) ((DefaultFactHandle) ((Tuple) ((Object[]) this.sink.getAsserted().get( 0 ))[0]).get( 1 )).getObject()).isEmpty() );
-
-        // assert tuple, should add left memory 
-        final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese",
-                                                                                                                  null,
-                                                                                                                  null );
-
-        final LeftTuple tuple1 = new LeftTuple( f1,
-                                                this.node,
-                                                true );
-        this.node.assertLeftTuple( tuple1,
-                                   this.contextAssert,
-                                   this.workingMemory );
-        assertEquals( 2,
-                      this.memory.betaMemory.getLeftTupleMemory().size() );
-        Assert.assertTrue( "An empty collection should be propagated",
-                           ((Collection) ((DefaultFactHandle) ((Tuple) ((Object[]) this.sink.getAsserted().get( 1 ))[0]).get( 1 )).getObject()).isEmpty() );
-
-        assertTrue( this.memory.betaMemory.getLeftTupleMemory().contains( tuple0 ) );
-        assertTrue( this.memory.betaMemory.getLeftTupleMemory().contains( tuple1 ) );
-
-        Assert.assertEquals( "Two tuples should have been propagated",
-                             2,
-                             this.sink.getAsserted().size() );
-    }
-
-    public void testAssertTupleWithObjects() {
-        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese",
-                                                                                                                  null,
-                                                                                                                  null );
-        final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese",
-                                                                                                                  null,
-                                                                                                                  null );
-
-        final LeftTuple tuple0 = new LeftTuple( f0,
-                                                this.node,
-                                                true );
-
-        this.node.assertObject( f0,
-                                this.contextAssert,
-                                this.workingMemory );
-        this.node.assertObject( f1,
-                                this.contextAssert,
-                                this.workingMemory );
-
-        // assert tuple, should add one to left memory
-        this.node.assertLeftTuple( tuple0,
-                                   this.contextAssert,
-                                   this.workingMemory );
-        // check memories 
-        assertEquals( 1,
-                      this.memory.betaMemory.getLeftTupleMemory().size() );
-        assertEquals( 2,
-                      this.memory.betaMemory.getRightTupleMemory().size() );
-        Assert.assertEquals( "Wrong number of elements in matching objects list ",
-                             2,
-                             ((Collection) ((DefaultFactHandle) ((Tuple) ((Object[]) this.sink.getAsserted().get( 0 ))[0]).get( 1 )).getObject()).size() );
-
-        // assert tuple, should add left memory 
-        final LeftTuple tuple1 = new LeftTuple( f1,
-                                                this.node,
-                                                true );
-        this.node.assertLeftTuple( tuple1,
-                                   this.contextAssert,
-                                   this.workingMemory );
-        assertEquals( 2,
-                      this.memory.betaMemory.getLeftTupleMemory().size() );
-        Assert.assertEquals( "Wrong number of elements in matching objects list ",
-                             2,
-                             ((Collection) ((DefaultFactHandle) ((Tuple) ((Object[]) this.sink.getAsserted().get( 1 ))[0]).get( 1 )).getObject()).size() );
-
-        assertTrue( this.memory.betaMemory.getLeftTupleMemory().contains( tuple0 ) );
-        assertTrue( this.memory.betaMemory.getLeftTupleMemory().contains( tuple1 ) );
-
-        Assert.assertEquals( "Two tuples should have been propagated",
-                             2,
-                             this.sink.getAsserted().size() );
-    }
-
-    public void testRetractTuple() {
-        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese",
-                                                                                                                  null,
-                                                                                                                  null );
-
-        final LeftTuple tuple0 = new LeftTuple( f0,
-                                                this.node,
-                                                true );
-
-        // assert tuple, should add one to left memory
-        this.node.assertLeftTuple( tuple0,
-                                   this.contextAssert,
-                                   this.workingMemory );
-        // check memories 
-        assertEquals( 1,
-                      this.memory.betaMemory.getLeftTupleMemory().size() );
-        assertEquals( 0,
-                      this.memory.betaMemory.getRightTupleMemory().size() );
-        Assert.assertTrue( "An empty collection should be propagated",
-                           ((Collection) ((DefaultFactHandle) ((Tuple) ((Object[]) this.sink.getAsserted().get( 0 ))[0]).get( 1 )).getObject()).isEmpty() );
-
-        this.node.retractLeftTuple( tuple0,
-                                    this.contextRetract,
-                                    this.workingMemory );
-        assertEquals( 0,
-                      this.memory.betaMemory.getLeftTupleMemory().size() );
-        assertEquals( 1,
-                      this.sink.getRetracted().size() );
-        assertEquals( 1,
-                      this.sink.getAsserted().size() );
-    }
-
-    public void testMemory() {
-        ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
-        BuildContext buildContext = new BuildContext( ruleBase,
-                                                      ruleBase.getReteooBuilder().getIdGenerator() );
-
-        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
-
-        final MockObjectSource objectSource = new MockObjectSource( 1 );
-        final MockTupleSource tupleSource = new MockTupleSource( 1 );
-
-        final CollectNode collectNode = new CollectNode( 2,
-                                                         tupleSource,
-                                                         objectSource,
-                                                         new AlphaNodeFieldConstraint[0],
-                                                         EmptyBetaConstraints.getInstance(),
-                                                         EmptyBetaConstraints.getInstance(),
-                                                         Behavior.EMPTY_BEHAVIOR_LIST,
-                                                         this.collect,
-                                                         false,
-                                                         buildContext );
-
-        final CollectMemory memory = (CollectMemory) workingMemory.getNodeMemory( collectNode );
-
-        assertNotNull( memory );
-    }
-
-    public void testAssertTupleSequentialMode() {
-        RuleBaseConfiguration conf = new RuleBaseConfiguration();
-        conf.setSequential( true );
-
-        this.workingMemory = new ReteooWorkingMemory( 1,
-                                                      (ReteooRuleBase) RuleBaseFactory.newRuleBase( conf ) );
-
-        this.memory = (CollectMemory) this.workingMemory.getNodeMemory( this.node );
-        this.node.setLeftTupleMemoryEnabled( false );
-
-        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese",
-                                                                                                                  null,
-                                                                                                                  null );
-        final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese",
-                                                                                                                  null,
-                                                                                                                  null );
-
-        final LeftTuple tuple0 = new LeftTuple( f0,
-                                                this.node,
-                                                true );
-
-        this.node.assertObject( f0,
-                                this.contextAssert,
-                                this.workingMemory );
-        this.node.assertObject( f1,
-                                this.contextAssert,
-                                this.workingMemory );
-
-        // assert tuple, should not add to left memory, since we are in sequential mode
-        this.node.assertLeftTuple( tuple0,
-                                   this.contextAssert,
-                                   this.workingMemory );
-        // check memories 
-        assertNull( this.memory.betaMemory.getLeftTupleMemory() );
-        assertEquals( 2,
-                      this.memory.betaMemory.getRightTupleMemory().size() );
-        Assert.assertEquals( "Wrong number of elements in matching objects list ",
-                             2,
-                             ((Collection) ((DefaultFactHandle) ((Tuple) ((Object[]) this.sink.getAsserted().get( 0 ))[0]).get( 1 )).getObject()).size() );
-
-        // assert tuple, should not add to left memory, since we are in sequential mode
-        final LeftTuple tuple1 = new LeftTuple( f1,
-                                                this.node,
-                                                true );
-        this.node.assertLeftTuple( tuple1,
-                                   this.contextAssert,
-                                   this.workingMemory );
-        assertNull( this.memory.betaMemory.getLeftTupleMemory() );
-        Assert.assertEquals( "Wrong number of elements in matching objects list ",
-                             2,
-                             ((Collection) ((DefaultFactHandle) ((Tuple) ((Object[]) this.sink.getAsserted().get( 1 ))[0]).get( 1 )).getObject()).size() );
-
-        Assert.assertEquals( "Two tuples should have been propagated",
-                             2,
-                             this.sink.getAsserted().size() );
-    }
-
-}

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/test/ReteDslTestEngine.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/test/ReteDslTestEngine.java	2010-04-12 20:12:05 UTC (rev 32523)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/test/ReteDslTestEngine.java	2010-04-12 21:37:43 UTC (rev 32524)
@@ -30,7 +30,6 @@
 import org.drools.reteoo.AccumulateNode;
 import org.drools.reteoo.BetaMemory;
 import org.drools.reteoo.BetaNode;
-import org.drools.reteoo.CollectNode;
 import org.drools.reteoo.LeftTuple;
 import org.drools.reteoo.LeftTupleMemory;
 import org.drools.reteoo.LeftTupleSink;
@@ -44,12 +43,10 @@
 import org.drools.reteoo.RuleTerminalNode;
 import org.drools.reteoo.Sink;
 import org.drools.reteoo.AccumulateNode.AccumulateMemory;
-import org.drools.reteoo.CollectNode.CollectMemory;
 import org.drools.reteoo.builder.BuildContext;
 import org.drools.reteoo.test.dsl.AccumulateNodeStep;
 import org.drools.reteoo.test.dsl.BetaNodeStep;
 import org.drools.reteoo.test.dsl.BindingStep;
-import org.drools.reteoo.test.dsl.CollectNodeStep;
 import org.drools.reteoo.test.dsl.DSLMock;
 import org.drools.reteoo.test.dsl.DslStep;
 import org.drools.reteoo.test.dsl.EvalNodeStep;
@@ -90,7 +87,6 @@
     private static final String JOIN_NODE                = "JoinNode";
     private static final String NOT_NODE                 = "NotNode";
     private static final String EXISTS_NODE              = "ExistsNode";
-    private static final String COLLECT_NODE             = "CollectNode";
     private static final String ACCUMULATE_NODE          = "AccumulateNode";
     private static final String RULE_TERMINAL_NODE       = "RuleTerminalNode";
     private static final String EVAL_NODE                = "EvalNode";
@@ -121,8 +117,6 @@
                         new NotNodeStep( this.reteTesterHelper ) );
         this.steps.put( EXISTS_NODE,
                         new ExistsNodeStep( this.reteTesterHelper ) );
-        this.steps.put( COLLECT_NODE,
-                        new CollectNodeStep( this.reteTesterHelper ) );
         this.steps.put( ACCUMULATE_NODE,
                         new AccumulateNodeStep( this.reteTesterHelper ) );
         this.steps.put( RULE_TERMINAL_NODE,
@@ -293,10 +287,7 @@
             List<InternalFactHandle> handles = (List<InternalFactHandle>) context.get( "Handles" );
 
             BetaMemory memory = null;
-            if ( node instanceof CollectNode ) {
-                CollectMemory colmem = (CollectMemory) wm.getNodeMemory( node );
-                memory = colmem.betaMemory;
-            } else if ( node instanceof AccumulateNode ) {
+            if ( node instanceof AccumulateNode ) {
                 AccumulateMemory accmem = (AccumulateMemory) wm.getNodeMemory( node );
                 memory = accmem.betaMemory;
             } else {

Deleted: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/test/dsl/CollectNodeStep.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/test/dsl/CollectNodeStep.java	2010-04-12 20:12:05 UTC (rev 32523)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/test/dsl/CollectNodeStep.java	2010-04-12 21:37:43 UTC (rev 32524)
@@ -1,127 +0,0 @@
-/*
- * Copyright 2008 Red Hat
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.drools.reteoo.test.dsl;
-
-import java.beans.IntrospectionException;
-import java.util.List;
-import java.util.Map;
-
-import org.drools.base.ClassObjectType;
-import org.drools.common.EmptyBetaConstraints;
-import org.drools.common.SingleBetaConstraints;
-import org.drools.reteoo.CollectNode;
-import org.drools.reteoo.LeftTupleSource;
-import org.drools.reteoo.ObjectSource;
-import org.drools.reteoo.ObjectTypeNode;
-import org.drools.reteoo.builder.BuildContext;
-import org.drools.rule.BehaviorManager;
-import org.drools.rule.Collect;
-import org.drools.rule.Declaration;
-import org.drools.rule.Pattern;
-import org.drools.spi.AlphaNodeFieldConstraint;
-import org.drools.spi.BetaNodeFieldConstraint;
-import org.mockito.Mockito;
-
-public class CollectNodeStep
-    implements
-    Step {
-
-    private ReteTesterHelper reteTesterHelper;
-
-    public CollectNodeStep(ReteTesterHelper reteTesterHelper) {
-        this.reteTesterHelper = reteTesterHelper;
-    }
-
-    public void execute(Map<String, Object> context,
-                        List<String[]> args) {
-        BuildContext buildContext = (BuildContext) context.get( "BuildContext" );
-
-        if ( args.size() != 0 ) {
-            String[] a = args.get( 0 );
-            String name = a[0].trim();
-            String leftInput = a[1].trim();
-            String rightInput = a[2].trim();
-            String returnType = a[3].trim();
-
-            LeftTupleSource leftTupleSource;
-            if ( "mock".equals( leftInput ) ) {
-                leftTupleSource = Mockito.mock( LeftTupleSource.class );
-            } else {
-                leftTupleSource = (LeftTupleSource) context.get( leftInput );
-            }
-
-            ObjectSource rightObjectSource;
-            if ( "mock".equals( rightInput ) ) {
-                rightObjectSource = Mockito.mock( ObjectSource.class );;
-            } else {
-                rightObjectSource = (ObjectSource) context.get( rightInput );
-            }
-
-            a = args.get( 1 );
-            String fieldName = a[0].trim();
-            String operator = a[1].trim();
-            String var = a[2].trim();
-
-            Declaration declr = (Declaration) context.get( var );
-
-            Pattern sourcePattern;
-            Pattern resultPattern;
-            try {
-                sourcePattern = reteTesterHelper.getPattern( 0,
-                                                             ((ClassObjectType) ((ObjectTypeNode) rightObjectSource).getObjectType()).getClassName() );
-                resultPattern = reteTesterHelper.getPattern( buildContext.getNextId(),
-                                                             returnType );
-            } catch ( Exception e ) {
-                throw new IllegalArgumentException();
-            }
-
-            BetaNodeFieldConstraint betaConstraint;
-            try {
-                betaConstraint = this.reteTesterHelper.getBoundVariableConstraint( sourcePattern,
-                                                                                   fieldName,
-                                                                                   declr,
-                                                                                   operator );
-            } catch ( IntrospectionException e ) {
-                throw new IllegalArgumentException();
-            }
-
-            SingleBetaConstraints constraints = new SingleBetaConstraints( betaConstraint,
-                                                                           buildContext.getRuleBase().getConfiguration() );
-
-            Collect collect = new Collect( sourcePattern,
-                                           resultPattern );
-
-            CollectNode collectNode = new CollectNode( buildContext.getNextId(),
-                                                       leftTupleSource,
-                                                       rightObjectSource,
-                                                       new AlphaNodeFieldConstraint[0],
-                                                       constraints,
-                                                       new EmptyBetaConstraints(),
-                                                       BehaviorManager.NO_BEHAVIORS,
-                                                       collect,
-                                                       false,
-                                                       buildContext );
-            collectNode.attach();
-            context.put( name,
-                         collectNode );
-
-        } else {
-            throw new IllegalArgumentException( "Cannot arguments " + args );
-
-        }
-    }
-}
\ No newline at end of file

Deleted: labs/jbossrules/trunk/drools-core/src/test/resources/org/drools/reteoo/test/CollectNodeAssertRetractTest.nodeTestCase
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/resources/org/drools/reteoo/test/CollectNodeAssertRetractTest.nodeTestCase	2010-04-12 20:12:05 UTC (rev 32523)
+++ labs/jbossrules/trunk/drools-core/src/test/resources/org/drools/reteoo/test/CollectNodeAssertRetractTest.nodeTestCase	2010-04-12 21:37:43 UTC (rev 32524)
@@ -1,150 +0,0 @@
-TestCase "Collect Node assert/retract test case"
-
-Setup
-	ObjectTypeNode:
-	    otnLeft1, org.drools.Person;
-	LeftInputAdapterNode:
-	    lian0, otnLeft1;
-	ObjectTypeNode:
-	    otnRight1, org.drools.Cheese;
-	Binding:
-	     l1, 0, org.drools.Person, likes;
-	CollectNode:
-	    col1, lian0, otnRight1, java.util.ArrayList;
-	    type, ==, l1;
-	LeftTupleSink:
-	    sink1, col1;
-	Facts:
-	    new org.drools.Person('darth', 35, "brie"), new org.drools.Person('bobba', 36, 'stilton'),
-	    new org.drools.Cheese('brie', 10), new org.drools.Cheese('brie', 12),
-	    new org.drools.Cheese('stilton', 15), new org.drools.Cheese('muzzarella', 12);
-	
-/**
- * check single left assertion and retraction
- */
-Test "Simple assertion and retraction"	
-	assert:
-	    otnLeft1, [h0];
-	col1:
-	    leftMemory, [[h0]];
-	sink1:
-	    verify, assertLeft, count, 1;
-	    verify, assertLeft, tuple0[0], sameInstance(h0);
-	    verify, assertLeft, tuple0[1].object, instanceOf( java.util.Collection );  
-	    verify, assertLeft, tuple0[1].object.isEmpty();  
-	retract:
-	    otnLeft1, [h0];   
-	col1:
-	    leftMemory, [];
-	sink1:
-	    verify, retractLeft, count, 1;
-	    verify, retractLeft, tuple0[0], sameInstance(h0);
-	    
-/**    
- * check single right assertion and retraction
- */
-Test "Single right assertion and retraction"
-	assert:
-	    otnRight1, [h2];
-	col1:
-	    rightMemory, [h2];
-	retract:
-	    otnRight1, [h2]; 
-	col1:
-	    rightMemory, [];
-	sink1:
-	    verify, assertLeft, count, 0;
-	    verify, retractLeft, count, 0;
-	
-/**        
- *  check single left then right assertion
- */
- Test "collect node single left then right assertion" 
-	assert:
-	    otnLeft1, [h0];  
-	sink1:
-	    verify, assertLeft, count, 1;
-	    verify, assertLeft, tuple0[1].object.isEmpty();
-	assert:
-	    otnRight1, [h2];
-	col1:
-	    leftMemory, [[h0]];  
-	    rightMemory, [h2];  
-	sink1:
-	    verify, modifyLeft, count, 1;
-	    verify, modifyLeft, tuple0[1].object, hasItem( h2.object );
-	retract:
-	    otnLeft1, [h0]; 
-	    otnRight1, [h2];
-	sink1:
-	    verify, retractLeft, count, 1;
-	    verify, modifyLeft, count, 1; // still 1, so no new calls on the retract
-	    verify, assertLeft, count, 1; // checking just in case
-	   
-/**    
- *  check single right then left assertion
- */
-Test "single right then left assertion" 
-	assert:
-	    otnRight1, [h2];
-	    otnLeft1, [h1];  
-	col1:
-	    leftMemory, [[h1]];  
-	    rightMemory, [h2];  
-	sink1:
-	    verify, assertLeft, count, 1;
-	    verify, assertLeft, tuple0[1].object.isEmpty();
-	    verify, modifyLeft, count, 0; // checking, just in case
-	retract:
-	    otnLeft1, [h1]; 
-	    otnRight1, [h2];    
-	sink1:
-	    verify, retractLeft, count, 1;
-	    verify, modifyLeft, count, 0;
-	
-/**    
- * assert two left and two right, with incremental first removal
- */
-Test "two left and two right" 
-	assert:
-	    otnLeft1, [h0, h1];
-	    otnRight1, [h2, h3];
-	col1:
-	    leftMemory, [[h0]];
-	    leftMemory, [[h1]];  
-	    rightMemory, [h2, h3];  
-	sink1:
-	    verify, assertLeft, count, 2;
-	    verify, modifyLeft, count, 2;
-	    verify, assertLeft, tuple0[0], is( h0 );
-	    verify, assertLeft, tuple1[0], is( h1 );
-	    verify, modifyLeft, tuple1[1].object.size() == 2;
-	    verify, modifyLeft, tuple1[1].object, hasItem( h2.object );
-	    verify, modifyLeft, tuple1[1].object, hasItem( h3.object );
-	retract:
-	    otnLeft1, [h0];
-	col1:
-	    leftMemory, [[h1]];  
-	    rightMemory, [h2, h3];  
-	sink1:
-	    verify, retractLeft, count, 1;
-	    verify, retractLeft, tuple0[0], is( h0 );
-	retract:
-	    otnRight1, [h2];	
-	col1:
-	    leftMemory, [[h1]];  
-	    rightMemory, [h3];  
-	sink1:
-	    verify, retractLeft, count, 1; // still 1, so no retracts were called
-	    verify, modifyLeft, count, 2; // still 2, so no modifies were called
-	retract:
-	    otnLeft1, [h1]; 
-	sink1:
-	    verify, retractLeft, count, 2; 
-	retract:
-	    otnRight1, [h3]; 
-	col1:
-	    leftMemory, [];  
-	    rightMemory, [];  
-
-	



More information about the jboss-svn-commits mailing list