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

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sat Apr 12 13:37:09 EDT 2008


Author: tirelli
Date: 2008-04-12 13:37:09 -0400 (Sat, 12 Apr 2008)
New Revision: 19536

Modified:
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilder.java
   labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/CepEspTest.java
   labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/testframework/MockWorkingMemory.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractFactHandleFactory.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalWorkingMemory.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/NamedEntryPoint.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ClassObjectTypeConf.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CollectNode.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/FactTemplateTypeConf.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/FromNode.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectTypeConf.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooFactHandleFactory.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooStatefulSession.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooStatelessSession.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightInputAdapterNode.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/TypeDeclaration.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/FactHandleFactory.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/common/EqualityKeyTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AccumulateNodeTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CollectNodeTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CompositeObjectSinkAdapterTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/DefaultFactHandleFactoryTest.java
   labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/Jsr94FactHandleFactory.java
Log:
JBRULES-1390: adding support to declaring the duration attribute for events

Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilder.java	2008-04-12 14:51:42 UTC (rev 19535)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilder.java	2008-04-12 17:37:09 UTC (rev 19536)
@@ -24,6 +24,7 @@
 import java.util.List;
 import java.util.Set;
 
+import org.drools.base.ClassFieldExtractor;
 import org.drools.base.ClassFieldExtractorCache;
 import org.drools.base.ClassTypeResolver;
 import org.drools.base.TypeResolver;
@@ -51,6 +52,7 @@
 import org.drools.rule.TypeDeclaration;
 import org.drools.rule.builder.RuleBuildContext;
 import org.drools.rule.builder.RuleBuilder;
+import org.drools.spi.FieldExtractor;
 import org.drools.xml.XmlPackageReader;
 import org.drools.xml.XmlProcessReader;
 import org.xml.sax.SAXException;
@@ -262,7 +264,7 @@
         validateUniqueRuleNames( packageDescr );
 
         String dialectName = null;
-       
+
         for ( Iterator it = packageDescr.getAttributes().iterator(); it.hasNext(); ) {
             AttributeDescr value = (AttributeDescr) it.next();
             if ( "dialect".equals( value.getName() ) ) {
@@ -294,12 +296,12 @@
             }
 
             if ( !packageDescr.getFunctions().isEmpty() ) {
-            	
+
                 for ( final Iterator it = packageDescr.getFunctions().iterator(); it.hasNext(); ) {
-                	FunctionDescr functionDescr = (FunctionDescr) it.next();
+                    FunctionDescr functionDescr = (FunctionDescr) it.next();
                     preCompileAddFunction( functionDescr );
-                }    
-                
+                }
+
                 // iterate and compile
                 for ( final Iterator it = packageDescr.getFunctions().iterator(); it.hasNext(); ) {
                     // inherit the dialect from the package
@@ -310,11 +312,11 @@
 
                 // We need to compile all the functions now, so scripting languages like mvel can find them
                 this.dialectRegistry.compileAll();
-                
+
                 for ( final Iterator it = packageDescr.getFunctions().iterator(); it.hasNext(); ) {
-                	FunctionDescr functionDescr = (FunctionDescr) it.next();
+                    FunctionDescr functionDescr = (FunctionDescr) it.next();
                     postCompileAddFunction( functionDescr );
-                }                
+                }
             }
 
             // iterate and compile
@@ -417,14 +419,15 @@
 
             // is it a POJO or a template?
             String templateName = typeDescr.getAttribute( TypeDeclarationDescr.ATTR_TEMPLATE );
-            if( templateName != null ) {
+            if ( templateName != null ) {
                 type.setFormat( TypeDeclaration.Format.TEMPLATE );
                 FactTemplate template = this.pkg.getFactTemplate( templateName );
-                if( template != null ) {
+                if ( template != null ) {
                     type.setTypeTemplate( template );
                 } else {
                     this.results.add( new TypeDeclarationError( "Template not found '" + template + "' for type '" + type.getTypeName() + "'",
                                                                 typeDescr.getLine() ) );
+                    continue;
                 }
             } else {
                 String className = typeDescr.getAttribute( TypeDeclarationDescr.ATTR_CLASS );
@@ -439,6 +442,7 @@
                 } catch ( final ClassNotFoundException e ) {
                     this.results.add( new TypeDeclarationError( "Class not found '" + className + "' for type '" + type.getTypeName() + "'",
                                                                 typeDescr.getLine() ) );
+                    continue;
                 }
             }
 
@@ -453,8 +457,12 @@
             String duration = typeDescr.getAttribute( TypeDeclarationDescr.ATTR_DURATION );
             if ( duration != null ) {
                 type.setDurationAttribute( duration );
+                FieldExtractor extractor = ClassFieldExtractorCache.getInstance().getExtractor( type.getTypeClass(),
+                                                                                                duration,
+                                                                                                this.configuration.getClassLoader() );
+                type.setDurationExtractor( extractor );
             }
-            
+
             this.pkg.addTypeDeclaration( type );
         }
     }
@@ -463,13 +471,15 @@
         this.dialect.addFunction( functionDescr,
                                   getTypeResolver() );
     }
-    
+
     private void preCompileAddFunction(final FunctionDescr functionDescr) {
-        this.dialect.preCompileAddFunction( functionDescr, getTypeResolver() );
+        this.dialect.preCompileAddFunction( functionDescr,
+                                            getTypeResolver() );
     }
-    
+
     private void postCompileAddFunction(final FunctionDescr functionDescr) {
-        this.dialect.postCompileAddFunction( functionDescr, getTypeResolver() );
+        this.dialect.postCompileAddFunction( functionDescr,
+                                             getTypeResolver() );
     }
 
     private void addFactTemplate(final FactTemplateDescr factTemplateDescr) {

Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/CepEspTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/CepEspTest.java	2008-04-12 14:51:42 UTC (rev 19535)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/CepEspTest.java	2008-04-12 17:37:09 UTC (rev 19536)
@@ -112,7 +112,7 @@
 
     }
 
-    public void FIXME_testEventAssertionWithDuration() throws Exception {
+    public void testEventAssertionWithDuration() throws Exception {
         // read in the source
         final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_CEP_SimpleEventAssertionWithDuration.drl" ) );
         final RuleBase ruleBase = loadRuleBase( reader );

Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/testframework/MockWorkingMemory.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/testframework/MockWorkingMemory.java	2008-04-12 14:51:42 UTC (rev 19535)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/testframework/MockWorkingMemory.java	2008-04-12 17:37:09 UTC (rev 19536)
@@ -22,6 +22,7 @@
 import org.drools.common.InternalWorkingMemory;
 import org.drools.common.NodeMemory;
 import org.drools.common.ObjectStore;
+import org.drools.common.ObjectTypeConfigurationRegistry;
 import org.drools.common.TruthMaintenanceSystem;
 import org.drools.common.WorkingMemoryAction;
 import org.drools.concurrent.ExecutorService;
@@ -516,4 +517,9 @@
         return null;
     }
 
+    public ObjectTypeConfigurationRegistry getObjectTypeConfigurationRegistry() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
 }

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractFactHandleFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractFactHandleFactory.java	2008-04-12 14:51:42 UTC (rev 19535)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractFactHandleFactory.java	2008-04-12 17:37:09 UTC (rev 19536)
@@ -16,18 +16,17 @@
  * limitations under the License.
  */
 
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicLong;
 
 import org.drools.WorkingMemory;
+import org.drools.reteoo.ObjectTypeConf;
 import org.drools.spi.FactHandleFactory;
-import org.drools.util.PrimitiveLongStack;
 
-import java.io.Externalizable;
-import java.io.ObjectInput;
-import java.io.IOException;
-import java.io.ObjectOutput;
-
 public abstract class AbstractFactHandleFactory
     implements
     FactHandleFactory, Externalizable {
@@ -65,8 +64,8 @@
     * @see org.drools.reteoo.FactHandleFactory#newFactHandle()
     */
     public final InternalFactHandle newFactHandle(final Object object,
-                                                  final boolean isEvent,
-                                                  final WorkingMemory workingMemory) {
+                                                  final ObjectTypeConf conf,
+                                                  final InternalWorkingMemory workingMemory) {
 // @FIXME make id re-cycling thread safe        
 //        if ( !this.factHandlePool.isEmpty() ) {
 //            return newFactHandle( this.factHandlePool.pop(),
@@ -77,7 +76,7 @@
 //        }
         return newFactHandle( this.id.incrementAndGet(),
                               object,
-                              isEvent,
+                              conf,
                               workingMemory );
     }
 
@@ -86,12 +85,12 @@
      */
     protected final InternalFactHandle newFactHandle(final int id,
                                                      final Object object,
-                                                     final boolean isEvent,
-                                                     final WorkingMemory workingMemory) {
+                                                     final ObjectTypeConf conf,
+                                                     final InternalWorkingMemory workingMemory) {
         return newFactHandle( id,
                               object,
                               this.counter.incrementAndGet(),
-                              isEvent,
+                              conf,
                               workingMemory );
     }
 
@@ -101,8 +100,8 @@
     protected abstract InternalFactHandle newFactHandle(final int id,
                                                         final Object object,
                                                         final long recency,
-                                                        final boolean isEvent,
-                                                        final WorkingMemory workingMemory);
+                                                        final ObjectTypeConf conf,
+                                                        final InternalWorkingMemory workingMemory);
 
     /* (non-Javadoc)
      * @see org.drools.reteoo.FactHandleFactory#increaseFactHandleRecency(org.drools.FactHandle)

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java	2008-04-12 14:51:42 UTC (rev 19535)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java	2008-04-12 17:37:09 UTC (rev 19536)
@@ -70,7 +70,6 @@
 import org.drools.process.instance.WorkItemManager;
 import org.drools.process.instance.context.variable.VariableScopeInstance;
 import org.drools.process.instance.timer.TimerManager;
-import org.drools.reteoo.ClassObjectTypeConf;
 import org.drools.reteoo.EntryPointNode;
 import org.drools.reteoo.LIANodePropagation;
 import org.drools.reteoo.ObjectTypeConf;
@@ -755,7 +754,7 @@
 
         if ( isSequential() ) {
             handle = this.handleFactory.newFactHandle( object,
-                                                       typeConf.isEvent(),
+                                                       typeConf,
                                                        this );
             this.objectStore.addHandle( handle,
                                         object );
@@ -813,7 +812,7 @@
                     // stated/logical
                     // assert
                     handle = this.handleFactory.newFactHandle( object,
-                                                               typeConf.isEvent(),
+                                                               typeConf,
                                                                this );
                     this.objectStore.addHandle( handle,
                                                 object );
@@ -867,7 +866,7 @@
                             // assertion
                             key.setStatus( EqualityKey.STATED );
                             handle = this.handleFactory.newFactHandle( object,
-                                                                       typeConf.isEvent(),
+                                                                       typeConf,
                                                                        this );
                             handle.setEqualityKey( key );
                             key.addFactHandle( handle );
@@ -878,7 +877,7 @@
 
                     } else {
                         handle = this.handleFactory.newFactHandle( object,
-                                                                   typeConf.isEvent(),
+                                                                   typeConf,
                                                                    this );
                         this.objectStore.addHandle( handle,
                                                     object );
@@ -909,7 +908,7 @@
                     return handle;
                 }
                 handle = this.handleFactory.newFactHandle( object,
-                                                           typeConf.isEvent(),
+                                                           typeConf,
                                                            this );
                 this.objectStore.addHandle( handle,
                                             object );

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalWorkingMemory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalWorkingMemory.java	2008-04-12 14:51:42 UTC (rev 19535)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalWorkingMemory.java	2008-04-12 17:37:09 UTC (rev 19536)
@@ -93,4 +93,7 @@
     public ExecutorService getExecutorService();
 
     public void setExecutorService(ExecutorService executor);    
+    
+    public ObjectTypeConfigurationRegistry getObjectTypeConfigurationRegistry();
+    
 }

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/NamedEntryPoint.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/NamedEntryPoint.java	2008-04-12 14:51:42 UTC (rev 19535)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/NamedEntryPoint.java	2008-04-12 17:37:09 UTC (rev 19536)
@@ -105,7 +105,7 @@
                                                                       object );
 
         InternalFactHandle handle = this.handleFactory.newFactHandle( object,
-                                                                      typeConf.isEvent(),
+                                                                      typeConf,
                                                                       wm );
         this.objectStore.addHandle( handle,
                                     object );

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java	2008-04-12 14:51:42 UTC (rev 19535)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java	2008-04-12 17:37:09 UTC (rev 19536)
@@ -179,7 +179,8 @@
         }
 
         final InternalFactHandle handle = workingMemory.getFactHandleFactory().newFactHandle( result,
-                                                                                              false,
+                                                                                              workingMemory.getObjectTypeConfigurationRegistry().getObjectTypeConf( context.getEntryPoint(),
+                                                                                                                                                                    result ),
                                                                                               workingMemory ); // so far, result is not an event
 
         accresult.result = new RightTuple( handle,
@@ -305,11 +306,11 @@
             } else {
                 // does not support reverse, so needs to be fully retracted and reasserted
                 LeftTuple match = childTuple.getParent();
-                
+
                 // but first, needs to remove the matching child
                 childTuple.unlinkFromLeftParent();
                 childTuple.unlinkFromRightParent();
-                
+
                 this.retractLeftTuple( match,
                                        context,
                                        workingMemory );
@@ -327,7 +328,7 @@
      * @param leftTuple
      */
     private void removeMatchingChild(final LeftTuple leftTuple,
-                                     final RightTuple rightTuple ) {
+                                     final RightTuple rightTuple) {
         if ( leftTuple.getBetaChildren() != null ) {
             // removing link between left and right
             LeftTuple match = leftTuple.getBetaChildren();
@@ -451,7 +452,7 @@
                                            final PropagationContext context,
                                            final InternalWorkingMemory workingMemory,
                                            final AccumulateMemory memory,
-                                           final AccumulateContext accctx ) {
+                                           final AccumulateContext accctx) {
         // First alpha node filters
         boolean isAllowed = true;
         for ( int i = 0, length = this.resultConstraints.length; i < length; i++ ) {
@@ -510,7 +511,7 @@
         final Iterator tupleIter = memory.betaMemory.getLeftTupleMemory().iterator();
         for ( LeftTuple leftTuple = (LeftTuple) tupleIter.next(); leftTuple != null; leftTuple = (LeftTuple) tupleIter.next() ) {
             AccumulateContext accctx = (AccumulateContext) memory.betaMemory.getCreatedHandles().get( leftTuple );
-            if( accctx.propagated ) {
+            if ( accctx.propagated ) {
                 sink.assertLeftTuple( new LeftTuple( leftTuple,
                                                      accctx.result,
                                                      sink,

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ClassObjectTypeConf.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ClassObjectTypeConf.java	2008-04-12 14:51:42 UTC (rev 19535)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ClassObjectTypeConf.java	2008-04-12 17:37:09 UTC (rev 19536)
@@ -58,6 +58,8 @@
 
     private ObjectTypeNode                 concreteObjectTypeNode;
     private EntryPoint                     entryPoint;
+    
+    private TypeDeclaration                typeDecl;
 
     public ClassObjectTypeConf() {
 
@@ -69,8 +71,8 @@
         this.cls = clazz;
         this.ruleBase = ruleBase;
         this.entryPoint = entryPoint;
-        TypeDeclaration type = ruleBase.getTypeDeclaration( clazz );
-        final boolean isEvent = type != null && type.getRole() == TypeDeclaration.Role.EVENT;
+        this.typeDecl = ruleBase.getTypeDeclaration( clazz );
+        final boolean isEvent = typeDecl != null && typeDecl.getRole() == TypeDeclaration.Role.EVENT;
 
         ObjectType objectType = new ClassObjectType( clazz,
                                                      isEvent );
@@ -320,4 +322,8 @@
     public boolean isEvent() {
         return this.concreteObjectTypeNode.getObjectType().isEvent();
     }
+
+    public TypeDeclaration getTypeDeclaration() {
+        return typeDecl;
+    }
 }
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CollectNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CollectNode.java	2008-04-12 14:51:42 UTC (rev 19535)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CollectNode.java	2008-04-12 17:37:09 UTC (rev 19536)
@@ -131,7 +131,8 @@
 
         final Collection result = this.collect.instantiateResultObject();
         final InternalFactHandle resultHandle = workingMemory.getFactHandleFactory().newFactHandle( result,
-                                                                                                    false,
+                                                                                                    workingMemory.getObjectTypeConfigurationRegistry().getObjectTypeConf( context.getEntryPoint(),
+                                                                                                                                                                          result ),
                                                                                                     workingMemory );
 
         final CollectContext colctx = new CollectContext();

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/FactTemplateTypeConf.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/FactTemplateTypeConf.java	2008-04-12 14:51:42 UTC (rev 19535)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/FactTemplateTypeConf.java	2008-04-12 17:37:09 UTC (rev 19536)
@@ -30,6 +30,7 @@
 import org.drools.reteoo.builder.BuildContext;
 import org.drools.reteoo.builder.PatternBuilder;
 import org.drools.rule.EntryPoint;
+import org.drools.rule.TypeDeclaration;
 import org.drools.spi.ObjectType;
 
 public class FactTemplateTypeConf
@@ -121,4 +122,8 @@
         return false;
     }
 
+    public TypeDeclaration getTypeDeclaration() {
+        return null;
+    }
+
 }
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/FromNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/FromNode.java	2008-04-12 14:51:42 UTC (rev 19535)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/FromNode.java	2008-04-12 17:37:09 UTC (rev 19536)
@@ -123,7 +123,8 @@
             final Object object = it.next();
 
             final InternalFactHandle handle = workingMemory.getFactHandleFactory().newFactHandle( object,
-                                                                                                  false,
+                                                                                                  workingMemory.getObjectTypeConfigurationRegistry().getObjectTypeConf( context.getEntryPoint(),
+                                                                                                                                                                        object ),
                                                                                                   workingMemory );
 
             RightTuple rightTuple = new RightTuple( handle,

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectTypeConf.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectTypeConf.java	2008-04-12 14:51:42 UTC (rev 19535)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectTypeConf.java	2008-04-12 17:37:09 UTC (rev 19536)
@@ -18,6 +18,7 @@
 package org.drools.reteoo;
 
 import org.drools.RuntimeDroolsException;
+import org.drools.rule.TypeDeclaration;
 
 public interface ObjectTypeConf {
     public ObjectTypeNode[] getObjectTypeNodes();
@@ -35,4 +36,6 @@
     public boolean isActive();
 
     public boolean isEvent();
+    
+    public TypeDeclaration getTypeDeclaration();    
 }
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooFactHandleFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooFactHandleFactory.java	2008-04-12 14:51:42 UTC (rev 19535)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooFactHandleFactory.java	2008-04-12 17:37:09 UTC (rev 19536)
@@ -21,13 +21,13 @@
 import java.io.ObjectOutput;
 
 import org.drools.TemporalSession;
-import org.drools.WorkingMemory;
 import org.drools.common.AbstractFactHandleFactory;
 import org.drools.common.DefaultFactHandle;
 import org.drools.common.EventFactHandle;
 import org.drools.common.InternalFactHandle;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.rule.TypeDeclaration;
 import org.drools.spi.FactHandleFactory;
-import org.drools.temporal.SessionClock;
 
 public class ReteooFactHandleFactory extends AbstractFactHandleFactory {
 
@@ -52,15 +52,20 @@
     protected final InternalFactHandle newFactHandle(final int id,
                                                      final Object object,
                                                      final long recency,
-                                                     final boolean isEvent,
-                                                     final WorkingMemory workingMemory) {
-        if ( isEvent ) {
-            SessionClock clock = ((TemporalSession) workingMemory).getSessionClock();
+                                                     final ObjectTypeConf conf,
+                                                     final InternalWorkingMemory workingMemory) {
+        if ( conf != null && conf.isEvent() ) {
+            TypeDeclaration type = conf.getTypeDeclaration();
+            long timestamp = ((TemporalSession) workingMemory).getSessionClock().getCurrentTime();
+            long duration = 0;
+            if( type.getDurationExtractor() != null ) {
+                duration = type.getDurationExtractor().getLongValue( workingMemory, object );
+            }
             return new EventFactHandle( id,
                                         object,
                                         recency,
-                                        clock.getCurrentTime(),
-                                        0 ); // primitive events have 0 duration
+                                        timestamp,
+                                        duration ); 
         } else {
             return new DefaultFactHandle( id,
                                           object,

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java	2008-04-12 14:51:42 UTC (rev 19535)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java	2008-04-12 17:37:09 UTC (rev 19536)
@@ -274,9 +274,11 @@
                     addEventListener( (RuleBaseEventListener) it.next() );
                 }
             }
+            
+            final InitialFactHandleDummyObject initialFact = new InitialFactHandleDummyObject();
 
-            final InitialFactHandle handle = new InitialFactHandle( session.getFactHandleFactory().newFactHandle( new InitialFactHandleDummyObject(),
-                                                                                                                  false,
+            final InitialFactHandle handle = new InitialFactHandle( session.getFactHandleFactory().newFactHandle( initialFact,
+                                                                                                                  null,
                                                                                                                   session ) );
 
             session.queueWorkingMemoryAction( new WorkingMemoryReteAssertAction( handle,

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooStatefulSession.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooStatefulSession.java	2008-04-12 14:51:42 UTC (rev 19535)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooStatefulSession.java	2008-04-12 17:37:09 UTC (rev 19536)
@@ -5,10 +5,9 @@
 import java.util.Iterator;
 import java.util.List;
 
-import org.drools.WorkingMemoryEntryPoint;
 import org.drools.FactHandle;
 import org.drools.StatefulSession;
-import org.drools.common.InternalRuleBase; //import org.drools.common.AbstractWorkingMemory.EntryPointInterfaceImpl;
+import org.drools.common.InternalRuleBase;
 import org.drools.concurrent.AssertObject;
 import org.drools.concurrent.AssertObjects;
 import org.drools.concurrent.ExecutorService;
@@ -17,7 +16,6 @@
 import org.drools.concurrent.RetractObject;
 import org.drools.concurrent.UpdateObject;
 import org.drools.event.RuleBaseEventListener;
-import org.drools.rule.EntryPoint;
 import org.drools.spi.AgendaFilter;
 import org.drools.spi.RuleBaseUpdateListener;
 import org.drools.spi.RuleBaseUpdateListenerFactory;

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooStatelessSession.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooStatelessSession.java	2008-04-12 14:51:42 UTC (rev 19535)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooStatelessSession.java	2008-04-12 17:37:09 UTC (rev 19536)
@@ -84,8 +84,10 @@
             wm.setAgendaEventSupport( this.agendaEventSupport );
             wm.setRuleFlowEventSupport( ruleFlowEventSupport );
 
-            final InitialFactHandle handle = new InitialFactHandle( wm.getFactHandleFactory().newFactHandle( new InitialFactHandleDummyObject(),
-                                                                                                             false,
+            final InitialFactHandleDummyObject initialFact = new InitialFactHandleDummyObject();
+            final InitialFactHandle handle = new InitialFactHandle( wm.getFactHandleFactory().newFactHandle( initialFact,
+                                                                                                             wm.getObjectTypeConfigurationRegistry().getObjectTypeConf( EntryPoint.DEFAULT,
+                                                                                                                                                                        initialFact ),
                                                                                                              wm ) );
 
             wm.queueWorkingMemoryAction( new WorkingMemoryReteAssertAction( handle,

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java	2008-04-12 14:51:42 UTC (rev 19535)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java	2008-04-12 17:37:09 UTC (rev 19536)
@@ -88,7 +88,8 @@
         Object object = new DroolsQuery( query,
                                          arguments );
         InternalFactHandle handle = this.handleFactory.newFactHandle( object,
-                                                                      false,
+                                                                      this.getObjectTypeConfigurationRegistry().getObjectTypeConf( EntryPoint.DEFAULT,
+                                                                                                                                   object ),
                                                                       this );
 
         insert( handle,

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightInputAdapterNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightInputAdapterNode.java	2008-04-12 14:51:42 UTC (rev 19535)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightInputAdapterNode.java	2008-04-12 17:37:09 UTC (rev 19536)
@@ -23,6 +23,7 @@
 import org.drools.common.NodeMemory;
 import org.drools.common.PropagationContextImpl;
 import org.drools.reteoo.builder.BuildContext;
+import org.drools.rule.EntryPoint;
 import org.drools.spi.PropagationContext;
 import org.drools.util.Iterator;
 import org.drools.util.ObjectHashMap;
@@ -118,7 +119,8 @@
 
         // creating a dummy fact handle to wrap the tuple
         final InternalFactHandle handle = workingMemory.getFactHandleFactory().newFactHandle( tuple,
-                                                                                              false,
+                                                                                              workingMemory.getObjectTypeConfigurationRegistry().getObjectTypeConf( context.getEntryPoint(),
+                                                                                                                                                           tuple ),
                                                                                               workingMemory );
 
         if ( this.tupleMemoryEnabled ) {

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/TypeDeclaration.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/TypeDeclaration.java	2008-04-12 14:51:42 UTC (rev 19535)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/TypeDeclaration.java	2008-04-12 17:37:09 UTC (rev 19536)
@@ -18,30 +18,33 @@
 
 package org.drools.rule;
 
-import org.drools.facttemplates.FactTemplate;
-
-import java.io.Serializable;
 import java.io.Externalizable;
+import java.io.IOException;
 import java.io.ObjectInput;
-import java.io.IOException;
 import java.io.ObjectOutput;
 
+import org.drools.base.ClassFieldExtractorCache;
+import org.drools.common.DroolsObjectInputStream;
+import org.drools.facttemplates.FactTemplate;
+import org.drools.spi.FieldExtractor;
+
 /**
  * The type declaration class stores all type's metadata
  * declared in source files.
  *  
  * @author etirelli
  */
-public class TypeDeclaration implements Externalizable {
+public class TypeDeclaration
+    implements
+    Externalizable {
 
     public static enum Role {
-        FACT,
-        EVENT;
+        FACT, EVENT;
 
-        public static Role parseRole( String role ) {
-            if( "event".equalsIgnoreCase( role ) ) {
+        public static Role parseRole(String role) {
+            if ( "event".equalsIgnoreCase( role ) ) {
                 return EVENT;
-            } else if( "fact".equalsIgnoreCase( role ) ) {
+            } else if ( "fact".equalsIgnoreCase( role ) ) {
                 return FACT;
             }
             return null;
@@ -49,13 +52,12 @@
     }
 
     public static enum Format {
-        POJO,
-        TEMPLATE;
+        POJO, TEMPLATE;
 
-        public static Format parseFormat( String format ) {
-            if( "pojo".equalsIgnoreCase( format ) ) {
+        public static Format parseFormat(String format) {
+            if ( "pojo".equalsIgnoreCase( format ) ) {
                 return POJO;
-            } else if( "template".equalsIgnoreCase( format ) ) {
+            } else if ( "template".equalsIgnoreCase( format ) ) {
                 return TEMPLATE;
             }
             return null;
@@ -63,41 +65,38 @@
     }
 
     public static enum ClockStrategy {
-        NONE,
-        PSEUDO,
-        SYSTEM,
-        HEARTBEAT,
-        ATTRIBUTE;
+        NONE, PSEUDO, SYSTEM, HEARTBEAT, ATTRIBUTE;
 
-        public static ClockStrategy parseClockStrategy( String clockStrategy ) {
-            if( "none".equalsIgnoreCase( clockStrategy ) ) {
+        public static ClockStrategy parseClockStrategy(String clockStrategy) {
+            if ( "none".equalsIgnoreCase( clockStrategy ) ) {
                 return NONE;
-            } else if( "pseudo".equalsIgnoreCase( clockStrategy ) ) {
+            } else if ( "pseudo".equalsIgnoreCase( clockStrategy ) ) {
                 return PSEUDO;
-            } else if( "system".equalsIgnoreCase( clockStrategy ) ) {
+            } else if ( "system".equalsIgnoreCase( clockStrategy ) ) {
                 return SYSTEM;
-            } else if( "heartbeat".equalsIgnoreCase( clockStrategy ) ) {
+            } else if ( "heartbeat".equalsIgnoreCase( clockStrategy ) ) {
                 return HEARTBEAT;
-            } else if( "attribute".equalsIgnoreCase( clockStrategy ) ) {
+            } else if ( "attribute".equalsIgnoreCase( clockStrategy ) ) {
                 return ATTRIBUTE;
             }
             return null;
         }
     }
 
-    private String typeName;
-    private Role role;
-    private Format format;
-    private ClockStrategy clockStrategy;
-    private String timestampAttribute;
-    private String durationAttribute;
-    private Class<?> typeClass;
-    private FactTemplate typeTemplate;
+    private String                   typeName;
+    private Role                     role;
+    private Format                   format;
+    private ClockStrategy            clockStrategy;
+    private String                   timestampAttribute;
+    private String                   durationAttribute;
+    private transient FieldExtractor durationExtractor;
+    private Class< ? >               typeClass;
+    private FactTemplate             typeTemplate;
 
     public TypeDeclaration() {
     }
 
-    public TypeDeclaration( String typeName ) {
+    public TypeDeclaration(String typeName) {
         this.typeName = typeName;
         this.role = Role.FACT;
         this.format = Format.POJO;
@@ -108,26 +107,35 @@
         this.typeTemplate = null;
     }
 
-    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        this.typeName = (String)in.readObject();
-        this.role = (Role)in.readObject();
-        this.format = (Format)in.readObject();
-        this.clockStrategy = (ClockStrategy)in.readObject();
-        this.durationAttribute = (String)in.readObject();
-        this.timestampAttribute = (String)in.readObject();
-        this.typeClass = (Class<?>)in.readObject();
-        this.typeTemplate = (FactTemplate)in.readObject();
+    public void readExternal(ObjectInput in) throws IOException,
+                                            ClassNotFoundException {
+        this.typeName = (String) in.readObject();
+        this.role = (Role) in.readObject();
+        this.format = (Format) in.readObject();
+        this.clockStrategy = (ClockStrategy) in.readObject();
+        this.durationAttribute = (String) in.readObject();
+        this.timestampAttribute = (String) in.readObject();
+        this.typeClass = (Class< ? >) in.readObject();
+        this.typeTemplate = (FactTemplate) in.readObject();
+
+        if( this.durationAttribute != null ) {
+            // generate the extractor
+            DroolsObjectInputStream dois = (DroolsObjectInputStream) in;
+            this.durationExtractor = dois.getExtractorFactory().getExtractor( this.typeClass,
+                                                                              this.durationAttribute,
+                                                                              dois.getClassLoader() );
+        }
     }
 
     public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeObject(typeName);
-        out.writeObject(role);
-        out.writeObject(format);
-        out.writeObject(clockStrategy);
-        out.writeObject(durationAttribute);
-        out.writeObject(timestampAttribute);
-        out.writeObject(typeClass);
-        out.writeObject(typeTemplate);
+        out.writeObject( typeName );
+        out.writeObject( role );
+        out.writeObject( format );
+        out.writeObject( clockStrategy );
+        out.writeObject( durationAttribute );
+        out.writeObject( timestampAttribute );
+        out.writeObject( typeClass );
+        out.writeObject( typeTemplate );
     }
 
     /**
@@ -241,36 +249,42 @@
      * @param clazz
      * @return
      */
-    public boolean matches( Object clazz ) {
+    public boolean matches(Object clazz) {
         boolean matches = false;
-        if( clazz instanceof FactTemplate ) {
+        if ( clazz instanceof FactTemplate ) {
             matches = this.typeTemplate.equals( clazz );
         } else {
-            matches = this.typeClass.isAssignableFrom( (Class<?>) clazz );
+            matches = this.typeClass.isAssignableFrom( (Class< ? >) clazz );
         }
         return matches;
     }
 
     public boolean equals(Object obj) {
-        if (obj == this) {
+        if ( obj == this ) {
             return true;
-        } else if (obj instanceof TypeDeclaration) {
-            TypeDeclaration that    = (TypeDeclaration)obj;
-            return isObjectEqual(typeName, that.typeName) &&
-                   role == that.role &&
-                   format == that.format &&
-                   clockStrategy == that.clockStrategy &&
-                   isObjectEqual(timestampAttribute, that.timestampAttribute) &&
-                   isObjectEqual(durationAttribute, that.durationAttribute) &&
-                   typeClass == that.typeClass &&
-                   isObjectEqual(typeTemplate, that.typeTemplate);
+        } else if ( obj instanceof TypeDeclaration ) {
+            TypeDeclaration that = (TypeDeclaration) obj;
+            return isObjectEqual( typeName,
+                                  that.typeName ) && role == that.role && format == that.format && clockStrategy == that.clockStrategy && isObjectEqual( timestampAttribute,
+                                                                                                                                                         that.timestampAttribute ) && isObjectEqual( durationAttribute,
+                                                                                                                                                                                                     that.durationAttribute )
+                   && typeClass == that.typeClass && isObjectEqual( typeTemplate,
+                                                                    that.typeTemplate );
         }
         return false;
     }
 
+    private static boolean isObjectEqual(Object a,
+                                         Object b) {
+        return a == b || a != null && a.equals( b );
+    }
 
-    private static boolean isObjectEqual(Object a, Object b) {
-        return a == b || a != null && a.equals(b);
+    public FieldExtractor getDurationExtractor() {
+        return durationExtractor;
     }
 
+    public void setDurationExtractor(FieldExtractor durationExtractor) {
+        this.durationExtractor = durationExtractor;
+    }
+
 }

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/FactHandleFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/FactHandleFactory.java	2008-04-12 14:51:42 UTC (rev 19535)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/FactHandleFactory.java	2008-04-12 17:37:09 UTC (rev 19536)
@@ -19,8 +19,9 @@
 import java.io.Serializable;
 
 import org.drools.FactHandle;
-import org.drools.WorkingMemory;
 import org.drools.common.InternalFactHandle;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.reteoo.ObjectTypeConf;
 
 /**
  * Factory Interface to return new <code>FactHandle</code>s
@@ -38,7 +39,7 @@
      * 
      * @return The handle.
      */
-    public InternalFactHandle newFactHandle(Object object, boolean isEvent, WorkingMemory workingMemory );
+    public InternalFactHandle newFactHandle(Object object, ObjectTypeConf conf, InternalWorkingMemory workingMemory );
     
     /**
      * Increases the recency of the FactHandle

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/common/EqualityKeyTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/common/EqualityKeyTest.java	2008-04-12 14:51:42 UTC (rev 19535)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/common/EqualityKeyTest.java	2008-04-12 17:37:09 UTC (rev 19536)
@@ -10,13 +10,13 @@
     public void test1() {
         ReteooFactHandleFactory factory = new ReteooFactHandleFactory();
         
-        InternalFactHandle ch1 = factory.newFactHandle( new Cheese ("c", 10), false, null );
+        InternalFactHandle ch1 = factory.newFactHandle( new Cheese ("c", 10), null, null );
         EqualityKey key = new EqualityKey( ch1 );
         
         assertSame( ch1, key.getFactHandle() );
         assertNull( key.getOtherFactHandle() );
         
-        InternalFactHandle ch2 = factory.newFactHandle( new Cheese ("c", 10), false, null );
+        InternalFactHandle ch2 = factory.newFactHandle( new Cheese ("c", 10), null, null );
         key.addFactHandle( ch2 );
         
         assertEquals( 1, key.getOtherFactHandle().size() );

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AccumulateNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AccumulateNodeTest.java	2008-04-12 14:51:42 UTC (rev 19535)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AccumulateNodeTest.java	2008-04-12 17:37:09 UTC (rev 19536)
@@ -127,14 +127,14 @@
                              this.sink.getAsserted().size() );
 
         this.node.assertLeftTuple( new LeftTuple( this.workingMemory.getFactHandleFactory().newFactHandle( "cheese",
-                                                                                                           false,
+                                                                                                           null,
                                                                                                            null ),
                                                   null,
                                                   true ),
                                    this.context,
                                    this.workingMemory );
         this.node.assertLeftTuple( new LeftTuple( this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese",
-                                                                                                           false,
+                                                                                                           null,
                                                                                                            null ),
                                                   null,
                                                   true ),
@@ -162,7 +162,7 @@
      */
     public void testAssertTuple() {
         final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese",
-                                                                                                                  false,
+                                                                                                                  null,
                                                                                                                   null );
         final LeftTuple tuple0 = new LeftTuple( f0,
                                                 null,
@@ -182,7 +182,7 @@
 
         // assert tuple, should add left memory 
         final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese",
-                                                                                                                  false,
+                                                                                                                  null,
                                                                                                                   null );
 
         final LeftTuple tuple1 = new LeftTuple( f1,
@@ -210,10 +210,10 @@
      */
     public void testAssertTupleWithObjects() {
         final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese",
-                                                                                                                  false,
+                                                                                                                  null,
                                                                                                                   null );
         final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese",
-                                                                                                                  false,
+                                                                                                                  null,
                                                                                                                   null );
 
         final LeftTuple tuple0 = new LeftTuple( f0,
@@ -267,7 +267,7 @@
      */
     public void testRetractTuple() {
         final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese",
-                                                                                                                  false,
+                                                                                                                  null,
                                                                                                                   null );
 
         final LeftTuple tuple0 = new LeftTuple( f0,
@@ -302,10 +302,10 @@
      */
     public void testAssertObject() {
         final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese",
-                                                                                                                  false,
+                                                                                                                  null,
                                                                                                                   null );
         final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese",
-                                                                                                                  false,
+                                                                                                                  null,
                                                                                                                   null );
 
         final LeftTuple tuple0 = new LeftTuple( f0,
@@ -353,10 +353,10 @@
      */
     public void testRetractObject() {
         final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese",
-                                                                                                                  false,
+                                                                                                                  null,
                                                                                                                   null );
         final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese",
-                                                                                                                  false,
+                                                                                                                  null,
                                                                                                                   null );
 
         final LeftTuple tuple0 = new LeftTuple( f0,
@@ -470,10 +470,10 @@
         this.memory = ((AccumulateMemory) this.workingMemory.getNodeMemory( this.node )).betaMemory;
 
         final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese",
-                                                                                                                  false,
+                                                                                                                  null,
                                                                                                                   null );
         final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese",
-                                                                                                                  false,
+                                                                                                                  null,
                                                                                                                   null );
 
         final LeftTuple tuple0 = new LeftTuple( f0, null,

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CollectNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CollectNodeTest.java	2008-04-12 14:51:42 UTC (rev 19535)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CollectNodeTest.java	2008-04-12 17:37:09 UTC (rev 19536)
@@ -127,14 +127,14 @@
                              this.sink.getAsserted().size() );
 
         this.node.assertLeftTuple( new LeftTuple( this.workingMemory.getFactHandleFactory().newFactHandle( "cheese",
-                                                                                                           false,
+                                                                                                           null,
                                                                                                            null ),
                                                   this.node,
                                                   true ),
                                    this.contextAssert,
                                    this.workingMemory );
         this.node.assertLeftTuple( new LeftTuple( this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese",
-                                                                                                           false,
+                                                                                                           null,
                                                                                                            null ),
                                                   this.node,
                                                   true ),
@@ -159,7 +159,7 @@
 
     public void testAssertTuple() {
         final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese",
-                                                                                                                  false,
+                                                                                                                  null,
                                                                                                                   null );
         final LeftTuple tuple0 = new LeftTuple( f0,
                                                 this.node,
@@ -179,7 +179,7 @@
 
         // assert tuple, should add left memory 
         final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese",
-                                                                                                                  false,
+                                                                                                                  null,
                                                                                                                   null );
 
         final LeftTuple tuple1 = new LeftTuple( f1,
@@ -203,10 +203,10 @@
 
     public void testAssertTupleWithObjects() {
         final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese",
-                                                                                                                  false,
+                                                                                                                  null,
                                                                                                                   null );
         final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese",
-                                                                                                                  false,
+                                                                                                                  null,
                                                                                                                   null );
 
         final LeftTuple tuple0 = new LeftTuple( f0,
@@ -256,7 +256,7 @@
 
     public void testRetractTuple() {
         final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese",
-                                                                                                                  false,
+                                                                                                                  null,
                                                                                                                   null );
 
         final LeftTuple tuple0 = new LeftTuple( f0,
@@ -288,10 +288,10 @@
 
     public void testAssertObject() {
         final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese",
-                                                                                                                  false,
+                                                                                                                  null,
                                                                                                                   null );
         final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese",
-                                                                                                                  false,
+                                                                                                                  null,
                                                                                                                   null );
 
         final LeftTuple tuple0 = new LeftTuple( f0,
@@ -338,10 +338,10 @@
 
     public void testRetractObject() {
         final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese",
-                                                                                                                  false,
+                                                                                                                  null,
                                                                                                                   null );
         final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese",
-                                                                                                                  false,
+                                                                                                                  null,
                                                                                                                   null );
 
         final LeftTuple tuple0 = new LeftTuple( f0,
@@ -437,10 +437,10 @@
         this.node.setLeftTupleMemoryEnabled( false );
 
         final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese",
-                                                                                                                  false,
+                                                                                                                  null,
                                                                                                                   null );
         final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese",
-                                                                                                                  false,
+                                                                                                                  null,
                                                                                                                   null );
 
         final LeftTuple tuple0 = new LeftTuple( f0,

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CompositeObjectSinkAdapterTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CompositeObjectSinkAdapterTest.java	2008-04-12 14:51:42 UTC (rev 19535)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CompositeObjectSinkAdapterTest.java	2008-04-12 17:37:09 UTC (rev 19536)
@@ -360,7 +360,7 @@
         ad.addObjectSink( al3 );
 
         InternalFactHandle handle = new ReteooFactHandleFactory().newFactHandle( new Cheese(),
-                                                                                 false,
+                                                                                 null,
                                                                                  null );
         try {
             ad.propagateAssertObject( handle,

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/DefaultFactHandleFactoryTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/DefaultFactHandleFactoryTest.java	2008-04-12 14:51:42 UTC (rev 19535)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/DefaultFactHandleFactoryTest.java	2008-04-12 17:37:09 UTC (rev 19536)
@@ -27,21 +27,21 @@
      */
     public void testNewFactHandle() {
         final ReteooFactHandleFactory factory = new ReteooFactHandleFactory();
-        DefaultFactHandle handle = (DefaultFactHandle) factory.newFactHandle( "cheese", false, null );
+        DefaultFactHandle handle = (DefaultFactHandle) factory.newFactHandle( "cheese", null, null );
         assertEquals( 0,
                       handle.getId() );
         assertEquals( 0,
                       handle.getRecency() );
 
         // issue  new handle
-        handle = (DefaultFactHandle) factory.newFactHandle( "cheese", false, null );
+        handle = (DefaultFactHandle) factory.newFactHandle( "cheese", null, null );
         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", false, null );
+        final DefaultFactHandle handle2 = (DefaultFactHandle) factory.newFactHandle( "cheese", null, null );
         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", false, null );
+        handle = (DefaultFactHandle) factory.newFactHandle( "cheese", null, null );
         assertEquals( 3,
                       handle.getId() );
         assertEquals( 4,

Modified: labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/Jsr94FactHandleFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/Jsr94FactHandleFactory.java	2008-04-12 14:51:42 UTC (rev 19535)
+++ labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/Jsr94FactHandleFactory.java	2008-04-12 17:37:09 UTC (rev 19536)
@@ -17,11 +17,12 @@
  */
 
 import org.drools.TemporalSession;
-import org.drools.WorkingMemory;
 import org.drools.common.AbstractFactHandleFactory;
 import org.drools.common.InternalFactHandle;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.reteoo.ObjectTypeConf;
+import org.drools.rule.TypeDeclaration;
 import org.drools.spi.FactHandleFactory;
-import org.drools.temporal.SessionClock;
 
 /**
  * A factory for creating <code>Handle</code>s.
@@ -33,33 +34,32 @@
 	private static final long serialVersionUID = 4964273923122006124L;
 
 	protected final InternalFactHandle newFactHandle(final int id,
-			final Object object, final long recency, final boolean isEvent,
-			final WorkingMemory workingMemory) {
-		return this.newFactHandle(id, object, recency, isEvent, 0,
-				workingMemory);
+			final Object object, final long recency, final ObjectTypeConf conf,
+			final InternalWorkingMemory workingMemory) {
+        if ( conf != null && conf.isEvent() ) {
+            // later we need to centralize the following code snippet in a common method
+            // shared by all fact handle factory implementations
+            TypeDeclaration type = conf.getTypeDeclaration();
+            long timestamp = ((TemporalSession) workingMemory).getSessionClock().getCurrentTime();
+            long duration = 0;
+            if( type.getDurationExtractor() != null ) {
+                duration = type.getDurationExtractor().getLongValue( workingMemory, object );
+            }
+            return new Jsr94EventFactHandle( id,
+                                        object,
+                                        recency,
+                                        timestamp,
+                                        duration ); 
+        } else {
+            return new Jsr94FactHandle( id,
+                                          object,
+                                          recency );
+        }
 	}
 
 	/*
 	 * (non-Javadoc)
 	 * 
-	 * @see org.drools.reteoo.FactHandleFactory#newFactHandle(long)
-	 */
-	protected final InternalFactHandle newFactHandle(final int id,
-			final Object object, final long recency, final boolean isEvent,
-			final long duration, final WorkingMemory workingMemory) {
-		if (isEvent) {
-			SessionClock clock = ((TemporalSession) workingMemory)
-					.getSessionClock();
-			return new Jsr94EventFactHandle(id, object, recency, clock
-					.getCurrentTime(), duration);
-		} else {
-			return new Jsr94FactHandle(id, object, recency);
-		}
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
 	 * @see org.drools.reteoo.FactHandleFactory#newInstance()
 	 */
 	public FactHandleFactory newInstance() {




More information about the jboss-svn-commits mailing list