[jboss-svn-commits] JBL Code SVN: r25938 - in labs/jbossrules/branches/salaboy_streams: drools-compiler/src/main/resources/org/drools/rule/builder/dialect/java and 9 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sat Apr 4 21:12:29 EDT 2009


Author: salaboy21
Date: 2009-04-04 21:12:27 -0400 (Sat, 04 Apr 2009)
New Revision: 25938

Modified:
   labs/jbossrules/branches/salaboy_streams/drools-api/src/main/java/org/drools/runtime/rule/WorkingMemory.java
   labs/jbossrules/branches/salaboy_streams/drools-api/src/main/java/org/drools/runtime/rule/WorkingMemoryEntryPoint.java
   labs/jbossrules/branches/salaboy_streams/drools-compiler/src/main/resources/org/drools/rule/builder/dialect/java/javaInvokers.mvel
   labs/jbossrules/branches/salaboy_streams/drools-compiler/src/test/java/org/drools/testframework/MockWorkingMemory.java
   labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/base/DefaultKnowledgeHelper.java
   labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/base/SequentialKnowledgeHelper.java
   labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/base/mvel/DroolsMVELFactory.java
   labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/base/mvel/DroolsMVELPreviousDeclarationVariable.java
   labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/common/NamedEntryPoint.java
   labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/impl/StatefulKnowledgeSessionImpl.java
   labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/marshalling/impl/AbstractProcessInstanceMarshaller.java
   labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/marshalling/impl/InputMarshaller.java
   labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/marshalling/impl/OutputMarshaller.java
   labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/marshalling/impl/RuleFlowProcessInstanceMarshaller.java
   labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/reteoo/LeftTuple.java
   labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java
   labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/spi/KnowledgeHelper.java
   labs/jbossrules/branches/salaboy_streams/drools-core/src/test/java/org/drools/reteoo/FromNodeTest.java
Log:
changes for modify and use the correct entry point in MVEL and Java. all test in core and compiler works

Modified: labs/jbossrules/branches/salaboy_streams/drools-api/src/main/java/org/drools/runtime/rule/WorkingMemory.java
===================================================================
--- labs/jbossrules/branches/salaboy_streams/drools-api/src/main/java/org/drools/runtime/rule/WorkingMemory.java	2009-04-04 20:40:08 UTC (rev 25937)
+++ labs/jbossrules/branches/salaboy_streams/drools-api/src/main/java/org/drools/runtime/rule/WorkingMemory.java	2009-04-05 01:12:27 UTC (rev 25938)
@@ -32,65 +32,9 @@
      * Returns the session clock instance assigned to this session
      * @return
      */
-    public SessionClock getSessionClock();
+    public <T extends SessionClock> T getSessionClock();
 
     /**
-     * Returns the fact handle associated with the given object. It is important to note that this 
-     * method behaves in accordance with the configured assert behaviour for this knowledge base
-     * (either IDENTITY or EQUALITY).
-     *  
-     * @param object 
-     *               the fact for which the fact handle will be returned.
-     * 
-     * @return the fact handle for the given object, or null in case no fact handle was found for the
-     *         given object.
-     *         
-     * @see KnowledgeBaseConfiguration
-     */
-    FactHandle getFactHandle(Object object);
-
-    /**
-     * Returns the object associated with the given FactHandle.
-     * 
-     * @param factHandle
-     * @return
-     */
-    Object getObject(FactHandle factHandle);
-
-    /**
-     * Returns all facts from the current session.
-     * 
-     * @return
-     */
-    Collection< ? extends Object > getObjects();
-
-    /**
-     * Returns all facts from the current session that are accepted by the given <code>ObjectFilter</code>.
-     * 
-     * @param filter the filter to be applied to the returned collection of facts.
-     *  
-     * @return
-     */
-    Collection< ? extends Object > getObjects(ObjectFilter filter);
-
-    /**
-     * Returns all <code>FactHandle</code>s from the current session.
-     * 
-     * @return
-     */
-    Collection< ? extends FactHandle> getFactHandles();
-
-    /**
-     * Returns all <code>FactHandle</code>s from the current session for which the facts are accepted by 
-     * the given filter.
-     * 
-     * @param filter the filter to be applied to the returned collection of <code>FactHandle</code>s.
-     * 
-     * @return
-     */
-    Collection< ? extends FactHandle> getFactHandles(ObjectFilter filter);
-
-    /**
      * Returns a reference to this session's <code>Agenda</code>.
      * 
      * @return

Modified: labs/jbossrules/branches/salaboy_streams/drools-api/src/main/java/org/drools/runtime/rule/WorkingMemoryEntryPoint.java
===================================================================
--- labs/jbossrules/branches/salaboy_streams/drools-api/src/main/java/org/drools/runtime/rule/WorkingMemoryEntryPoint.java	2009-04-04 20:40:08 UTC (rev 25937)
+++ labs/jbossrules/branches/salaboy_streams/drools-api/src/main/java/org/drools/runtime/rule/WorkingMemoryEntryPoint.java	2009-04-05 01:12:27 UTC (rev 25938)
@@ -1,5 +1,10 @@
 package org.drools.runtime.rule;
 
+import java.util.Collection;
+
+import org.drools.KnowledgeBaseConfiguration;
+import org.drools.runtime.ObjectFilter;
+
 /**
  * <p>An entry-point is an abstract channel through where facts are inserted into the engine.</p>
  * <p>Drools 5 supports multiple entry-points into a single <code>StatefulKnowledgeBase</code>: the
@@ -55,4 +60,59 @@
     void update(FactHandle handle,
                 Object object);
 
+    /**
+     * Returns the fact handle associated with the given object. It is important to note that this 
+     * method behaves in accordance with the configured assert behaviour for this knowledge base
+     * (either IDENTITY or EQUALITY).
+     *  
+     * @param object 
+     *               the fact for which the fact handle will be returned.
+     * 
+     * @return the fact handle for the given object, or null in case no fact handle was found for the
+     *         given object.
+     *         
+     * @see KnowledgeBaseConfiguration
+     */
+    FactHandle getFactHandle(Object object);
+
+    /**
+     * Returns the object associated with the given FactHandle.
+     * 
+     * @param factHandle
+     * @return
+     */
+    Object getObject(FactHandle factHandle);
+
+    /**
+     * Returns all facts from the current session.
+     * 
+     * @return
+     */
+    Collection< ? extends Object > getObjects();
+
+    /**
+     * Returns all facts from the current session that are accepted by the given <code>ObjectFilter</code>.
+     * 
+     * @param filter the filter to be applied to the returned collection of facts.
+     *  
+     * @return
+     */
+    Collection< ? extends Object > getObjects(ObjectFilter filter);
+
+    /**
+     * Returns all <code>FactHandle</code>s from the current session.
+     * 
+     * @return
+     */
+    Collection< ? extends FactHandle> getFactHandles();
+
+    /**
+     * Returns all <code>FactHandle</code>s from the current session for which the facts are accepted by 
+     * the given filter.
+     * 
+     * @param filter the filter to be applied to the returned collection of <code>FactHandle</code>s.
+     * 
+     * @return
+     */
+    Collection< ? extends FactHandle> getFactHandles(ObjectFilter filter);    
 }

Modified: labs/jbossrules/branches/salaboy_streams/drools-compiler/src/main/resources/org/drools/rule/builder/dialect/java/javaInvokers.mvel
===================================================================
--- labs/jbossrules/branches/salaboy_streams/drools-compiler/src/main/resources/org/drools/rule/builder/dialect/java/javaInvokers.mvel	2009-04-04 20:40:08 UTC (rev 25937)
+++ labs/jbossrules/branches/salaboy_streams/drools-compiler/src/main/resources/org/drools/rule/builder/dialect/java/javaInvokers.mvel	2009-04-05 01:12:27 UTC (rev 25938)
@@ -334,8 +334,9 @@
 
         @foreach{type : declarationTypes, declr : declarations, index : indexes, notPattern : notPatterns}
           org.drools.common.InternalFactHandle @{declr.identifier}__Handle__ = ( org.drools.common.InternalFactHandle ) tuple.get( knowledgeHelper.getDeclaration( declarations[@{index}].getIdentifier() ) );
-          @{type} @{declr.identifier} = ( @{type} )  declarations[@{index}].@{declr.nativeReadMethod.name}( (org.drools.common.InternalWorkingMemory) workingMemory, @{declr.identifier}__Handle__.getObject() );
+          @{type} @{declr.identifier} = ( @{type} )  declarations[@{index}].@{declr.nativeReadMethod.name}((org.drools.common.InternalWorkingMemory) workingMemory, @{declr.identifier}__Handle__.getObject() );
           @if{notPattern}@{declr.identifier}__Handle__ =  (org.drools.common.InternalFactHandle) knowledgeHelper.getWorkingMemory().getFactHandle( @{declr.identifier} );@end{}
+          knowledgeHelper.getIdentityMap().put(@{declr.identifier}, @{declr.identifier}__Handle__ );
         @end{}
 
         @foreach{type : globalTypes, identifier : globals} @{type} @{identifier} = ( @{type} ) workingMemory.getGlobal( "@{identifier}" );

Modified: labs/jbossrules/branches/salaboy_streams/drools-compiler/src/test/java/org/drools/testframework/MockWorkingMemory.java
===================================================================
--- labs/jbossrules/branches/salaboy_streams/drools-compiler/src/test/java/org/drools/testframework/MockWorkingMemory.java	2009-04-04 20:40:08 UTC (rev 25937)
+++ labs/jbossrules/branches/salaboy_streams/drools-compiler/src/test/java/org/drools/testframework/MockWorkingMemory.java	2009-04-05 01:12:27 UTC (rev 25938)
@@ -47,6 +47,7 @@
 import org.drools.runtime.Environment;
 import org.drools.runtime.ExitPoint;
 import org.drools.runtime.KnowledgeRuntime;
+import org.drools.runtime.ObjectFilter;
 import org.drools.runtime.impl.BatchExecutionResultImpl;
 import org.drools.spi.Activation;
 import org.drools.spi.AgendaFilter;
@@ -541,4 +542,24 @@
         
     }
 
+    public Collection< ? extends org.drools.runtime.rule.FactHandle> getFactHandles() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public Collection< ? extends org.drools.runtime.rule.FactHandle> getFactHandles(ObjectFilter filter) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public Collection< ? extends Object> getObjects() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public Collection< ? extends Object> getObjects(ObjectFilter filter) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
 }

Modified: labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/base/DefaultKnowledgeHelper.java
===================================================================
--- labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/base/DefaultKnowledgeHelper.java	2009-04-04 20:40:08 UTC (rev 25937)
+++ labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/base/DefaultKnowledgeHelper.java	2009-04-05 01:12:27 UTC (rev 25938)
@@ -25,6 +25,8 @@
 import java.util.Map;
 
 import org.drools.FactException;
+import org.drools.FactHandle;
+import org.drools.WorkingMemory;
 import org.drools.common.InternalWorkingMemoryActions;
 import org.drools.impl.StatefulKnowledgeSessionImpl;
 import org.drools.reteoo.ReteooWorkingMemory;
@@ -56,16 +58,14 @@
     private InternalWorkingMemoryActions workingMemory;
 
     private IdentityHashMap<Object,FactHandle>              identityMap;
-    
+
     public DefaultKnowledgeHelper() {
-       
-        //this.identityMap =  new IdentityHashMap<Object,FactHandle>();
 
     }
 
     public DefaultKnowledgeHelper(final WorkingMemory workingMemory) {
         this.workingMemory = (InternalWorkingMemoryActions) workingMemory;
-     
+
        this.identityMap =  new IdentityHashMap<Object,FactHandle>();
 
     }
@@ -122,7 +122,6 @@
     public void insertLogical(final Object object) throws FactException {
         insertLogical( object,
                        false );
-
     }
 
     public void insertLogical(final Object object,
@@ -276,33 +275,22 @@
     //    }
 
     public Object get(final Declaration declaration) {
-        //((InternalWorkingMemoryActions)((InternalFactHandle)this.tuple.get( declaration )).getEntryPoint())
-//        getIdentityMap().put(declaration.getValue(
-//                                ((InternalWorkingMemoryActions)(this.tuple.get(declaration)).getEntryPoint()),
-//                                     this.tuple.get( declaration ).getObject() ),
-//                                     tuple.get(declaration));
-        InternalWorkingMemoryEntryPoint wmTmp = ((InternalWorkingMemoryEntryPoint)(this.tuple.get(declaration)).getEntryPoint());
-       
+         InternalWorkingMemoryEntryPoint wmTmp = ((InternalWorkingMemoryEntryPoint)(this.tuple.get(declaration)).getEntryPoint());
+         
         if(wmTmp != null){
         Object object = declaration.getValue( wmTmp.getInternalWorkingMemory() ,
                                      this.tuple.get( declaration ).getObject() );
-        
+
                 getIdentityMap().put(object, wmTmp.getFactHandleByIdentity(object));
                 return object;
         }
         return null;
+      //  return declaration.getValue( workingMemory,
+      //                               this.tuple.get( declaration ).getObject() );
     }
 
     public Declaration getDeclaration(final String identifier) {
-        Declaration declaration = (Declaration) this.subrule.getOuterDeclarations().get( identifier );
-        Object object = get(declaration);
-        InternalWorkingMemoryEntryPoint wmTmp = ((InternalWorkingMemoryEntryPoint)(this.tuple.get(declaration)).getEntryPoint());
-        
-        if(wmTmp != null && object != null){
-            getIdentityMap().put(object, wmTmp.getFactHandleByIdentity(object));
-        }
-        //((InternalWorkingMemoryActions)(this.tuple.get(declaration)).getEntryPoint()).getFactHandleByIdentity(declaration.getValue( ((InternalWorkingMemoryActions)(this.tuple.get(declaration)).getEntryPoint()),this.tuple.get( declaration ).getObject() ))
-        return declaration;
+             return (Declaration) this.subrule.getOuterDeclarations().get( identifier );
     }
 
     public void halt() {
@@ -330,7 +318,7 @@
      */
     public IdentityHashMap<Object, FactHandle> getIdentityMap() {
         return identityMap;
-    }
+}
 
     /**
      * @param identityMap the identityMap to set

Modified: labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/base/SequentialKnowledgeHelper.java
===================================================================
--- labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/base/SequentialKnowledgeHelper.java	2009-04-04 20:40:08 UTC (rev 25937)
+++ labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/base/SequentialKnowledgeHelper.java	2009-04-05 01:12:27 UTC (rev 25938)
@@ -17,6 +17,7 @@
  */
 
 import java.util.Collections;
+import java.util.IdentityHashMap;
 import java.util.Map;
 
 import org.drools.FactException;
@@ -47,6 +48,7 @@
     private Activation                         activation;
     private Tuple                              tuple;
     private final InternalWorkingMemoryActions workingMemory;
+    private IdentityHashMap<Object,FactHandle>              identityMap;
 
     public SequentialKnowledgeHelper(final WorkingMemory workingMemory) {
         this.workingMemory = (InternalWorkingMemoryActions) workingMemory;
@@ -57,6 +59,7 @@
         this.subrule = agendaItem.getSubRule();
         this.activation = agendaItem;
         this.tuple = agendaItem.getTuple();
+        this.identityMap = new IdentityHashMap<Object,FactHandle>();
     }
     
     public void reset() {
@@ -204,4 +207,12 @@
     public Map<String, ExitPoint> getExitPoints() {
         return Collections.unmodifiableMap( this.workingMemory.getExitPoints() );
     }
+
+    public IdentityHashMap<Object, FactHandle> getIdentityMap() {
+        return this.identityMap;
+    }
+
+    public void setIdentityMap(IdentityHashMap<Object, FactHandle> identityMap) {
+        this.identityMap = identityMap;
+    }
 }

Modified: labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/base/mvel/DroolsMVELFactory.java
===================================================================
--- labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/base/mvel/DroolsMVELFactory.java	2009-04-04 20:40:08 UTC (rev 25937)
+++ labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/base/mvel/DroolsMVELFactory.java	2009-04-05 01:12:27 UTC (rev 25938)
@@ -8,7 +8,9 @@
 import java.util.HashMap;
 import java.util.Map;
 
+import org.drools.FactHandle;
 import org.drools.WorkingMemory;
+import org.drools.common.InternalFactHandle;
 import org.drools.reteoo.LeftTuple;
 import org.drools.rule.Declaration;
 import org.drools.spi.KnowledgeHelper;
@@ -33,7 +35,7 @@
     /**
      * Holds the instance of the variables.
      */
-    private Object[] tupleObjects;
+    private InternalFactHandle[] tupleObjects;
  
     private KnowledgeHelper knowledgeHelper;
  
@@ -79,7 +81,7 @@
  
     public void readExternal(ObjectInput in) throws IOException,
             ClassNotFoundException {
-        tupleObjects = (Object[]) in.readObject();
+        tupleObjects = (InternalFactHandle[]) in.readObject();
         knowledgeHelper = (KnowledgeHelper) in.readObject();
         object = in.readObject();
         localDeclarations = (Map) in.readObject();
@@ -143,7 +145,7 @@
                            final WorkingMemory workingMemory,
                            final Map variables) {
         if (tuple != null) {
-            this.tupleObjects = ((LeftTuple) tuple).toObjectArray();
+            this.tupleObjects = ((LeftTuple) tuple).getFactHandles();
         }
         this.knowledgeHelper = knowledgeHelper;
         this.object = object;
@@ -167,6 +169,10 @@
  
     public Object getValue(final Declaration declaration) {
         int i = declaration.getPattern().getOffset();
+        return this.tupleObjects[i].getObject();
+    }
+    public InternalFactHandle getFactHandle(final Declaration declaration){
+        int i = declaration.getPattern().getOffset();
         return this.tupleObjects[i];
     }
  

Modified: labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/base/mvel/DroolsMVELPreviousDeclarationVariable.java
===================================================================
--- labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/base/mvel/DroolsMVELPreviousDeclarationVariable.java	2009-04-04 20:40:08 UTC (rev 25937)
+++ labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/base/mvel/DroolsMVELPreviousDeclarationVariable.java	2009-04-05 01:12:27 UTC (rev 25938)
@@ -5,8 +5,12 @@
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
 
+
+import org.drools.common.InternalFactHandle;
 import org.drools.common.InternalWorkingMemory;
+import org.drools.common.NamedEntryPoint;
 import org.drools.rule.Declaration;
+import org.drools.runtime.rule.WorkingMemoryEntryPoint;
 import org.mvel2.integration.VariableResolver;
 
 public class DroolsMVELPreviousDeclarationVariable
@@ -46,10 +50,24 @@
 
     public Object getValue() {
         Declaration decl = this.declaration;
+       
         if( this.factory.getKnowledgeHelper() != null ) {
             decl = this.factory.getKnowledgeHelper().getDeclaration( this.declaration.getIdentifier() );
+            
+            InternalFactHandle factHandle = (InternalFactHandle)this.factory.getFactHandle(decl);
+            WorkingMemoryEntryPoint entryPoint = factHandle.getEntryPoint();
+            if(entryPoint !=  null){
+
+                this.factory.getKnowledgeHelper()
+                        .getIdentityMap()
+                        .put(entryPoint.getObject(factHandle), factHandle);
+            }
         }
+        
+
+        
         return decl.getValue( (InternalWorkingMemory) this.factory.getWorkingMemory(), this.factory.getValue( decl ) );
+
     }    
 
     public void setValue(final Object value) {

Modified: labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/common/NamedEntryPoint.java
===================================================================
--- labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/common/NamedEntryPoint.java	2009-04-04 20:40:08 UTC (rev 25937)
+++ labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/common/NamedEntryPoint.java	2009-04-05 01:12:27 UTC (rev 25938)
@@ -5,6 +5,7 @@
 
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.util.Collection;
 import java.util.concurrent.locks.ReentrantLock;
 
 import org.drools.FactException;
@@ -12,6 +13,7 @@
 import org.drools.RuntimeDroolsException;
 import org.drools.WorkingMemoryEntryPoint;
 import org.drools.RuleBaseConfiguration.AssertBehaviour;
+import org.drools.impl.StatefulKnowledgeSessionImpl.ObjectStoreWrapper;
 import org.drools.reteoo.EntryPointNode;
 import org.drools.reteoo.LeftTuple;
 import org.drools.reteoo.ObjectTypeConf;
@@ -22,7 +24,7 @@
 import org.drools.spi.Activation;
 import org.drools.spi.FactHandleFactory;
 import org.drools.spi.PropagationContext;
- 
+
 public class NamedEntryPoint
     implements
     InternalWorkingMemoryEntryPoint,
@@ -68,14 +70,14 @@
         this.typeConfReg = new ObjectTypeConfigurationRegistry( this.ruleBase );
         this.handleFactory = this.wm.getFactHandleFactory();
         this.objectStore = new SingleThreadedObjectStore( this.ruleBase.getConfiguration(),
-                                                        this.lock );   
+                                                          this.lock );
     }
 
     /**
      * @see WorkingMemory
      */
     public FactHandle insert(final Object object) throws FactException {
-         return insert( object, /* Not-Dynamic */
+        return insert( object, /* Not-Dynamic */
                        false,
                        false,
                        null,
@@ -121,7 +123,7 @@
                     object,
                     rule,
                     activation );
-            
+
         } finally {
             this.lock.unlock();
         }
@@ -493,15 +495,47 @@
                                     object );
         return handle;
     }
+    
+    public FactHandle getFactHandle(Object object) {
+        return this.objectStore.getHandleForObject( object );
+    }
 
     public EntryPoint getEntryPoint() {
         return this.entryPoint;
     }
-
+    
     public InternalWorkingMemory getInternalWorkingMemory() {
         return this.wm;
     }
     public FactHandle getFactHandleByIdentity(final Object object) {
         return this.objectStore.getHandleForObjectIdentity( object );
     }
-}
\ No newline at end of file
+    public Object getObject(org.drools.runtime.rule.FactHandle factHandle) {
+        return this.objectStore.getObjectForHandle( (InternalFactHandle) factHandle );
+    }    
+    
+    public Collection< ? extends FactHandle> getFactHandles() {
+        return new ObjectStoreWrapper( this.objectStore,
+                                       null,
+                                       ObjectStoreWrapper.FACT_HANDLE );
+    }
+
+    public Collection< ? extends FactHandle> getFactHandles(org.drools.runtime.ObjectFilter filter) {
+        return new ObjectStoreWrapper( this.objectStore,
+                                       filter,
+                                       ObjectStoreWrapper.FACT_HANDLE );
+    }
+
+    public Collection< ? > getObjects() {
+        return new ObjectStoreWrapper( this.objectStore,
+                                       null,
+                                       ObjectStoreWrapper.OBJECT );
+    }
+
+    public Collection< ? > getObjects(org.drools.runtime.ObjectFilter filter) {
+        return new ObjectStoreWrapper( this.objectStore,
+                                       filter,
+                                       ObjectStoreWrapper.OBJECT );
+    }    
+
+}

Modified: labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/impl/StatefulKnowledgeSessionImpl.java
===================================================================
--- labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/impl/StatefulKnowledgeSessionImpl.java	2009-04-04 20:40:08 UTC (rev 25937)
+++ labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/impl/StatefulKnowledgeSessionImpl.java	2009-04-05 01:12:27 UTC (rev 25938)
@@ -63,7 +63,6 @@
 import org.drools.runtime.process.WorkItemManager;
 import org.drools.runtime.rule.Agenda;
 import org.drools.runtime.rule.AgendaFilter;
-
 import org.drools.runtime.rule.FactHandle;
 import org.drools.runtime.rule.QueryResults;
 import org.drools.runtime.rule.WorkingMemoryEntryPoint;
@@ -200,8 +199,9 @@
         this.session.fireUntilHalt( new AgendaFilterWrapper( agendaFilter ) );
     }
 
-    public SessionClock getSessionClock() {
-        return this.session.getSessionClock();
+    @SuppressWarnings("unchecked")
+    public <T extends SessionClock> T getSessionClock() {
+        return (T) this.session.getSessionClock();
     }
 
     public void halt() {

Modified: labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/marshalling/impl/AbstractProcessInstanceMarshaller.java
===================================================================
--- labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/marshalling/impl/AbstractProcessInstanceMarshaller.java	2009-04-04 20:40:08 UTC (rev 25937)
+++ labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/marshalling/impl/AbstractProcessInstanceMarshaller.java	2009-04-05 01:12:27 UTC (rev 25938)
@@ -12,11 +12,12 @@
 
 import org.drools.common.InternalRuleBase;
 import org.drools.common.InternalWorkingMemory;
+import org.drools.process.core.Context;
+import org.drools.process.core.Process;
 import org.drools.process.core.context.swimlane.SwimlaneContext;
 import org.drools.process.core.context.variable.VariableScope;
 import org.drools.process.instance.context.swimlane.SwimlaneContextInstance;
 import org.drools.process.instance.context.variable.VariableScopeInstance;
-import org.drools.process.instance.impl.ProcessInstanceImpl;
 import org.drools.ruleflow.instance.RuleFlowProcessInstance;
 import org.drools.runtime.process.NodeInstance;
 import org.drools.runtime.process.NodeInstanceContainer;
@@ -34,7 +35,13 @@
 import org.drools.workflow.instance.node.TimerNodeInstance;
 import org.drools.workflow.instance.node.WorkItemNodeInstance;
 
-/* Author: mfossati, salaboy */
+/**
+ * Default implementation of a process instance marshaller.
+ * 
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ * @author mfossati
+ * @author salaboy
+ */
 public abstract class AbstractProcessInstanceMarshaller implements
 		ProcessInstanceMarshaller {
 
@@ -76,7 +83,9 @@
 				stream.writeUTF(entry.getKey());
 				stream.writeUTF(entry.getValue());
 			}
-		}
+		}else{
+            stream.writeInt(0);
+        }
 		List<NodeInstance> nodeInstances = new ArrayList<NodeInstance>( workFlow.getNodeInstances() );
         Collections.sort( nodeInstances,
                           new Comparator<NodeInstance>() {
@@ -108,10 +117,10 @@
 	            stream.writeShort( PersisterEnums.RULE_SET_NODE_INSTANCE );
 	        } else if ( nodeInstance instanceof HumanTaskNodeInstance ) {
 	            stream.writeShort( PersisterEnums.HUMAN_TASK_NODE_INSTANCE );
-	            stream.writeLong( ((HumanTaskNodeInstance) nodeInstance).getWorkItem().getId() );
+	            stream.writeLong( ((HumanTaskNodeInstance) nodeInstance).getWorkItemId() );
 	        } else if ( nodeInstance instanceof WorkItemNodeInstance ) {
 	            stream.writeShort( PersisterEnums.WORK_ITEM_NODE_INSTANCE );
-	            stream.writeLong( ((WorkItemNodeInstance) nodeInstance).getWorkItem().getId() );
+	            stream.writeLong( ((WorkItemNodeInstance) nodeInstance).getWorkItemId() );
 	        } else if ( nodeInstance instanceof SubProcessNodeInstance ) {
 	            stream.writeShort( PersisterEnums.SUB_PROCESS_NODE_INSTANCE );
 	            stream.writeLong( ((SubProcessNodeInstance) nodeInstance).getProcessInstanceId() );
@@ -198,70 +207,72 @@
 	            }
 	            stream.writeShort( PersisterEnums.END );
 	        } else {
-	            // TODO ForEachNodeInstance
-	            // TODO timer manager
 	            throw new IllegalArgumentException( "Unknown node instance type: " + nodeInstance );
 	        }
 	}
 
 	// Input methods
 
-	public ProcessInstance readProcessInstance(MarshallerReaderContext context)
-			throws IOException {
+	public ProcessInstance readProcessInstance(MarshallerReaderContext context)	throws IOException {
 		ObjectInputStream stream = context.stream;
-        InternalRuleBase ruleBase = context.ruleBase;
-        InternalWorkingMemory wm = context.wm;
+		InternalRuleBase ruleBase = context.ruleBase;
+		InternalWorkingMemory wm = context.wm;
 
-        RuleFlowProcessInstance processInstance = new RuleFlowProcessInstance();
-        processInstance.setId( stream.readLong() );
-        String processId = stream.readUTF();
-        processInstance.setProcessId( processId );
-        if ( ruleBase != null ) {
-            processInstance.setProcess( ruleBase.getProcess( processId ) );
-        }
-        processInstance.setState( stream.readInt() );
-        long nodeInstanceCounter = stream.readLong();
-        processInstance.setWorkingMemory( wm );
+		WorkflowProcessInstanceImpl processInstance = createProcessInstance();
+		processInstance.setId(stream.readLong());
+		String processId = stream.readUTF();
+		processInstance.setProcessId(processId);
+		Process process = ruleBase.getProcess(processId);
+		if (ruleBase != null) {
+			processInstance.setProcess(process);
+		}
+		processInstance.setState(stream.readInt());
+		long nodeInstanceCounter = stream.readLong();
+		processInstance.setWorkingMemory(wm);
 
-        int nbVariables = stream.readInt();
-        if ( nbVariables > 0 ) {
-            VariableScopeInstance variableScopeInstance = (VariableScopeInstance) processInstance.getContextInstance( VariableScope.VARIABLE_SCOPE );
-            for ( int i = 0; i < nbVariables; i++ ) {
-                String name = stream.readUTF();
-                try {
-                    Object value = stream.readObject();
-                    variableScopeInstance.setVariable( name,
-                                                       value );
-                } catch ( ClassNotFoundException e ) {
-                    throw new IllegalArgumentException( "Could not reload variable " + name );
-                }
-            }
-        }
+		int nbVariables = stream.readInt();
+		if (nbVariables > 0) {
+			Context variableScope = process
+					.getDefaultContext(VariableScope.VARIABLE_SCOPE);
+			VariableScopeInstance variableScopeInstance = (VariableScopeInstance)
+				processInstance.getContextInstance(variableScope);
+			for (int i = 0; i < nbVariables; i++) {
+				String name = stream.readUTF();
+				try {
+					Object value = stream.readObject();
+					variableScopeInstance.setVariable(name, value);
+				} catch (ClassNotFoundException e) {
+					throw new IllegalArgumentException(
+						"Could not reload variable " + name);
+				}
+			}
+		}
 
-        int nbSwimlanes = stream.readInt();
-        if ( nbSwimlanes > 0 ) {
-            SwimlaneContextInstance swimlaneContextInstance = (SwimlaneContextInstance) processInstance.getContextInstance( SwimlaneContext.SWIMLANE_SCOPE );
-            for ( int i = 0; i < nbSwimlanes; i++ ) {
-                String name = stream.readUTF();
-                String value = stream.readUTF();
-                swimlaneContextInstance.setActorId( name,
-                                                    value );
-            }
-        }
+		int nbSwimlanes = stream.readInt();
+		if (nbSwimlanes > 0) {
+			Context swimlaneContext = process.getDefaultContext(SwimlaneContext.SWIMLANE_SCOPE);
+			SwimlaneContextInstance swimlaneContextInstance = (SwimlaneContextInstance)
+				processInstance.getContextInstance(swimlaneContext);
+			for (int i = 0; i < nbSwimlanes; i++) {
+				String name = stream.readUTF();
+				String value = stream.readUTF();
+				swimlaneContextInstance.setActorId(name, value);
+			}
+		}
 
-        while ( stream.readShort() == PersisterEnums.NODE_INSTANCE ) {
-            readNodeInstance( context,
-                              processInstance,
-                              processInstance );
-        }
+		while (stream.readShort() == PersisterEnums.NODE_INSTANCE) {
+			readNodeInstance(context, processInstance, processInstance);
+		}
 
-        processInstance.internalSetNodeInstanceCounter( nodeInstanceCounter );
-        if ( wm != null ) {
-            processInstance.reconnect();
-        }
-        return processInstance;
+		processInstance.internalSetNodeInstanceCounter(nodeInstanceCounter);
+		if (wm != null) {
+			processInstance.reconnect();
+		}
+		return processInstance;
 	}
-
+	
+	protected abstract WorkflowProcessInstanceImpl createProcessInstance();
+	
 	public NodeInstance readNodeInstance(MarshallerReaderContext context,
 			NodeInstanceContainer nodeInstanceContainer,
 			WorkflowProcessInstance processInstance) throws IOException {
@@ -277,6 +288,42 @@
 		nodeInstance.setProcessInstance(processInstance);
 		nodeInstance.setId(id);
 
+		switch ( nodeType ) {
+	        case PersisterEnums.COMPOSITE_NODE_INSTANCE :
+	            int nbVariables = stream.readInt();
+	            if ( nbVariables > 0 ) {
+	            	Context variableScope = ((org.drools.process.core.Process)
+            			processInstance.getProcess()).getDefaultContext(VariableScope.VARIABLE_SCOPE);
+	    			VariableScopeInstance variableScopeInstance = (VariableScopeInstance)
+	    				((CompositeContextNodeInstance) nodeInstance).getContextInstance(variableScope);
+	                for ( int i = 0; i < nbVariables; i++ ) {
+	                    String name = stream.readUTF();
+	                    try {
+	                        Object value = stream.readObject();
+	                        variableScopeInstance.setVariable( name,
+	                                                           value );
+	                    } catch ( ClassNotFoundException e ) {
+	                        throw new IllegalArgumentException( "Could not reload variable " + name );
+	                    }
+	                }
+	            }
+	            while ( stream.readShort() == PersisterEnums.NODE_INSTANCE ) {
+	                readNodeInstance( context,
+	                                  (CompositeContextNodeInstance) nodeInstance,
+	                                  processInstance );
+	            }
+	            break;
+	        case PersisterEnums.FOR_EACH_NODE_INSTANCE :
+	            while ( stream.readShort() == PersisterEnums.NODE_INSTANCE ) {
+	                readNodeInstance( context,
+	                                  (ForEachNodeInstance) nodeInstance,
+	                                  processInstance );
+	            }
+	            break;
+	        default :
+	            // do nothing
+	    }
+		
 		return nodeInstance;
 	}
 

Modified: labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/marshalling/impl/InputMarshaller.java
===================================================================
--- labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/marshalling/impl/InputMarshaller.java	2009-04-04 20:40:08 UTC (rev 25937)
+++ labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/marshalling/impl/InputMarshaller.java	2009-04-05 01:12:27 UTC (rev 25938)
@@ -361,7 +361,6 @@
         int strategyIndex = context.stream.readInt();
         ObjectMarshallingStrategy strategy = context.resolverStrategyFactory.getStrategy( strategyIndex );
         Object object = strategy.read( context.stream );
-        
 
         InternalFactHandle handle = new DefaultFactHandle( id,
                                                            object,
@@ -797,166 +796,11 @@
     public static void readProcessInstances(MarshallerReaderContext context) throws IOException {
         ObjectInputStream stream = context.stream;
         while ( stream.readShort() == PersisterEnums.PROCESS_INSTANCE ) {
-            readProcessInstance( context );
+        	String processType = stream.readUTF();
+        	ProcessMarshallerRegistry.INSTANCE.getMarshaller(processType).readProcessInstance(context);
         }
     }
 
-    public static ProcessInstance readProcessInstance(MarshallerReaderContext context) throws IOException {
-        ObjectInputStream stream = context.stream;
-        InternalRuleBase ruleBase = context.ruleBase;
-        InternalWorkingMemory wm = context.wm;
-
-        RuleFlowProcessInstance processInstance = new RuleFlowProcessInstance();
-        processInstance.setId( stream.readLong() );
-        String processId = stream.readUTF();
-        processInstance.setProcessId( processId );
-        if ( ruleBase != null ) {
-            processInstance.setProcess( ruleBase.getProcess( processId ) );
-        }
-        processInstance.setState( stream.readInt() );
-        long nodeInstanceCounter = stream.readLong();
-        processInstance.setWorkingMemory( wm );
-
-        int nbVariables = stream.readInt();
-        if ( nbVariables > 0 ) {
-            VariableScopeInstance variableScopeInstance = (VariableScopeInstance) processInstance.getContextInstance( VariableScope.VARIABLE_SCOPE );
-            for ( int i = 0; i < nbVariables; i++ ) {
-                String name = stream.readUTF();
-                try {
-                    Object value = stream.readObject();
-                    variableScopeInstance.setVariable( name,
-                                                       value );
-                } catch ( ClassNotFoundException e ) {
-                    throw new IllegalArgumentException( "Could not reload variable " + name );
-                }
-            }
-        }
-
-        int nbSwimlanes = stream.readInt();
-        if ( nbSwimlanes > 0 ) {
-            SwimlaneContextInstance swimlaneContextInstance = (SwimlaneContextInstance) processInstance.getContextInstance( SwimlaneContext.SWIMLANE_SCOPE );
-            for ( int i = 0; i < nbSwimlanes; i++ ) {
-                String name = stream.readUTF();
-                String value = stream.readUTF();
-                swimlaneContextInstance.setActorId( name,
-                                                    value );
-            }
-        }
-
-        while ( stream.readShort() == PersisterEnums.NODE_INSTANCE ) {
-            readNodeInstance( context,
-                              processInstance,
-                              processInstance );
-        }
-
-        processInstance.internalSetNodeInstanceCounter( nodeInstanceCounter );
-        if ( wm != null ) {
-            processInstance.reconnect();
-        }
-        return processInstance;
-    }
-
-    public static NodeInstance readNodeInstance(MarshallerReaderContext context,
-                                                NodeInstanceContainer nodeInstanceContainer,
-                                                RuleFlowProcessInstance processInstance) throws IOException {
-        ObjectInputStream stream = context.stream;
-        NodeInstanceImpl nodeInstance = null;
-        long id = stream.readLong();
-        long nodeId = stream.readLong();
-        int nodeType = stream.readShort();
-        switch ( nodeType ) {
-            case PersisterEnums.RULE_SET_NODE_INSTANCE :
-                nodeInstance = new RuleSetNodeInstance();
-                break;
-            case PersisterEnums.HUMAN_TASK_NODE_INSTANCE :
-                nodeInstance = new HumanTaskNodeInstance();
-                ((HumanTaskNodeInstance) nodeInstance).internalSetWorkItemId( stream.readLong() );
-                break;
-            case PersisterEnums.WORK_ITEM_NODE_INSTANCE :
-                nodeInstance = new WorkItemNodeInstance();
-                ((WorkItemNodeInstance) nodeInstance).internalSetWorkItemId( stream.readLong() );
-                break;
-            case PersisterEnums.SUB_PROCESS_NODE_INSTANCE :
-                nodeInstance = new SubProcessNodeInstance();
-                ((SubProcessNodeInstance) nodeInstance).internalSetProcessInstanceId( stream.readLong() );
-                break;
-            case PersisterEnums.MILESTONE_NODE_INSTANCE :
-                nodeInstance = new MilestoneNodeInstance();
-                int nbTimerInstances = stream.readInt();
-                if (nbTimerInstances > 0) {
-                	List<Long> timerInstances = new ArrayList<Long>();
-                	for (int i = 0; i < nbTimerInstances; i++) {
-                		timerInstances.add(stream.readLong());
-                	}
-                	((MilestoneNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
-                }
-                break;
-            case PersisterEnums.TIMER_NODE_INSTANCE :
-                nodeInstance = new TimerNodeInstance();
-                ((TimerNodeInstance) nodeInstance).internalSetTimerId( stream.readLong() );
-                break;
-            case PersisterEnums.JOIN_NODE_INSTANCE :
-                nodeInstance = new JoinInstance();
-                int number = stream.readInt();
-                if ( number > 0 ) {
-                    Map<Long, Integer> triggers = new HashMap<Long, Integer>();
-                    for ( int i = 0; i < number; i++ ) {
-                        long l = stream.readLong();
-                        int count = stream.readInt();
-                        triggers.put( l,
-                                      count );
-                    }
-                    ((JoinInstance) nodeInstance).internalSetTriggers( triggers );
-                }
-                break;
-            case PersisterEnums.COMPOSITE_NODE_INSTANCE :
-                nodeInstance = new CompositeContextNodeInstance();
-                break;
-            case PersisterEnums.FOR_EACH_NODE_INSTANCE :
-                nodeInstance = new ForEachNodeInstance();
-                break;
-            default :
-                throw new IllegalArgumentException( "Unknown node type: " + nodeType );
-        }
-        nodeInstance.setNodeId( nodeId );
-        nodeInstance.setNodeInstanceContainer( nodeInstanceContainer );
-        nodeInstance.setProcessInstance( processInstance );
-        nodeInstance.setId( id );
-        switch ( nodeType ) {
-            case PersisterEnums.COMPOSITE_NODE_INSTANCE :
-                int nbVariables = stream.readInt();
-                if ( nbVariables > 0 ) {
-                    VariableScopeInstance variableScopeInstance = (VariableScopeInstance) ((CompositeContextNodeInstance) nodeInstance).getContextInstance( VariableScope.VARIABLE_SCOPE );
-                    for ( int i = 0; i < nbVariables; i++ ) {
-                        String name = stream.readUTF();
-                        try {
-                            Object value = stream.readObject();
-                            variableScopeInstance.setVariable( name,
-                                                               value );
-                        } catch ( ClassNotFoundException e ) {
-                            throw new IllegalArgumentException( "Could not reload variable " + name );
-                        }
-                    }
-                }
-                while ( stream.readShort() == PersisterEnums.NODE_INSTANCE ) {
-                    readNodeInstance( context,
-                                      (CompositeContextNodeInstance) nodeInstance,
-                                      processInstance );
-                }
-                break;
-            case PersisterEnums.FOR_EACH_NODE_INSTANCE :
-                while ( stream.readShort() == PersisterEnums.NODE_INSTANCE ) {
-                    readNodeInstance( context,
-                                      (ForEachNodeInstance) nodeInstance,
-                                      processInstance );
-                }
-                break;
-            default :
-                // do nothing
-        }
-        return nodeInstance;
-    }
-
     public static void readWorkItems(MarshallerReaderContext context) throws IOException {
         InternalWorkingMemory wm = context.wm;
         ObjectInputStream stream = context.stream;

Modified: labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/marshalling/impl/OutputMarshaller.java
===================================================================
--- labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/marshalling/impl/OutputMarshaller.java	2009-04-04 20:40:08 UTC (rev 25937)
+++ labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/marshalling/impl/OutputMarshaller.java	2009-04-05 01:12:27 UTC (rev 25938)
@@ -4,7 +4,6 @@
 import java.io.ObjectOutputStream;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.Date;
@@ -16,7 +15,6 @@
 import java.util.Map.Entry;
 
 import org.drools.InitialFact;
-import org.drools.WorkingMemoryEntryPoint;
 import org.drools.base.ClassObjectType;
 import org.drools.common.AgendaItem;
 import org.drools.common.DefaultAgenda;
@@ -26,17 +24,13 @@
 import org.drools.common.InternalWorkingMemory;
 import org.drools.common.InternalWorkingMemoryEntryPoint;
 import org.drools.common.LogicalDependency;
-import org.drools.common.NamedEntryPoint;
 import org.drools.common.NodeMemory;
 import org.drools.common.ObjectStore;
 import org.drools.common.RuleFlowGroupImpl;
 import org.drools.common.WorkingMemoryAction;
 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.WorkItemManager;
-import org.drools.process.instance.context.swimlane.SwimlaneContextInstance;
-import org.drools.process.instance.context.variable.VariableScopeInstance;
+import org.drools.process.instance.impl.ProcessInstanceImpl;
 import org.drools.process.instance.timer.TimerInstance;
 import org.drools.process.instance.timer.TimerManager;
 import org.drools.reteoo.BetaNode;
@@ -51,11 +45,8 @@
 import org.drools.reteoo.AccumulateNode.AccumulateMemory;
 import org.drools.reteoo.CollectNode.CollectContext;
 import org.drools.reteoo.CollectNode.CollectMemory;
-import org.drools.reteoo.ReteooStatefulSession;
 import org.drools.rule.EntryPoint;
 import org.drools.rule.Rule;
-import org.drools.ruleflow.instance.RuleFlowProcessInstance;
-import org.drools.runtime.process.NodeInstance;
 import org.drools.runtime.process.WorkItem;
 import org.drools.spi.ActivationGroup;
 import org.drools.spi.AgendaGroup;
@@ -63,15 +54,6 @@
 import org.drools.spi.RuleFlowGroup;
 import org.drools.util.ObjectHashMap;
 import org.drools.util.ObjectHashSet;
-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 OutputMarshaller {
     public static void writeSession(MarshallerWriteContext context) throws IOException {
@@ -281,7 +263,7 @@
                                         InternalFactHandle handle) throws IOException {
         stream.writeInt( handle.getId() );
         stream.writeLong( handle.getRecency() );
-        
+
 //        context.out.println( "Object : int:" + handle.getId() + " long:" + handle.getRecency() );
 //        context.out.println( handle.getObject() );
 
@@ -307,7 +289,7 @@
         }else{
             stream.writeBoolean(false);
         }
-        
+
     }
 
     public static InternalFactHandle[] orderFacts(ObjectStore objectStore) {
@@ -762,166 +744,15 @@
                               }
                           } );
         for ( org.drools.runtime.process.ProcessInstance processInstance : processInstances ) {
-            stream.writeShort( PersisterEnums.PROCESS_INSTANCE );
-            writeProcessInstance( context,
-                                  (RuleFlowProcessInstance) processInstance );
+            stream.writeShort(PersisterEnums.PROCESS_INSTANCE);
+            String processType = ((ProcessInstanceImpl) processInstance).getProcess().getType();
+            stream.writeUTF(processType);
+            ProcessMarshallerRegistry.INSTANCE.getMarshaller(processType)
+            	.writeProcessInstance(context, processInstance);
         }
         stream.writeShort( PersisterEnums.END );
     }
 
-    public static void writeProcessInstance(MarshallerWriteContext context,
-                                            RuleFlowProcessInstance processInstance) throws IOException {
-        ObjectOutputStream stream = context.stream;
-        stream.writeLong( processInstance.getId() );
-        stream.writeUTF( processInstance.getProcessId() );
-        stream.writeInt( processInstance.getState() );
-        stream.writeLong( processInstance.getNodeInstanceCounter() );
-
-        VariableScopeInstance variableScopeInstance = (VariableScopeInstance) processInstance.getContextInstance( VariableScope.VARIABLE_SCOPE );
-        Map<String, Object> variables = variableScopeInstance.getVariables();
-        List<String> keys = new ArrayList<String>( variables.keySet() );
-        Collections.sort( keys,
-                          new Comparator<String>() {
-                              public int compare(String o1,
-                                                 String o2) {
-                                  return o1.compareTo( o2 );
-                              }
-                          } );
-        stream.writeInt( keys.size() );
-        for ( String key : keys ) {
-            stream.writeUTF( key );
-            stream.writeObject( variables.get( key ) );
-        }
-
-        SwimlaneContextInstance swimlaneContextInstance = (SwimlaneContextInstance) processInstance.getContextInstance( SwimlaneContext.SWIMLANE_SCOPE );
-        Map<String, String> swimlaneActors = swimlaneContextInstance.getSwimlaneActors();
-        stream.writeInt( swimlaneActors.size() );
-        for ( Map.Entry<String, String> entry : swimlaneActors.entrySet() ) {
-            stream.writeUTF( entry.getKey() );
-            stream.writeUTF( entry.getValue() );
-        }
-
-        List<NodeInstance> nodeInstances = new ArrayList<NodeInstance>( processInstance.getNodeInstances() );
-        Collections.sort( nodeInstances,
-                          new Comparator<NodeInstance>() {
-                              public int compare(NodeInstance o1,
-                                                 NodeInstance o2) {
-                                  return (int) (o1.getId() - o2.getId());
-                              }
-                          } );
-        for ( NodeInstance nodeInstance : nodeInstances ) {
-            stream.writeShort( PersisterEnums.NODE_INSTANCE );
-            writeNodeInstance( context,
-                               nodeInstance );
-        }
-        stream.writeShort( PersisterEnums.END );
-    }
-
-    public static void writeNodeInstance(MarshallerWriteContext context,
-                                         NodeInstance nodeInstance) throws IOException {
-        ObjectOutputStream stream = context.stream;
-        stream.writeLong( nodeInstance.getId() );
-        stream.writeLong( nodeInstance.getNodeId() );
-        if ( nodeInstance instanceof RuleSetNodeInstance ) {
-            stream.writeShort( PersisterEnums.RULE_SET_NODE_INSTANCE );
-        } else if ( nodeInstance instanceof HumanTaskNodeInstance ) {
-            stream.writeShort( PersisterEnums.HUMAN_TASK_NODE_INSTANCE );
-            stream.writeLong( ((HumanTaskNodeInstance) nodeInstance).getWorkItem().getId() );
-        } else if ( nodeInstance instanceof WorkItemNodeInstance ) {
-            stream.writeShort( PersisterEnums.WORK_ITEM_NODE_INSTANCE );
-            stream.writeLong( ((WorkItemNodeInstance) nodeInstance).getWorkItem().getId() );
-        } else if ( nodeInstance instanceof SubProcessNodeInstance ) {
-            stream.writeShort( PersisterEnums.SUB_PROCESS_NODE_INSTANCE );
-            stream.writeLong( ((SubProcessNodeInstance) nodeInstance).getProcessInstanceId() );
-        } else if ( nodeInstance instanceof MilestoneNodeInstance ) {
-            stream.writeShort( PersisterEnums.MILESTONE_NODE_INSTANCE );
-            List<Long> timerInstances = 
-            	((MilestoneNodeInstance) nodeInstance).getTimerInstances();
-            if (timerInstances != null) {
-            	stream.writeInt(timerInstances.size());
-            	for (Long id: timerInstances) {
-            		stream.writeLong(id);
-            	}
-            } else {
-            	stream.writeInt(0);
-            }
-        } else if ( nodeInstance instanceof TimerNodeInstance ) {
-            stream.writeShort( PersisterEnums.TIMER_NODE_INSTANCE );
-            stream.writeLong( ((TimerNodeInstance) nodeInstance).getTimerId() );
-        } else if ( nodeInstance instanceof JoinInstance ) {
-            stream.writeShort( PersisterEnums.JOIN_NODE_INSTANCE );
-            Map<Long, Integer> triggers = ((JoinInstance) nodeInstance).getTriggers();
-            stream.writeInt( triggers.size() );
-            List<Long> keys = new ArrayList<Long>( triggers.keySet() );
-            Collections.sort( keys,
-                              new Comparator<Long>() {
-                                  public int compare(Long o1,
-                                                     Long o2) {
-                                      return o1.compareTo( o2 );
-                                  }
-                              } );
-            for ( Long key : keys ) {
-                stream.writeLong( key );
-                stream.writeInt( triggers.get( key ) );
-            }
-        } else if ( nodeInstance instanceof CompositeContextNodeInstance ) {
-            stream.writeShort( PersisterEnums.COMPOSITE_NODE_INSTANCE );
-            CompositeContextNodeInstance compositeNodeInstance = (CompositeContextNodeInstance) nodeInstance;
-            VariableScopeInstance variableScopeInstance = (VariableScopeInstance) compositeNodeInstance.getContextInstance( VariableScope.VARIABLE_SCOPE );
-            Map<String, Object> variables = variableScopeInstance.getVariables();
-            List<String> keys = new ArrayList<String>( variables.keySet() );
-            Collections.sort( keys,
-                              new Comparator<String>() {
-                                  public int compare(String o1,
-                                                     String o2) {
-                                      return o1.compareTo( o2 );
-                                  }
-                              } );
-            stream.writeInt( keys.size() );
-            for ( String key : keys ) {
-                stream.writeUTF( key );
-                stream.writeObject( variables.get( key ) );
-            }
-            List<NodeInstance> nodeInstances = new ArrayList<NodeInstance>( compositeNodeInstance.getNodeInstances() );
-            Collections.sort( nodeInstances,
-                              new Comparator<NodeInstance>() {
-                                  public int compare(NodeInstance o1,
-                                                     NodeInstance o2) {
-                                      return (int) (o1.getId() - o2.getId());
-                                  }
-                              } );
-            for ( NodeInstance subNodeInstance : nodeInstances ) {
-                stream.writeShort( PersisterEnums.NODE_INSTANCE );
-                writeNodeInstance( context,
-                                   subNodeInstance );
-            }
-            stream.writeShort( PersisterEnums.END );
-        } else if ( nodeInstance instanceof ForEachNodeInstance ) {
-            stream.writeShort( PersisterEnums.FOR_EACH_NODE_INSTANCE );
-            ForEachNodeInstance forEachNodeInstance = (ForEachNodeInstance) nodeInstance;
-            List<NodeInstance> nodeInstances = new ArrayList<NodeInstance>( forEachNodeInstance.getNodeInstances() );
-            Collections.sort( nodeInstances,
-                              new Comparator<NodeInstance>() {
-                                  public int compare(NodeInstance o1,
-                                                     NodeInstance o2) {
-                                      return (int) (o1.getId() - o2.getId());
-                                  }
-                              } );
-            for ( NodeInstance subNodeInstance : nodeInstances ) {
-                if ( subNodeInstance instanceof CompositeContextNodeInstance ) {
-                    stream.writeShort( PersisterEnums.NODE_INSTANCE );
-                    writeNodeInstance( context,
-                                       subNodeInstance );
-                }
-            }
-            stream.writeShort( PersisterEnums.END );
-        } else {
-            // TODO ForEachNodeInstance
-            // TODO timer manager
-            throw new IllegalArgumentException( "Unknown node instance type: " + nodeInstance );
-        }
-    }
-
     public static void writeWorkItems(MarshallerWriteContext context) throws IOException {
         ObjectOutputStream stream = context.stream;
 

Modified: labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/marshalling/impl/RuleFlowProcessInstanceMarshaller.java
===================================================================
--- labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/marshalling/impl/RuleFlowProcessInstanceMarshaller.java	2009-04-04 20:40:08 UTC (rev 25937)
+++ labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/marshalling/impl/RuleFlowProcessInstanceMarshaller.java	2009-04-05 01:12:27 UTC (rev 25938)
@@ -1,22 +1,12 @@
 package org.drools.marshalling.impl;
 
-import java.io.IOException;
-import java.io.ObjectInputStream;
-
-import org.drools.common.InternalRuleBase;
-import org.drools.common.InternalWorkingMemory;
-import org.drools.process.core.context.swimlane.SwimlaneContext;
-import org.drools.process.core.context.variable.VariableScope;
-import org.drools.process.instance.context.swimlane.SwimlaneContextInstance;
-import org.drools.process.instance.context.variable.VariableScopeInstance;
 import org.drools.ruleflow.instance.RuleFlowProcessInstance;
-import org.drools.runtime.process.NodeInstance;
-import org.drools.runtime.process.ProcessInstance;
-import org.drools.workflow.instance.impl.NodeInstanceImpl;
+import org.drools.workflow.instance.impl.WorkflowProcessInstanceImpl;
 
 /**
  * Marshaller class for RuleFlowProcessInstances
  * 
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
  * @author mfossati
  */
 
@@ -28,58 +18,8 @@
 	private RuleFlowProcessInstanceMarshaller() {
 	}
 
-	public ProcessInstance readProcessInstance(MarshallerReaderContext context)
-			throws IOException {
-		ObjectInputStream stream = context.stream;
-		InternalRuleBase ruleBase = context.ruleBase;
-		InternalWorkingMemory wm = context.wm;
-
-		RuleFlowProcessInstance processInstance = new RuleFlowProcessInstance();
-		processInstance.setId(stream.readLong());
-		String processId = stream.readUTF();
-		processInstance.setProcessId(processId);
-		if (ruleBase != null) {
-			processInstance.setProcess(ruleBase.getProcess(processId));
-		}
-		processInstance.setState(stream.readInt());
-		long nodeInstanceCounter = stream.readLong();
-		processInstance.setWorkingMemory(wm);
-
-		int nbVariables = stream.readInt();
-		if (nbVariables > 0) {
-			VariableScopeInstance variableScopeInstance = (VariableScopeInstance) processInstance
-					.getContextInstance(VariableScope.VARIABLE_SCOPE);
-			for (int i = 0; i < nbVariables; i++) {
-				String name = stream.readUTF();
-				try {
-					Object value = stream.readObject();
-					variableScopeInstance.setVariable(name, value);
-				} catch (ClassNotFoundException e) {
-					throw new IllegalArgumentException(
-							"Could not reload variable " + name);
-				}
-			}
-		}
-
-		int nbSwimlanes = stream.readInt();
-		if (nbSwimlanes > 0) {
-			SwimlaneContextInstance swimlaneContextInstance = (SwimlaneContextInstance) processInstance
-					.getContextInstance(SwimlaneContext.SWIMLANE_SCOPE);
-			for (int i = 0; i < nbSwimlanes; i++) {
-				String name = stream.readUTF();
-				String value = stream.readUTF();
-				swimlaneContextInstance.setActorId(name, value);
-			}
-		}
-
-		while (stream.readShort() == PersisterEnums.NODE_INSTANCE) {
-			readNodeInstance(context, processInstance, processInstance);
-		}
-
-		processInstance.internalSetNodeInstanceCounter(nodeInstanceCounter);
-		if (wm != null) {
-			processInstance.reconnect();
-		}
-		return processInstance;
+	protected WorkflowProcessInstanceImpl createProcessInstance() {
+		return new RuleFlowProcessInstance();
 	}
+
 }

Modified: labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/reteoo/LeftTuple.java
===================================================================
--- labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/reteoo/LeftTuple.java	2009-04-04 20:40:08 UTC (rev 25937)
+++ labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/reteoo/LeftTuple.java	2009-04-05 01:12:27 UTC (rev 25938)
@@ -311,16 +311,15 @@
      * Returns the fact handles in reverse order
      */
     public InternalFactHandle[] getFactHandles() {
-        final List list = new ArrayList();
+        InternalFactHandle[] handles = new InternalFactHandle[this.index + 1];
         LeftTuple entry = this;
         while ( entry != null ) {
-            list.add( entry.handle );
+            handles[entry.index] = entry.handle;
             entry = entry.parent;
         }
-
-        return (InternalFactHandle[]) list.toArray( new InternalFactHandle[list.size()] );
+        return handles;
     }
-
+    
     public long getRecency() {
         return this.recency;
     }

Modified: labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java
===================================================================
--- labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java	2009-04-04 20:40:08 UTC (rev 25937)
+++ labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java	2009-04-05 01:12:27 UTC (rev 25938)
@@ -19,6 +19,7 @@
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
@@ -43,6 +44,8 @@
 import org.drools.rule.Query;
 import org.drools.rule.Rule;
 import org.drools.runtime.Environment;
+import org.drools.runtime.ObjectFilter;
+import org.drools.runtime.rule.FactHandle;
 import org.drools.spi.FactHandleFactory;
 import org.drools.spi.PropagationContext;
 
@@ -56,7 +59,7 @@
 public class ReteooWorkingMemory extends AbstractWorkingMemory {
 
     /**
-     * 
+     *
      */
     private static final long serialVersionUID = 400L;
     
@@ -192,6 +195,8 @@
         this.queryResults.put( query,
                                node );
     }
+    
+    
 
     public static class WorkingMemoryReteAssertAction
         implements
@@ -335,7 +340,7 @@
             ((EventFactHandle)factHandle).setExpired( true );
             this.node.retractObject( factHandle,
                                      context,
-                                     workingMemory ); 
+                                     workingMemory );
             
             // if no activations for this expired event
             if( ((EventFactHandle)factHandle).getActivationsCount() == 0 ) {
@@ -351,4 +356,20 @@
         return this;
     }
 
+    public Collection< ? extends FactHandle> getFactHandles() {
+        throw new UnsupportedOperationException("this is implementedby StatefulKnowledgeImpl");
+    }
+
+    public Collection< ? extends FactHandle> getFactHandles(ObjectFilter filter) {
+        throw new UnsupportedOperationException("this is implementedby StatefulKnowledgeImpl");
+    }
+
+    public Collection< ? extends Object> getObjects() {
+        throw new UnsupportedOperationException("this is implementedby StatefulKnowledgeImpl");
+    }
+
+    public Collection< ? extends Object> getObjects(ObjectFilter filter) {
+        throw new UnsupportedOperationException("this is implementedby StatefulKnowledgeImpl");
+    }
+
 }

Modified: labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/spi/KnowledgeHelper.java
===================================================================
--- labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/spi/KnowledgeHelper.java	2009-04-04 20:40:08 UTC (rev 25937)
+++ labs/jbossrules/branches/salaboy_streams/drools-core/src/main/java/org/drools/spi/KnowledgeHelper.java	2009-04-05 01:12:27 UTC (rev 25938)
@@ -17,6 +17,7 @@
  */
 
 import java.io.Serializable;
+import java.util.IdentityHashMap;
 import java.util.Map;
 
 import org.drools.FactException;
@@ -127,4 +128,7 @@
     
     public void halt();
 
+     public IdentityHashMap<Object, FactHandle> getIdentityMap();
+
+    public void setIdentityMap(IdentityHashMap<Object, FactHandle> identityMap);
 }
\ No newline at end of file

Modified: labs/jbossrules/branches/salaboy_streams/drools-core/src/test/java/org/drools/reteoo/FromNodeTest.java
===================================================================
--- labs/jbossrules/branches/salaboy_streams/drools-core/src/test/java/org/drools/reteoo/FromNodeTest.java	2009-04-04 20:40:08 UTC (rev 25937)
+++ labs/jbossrules/branches/salaboy_streams/drools-core/src/test/java/org/drools/reteoo/FromNodeTest.java	2009-04-05 01:12:27 UTC (rev 25938)
@@ -117,9 +117,9 @@
                       asserted.size() );
         Tuple tuple = (Tuple) ((Object[]) asserted.get( 0 ))[0];
         assertSame( person2,
+                    tuple.getFactHandles()[0].getObject() );
+        assertSame( cheese1,
                     tuple.getFactHandles()[1].getObject() );
-        assertSame( cheese1,
-                    tuple.getFactHandles()[0].getObject() );
 
         cheese2.setType( "stilton" );
         final Person person3 = new Person( "xxx2",
@@ -135,14 +135,14 @@
                       asserted.size() );
         tuple = (Tuple) ((Object[]) asserted.get( 1 ))[0];
         assertSame( person3,
+                    tuple.getFactHandles()[0].getObject() );
+        assertSame( cheese1,
                     tuple.getFactHandles()[1].getObject() );
-        assertSame( cheese1,
-                    tuple.getFactHandles()[0].getObject() );
         tuple = (Tuple) ((Object[]) asserted.get( 2 ))[0];
         assertSame( person3,
+                    tuple.getFactHandles()[0].getObject() );
+        assertSame( cheese2,
                     tuple.getFactHandles()[1].getObject() );
-        assertSame( cheese2,
-                    tuple.getFactHandles()[0].getObject() );
 
         assertNotSame( cheese1,
                        cheese2 );
@@ -230,9 +230,9 @@
                       asserted.size() );
         Tuple tuple = (Tuple) ((Object[]) asserted.get( 0 ))[0];
         assertSame( person2,
+                    tuple.getFactHandles()[0].getObject() );
+        assertSame( cheese1,
                     tuple.getFactHandles()[1].getObject() );
-        assertSame( cheese1,
-                    tuple.getFactHandles()[0].getObject() );
 
         cheese2.setPrice( 30 );
         final Person person3 = new Person( "xxx2",
@@ -248,14 +248,14 @@
                       asserted.size() );
         tuple = (Tuple) ((Object[]) asserted.get( 1 ))[0];
         assertSame( person3,
+                    tuple.getFactHandles()[0].getObject() );
+        assertSame( cheese1,
                     tuple.getFactHandles()[1].getObject() );
-        assertSame( cheese1,
-                    tuple.getFactHandles()[0].getObject() );
         tuple = (Tuple) ((Object[]) asserted.get( 2 ))[0];
         assertSame( person3,
+                    tuple.getFactHandles()[0].getObject() );
+        assertSame( cheese2,
                     tuple.getFactHandles()[1].getObject() );
-        assertSame( cheese2,
-                    tuple.getFactHandles()[0].getObject() );
 
         assertNotSame( cheese1,
                        cheese2 );




More information about the jboss-svn-commits mailing list