[jboss-svn-commits] JBL Code SVN: r16846 - in labs/jbossrules/branches/temporal_rete: drools-core/src/main/java/org/drools/common and 5 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Nov 26 16:24:04 EST 2007


Author: tirelli
Date: 2007-11-26 16:24:03 -0500 (Mon, 26 Nov 2007)
New Revision: 16846

Added:
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/EventFactHandle.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ClassObjectTypeConf.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/FactTemplateTypeConf.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ObjectTypeConf.java
   labs/jbossrules/branches/temporal_rete/drools-jsr94/src/main/java/org/drools/jsr94/rules/Jsr94EventFactHandle.java
Modified:
   labs/jbossrules/branches/temporal_rete/drools-compiler/src/test/java/org/drools/integrationtests/CepEspTest.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/AbstractFactHandleFactory.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/DefaultFactHandle.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/InternalWorkingMemory.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/CollectNode.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/FromNode.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/Rete.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ReteooFactHandleFactory.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ReteooStatelessSession.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/RightInputAdapterNode.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/spi/FactHandleFactory.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/common/EqualityKeyTest.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/AccumulateNodeTest.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/CollectNodeTest.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/CompositeObjectSinkAdapterTest.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/DefaultFactHandleFactoryTest.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/ObjectTypeConfTest.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/ReteTest.java
   labs/jbossrules/branches/temporal_rete/drools-jsr94/src/main/java/org/drools/jsr94/rules/Jsr94FactHandle.java
   labs/jbossrules/branches/temporal_rete/drools-jsr94/src/main/java/org/drools/jsr94/rules/Jsr94FactHandleFactory.java
Log:
JBRULES-1332: adding support to event type fact handlers

Modified: labs/jbossrules/branches/temporal_rete/drools-compiler/src/test/java/org/drools/integrationtests/CepEspTest.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-compiler/src/test/java/org/drools/integrationtests/CepEspTest.java	2007-11-26 21:05:04 UTC (rev 16845)
+++ labs/jbossrules/branches/temporal_rete/drools-compiler/src/test/java/org/drools/integrationtests/CepEspTest.java	2007-11-26 21:24:03 UTC (rev 16846)
@@ -9,7 +9,6 @@
 import junit.framework.Assert;
 import junit.framework.TestCase;
 
-import org.drools.FactHandle;
 import org.drools.RuleBase;
 import org.drools.RuleBaseConfiguration;
 import org.drools.RuleBaseFactory;
@@ -94,11 +93,10 @@
         assertNotNull( handle3 );
         assertNotNull( handle4 );
         
-        // FIXME
-//        assertTrue( handle1.isEvent() );
-//        assertTrue( handle2.isEvent() );
-//        assertTrue( handle3.isEvent() );
-//        assertTrue( handle4.isEvent() );
+        assertTrue( handle1.isEvent() );
+        assertTrue( handle2.isEvent() );
+        assertTrue( handle3.isEvent() );
+        assertTrue( handle4.isEvent() );
         
         wm.fireAllRules();
 

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/AbstractFactHandleFactory.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/AbstractFactHandleFactory.java	2007-11-26 21:05:04 UTC (rev 16845)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/AbstractFactHandleFactory.java	2007-11-26 21:24:03 UTC (rev 16846)
@@ -39,24 +39,28 @@
     /* (non-Javadoc)
      * @see org.drools.reteoo.FactHandleFactory#newFactHandle()
      */
-    public final InternalFactHandle newFactHandle(final Object object) {
+    public final InternalFactHandle newFactHandle( final Object object, final boolean isEvent ) {
         if ( !this.factHandlePool.isEmpty() ) {
             return newFactHandle( this.factHandlePool.pop(),
-                                  object );
+                                  object, 
+                                  isEvent );
         }
 
         return newFactHandle( this.id++,
-                              object );
+                              object,
+                              isEvent );
     }
 
     /* (non-Javadoc)
      * @see org.drools.reteoo.FactHandleFactory#newFactHandle(long)
      */
     protected final InternalFactHandle newFactHandle(final long id,
-                                                     final Object object) {
+                                                     final Object object,
+                                                     final boolean isEvent ) {
         return newFactHandle( id,
                               object,
-                              this.counter++ );
+                              this.counter++,
+                              isEvent );
     }
 
     /* (non-Javadoc)
@@ -64,7 +68,8 @@
      */
     protected abstract InternalFactHandle newFactHandle(final long id,
                                                         final Object object,
-                                                        final long recency);
+                                                        final long recency,
+                                                        final boolean isEvent );
 
     /* (non-Javadoc)
      * @see org.drools.reteoo.FactHandleFactory#increaseFactHandleRecency(org.drools.FactHandle)

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java	2007-11-26 21:05:04 UTC (rev 16845)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java	2007-11-26 21:24:03 UTC (rev 16846)
@@ -50,7 +50,11 @@
 import org.drools.event.RuleFlowEventSupport;
 import org.drools.event.WorkingMemoryEventListener;
 import org.drools.event.WorkingMemoryEventSupport;
+import org.drools.facttemplates.Fact;
+import org.drools.reteoo.ClassObjectTypeConf;
+import org.drools.reteoo.FactTemplateTypeConf;
 import org.drools.reteoo.LIANodePropagation;
+import org.drools.reteoo.ObjectTypeConf;
 import org.drools.rule.Declaration;
 import org.drools.rule.Rule;
 import org.drools.ruleflow.common.core.Process;
@@ -151,6 +155,8 @@
 
     private int                            processCounter;
 
+    private Map<Object, ObjectTypeConf>    typeConfMap;
+
     // ------------------------------------------------------------
     // Constructors
     // ------------------------------------------------------------
@@ -195,6 +201,8 @@
         } else {
             this.discardOnLogicalOverride = false;
         }
+        
+        this.typeConfMap = new HashMap<Object, ObjectTypeConf>();
     }
 
     // ------------------------------------------------------------
@@ -566,7 +574,7 @@
         }
 
     }
-    
+
     public ObjectHashMap getAssertMap() {
         return this.assertMap;
     }
@@ -701,11 +709,13 @@
             // you cannot assert a null object
             return null;
         }
+        
+        ObjectTypeConf typeConf = getObjectTypeConf( object );
 
         InternalFactHandle handle = null;
 
         if ( isSequential() ) {
-            handle = this.handleFactory.newFactHandle( object );
+            handle = this.handleFactory.newFactHandle( object, typeConf.isEvent() );
             addHandleToMaps( handle );
             insert( handle,
                     object,
@@ -757,7 +767,7 @@
                 if ( key == null ) {
                     // key is also null, so treat as a totally new stated/logical
                     // assert
-                    handle = this.handleFactory.newFactHandle( object );
+                    handle = this.handleFactory.newFactHandle( object, typeConf.isEvent() );
                     addHandleToMaps( handle );
 
                     key = new EqualityKey( handle );
@@ -811,7 +821,7 @@
                         } else {
                             // override, then instantiate new handle for assertion
                             key.setStatus( EqualityKey.STATED );
-                            handle = this.handleFactory.newFactHandle( object );
+                            handle = this.handleFactory.newFactHandle( object, typeConf.isEvent() );
                             handle.setEqualityKey( key );
                             key.addFactHandle( handle );
                             addHandleToMaps( handle );
@@ -819,7 +829,7 @@
                         }
 
                     } else {
-                        handle = this.handleFactory.newFactHandle( object );
+                        handle = this.handleFactory.newFactHandle( object, typeConf.isEvent() );
                         addHandleToMaps( handle );
                         key.addFactHandle( handle );
                         handle.setEqualityKey( key );
@@ -846,7 +856,7 @@
                 if ( handle != null ) {
                     return handle;
                 }
-                handle = this.handleFactory.newFactHandle( object );
+                handle = this.handleFactory.newFactHandle( object, typeConf.isEvent() );
                 addHandleToMaps( handle );
 
             }
@@ -1454,4 +1464,51 @@
         return result;
     }
 
+    /**
+     * Returns the ObjectTypeConfiguration object for the given object
+     * or creates a new one if none is found in the cache
+     * 
+     * @param object
+     * @return
+     */
+    public ObjectTypeConf getObjectTypeConf(Object object) {
+        ObjectTypeConf objectTypeConf;
+
+        if ( object instanceof Fact ) {
+            String key = ((Fact) object).getFactTemplate().getName();
+            objectTypeConf = (ObjectTypeConf) this.typeConfMap.get( key );
+            if ( objectTypeConf == null ) {
+                objectTypeConf = new FactTemplateTypeConf( ((Fact) object).getFactTemplate(),
+                                                          this.ruleBase );
+                this.typeConfMap.put( key,
+                                      objectTypeConf );
+            }
+            object = key;
+        } else {
+            Class cls = null;
+            if ( object instanceof ShadowProxy ) {
+                cls = ((ShadowProxy) object).getShadowedObject().getClass();
+            } else {
+                cls = object.getClass();
+            }
+
+            objectTypeConf = (ObjectTypeConf) this.typeConfMap.get( cls );
+            if ( objectTypeConf == null ) {
+
+                final boolean isEvent = this.ruleBase.isEvent( cls );
+                objectTypeConf = new ClassObjectTypeConf( cls,
+                                                         isEvent,
+                                                         this.ruleBase );
+                this.typeConfMap.put( cls,
+                                      objectTypeConf );
+            }
+
+        }
+        return objectTypeConf;
+    }
+    
+    public Map<Object, ObjectTypeConf> getObjectTypeConfMap() {
+        return this.typeConfMap;
+    }
+
 }

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/DefaultFactHandle.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/DefaultFactHandle.java	2007-11-26 21:05:04 UTC (rev 16845)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/DefaultFactHandle.java	2007-11-26 21:24:03 UTC (rev 16846)
@@ -52,10 +52,9 @@
 
     public DefaultFactHandle(final long id,
                              final Object object) {
-        this.id = id;
-        this.recency = id;
-        this.object = object;
-        this.objectHashCode = object.hashCode();
+        this( id,
+              object,
+              id );
     }
 
     /**
@@ -107,7 +106,7 @@
      * @see FactHandle
      */
     public String toExternalForm() {
-        return "[fid:" + this.id + ":" + this.recency + ":" + this.object + "]";
+        return "[fact fid:" + this.id + ":" + this.recency + ":" + this.object + "]";
     }
 
     /**

Added: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/EventFactHandle.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/EventFactHandle.java	                        (rev 0)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/EventFactHandle.java	2007-11-26 21:24:03 UTC (rev 16846)
@@ -0,0 +1,58 @@
+package org.drools.common;
+
+import org.drools.FactHandle;
+
+public class EventFactHandle extends DefaultFactHandle {
+
+    private static final long serialVersionUID = 5997141759543399455L;
+
+    // ----------------------------------------------------------------------
+    // Constructors
+    // ----------------------------------------------------------------------
+
+    public EventFactHandle() {
+        super();
+    }
+
+    public EventFactHandle(final long id,
+                           final Object object) {
+        super( id,
+               object );
+    }
+
+    /**
+     * Construct.
+     * 
+     * @param id
+     *            Handle id.
+     */
+    public EventFactHandle(final long id,
+                           final Object object,
+                           final long recency) {
+        super( id,
+               object,
+               recency );
+    }
+    
+    /**
+     * @see FactHandle
+     */
+    public String toExternalForm() {
+        return "[event fid:" + getId() + ":" + getRecency() + ":" + getObject() + "]";
+    }
+
+    /**
+     * @see Object
+     */
+    public String toString() {
+        return toExternalForm();
+    }
+
+    /**
+     * Always returns true, since the EventFactHandle is
+     * only used for Events, and not for regular Facts
+     */
+    public boolean isEvent() {
+        return true;
+    }
+}

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/InternalWorkingMemory.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/InternalWorkingMemory.java	2007-11-26 21:05:04 UTC (rev 16845)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/InternalWorkingMemory.java	2007-11-26 21:24:03 UTC (rev 16846)
@@ -9,6 +9,7 @@
 import org.drools.event.RuleFlowEventSupport;
 import org.drools.event.WorkingMemoryEventSupport;
 import org.drools.reteoo.LIANodePropagation;
+import org.drools.reteoo.ObjectTypeConf;
 import org.drools.rule.Rule;
 import org.drools.spi.Activation;
 import org.drools.spi.FactHandleFactory;
@@ -60,4 +61,21 @@
     public boolean isSequential();
     
     public void addLIANodePropagation(LIANodePropagation liaNodePropagation);
+    
+    /**
+     * Returns the ObjectTypeConfiguration object for the given object
+     * or creates a new one if none is found in the cache
+     * 
+     * @param object
+     * @return
+     */
+    public ObjectTypeConf getObjectTypeConf(Object object);
+    
+    /**
+     * Returns the Map<Object key, ObjectTypeConf conf> of object type
+     * confs in this working memory
+     *  
+     * @return
+     */
+    public Map<Object, ObjectTypeConf> getObjectTypeConfMap();
 }

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java	2007-11-26 21:05:04 UTC (rev 16845)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java	2007-11-26 21:24:03 UTC (rev 16846)
@@ -161,7 +161,7 @@
             this.resultBinder.updateFromTuple( workingMemory,
                                                leftTuple );
             if ( this.resultBinder.isAllowedCachedLeft( result ) ) {
-                final InternalFactHandle handle = workingMemory.getFactHandleFactory().newFactHandle( result );
+                final InternalFactHandle handle = workingMemory.getFactHandleFactory().newFactHandle( result, false ); // so far, result is not an event
                 accresult.handle = handle;
 
                 this.sink.propagateAssertTuple( leftTuple,
@@ -379,7 +379,7 @@
             this.resultBinder.updateFromTuple( workingMemory,
                                                leftTuple );
             if ( this.resultBinder.isAllowedCachedLeft( result ) ) {
-                final InternalFactHandle createdHandle = workingMemory.getFactHandleFactory().newFactHandle( result );
+                final InternalFactHandle createdHandle = workingMemory.getFactHandleFactory().newFactHandle( result, false ); // so far, result is not an event
                 accresult.handle = createdHandle;
 
                 this.sink.propagateAssertTuple( leftTuple,

Added: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ClassObjectTypeConf.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ClassObjectTypeConf.java	                        (rev 0)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ClassObjectTypeConf.java	2007-11-26 21:24:03 UTC (rev 16846)
@@ -0,0 +1,298 @@
+/*
+ * 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 Nov 26, 2007
+ */
+package org.drools.reteoo;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import org.drools.FactException;
+import org.drools.RuntimeDroolsException;
+import org.drools.base.ClassObjectType;
+import org.drools.base.DroolsQuery;
+import org.drools.base.ShadowProxy;
+import org.drools.base.ShadowProxyFactory;
+import org.drools.common.DroolsObjectInputStream;
+import org.drools.common.InternalRuleBase;
+import org.drools.objenesis.Objenesis;
+import org.drools.objenesis.ObjenesisStd;
+import org.drools.objenesis.instantiator.ObjectInstantiator;
+import org.drools.reteoo.builder.BuildContext;
+import org.drools.reteoo.builder.PatternBuilder;
+import org.drools.spi.ObjectType;
+import org.drools.util.Iterator;
+import org.drools.util.ObjectHashMap.ObjectEntry;
+
+public class ClassObjectTypeConf
+    implements
+    ObjectTypeConf,
+    Serializable {
+    // Objenesis instance without cache (false)
+    private static final Objenesis         OBJENESIS = new ObjenesisStd( false );
+
+    private final Class                    cls;
+    private transient InternalRuleBase     ruleBase;
+    private ObjectTypeNode[]               objectTypeNodes;
+
+    protected boolean                      shadowEnabled;
+    protected Class                        shadowClass;
+    protected transient ObjectInstantiator instantiator;
+
+    private ObjectTypeNode                 concreteObjectTypeNode;
+    
+    public ClassObjectTypeConf(final Class clazz, final boolean isEvent,
+                               final InternalRuleBase ruleBase) {
+        this.cls = clazz;
+        this.ruleBase = ruleBase;
+
+        ObjectType objectType = new ClassObjectType( clazz, isEvent );
+        this.concreteObjectTypeNode = (ObjectTypeNode) ruleBase.getRete().getObjectTypeNodes().get( objectType );
+        if ( this.concreteObjectTypeNode == null ) {
+            BuildContext context = new BuildContext( ruleBase,
+                                                     ((ReteooRuleBase) ruleBase.getRete().getRuleBase()).getReteooBuilder().getIdGenerator() );
+            if ( DroolsQuery.class == clazz ) {
+                context.setTupleMemoryEnabled( false );
+                context.setObjectTypeNodeMemoryEnabled( false );
+                context.setTerminalNodeMemoryEnabled( false );
+            } else if ( context.getRuleBase().getConfiguration().isSequential() ) {
+                // We are in sequential mode, so no nodes should have memory
+                context.setTupleMemoryEnabled( false );
+                context.setObjectTypeNodeMemoryEnabled( false );
+                context.setTerminalNodeMemoryEnabled( false );
+            } else {
+                context.setTupleMemoryEnabled( true );
+                context.setObjectTypeNodeMemoryEnabled( true );
+                context.setTerminalNodeMemoryEnabled( true );
+            }
+            // there must exist an ObjectTypeNode for this concrete class
+            this.concreteObjectTypeNode = PatternBuilder.attachObjectTypeNode( context,
+                                                                               objectType );
+        }
+
+        defineShadowProxyData( clazz );
+    }
+
+    public boolean isAssignableFrom(Object object) {
+        return this.cls.isAssignableFrom( (Class) object );
+    }
+
+    public ObjectTypeNode getConcreteObjectTypeNode() {
+        return this.concreteObjectTypeNode;
+    }
+
+    private void defineShadowProxyData(Class clazz) {
+        Rete rete = this.ruleBase.getRete();
+
+        if ( !ruleBase.getConfiguration().isShadowProxy() || clazz == null || !ruleBase.getConfiguration().isShadowed( clazz.getName() ) ) {
+            this.shadowEnabled = false;
+            this.shadowClass = null;
+            this.instantiator = null;
+            return;
+        }
+
+        //String pkgName = (pkg != null) ? pkg.getName() : "";
+        String pkgName = getPackageName( clazz,
+                                         clazz.getPackage() );
+        if ( "org.drools.reteoo".equals( pkgName ) || "org.drools.base".equals( pkgName ) ) {
+            // We don't shadow internal classes
+            this.shadowEnabled = false;
+            this.shadowClass = null;
+            this.instantiator = null;
+            return;
+        }
+
+        // try to generate proxy for the actual class
+        Class shadowClass = loadOrGenerateProxy( clazz,
+                                                 rete );
+
+        if ( shadowClass == null ) {
+            // if it failed, try to find a parent class
+            ObjectTypeNode[] nodes = this.getMatchingObjectTypes( clazz );
+            Class shadowClassRoot = clazz;
+            while ( shadowClass == null && (shadowClassRoot = this.findAFeasibleSuperclassOrInterface( nodes,
+                                                                                                       shadowClassRoot )) != null ) {
+                shadowClass = loadOrGenerateProxy( shadowClassRoot,
+                                                   rete );
+            }
+        }
+
+        if ( shadowClass != null ) {
+            this.shadowClass = shadowClass;
+            this.shadowEnabled = true;
+            setInstantiator();
+        }
+    }
+
+    /**
+     * This will return the package name - if the package is null, it will
+     * work it out from the class name (this is in cases where funky classloading is used).
+     */
+    public static String getPackageName(Class clazz,
+                                        Package pkg) {
+        String pkgName = "";
+        if ( pkg == null ) {
+            int index = clazz.getName().lastIndexOf( '.' );
+            if ( index != -1 ) pkgName = clazz.getName().substring( 0,
+                                                                    index );
+        } else {
+            pkgName = pkg.getName();
+        }
+        return pkgName;
+
+    }
+
+    private Class loadOrGenerateProxy(Class clazz,
+                                      Rete rete) {
+        Class shadowClass = null;
+        final String shadowProxyName = ShadowProxyFactory.getProxyClassNameForClass( clazz );
+        try {
+            // if already loaded
+            shadowClass = rete.getRuleBase().getMapBackedClassLoader().loadClass( shadowProxyName );
+        } catch ( final ClassNotFoundException cnfe ) {
+            // otherwise, create and load
+            final byte[] proxyBytes = ShadowProxyFactory.getProxyBytes( clazz );
+            if ( proxyBytes != null ) {
+                rete.getRuleBase().getMapBackedClassLoader().addClass( shadowProxyName,
+                                                                       proxyBytes );
+                try {
+                    shadowClass = rete.getRuleBase().getMapBackedClassLoader().loadClass( shadowProxyName );
+                } catch ( ClassNotFoundException e ) {
+                    throw new RuntimeException( "Unable to find or generate the ShadowProxy implementation for '" + clazz + "'" );
+                }
+            }
+
+        }
+        return shadowClass;
+    }
+
+    private Class findAFeasibleSuperclassOrInterface(ObjectTypeNode[] nodes,
+                                                     Class clazz) {
+
+        // check direct superclass
+        Class ret = clazz.getSuperclass();
+        boolean isOk = ret != null && ret != Object.class; // we don't want to shadow java.lang.Object
+        if ( isOk ) {
+            for ( int i = 0; isOk && ret != null && i < nodes.length; i++ ) {
+                isOk = nodes[i].getSinkPropagator().size() == 0 || nodes[i].isAssignableFrom( ret );
+            }
+        }
+
+        if ( !isOk ) {
+            // try the interfaces now...
+            Class[] interfaces = clazz.getInterfaces();
+            boolean notFound = true;
+            isOk = interfaces.length > 0;
+            for ( int i = 0; notFound && i < interfaces.length; i++ ) {
+                ret = interfaces[i];
+                isOk = interfaces[i] != Serializable.class && interfaces[i] != Cloneable.class && interfaces[i] != Comparable.class;
+                for ( int j = 0; isOk && j < nodes.length; j++ ) {
+                    isOk = nodes[j].getSinkPropagator().size() == 0 || nodes[j].isAssignableFrom( ret );
+                }
+                notFound = !isOk;
+            }
+            if ( notFound ) {
+                ret = null;
+            }
+        }
+
+        // ret now contains a superclass/interface that can be shadowed or null if none
+        return ret;
+    }
+
+    private void readObject(ObjectInputStream stream) throws IOException,
+                                                     ClassNotFoundException {
+        stream.defaultReadObject();
+        this.ruleBase = ((DroolsObjectInputStream) stream).getRuleBase();
+    }
+
+    /**
+     *
+     */
+    private void setInstantiator() {
+        this.instantiator = OBJENESIS.getInstantiatorOf( this.shadowClass );
+    }
+
+    public Object getShadow(final Object fact) throws RuntimeDroolsException {
+        ShadowProxy proxy = null;
+        if ( isShadowEnabled() ) {
+            try {
+                if ( Collection.class.isAssignableFrom( this.shadowClass ) || Map.class.isAssignableFrom( this.shadowClass ) ) {
+                    // if it is a collection, try to instantiate using constructor
+                    try {
+                        proxy = (ShadowProxy) this.shadowClass.getConstructor( new Class[]{cls} ).newInstance( new Object[]{fact} );
+                    } catch ( Exception e ) {
+                        // not possible to instantiate using constructor
+                    }
+                }
+                if ( proxy == null ) {
+                    if ( this.instantiator == null ) {
+                        this.setInstantiator();
+                    }
+                    proxy = (ShadowProxy) this.instantiator.newInstance();
+                }
+                proxy.setShadowedObject( fact );
+            } catch ( final Exception e ) {
+                throw new RuntimeDroolsException( "Error creating shadow fact for object: " + fact,
+                                                  e );
+            }
+        }
+        return proxy;
+    }
+
+    public boolean isShadowEnabled() {
+        return this.shadowEnabled;
+    }
+
+    public void resetCache() {
+        this.objectTypeNodes = null;
+        defineShadowProxyData( cls );
+    }
+
+    public ObjectTypeNode[] getObjectTypeNodes() {
+        if ( this.objectTypeNodes == null ) {
+            this.objectTypeNodes = getMatchingObjectTypes( this.cls );
+        }
+        return this.objectTypeNodes;
+    }
+
+    private ObjectTypeNode[] getMatchingObjectTypes(final Class clazz) throws FactException {
+        final List cache = new ArrayList();
+
+        final Iterator it = ruleBase.getRete().getObjectTypeNodes().newIterator();
+        for ( ObjectEntry entry = (ObjectEntry) it.next(); entry != null; entry = (ObjectEntry) it.next() ) {
+            final ObjectTypeNode node = (ObjectTypeNode) entry.getValue();
+            if ( node.isAssignableFrom( clazz ) ) {
+                cache.add( node );
+            }
+        }
+
+        return (ObjectTypeNode[]) cache.toArray( new ObjectTypeNode[cache.size()] );
+    }
+
+    public boolean isActive() {
+        return getConcreteObjectTypeNode().getSinkPropagator().getSinks().length > 0;
+    }
+    
+    public boolean isEvent() {
+        return this.concreteObjectTypeNode.getObjectType().isEvent();
+    }
+}
\ No newline at end of file

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/CollectNode.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/CollectNode.java	2007-11-26 21:05:04 UTC (rev 16845)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/CollectNode.java	2007-11-26 21:24:03 UTC (rev 16846)
@@ -107,7 +107,7 @@
         final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
 
         final Collection result = this.collect.instantiateResultObject();
-        final InternalFactHandle resultHandle = workingMemory.getFactHandleFactory().newFactHandle( result );
+        final InternalFactHandle resultHandle = workingMemory.getFactHandleFactory().newFactHandle( result, false );
         CollectResult colresult = new CollectResult();
         colresult.handle = resultHandle;
         colresult.propagated = false;

Added: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/FactTemplateTypeConf.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/FactTemplateTypeConf.java	                        (rev 0)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/FactTemplateTypeConf.java	2007-11-26 21:24:03 UTC (rev 16846)
@@ -0,0 +1,100 @@
+/*
+ * 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 Nov 26, 2007
+ */
+package org.drools.reteoo;
+
+import java.io.Serializable;
+
+import org.drools.RuntimeDroolsException;
+import org.drools.common.InternalRuleBase;
+import org.drools.facttemplates.FactTemplate;
+import org.drools.facttemplates.FactTemplateObjectType;
+import org.drools.reteoo.builder.BuildContext;
+import org.drools.reteoo.builder.PatternBuilder;
+import org.drools.spi.ObjectType;
+
+public class FactTemplateTypeConf
+    implements
+    ObjectTypeConf,
+    Serializable {
+    private InternalRuleBase ruleBase;
+    private FactTemplate     factTemplate;
+    private ObjectTypeNode   concreteObjectTypeNode;
+    private ObjectTypeNode[] cache;
+
+    public FactTemplateTypeConf(FactTemplate factTemplate,
+                                InternalRuleBase ruleBase) {
+        this.ruleBase = ruleBase;
+        this.factTemplate = factTemplate;
+        ObjectType objectType = new FactTemplateObjectType( factTemplate );
+        this.concreteObjectTypeNode = (ObjectTypeNode) ruleBase.getRete().getObjectTypeNodes().get( objectType );
+        if ( this.concreteObjectTypeNode == null ) {
+            BuildContext context = new BuildContext( ruleBase,
+                                                     ((ReteooRuleBase) ruleBase.getRete().getRuleBase()).getReteooBuilder().getIdGenerator() );
+            if ( context.getRuleBase().getConfiguration().isSequential() ) {
+                // We are in sequential mode, so no nodes should have memory
+                context.setTupleMemoryEnabled( false );
+                context.setObjectTypeNodeMemoryEnabled( false );
+                context.setTerminalNodeMemoryEnabled( false );
+            } else {
+                context.setTupleMemoryEnabled( true );
+                context.setObjectTypeNodeMemoryEnabled( true );
+                context.setTerminalNodeMemoryEnabled( true );
+            }
+            // there must exist an ObjectTypeNode for this concrete class                
+            this.concreteObjectTypeNode = PatternBuilder.attachObjectTypeNode( context,
+                                                                               objectType );
+        }
+        this.cache = new ObjectTypeNode[]{this.concreteObjectTypeNode};
+    }
+
+    public ObjectTypeNode getConcreteObjectTypeNode() {
+        return this.concreteObjectTypeNode;
+    }
+
+    public ObjectTypeNode[] getObjectTypeNodes() {
+        if ( this.cache == null ) {
+            this.cache = new ObjectTypeNode[]{this.concreteObjectTypeNode};
+        }
+        return this.cache;
+    }
+
+    public Object getShadow(Object fact) throws RuntimeDroolsException {
+        return null;
+    }
+
+    public boolean isShadowEnabled() {
+        return false;
+    }
+
+    public boolean isAssignableFrom(Object object) {
+        return this.factTemplate.equals( object );
+    }
+
+    public void resetCache() {
+        this.cache = null;
+    }
+
+    public boolean isActive() {
+        return true;
+    }
+    
+    public boolean isEvent() {
+        return false;
+    }
+
+}
\ No newline at end of file

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/FromNode.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/FromNode.java	2007-11-26 21:05:04 UTC (rev 16845)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/FromNode.java	2007-11-26 21:24:03 UTC (rev 16846)
@@ -83,7 +83,7 @@
             }
 
             if ( this.betaConstraints.isAllowedCachedLeft( object ) ) {
-                final InternalFactHandle handle = workingMemory.getFactHandleFactory().newFactHandle( object );
+                final InternalFactHandle handle = workingMemory.getFactHandleFactory().newFactHandle( object, false );
 
                 list.add( new LinkedListEntry( handle ) );
 

Added: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ObjectTypeConf.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ObjectTypeConf.java	                        (rev 0)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ObjectTypeConf.java	2007-11-26 21:24:03 UTC (rev 16846)
@@ -0,0 +1,38 @@
+/*
+ * 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 Nov 26, 2007
+ */
+package org.drools.reteoo;
+
+import org.drools.RuntimeDroolsException;
+
+public interface ObjectTypeConf {
+    public ObjectTypeNode[] getObjectTypeNodes();
+
+    public boolean isShadowEnabled();
+
+    public Object getShadow(final Object fact) throws RuntimeDroolsException;
+
+    public ObjectTypeNode getConcreteObjectTypeNode();
+
+    public void resetCache();
+
+    public boolean isAssignableFrom(Object object);
+    
+    public boolean isActive();
+    
+    public boolean isEvent();
+}
\ No newline at end of file

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/Rete.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/Rete.java	2007-11-26 21:05:04 UTC (rev 16845)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/Rete.java	2007-11-26 21:24:03 UTC (rev 16846)
@@ -19,39 +19,20 @@
 import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
 
-import org.drools.FactException;
-import org.drools.RuleBaseConfiguration;
-import org.drools.RuntimeDroolsException;
-import org.drools.base.ClassObjectType;
-import org.drools.base.DroolsQuery;
 import org.drools.base.ShadowProxy;
-import org.drools.base.ShadowProxyFactory;
 import org.drools.common.BaseNode;
 import org.drools.common.DroolsObjectInputStream;
 import org.drools.common.InternalFactHandle;
 import org.drools.common.InternalRuleBase;
 import org.drools.common.InternalWorkingMemory;
 import org.drools.common.NodeMemory;
-import org.drools.facttemplates.Fact;
-import org.drools.facttemplates.FactTemplate;
-import org.drools.facttemplates.FactTemplateObjectType;
-import org.drools.objenesis.Objenesis;
-import org.drools.objenesis.ObjenesisStd;
-import org.drools.objenesis.instantiator.ObjectInstantiator;
-import org.drools.reteoo.builder.BuildContext;
-import org.drools.reteoo.builder.PatternBuilder;
 import org.drools.spi.ObjectType;
 import org.drools.spi.PropagationContext;
 import org.drools.util.FactEntry;
 import org.drools.util.FactHashTable;
 import org.drools.util.Iterator;
 import org.drools.util.ObjectHashMap;
-import org.drools.util.ObjectHashMap.ObjectEntry;
 
 /**
  * The Rete-OO network.
@@ -75,8 +56,7 @@
 public class Rete extends ObjectSource
     implements
     Serializable,
-    ObjectSink,
-    NodeMemory {
+    ObjectSink {
     // ------------------------------------------------------------
     // Instance members
     // ------------------------------------------------------------
@@ -125,56 +105,22 @@
     public void assertObject(final InternalFactHandle handle,
                              final PropagationContext context,
                              final InternalWorkingMemory workingMemory) {
-        final ObjectHashMap memory = (ObjectHashMap) workingMemory.getNodeMemory( this );
 
-        Object object = handle.getObject();
+        ObjectTypeConf objectTypeConf = workingMemory.getObjectTypeConf( handle.getObject() );
 
-        ObjectTypeConf ojectTypeConf;
-        if ( object instanceof Fact ) {
-            String key = ((Fact) object).getFactTemplate().getName();
-            ojectTypeConf = (ObjectTypeConf) memory.get( key );
-            if ( ojectTypeConf == null ) {
-                ojectTypeConf = new FactTemplateTypeConf( ((Fact) object).getFactTemplate(),
-                                                          this.ruleBase );
-                memory.put( key,
-                            ojectTypeConf,
-                            false );
-            }
-            object = key;
-        } else {
-            Class cls = null;
-            if ( object instanceof ShadowProxy ) {
-                cls = ((ShadowProxy) object).getShadowedObject().getClass();
+        // checks if shadow is enabled
+        if ( objectTypeConf.isShadowEnabled() ) {
+            // need to improve this
+            if ( !(handle.getObject() instanceof ShadowProxy) ) {
+                // replaces the actual object by its shadow before propagating
+                handle.setObject( objectTypeConf.getShadow( handle.getObject() ) );
+                handle.setShadowFact( true );
             } else {
-                cls = object.getClass();
+                ((ShadowProxy) handle.getObject()).updateProxy();
             }
-
-            ojectTypeConf = (ObjectTypeConf) memory.get( cls );
-            if ( ojectTypeConf == null ) {
-                
-                final boolean isEvent = this.ruleBase.isEvent( cls );
-                ojectTypeConf = new ClassObjectTypeConf( cls,
-                                                         isEvent,
-                                                         this.ruleBase );
-                memory.put( cls,
-                            ojectTypeConf,
-                            false );
-            }
-
-            // checks if shadow is enabled
-            if ( ojectTypeConf.isShadowEnabled() ) {
-                // need to improve this
-                if ( !(handle.getObject() instanceof ShadowProxy) ) {
-                    // replaces the actual object by its shadow before propagating
-                    handle.setObject( ojectTypeConf.getShadow( handle.getObject() ) );
-                    handle.setShadowFact( true );
-                } else {
-                    ((ShadowProxy) handle.getObject()).updateProxy();
-                }
-            }
         }
 
-        ObjectTypeNode[] cachedNodes = ojectTypeConf.getObjectTypeNodes();
+        ObjectTypeNode[] cachedNodes = objectTypeConf.getObjectTypeNodes();
 
         for ( int i = 0, length = cachedNodes.length; i < length; i++ ) {
             cachedNodes[i].assertObject( handle,
@@ -195,17 +141,9 @@
     public void retractObject(final InternalFactHandle handle,
                               final PropagationContext context,
                               final InternalWorkingMemory workingMemory) {
-        final ObjectHashMap memory = (ObjectHashMap) workingMemory.getNodeMemory( this );
-
         final Object object = handle.getObject();
 
-        ObjectTypeConf objectTypeConf;
-        if ( object instanceof ShadowProxy ) {
-            objectTypeConf = (ObjectTypeConf) memory.get( ((ShadowProxy) object).getShadowedObject().getClass() );
-        } else {
-            objectTypeConf = (ObjectTypeConf) memory.get( object.getClass() );
-        }
-
+        ObjectTypeConf objectTypeConf = workingMemory.getObjectTypeConf( object );
         ObjectTypeNode[] cachedNodes = objectTypeConf.getObjectTypeNodes();
 
         if ( cachedNodes == null ) {
@@ -262,10 +200,6 @@
         return this.objectTypeNodes;
     }
 
-    public Object createMemory(final RuleBaseConfiguration config) {
-        return new ObjectHashMap();
-    }
-
     public InternalRuleBase getRuleBase() {
         return this.ruleBase;
     }
@@ -291,14 +225,10 @@
                            final PropagationContext context,
                            final InternalWorkingMemory workingMemory) {
         // JBRULES-612: the cache MUST be invalidated when a new node type is added to the network, so iterate and reset all caches.
-        final ObjectHashMap memory = (ObjectHashMap) workingMemory.getNodeMemory( this );
-        Iterator it = memory.iterator();
         final ObjectTypeNode node = (ObjectTypeNode) sink;
+        final ObjectType newObjectType = node.getObjectType();
 
-        ObjectType newObjectType = node.getObjectType();
-
-        for ( ObjectEntry entry = (ObjectEntry) it.next(); entry != null; entry = (ObjectEntry) it.next() ) {
-            ObjectTypeConf objectTypeConf = (ObjectTypeConf) entry.getValue();
+        for ( ObjectTypeConf objectTypeConf : workingMemory.getObjectTypeConfMap().values() ) {
             if ( newObjectType.isAssignableFrom( objectTypeConf.getConcreteObjectTypeNode().getObjectType() ) ) {
                 objectTypeConf.resetCache();
                 ObjectTypeNode sourceNode = objectTypeConf.getConcreteObjectTypeNode();
@@ -311,20 +241,6 @@
                 }
             }
         }
-
-        //        ObjectType
-        //        this.c
-
-        //        final ObjectTypeNode node = (ObjectTypeNode) sink;
-        //        it = workingMemory.getFactHandleMap().iterator();
-        //        for ( ObjectEntry entry = (ObjectEntry) it.next(); entry != null; entry = (ObjectEntry) it.next() ) {
-        //            final InternalFactHandle handle = (InternalFactHandle) entry.getValue();
-        //            if ( node.matches( handle.getObject() ) ) {
-        //                node.assertObject( handle,
-        //                                   context,
-        //                                   workingMemory );
-        //            }
-        //        }
     }
     
     public boolean isObjectMemoryEnabled() {
@@ -333,341 +249,6 @@
 
     public void setObjectMemoryEnabled(boolean objectMemoryEnabled) {
         throw new UnsupportedOperationException("ORete has no Object memory");
-    }     
-
-    public static interface ObjectTypeConf {
-        public ObjectTypeNode[] getObjectTypeNodes();
-
-        public boolean isShadowEnabled();
-
-        public Object getShadow(final Object fact) throws RuntimeDroolsException;
-
-        public ObjectTypeNode getConcreteObjectTypeNode();
-
-        public void resetCache();
-
-        public boolean isAssignableFrom(Object object);
-        
-        public boolean isActive();
     }
 
-    public static class FactTemplateTypeConf
-        implements
-        ObjectTypeConf,
-        Serializable {
-        private InternalRuleBase ruleBase;
-        private FactTemplate     factTemplate;
-        private ObjectTypeNode   concreteObjectTypeNode;
-        private ObjectTypeNode[] cache;
-
-        public FactTemplateTypeConf(FactTemplate factTemplate,
-                                    InternalRuleBase ruleBase) {
-            this.ruleBase = ruleBase;
-            this.factTemplate = factTemplate;
-            ObjectType objectType = new FactTemplateObjectType( factTemplate );
-            this.concreteObjectTypeNode = (ObjectTypeNode) ruleBase.getRete().getObjectTypeNodes().get( objectType );
-            if ( this.concreteObjectTypeNode == null ) {
-                BuildContext context = new BuildContext( ruleBase,
-                                                         ((ReteooRuleBase) ruleBase.getRete().getRuleBase()).getReteooBuilder().getIdGenerator() );
-                if ( context.getRuleBase().getConfiguration().isSequential() ) {
-                    // We are in sequential mode, so no nodes should have memory
-                    context.setTupleMemoryEnabled( false );
-                    context.setObjectTypeNodeMemoryEnabled( false );
-                    context.setTerminalNodeMemoryEnabled( false );
-                } else {
-                    context.setTupleMemoryEnabled( true );
-                    context.setObjectTypeNodeMemoryEnabled( true );
-                    context.setTerminalNodeMemoryEnabled( true );
-                }
-                // there must exist an ObjectTypeNode for this concrete class                
-                this.concreteObjectTypeNode = PatternBuilder.attachObjectTypeNode( context,
-                                                                                   objectType );
-            }
-            this.cache = new ObjectTypeNode[]{this.concreteObjectTypeNode};
-        }
-
-        public ObjectTypeNode getConcreteObjectTypeNode() {
-            return this.concreteObjectTypeNode;
-        }
-
-        public ObjectTypeNode[] getObjectTypeNodes() {
-            if ( this.cache == null ) {
-                this.cache = new ObjectTypeNode[]{this.concreteObjectTypeNode};
-            }
-            return this.cache;
-        }
-
-        public Object getShadow(Object fact) throws RuntimeDroolsException {
-            return null;
-        }
-
-        public boolean isShadowEnabled() {
-            return false;
-        }
-
-        public boolean isAssignableFrom(Object object) {
-            return this.factTemplate.equals( object );
-        }
-
-        public void resetCache() {
-            this.cache = null;
-        }
-
-        public boolean isActive() {
-            return true;
-        }
-
-    }
-
-    public static class ClassObjectTypeConf
-        implements
-        ObjectTypeConf,
-        Serializable {
-        // Objenesis instance without cache (false)
-        private static final Objenesis         OBJENESIS = new ObjenesisStd( false );
-
-        private final Class                    cls;
-        private transient InternalRuleBase     ruleBase;
-        private ObjectTypeNode[]               objectTypeNodes;
-
-        protected boolean                      shadowEnabled;
-        protected Class                        shadowClass;
-        protected transient ObjectInstantiator instantiator;
-
-        private ObjectTypeNode                 concreteObjectTypeNode;
-        
-        public ClassObjectTypeConf(final Class clazz, final boolean isEvent,
-                                   final InternalRuleBase ruleBase) {
-            this.cls = clazz;
-            this.ruleBase = ruleBase;
-
-            ObjectType objectType = new ClassObjectType( clazz, isEvent );
-            this.concreteObjectTypeNode = (ObjectTypeNode) ruleBase.getRete().getObjectTypeNodes().get( objectType );
-            if ( this.concreteObjectTypeNode == null ) {
-                BuildContext context = new BuildContext( ruleBase,
-                                                         ((ReteooRuleBase) ruleBase.getRete().getRuleBase()).getReteooBuilder().getIdGenerator() );
-                if ( DroolsQuery.class == clazz ) {
-                    context.setTupleMemoryEnabled( false );
-                    context.setObjectTypeNodeMemoryEnabled( false );
-                    context.setTerminalNodeMemoryEnabled( false );
-                } else if ( context.getRuleBase().getConfiguration().isSequential() ) {
-                    // We are in sequential mode, so no nodes should have memory
-                    context.setTupleMemoryEnabled( false );
-                    context.setObjectTypeNodeMemoryEnabled( false );
-                    context.setTerminalNodeMemoryEnabled( false );
-                } else {
-                    context.setTupleMemoryEnabled( true );
-                    context.setObjectTypeNodeMemoryEnabled( true );
-                    context.setTerminalNodeMemoryEnabled( true );
-                }
-                // there must exist an ObjectTypeNode for this concrete class
-                this.concreteObjectTypeNode = PatternBuilder.attachObjectTypeNode( context,
-                                                                                   objectType );
-            }
-
-            defineShadowProxyData( clazz );
-        }
-
-        public boolean isAssignableFrom(Object object) {
-            return this.cls.isAssignableFrom( (Class) object );
-        }
-
-        public ObjectTypeNode getConcreteObjectTypeNode() {
-            return this.concreteObjectTypeNode;
-        }
-
-        private void defineShadowProxyData(Class clazz) {
-            Rete rete = this.ruleBase.getRete();
-
-            if ( !ruleBase.getConfiguration().isShadowProxy() || clazz == null || !ruleBase.getConfiguration().isShadowed( clazz.getName() ) ) {
-                this.shadowEnabled = false;
-                this.shadowClass = null;
-                this.instantiator = null;
-                return;
-            }
-
-            //String pkgName = (pkg != null) ? pkg.getName() : "";
-            String pkgName = getPackageName( clazz,
-                                             clazz.getPackage() );
-            if ( "org.drools.reteoo".equals( pkgName ) || "org.drools.base".equals( pkgName ) ) {
-                // We don't shadow internal classes
-                this.shadowEnabled = false;
-                this.shadowClass = null;
-                this.instantiator = null;
-                return;
-            }
-
-            // try to generate proxy for the actual class
-            Class shadowClass = loadOrGenerateProxy( clazz,
-                                                     rete );
-
-            if ( shadowClass == null ) {
-                // if it failed, try to find a parent class
-                ObjectTypeNode[] nodes = this.getMatchingObjectTypes( clazz );
-                Class shadowClassRoot = clazz;
-                while ( shadowClass == null && (shadowClassRoot = this.findAFeasibleSuperclassOrInterface( nodes,
-                                                                                                           shadowClassRoot )) != null ) {
-                    shadowClass = loadOrGenerateProxy( shadowClassRoot,
-                                                       rete );
-                }
-            }
-
-            if ( shadowClass != null ) {
-                this.shadowClass = shadowClass;
-                this.shadowEnabled = true;
-                setInstantiator();
-            }
-        }
-
-        /**
-         * This will return the package name - if the package is null, it will
-         * work it out from the class name (this is in cases where funky classloading is used).
-         */
-        public static String getPackageName(Class clazz,
-                                            Package pkg) {
-            String pkgName = "";
-            if ( pkg == null ) {
-                int index = clazz.getName().lastIndexOf( '.' );
-                if ( index != -1 ) pkgName = clazz.getName().substring( 0,
-                                                                        index );
-            } else {
-                pkgName = pkg.getName();
-            }
-            return pkgName;
-
-        }
-
-        private Class loadOrGenerateProxy(Class clazz,
-                                          Rete rete) {
-            Class shadowClass = null;
-            final String shadowProxyName = ShadowProxyFactory.getProxyClassNameForClass( clazz );
-            try {
-                // if already loaded
-                shadowClass = rete.getRuleBase().getMapBackedClassLoader().loadClass( shadowProxyName );
-            } catch ( final ClassNotFoundException cnfe ) {
-                // otherwise, create and load
-                final byte[] proxyBytes = ShadowProxyFactory.getProxyBytes( clazz );
-                if ( proxyBytes != null ) {
-                    rete.getRuleBase().getMapBackedClassLoader().addClass( shadowProxyName,
-                                                                           proxyBytes );
-                    try {
-                        shadowClass = rete.getRuleBase().getMapBackedClassLoader().loadClass( shadowProxyName );
-                    } catch ( ClassNotFoundException e ) {
-                        throw new RuntimeException( "Unable to find or generate the ShadowProxy implementation for '" + clazz + "'" );
-                    }
-                }
-
-            }
-            return shadowClass;
-        }
-
-        private Class findAFeasibleSuperclassOrInterface(ObjectTypeNode[] nodes,
-                                                         Class clazz) {
-
-            // check direct superclass
-            Class ret = clazz.getSuperclass();
-            boolean isOk = ret != null && ret != Object.class; // we don't want to shadow java.lang.Object
-            if ( isOk ) {
-                for ( int i = 0; isOk && ret != null && i < nodes.length; i++ ) {
-                    isOk = nodes[i].getSinkPropagator().size() == 0 || nodes[i].isAssignableFrom( ret );
-                }
-            }
-
-            if ( !isOk ) {
-                // try the interfaces now...
-                Class[] interfaces = clazz.getInterfaces();
-                boolean notFound = true;
-                isOk = interfaces.length > 0;
-                for ( int i = 0; notFound && i < interfaces.length; i++ ) {
-                    ret = interfaces[i];
-                    isOk = interfaces[i] != Serializable.class && interfaces[i] != Cloneable.class && interfaces[i] != Comparable.class;
-                    for ( int j = 0; isOk && j < nodes.length; j++ ) {
-                        isOk = nodes[j].getSinkPropagator().size() == 0 || nodes[j].isAssignableFrom( ret );
-                    }
-                    notFound = !isOk;
-                }
-                if ( notFound ) {
-                    ret = null;
-                }
-            }
-
-            // ret now contains a superclass/interface that can be shadowed or null if none
-            return ret;
-        }
-
-        private void readObject(ObjectInputStream stream) throws IOException,
-                                                         ClassNotFoundException {
-            stream.defaultReadObject();
-            this.ruleBase = ((DroolsObjectInputStream) stream).getRuleBase();
-        }
-
-        /**
-         *
-         */
-        private void setInstantiator() {
-            this.instantiator = OBJENESIS.getInstantiatorOf( this.shadowClass );
-        }
-
-        public Object getShadow(final Object fact) throws RuntimeDroolsException {
-            ShadowProxy proxy = null;
-            if ( isShadowEnabled() ) {
-                try {
-                    if ( Collection.class.isAssignableFrom( this.shadowClass ) || Map.class.isAssignableFrom( this.shadowClass ) ) {
-                        // if it is a collection, try to instantiate using constructor
-                        try {
-                            proxy = (ShadowProxy) this.shadowClass.getConstructor( new Class[]{cls} ).newInstance( new Object[]{fact} );
-                        } catch ( Exception e ) {
-                            // not possible to instantiate using constructor
-                        }
-                    }
-                    if ( proxy == null ) {
-                        if ( this.instantiator == null ) {
-                            this.setInstantiator();
-                        }
-                        proxy = (ShadowProxy) this.instantiator.newInstance();
-                    }
-                    proxy.setShadowedObject( fact );
-                } catch ( final Exception e ) {
-                    throw new RuntimeDroolsException( "Error creating shadow fact for object: " + fact,
-                                                      e );
-                }
-            }
-            return proxy;
-        }
-
-        public boolean isShadowEnabled() {
-            return this.shadowEnabled;
-        }
-
-        public void resetCache() {
-            this.objectTypeNodes = null;
-            defineShadowProxyData( cls );
-        }
-
-        public ObjectTypeNode[] getObjectTypeNodes() {
-            if ( this.objectTypeNodes == null ) {
-                this.objectTypeNodes = getMatchingObjectTypes( this.cls );
-            }
-            return this.objectTypeNodes;
-        }
-
-        private ObjectTypeNode[] getMatchingObjectTypes(final Class clazz) throws FactException {
-            final List cache = new ArrayList();
-
-            final Iterator it = ruleBase.getRete().getObjectTypeNodes().newIterator();
-            for ( ObjectEntry entry = (ObjectEntry) it.next(); entry != null; entry = (ObjectEntry) it.next() ) {
-                final ObjectTypeNode node = (ObjectTypeNode) entry.getValue();
-                if ( node.isAssignableFrom( clazz ) ) {
-                    cache.add( node );
-                }
-            }
-
-            return (ObjectTypeNode[]) cache.toArray( new ObjectTypeNode[cache.size()] );
-        }
-
-        public boolean isActive() {
-            return getConcreteObjectTypeNode().getSinkPropagator().getSinks().length > 0;
-        }
-    }
-
 }

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ReteooFactHandleFactory.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ReteooFactHandleFactory.java	2007-11-26 21:05:04 UTC (rev 16845)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ReteooFactHandleFactory.java	2007-11-26 21:24:03 UTC (rev 16846)
@@ -18,6 +18,7 @@
 
 import org.drools.common.AbstractFactHandleFactory;
 import org.drools.common.DefaultFactHandle;
+import org.drools.common.EventFactHandle;
 import org.drools.common.InternalFactHandle;
 import org.drools.spi.FactHandleFactory;
 
@@ -30,10 +31,17 @@
      */
     protected final InternalFactHandle newFactHandle(final long id,
                                                      final Object object,
-                                                     final long recency) {
-        return new DefaultFactHandle( id,
-                                      object,
-                                      recency );
+                                                     final long recency,
+                                                     final boolean isEvent) {
+        if ( isEvent ) {
+            return new EventFactHandle( id,
+                                        object,
+                                        recency );
+        } else {
+            return new DefaultFactHandle( id,
+                                          object,
+                                          recency );
+        }
     }
 
     /* (non-Javadoc)

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java	2007-11-26 21:05:04 UTC (rev 16845)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java	2007-11-26 21:24:03 UTC (rev 16846)
@@ -235,7 +235,7 @@
                 super.addStatefulSession( session );
             }
 
-            final InitialFactHandle handle = new InitialFactHandle( session.getFactHandleFactory().newFactHandle( new InitialFactHandleDummyObject() ) );
+            final InitialFactHandle handle = new InitialFactHandle( session.getFactHandleFactory().newFactHandle( new InitialFactHandleDummyObject(), false ) );
 
             session.queueWorkingMemoryAction( new WorkingMemoryReteAssertAction( handle,
                                                                                  false,

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ReteooStatelessSession.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ReteooStatelessSession.java	2007-11-26 21:05:04 UTC (rev 16845)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ReteooStatelessSession.java	2007-11-26 21:24:03 UTC (rev 16846)
@@ -59,7 +59,7 @@
             wm.setAgendaEventSupport( this.agendaEventSupport );
             wm.setRuleFlowEventSupport( ruleFlowEventSupport );
 
-            final InitialFactHandle handle = new InitialFactHandle( wm.getFactHandleFactory().newFactHandle( new InitialFactHandleDummyObject() ) );
+            final InitialFactHandle handle = new InitialFactHandle( wm.getFactHandleFactory().newFactHandle( new InitialFactHandleDummyObject(), false ) );
 
             wm.queueWorkingMemoryAction( new WorkingMemoryReteAssertAction( handle,
                                                                             false,

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java	2007-11-26 21:05:04 UTC (rev 16845)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java	2007-11-26 21:24:03 UTC (rev 16846)
@@ -87,7 +87,7 @@
     public QueryResults getQueryResults(final String query, final Object[] arguments) {
 
         Object object = new DroolsQuery( query, arguments );
-        InternalFactHandle handle = this.handleFactory.newFactHandle( object );
+        InternalFactHandle handle = this.handleFactory.newFactHandle( object, false );
         
         insert( handle,
                 object,

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/RightInputAdapterNode.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/RightInputAdapterNode.java	2007-11-26 21:05:04 UTC (rev 16845)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/RightInputAdapterNode.java	2007-11-26 21:24:03 UTC (rev 16846)
@@ -92,7 +92,7 @@
                             final InternalWorkingMemory workingMemory) {
 
         // creating a dummy fact handle to wrap the tuple
-        final InternalFactHandle handle = workingMemory.getFactHandleFactory().newFactHandle( tuple );
+        final InternalFactHandle handle = workingMemory.getFactHandleFactory().newFactHandle( tuple, false );
         
         if ( this.tupleMemoryEnabled ) {
             final ObjectHashMap memory = (ObjectHashMap) workingMemory.getNodeMemory( this );

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/spi/FactHandleFactory.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/spi/FactHandleFactory.java	2007-11-26 21:05:04 UTC (rev 16845)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/spi/FactHandleFactory.java	2007-11-26 21:24:03 UTC (rev 16846)
@@ -37,7 +37,7 @@
      * 
      * @return The handle.
      */
-    InternalFactHandle newFactHandle(Object object);
+    InternalFactHandle newFactHandle(Object object, boolean isEvent);
 
     /**
      * Increases the recency of the FactHandle

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/common/EqualityKeyTest.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/common/EqualityKeyTest.java	2007-11-26 21:05:04 UTC (rev 16845)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/common/EqualityKeyTest.java	2007-11-26 21:24:03 UTC (rev 16846)
@@ -10,13 +10,13 @@
     public void test1() {
         ReteooFactHandleFactory factory = new ReteooFactHandleFactory();
         
-        InternalFactHandle ch1 = factory.newFactHandle( new Cheese ("c", 10) );
+        InternalFactHandle ch1 = factory.newFactHandle( new Cheese ("c", 10), false );
         EqualityKey key = new EqualityKey( ch1 );
         
         assertSame( ch1, key.getFactHandle() );
         assertNull( key.getOtherFactHandle() );
         
-        InternalFactHandle ch2 = factory.newFactHandle( new Cheese ("c", 10) );
+        InternalFactHandle ch2 = factory.newFactHandle( new Cheese ("c", 10), false );
         key.addFactHandle( ch2 );
         
         assertEquals( 1, key.getOtherFactHandle().size() );

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/AccumulateNodeTest.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/AccumulateNodeTest.java	2007-11-26 21:05:04 UTC (rev 16845)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/AccumulateNodeTest.java	2007-11-26 21:24:03 UTC (rev 16846)
@@ -128,10 +128,10 @@
                              0,
                              this.sink.getAsserted().size() );
 
-        this.node.assertTuple( new ReteTuple( this.workingMemory.getFactHandleFactory().newFactHandle( "cheese" ) ),
+        this.node.assertTuple( new ReteTuple( this.workingMemory.getFactHandleFactory().newFactHandle( "cheese", false ) ),
                                this.context,
                                this.workingMemory );
-        this.node.assertTuple( new ReteTuple( this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese" ) ),
+        this.node.assertTuple( new ReteTuple( this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese", false ) ),
                                this.context,
                                this.workingMemory );
 
@@ -155,7 +155,7 @@
      * Test method for {@link org.drools.reteoo.AccumulateNode#assertTuple(org.drools.reteoo.ReteTuple, org.drools.spi.PropagationContext, org.drools.reteoo.ReteooWorkingMemory)}.
      */
     public void testAssertTuple() {
-        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese" );
+        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese", false );
         final ReteTuple tuple0 = new ReteTuple( f0 );
 
         // assert tuple, should add one to left memory
@@ -171,7 +171,7 @@
                            this.accumulator.getMatchingObjects().isEmpty() );
 
         // assert tuple, should add left memory 
-        final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese" );
+        final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese", false );
 
         final ReteTuple tuple1 = new ReteTuple( f1 );
         this.node.assertTuple( tuple1,
@@ -195,8 +195,8 @@
      * Test method for {@link org.drools.reteoo.AccumulateNode#assertTuple(org.drools.reteoo.ReteTuple, org.drools.spi.PropagationContext, org.drools.reteoo.ReteooWorkingMemory)}.
      */
     public void testAssertTupleWithObjects() {
-        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese" );
-        final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese" );
+        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese", false );
+        final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese", false );
 
         final ReteTuple tuple0 = new ReteTuple( f0 );
 
@@ -244,7 +244,7 @@
      * Test method for {@link org.drools.reteoo.AccumulateNode#retractTuple(org.drools.reteoo.ReteTuple, org.drools.spi.PropagationContext, org.drools.reteoo.ReteooWorkingMemory)}.
      */
     public void testRetractTuple() {
-        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese" );
+        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese", false );
 
         final ReteTuple tuple0 = new ReteTuple( f0 );
 
@@ -275,8 +275,8 @@
      * Test method for {@link org.drools.reteoo.AccumulateNode#assertObject(InternalFactHandle, org.drools.spi.PropagationContext, InternalWorkingMemory)}.
      */
     public void testAssertObject() {
-        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese" );
-        final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese" );
+        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese", false );
+        final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese", false );
 
         final ReteTuple tuple0 = new ReteTuple( f0 );
 
@@ -320,8 +320,8 @@
      * Test method for {@link org.drools.reteoo.AccumulateNode#retractObject(InternalFactHandle, org.drools.spi.PropagationContext, InternalWorkingMemory)}.
      */
     public void testRetractObject() {
-        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese" );
-        final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese" );
+        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese", false );
+        final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese", false );
 
         final ReteTuple tuple0 = new ReteTuple( f0 );
 
@@ -431,8 +431,8 @@
         
         this.memory = ((AccumulateMemory) this.workingMemory.getNodeMemory( this.node )).betaMemory;
 
-        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese" );
-        final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese" );
+        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese", false );
+        final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese", false );
 
         final ReteTuple tuple0 = new ReteTuple( f0 );
 

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/CollectNodeTest.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/CollectNodeTest.java	2007-11-26 21:05:04 UTC (rev 16845)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/CollectNodeTest.java	2007-11-26 21:24:03 UTC (rev 16846)
@@ -125,10 +125,10 @@
                              0,
                              this.sink.getAsserted().size() );
 
-        this.node.assertTuple( new ReteTuple( this.workingMemory.getFactHandleFactory().newFactHandle( "cheese" ) ),
+        this.node.assertTuple( new ReteTuple( this.workingMemory.getFactHandleFactory().newFactHandle( "cheese", false ) ),
                                this.contextAssert,
                                this.workingMemory );
-        this.node.assertTuple( new ReteTuple( this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese" ) ),
+        this.node.assertTuple( new ReteTuple( this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese", false ) ),
                                this.contextAssert,
                                this.workingMemory );
 
@@ -149,7 +149,7 @@
     }
 
     public void testAssertTuple() {
-        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese" );
+        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese", false );
         final ReteTuple tuple0 = new ReteTuple( f0 );
 
         // assert tuple, should add one to left memory
@@ -165,7 +165,7 @@
                            ((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" );
+        final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese", false );
 
         final ReteTuple tuple1 = new ReteTuple( f1 );
         this.node.assertTuple( tuple1,
@@ -185,8 +185,8 @@
     }
 
     public void testAssertTupleWithObjects() {
-        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese" );
-        final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese" );
+        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese", false );
+        final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese", false );
 
         final ReteTuple tuple0 = new ReteTuple( f0 );
 
@@ -230,7 +230,7 @@
     }
 
     public void testRetractTuple() {
-        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese" );
+        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese", false );
 
         final ReteTuple tuple0 = new ReteTuple( f0 );
 
@@ -258,8 +258,8 @@
     }
 
     public void testAssertObject() {
-        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese" );
-        final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese" );
+        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese", false );
+        final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese", false );
 
         final ReteTuple tuple0 = new ReteTuple( f0 );
 
@@ -302,8 +302,8 @@
     }
 
     public void testRetractObject() {
-        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese" );
-        final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese" );
+        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese", false );
+        final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese", false );
 
         final ReteTuple tuple0 = new ReteTuple( f0 );
 
@@ -395,8 +395,8 @@
         this.memory = (BetaMemory) this.workingMemory.getNodeMemory( this.node );
         this.node.setTupleMemoryEnabled( false );
 
-        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese" );
-        final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese" );
+        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese", false );
+        final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese", false );
 
         final ReteTuple tuple0 = new ReteTuple( f0 );
 

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/CompositeObjectSinkAdapterTest.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/CompositeObjectSinkAdapterTest.java	2007-11-26 21:05:04 UTC (rev 16845)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/CompositeObjectSinkAdapterTest.java	2007-11-26 21:24:03 UTC (rev 16846)
@@ -257,7 +257,7 @@
         ad.addObjectSink( al2 );
         ad.addObjectSink( al3 );
 
-        InternalFactHandle handle = new ReteooFactHandleFactory().newFactHandle( new Cheese() );
+        InternalFactHandle handle = new ReteooFactHandleFactory().newFactHandle( new Cheese(), false );
         try {
             ad.propagateAssertObject( handle,
                                       null,

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/DefaultFactHandleFactoryTest.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/DefaultFactHandleFactoryTest.java	2007-11-26 21:05:04 UTC (rev 16845)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/DefaultFactHandleFactoryTest.java	2007-11-26 21:24:03 UTC (rev 16846)
@@ -27,21 +27,21 @@
      */
     public void testNewFactHandle() {
         final ReteooFactHandleFactory factory = new ReteooFactHandleFactory();
-        DefaultFactHandle handle = (DefaultFactHandle) factory.newFactHandle( "cheese" );
+        DefaultFactHandle handle = (DefaultFactHandle) factory.newFactHandle( "cheese", false );
         assertEquals( 0,
                       handle.getId() );
         assertEquals( 0,
                       handle.getRecency() );
 
         // issue  new handle
-        handle = (DefaultFactHandle) factory.newFactHandle( "cheese" );
+        handle = (DefaultFactHandle) factory.newFactHandle( "cheese", false );
         assertEquals( 1,
                       handle.getId() );
         assertEquals( 1,
                       handle.getRecency() );
 
         // issue  new handle, under a different reference so we  can destroy later        
-        final DefaultFactHandle handle2 = (DefaultFactHandle) factory.newFactHandle( "cheese" );
+        final DefaultFactHandle handle2 = (DefaultFactHandle) factory.newFactHandle( "cheese", false );
         assertEquals( 2,
                       handle2.getId() );
         assertEquals( 2,
@@ -53,7 +53,7 @@
                       handle.getRecency() );
 
         // issue new handle and make sure  recency is still inline
-        handle = (DefaultFactHandle) factory.newFactHandle( "cheese" );
+        handle = (DefaultFactHandle) factory.newFactHandle( "cheese", false );
         assertEquals( 3,
                       handle.getId() );
         assertEquals( 4,
@@ -63,14 +63,14 @@
         factory.destroyFactHandle( handle2 );
 
         // issue  new  fact handle and  make sure it  recycled the  id=2
-        handle = (DefaultFactHandle) factory.newFactHandle( "cheese" );
+        handle = (DefaultFactHandle) factory.newFactHandle( "cheese", false );
         assertEquals( 2,
                       handle.getId() );
         assertEquals( 5,
                       handle.getRecency() );
 
         // issue new  handle  making  sure it correctly resumes  ids  and recency
-        handle = (DefaultFactHandle) factory.newFactHandle( "cheese" );
+        handle = (DefaultFactHandle) factory.newFactHandle( "cheese", false );
         assertEquals( 4,
                       handle.getId() );
         assertEquals( 6,

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/ObjectTypeConfTest.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/ObjectTypeConfTest.java	2007-11-26 21:05:04 UTC (rev 16845)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/ObjectTypeConfTest.java	2007-11-26 21:24:03 UTC (rev 16846)
@@ -1,6 +1,5 @@
 package org.drools.reteoo;
 
-import org.drools.reteoo.Rete.ClassObjectTypeConf;
 
 import junit.framework.TestCase;
 

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/ReteTest.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/ReteTest.java	2007-11-26 21:05:04 UTC (rev 16845)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/ReteTest.java	2007-11-26 21:24:03 UTC (rev 16846)
@@ -22,6 +22,7 @@
 import java.util.Collection;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Map;
 import java.util.Properties;
 
 import org.drools.Cheese;
@@ -35,8 +36,6 @@
 import org.drools.common.DefaultFactHandle;
 import org.drools.common.InternalWorkingMemory;
 import org.drools.common.PropagationContextImpl;
-import org.drools.reteoo.Rete.ClassObjectTypeConf;
-import org.drools.reteoo.Rete.ObjectTypeConf;
 import org.drools.reteoo.ReteooBuilder.IdGenerator;
 import org.drools.reteoo.builder.BuildContext;
 import org.drools.spi.PropagationContext;
@@ -135,7 +134,7 @@
                                                        null ),
                            workingMemory );
 
-        final ObjectHashMap map = (ObjectHashMap) workingMemory.getNodeMemory( rete );
+        final Map map = workingMemory.getObjectTypeConfMap();
         ClassObjectTypeConf conf = (ClassObjectTypeConf) map.get( ArrayList.class );
         assertLength( 3,
                       conf.getObjectTypeNodes() );
@@ -239,7 +238,7 @@
                     rete.getObjectTypeNodes().get( new ClassObjectType( List.class ) ) );
 
         // ArrayConf should match two ObjectTypenodes for List and ArrayList
-        ObjectHashMap memory = (ObjectHashMap) workingMemory.getNodeMemory( rete );
+        Map memory = workingMemory.getObjectTypeConfMap();
         ObjectTypeConf arrayConf = (ObjectTypeConf) memory.get( ArrayList.class );
         final ObjectTypeNode arrayOtn = arrayConf.getConcreteObjectTypeNode();
         assertEquals( 2,

Added: labs/jbossrules/branches/temporal_rete/drools-jsr94/src/main/java/org/drools/jsr94/rules/Jsr94EventFactHandle.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-jsr94/src/main/java/org/drools/jsr94/rules/Jsr94EventFactHandle.java	                        (rev 0)
+++ labs/jbossrules/branches/temporal_rete/drools-jsr94/src/main/java/org/drools/jsr94/rules/Jsr94EventFactHandle.java	2007-11-26 21:24:03 UTC (rev 16846)
@@ -0,0 +1,84 @@
+package org.drools.jsr94.rules;
+
+/*
+ * $Id: Jsr94FactHandle.java,v 1.14 2005/02/04 02:13:38 mproctor Exp $
+ *
+ * Copyright 2003-2004 (C) The Werken Company. All Rights Reserved.
+ *
+ * Redistribution and use of this software and associated documentation
+ * ("Software"), with or without modification, are permitted provided that the
+ * following conditions are met:
+ *
+ * 1. Redistributions of source code must retain copyright statements and
+ * notices. Redistributions must also contain a copy of this document.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The name "drools" must not be used to endorse or promote products derived
+ * from this Software without prior written permission of The Werken Company.
+ * For written permission, please contact bob at werken.com.
+ *
+ * 4. Products derived from this Software may not be called "drools" nor may
+ * "drools" appear in their names without prior written permission of The Werken
+ * Company. "drools" is a registered trademark of The Werken Company.
+ *
+ * 5. Due credit should be given to The Werken Company.
+ * (http://drools.werken.com/).
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE WERKEN COMPANY AND CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE WERKEN COMPANY OR ITS CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+import javax.rules.Handle;
+
+import org.drools.common.EventFactHandle;
+
+/**
+ * The Drools implementation of the <code>Handle</code> interface which provides
+ * a marker interface for Drools-specific object identity mechanism. When using
+ * the <code>StatefulRuleSession</code> objects that are added to rule session
+ * state are identified using a Drools-supplied <code>Handle</code>
+ * implementation.
+ * <p/>
+ * <code>Handle</code>s are used to unambigiously identify objects within the
+ * rule session state and should not suffer many of the object identity issues
+ * that arise when using muliple class loaders, serializing
+ * <code>StatefulRuleSessions</code>, or using <code>Object.equals</code> or
+ * <code>object1 == object2</code> reference equality.
+ */
+public class Jsr94EventFactHandle extends EventFactHandle
+    implements
+    Handle {
+
+    private static final long serialVersionUID = -7338909470403134407L;
+
+    /**
+     * Constructs a new <code>Handle</code>.
+     *
+     * @param id A unique <code>Handle</code> id.
+     * @param recency A value indicating the recency of this <code>Handle</code>
+     *        (more recently created <code>Handle</code>s have greater values
+     *         than <code>Handle</code>s created further in the past)
+     *
+     * @see org.drools.conflict.RecencyConflictResolver
+     */
+    Jsr94EventFactHandle(final long id,
+                    final Object object,
+                    final long recency) {
+        super( id,
+               object,
+               recency );
+    }
+}

Modified: labs/jbossrules/branches/temporal_rete/drools-jsr94/src/main/java/org/drools/jsr94/rules/Jsr94FactHandle.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-jsr94/src/main/java/org/drools/jsr94/rules/Jsr94FactHandle.java	2007-11-26 21:05:04 UTC (rev 16845)
+++ labs/jbossrules/branches/temporal_rete/drools-jsr94/src/main/java/org/drools/jsr94/rules/Jsr94FactHandle.java	2007-11-26 21:24:03 UTC (rev 16846)
@@ -61,6 +61,9 @@
 public class Jsr94FactHandle extends DefaultFactHandle
     implements
     Handle {
+
+    private static final long serialVersionUID = 7664394510847222696L;
+
     /**
      * Constructs a new <code>Handle</code>.
      *

Modified: labs/jbossrules/branches/temporal_rete/drools-jsr94/src/main/java/org/drools/jsr94/rules/Jsr94FactHandleFactory.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-jsr94/src/main/java/org/drools/jsr94/rules/Jsr94FactHandleFactory.java	2007-11-26 21:05:04 UTC (rev 16845)
+++ labs/jbossrules/branches/temporal_rete/drools-jsr94/src/main/java/org/drools/jsr94/rules/Jsr94FactHandleFactory.java	2007-11-26 21:24:03 UTC (rev 16846)
@@ -17,7 +17,6 @@
  */
 
 import org.drools.common.AbstractFactHandleFactory;
-import org.drools.common.DefaultFactHandle;
 import org.drools.common.InternalFactHandle;
 import org.drools.spi.FactHandleFactory;
 
@@ -27,15 +26,25 @@
  */
 public final class Jsr94FactHandleFactory extends AbstractFactHandleFactory {
 
+
+    private static final long serialVersionUID = 4964273923122006124L;
+
     /* (non-Javadoc)
      * @see org.drools.reteoo.FactHandleFactory#newFactHandle(long)
      */
     protected final InternalFactHandle newFactHandle(final long id,
                                                      final Object object,
-                                                     final long recency) {
-        return new Jsr94FactHandle( id,
-                                    object,
-                                    recency );
+                                                     final long recency,
+                                                     final boolean isEvent) {
+        if ( isEvent ) {
+            return new Jsr94EventFactHandle( id,
+                                             object,
+                                             recency );
+        } else {
+            return new Jsr94FactHandle( id,
+                                        object,
+                                        recency );
+        }
     }
 
     /* (non-Javadoc)




More information about the jboss-svn-commits mailing list