[jboss-svn-commits] JBL Code SVN: r7010 - in labs/jbossrules/trunk/drools-core/src: main/java/org/drools/rule test/java/org/drools/examples/manners

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sun Oct 22 17:35:25 EDT 2006


Author: tirelli
Date: 2006-10-22 17:35:15 -0400 (Sun, 22 Oct 2006)
New Revision: 7010

Added:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/ReturnValueContextEntry.java
Modified:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/ReturnValueConstraint.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/ReturnValueRestriction.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/examples/manners/ReteooMannersTest.java
Log:
adding ReturnValueContextEntry interface

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/ReturnValueConstraint.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/ReturnValueConstraint.java	2006-10-22 21:11:12 UTC (rev 7009)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/ReturnValueConstraint.java	2006-10-22 21:35:15 UTC (rev 7010)
@@ -17,8 +17,6 @@
  */
 
 import org.drools.RuntimeDroolsException;
-import org.drools.common.InternalFactHandle;
-import org.drools.common.InternalWorkingMemory;
 import org.drools.reteoo.ReteTuple;
 import org.drools.spi.BetaNodeFieldConstraint;
 import org.drools.spi.Evaluator;
@@ -41,7 +39,8 @@
                                  final Declaration[] declarations,
                                  final Evaluator evaluator) {
         this.fieldExtractor = fieldExtractor;
-        this.restriction = new ReturnValueRestriction( declarations,
+        this.restriction = new ReturnValueRestriction( fieldExtractor,
+                                                       declarations,
                                                        evaluator );
     }
 
@@ -50,7 +49,8 @@
                                  final Declaration[] declarations,
                                  final Evaluator evaluator) {
         this.fieldExtractor = fieldExtractor;
-        this.restriction = new ReturnValueRestriction( expression,
+        this.restriction = new ReturnValueRestriction( fieldExtractor,
+                                                       expression,
                                                        declarations,
                                                        evaluator );
     }
@@ -104,7 +104,7 @@
     }
 
     public ContextEntry getContextEntry() {
-        return new ReturnValueContextEntry();
+        return this.restriction.getContextEntry();
     }
 
     public boolean isAllowedCachedLeft(ContextEntry context,
@@ -113,8 +113,8 @@
             ReturnValueContextEntry ctx = (ReturnValueContextEntry) context;
             return this.restriction.isAllowed( this.fieldExtractor,
                                                object,
-                                               ctx.leftTuple,
-                                               ctx.workingMemory );
+                                               ctx.getTuple(),
+                                               ctx.getWorkingMemory() );
         } catch ( Exception e ) {
             throw new RuntimeDroolsException( "Exception executing ReturnValue constraint " + this.restriction,
                                               e );
@@ -126,46 +126,13 @@
         try {
             ReturnValueContextEntry ctx = (ReturnValueContextEntry) context;
             return this.restriction.isAllowed( this.fieldExtractor,
-                                               ctx.rightObject,
+                                               ctx.getObject(),
                                                tuple,
-                                               ctx.workingMemory );
+                                               ctx.getWorkingMemory() );
         } catch ( Exception e ) {
             throw new RuntimeDroolsException( "Exception executing ReturnValue constraint " + this.restriction,
                                               e );
         }
     }
 
-    public static class ReturnValueContextEntry
-        implements
-        ContextEntry {
-        public ReteTuple             leftTuple;
-        public Object                rightObject;
-        public InternalWorkingMemory workingMemory;
-
-        private ContextEntry         entry;
-
-        public ReturnValueContextEntry() {
-        }
-
-        public ContextEntry getNext() {
-            return this.entry;
-        }
-
-        public void setNext(final ContextEntry entry) {
-            this.entry = entry;
-        }
-
-        public void updateFromFactHandle(InternalWorkingMemory workingMemory,
-                                         InternalFactHandle handle) {
-            this.workingMemory = workingMemory;
-            this.rightObject = handle.getObject();
-        }
-
-        public void updateFromTuple(InternalWorkingMemory workingMemory,
-                                    ReteTuple tuple) {
-            this.workingMemory = workingMemory;
-            this.leftTuple = tuple;
-        }
-    }
-
 }
\ No newline at end of file

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/ReturnValueContextEntry.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/ReturnValueContextEntry.java	2006-10-22 21:11:12 UTC (rev 7009)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/ReturnValueContextEntry.java	2006-10-22 21:35:15 UTC (rev 7010)
@@ -0,0 +1,34 @@
+package org.drools.rule;
+
+import org.drools.common.InternalWorkingMemory;
+import org.drools.reteoo.ReteTuple;
+import org.drools.spi.FieldExtractor;
+
+public interface ReturnValueContextEntry extends ContextEntry {
+
+    /**
+     * Returns the field extractor for the constrained field
+     */
+    public FieldExtractor getFieldExtractor();
+    
+    /**
+     * Returns the object to extract the field from
+     */
+    public Object getObject();
+
+    /**
+     * Returns the ReteTuple where the variable value is read from
+     */
+    public ReteTuple getTuple();
+
+    /**
+     * Returns the required declarations for the given restriction
+     */    
+    public Declaration[] getRequiredDeclarations();
+
+    /**
+     * Returns the current working memory for the context
+     */
+    public InternalWorkingMemory getWorkingMemory();
+
+}
\ No newline at end of file


Property changes on: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/ReturnValueContextEntry.java
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:keywords
   + id author date revision
Name: svn:eol-style
   + native

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/ReturnValueRestriction.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/ReturnValueRestriction.java	2006-10-22 21:11:12 UTC (rev 7009)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/ReturnValueRestriction.java	2006-10-22 21:35:15 UTC (rev 7010)
@@ -20,10 +20,12 @@
 
 import org.drools.RuntimeDroolsException;
 import org.drools.WorkingMemory;
+import org.drools.common.InternalFactHandle;
 import org.drools.common.InternalWorkingMemory;
 import org.drools.reteoo.ReteTuple;
 import org.drools.spi.Evaluator;
 import org.drools.spi.Extractor;
+import org.drools.spi.FieldExtractor;
 import org.drools.spi.Restriction;
 import org.drools.spi.ReturnValueExpression;
 import org.drools.spi.Tuple;
@@ -32,21 +34,6 @@
     implements
     Restriction {
 
-    private static int hashCode(final Object[] array) {
-        final int PRIME = 31;
-        if ( array == null ) {
-            return 0;
-        }
-        int result = 1;
-        for ( int index = 0; index < array.length; index++ ) {
-            result = PRIME * result + (array[index] == null ? 0 : array[index].hashCode());
-        }
-        return result;
-    }
-
-    /**
-     * 
-     */
     private static final long          serialVersionUID       = 320;
 
     private ReturnValueExpression      expression;
@@ -56,15 +43,20 @@
     private final Evaluator            evaluator;
 
     private static final Declaration[] noRequiredDeclarations = new Declaration[]{};
+    
+    private final ReturnValueContextEntry contextEntry;
 
-    public ReturnValueRestriction(final Declaration[] declarations,
+    public ReturnValueRestriction(final FieldExtractor fieldExtractor,
+                                  final Declaration[] declarations,
                                   final Evaluator evaluator) {
-        this( null,
+        this( fieldExtractor,
+              null,
               declarations,
               evaluator );
     }
 
-    public ReturnValueRestriction(final ReturnValueExpression returnValueExpression,
+    public ReturnValueRestriction(final FieldExtractor fieldExtractor,
+                                  final ReturnValueExpression returnValueExpression,
                                   final Declaration[] declarations,
                                   final Evaluator evaluator) {
         this.expression = returnValueExpression;
@@ -76,6 +68,7 @@
         }
 
         this.evaluator = evaluator;
+        this.contextEntry = new ReturnValueContextEntryImpl(fieldExtractor, requiredDeclarations);
     }
 
     public Declaration[] getRequiredDeclarations() {
@@ -124,7 +117,7 @@
                                         ContextEntry context) {
         throw new UnsupportedOperationException( "does not support method call isAllowed(Object object, InternalWorkingMemory workingMemoiry)" );
     }
-    
+
     public int hashCode() {
         final int PRIME = 31;
         int result = 1;
@@ -157,4 +150,92 @@
         return this.expression.equals( other.expression );
     }
 
+    private static int hashCode(final Object[] array) {
+        final int PRIME = 31;
+        if ( array == null ) {
+            return 0;
+        }
+        int result = 1;
+        for ( int index = 0; index < array.length; index++ ) {
+            result = PRIME * result + (array[index] == null ? 0 : array[index].hashCode());
+        }
+        return result;
+    }
+
+    public ContextEntry getContextEntry() {
+        return this.contextEntry;
+    }
+
+    public static class ReturnValueContextEntryImpl
+        implements
+        ReturnValueContextEntry {
+        private FieldExtractor        fieldExtractor;
+        private Object                object;
+        private ReteTuple             leftTuple;
+        private InternalWorkingMemory workingMemory;
+        private Declaration[]         requiredDeclarations;
+
+        private ContextEntry          entry;
+
+        public ReturnValueContextEntryImpl(FieldExtractor fieldExtractor, Declaration[] requiredDeclarations) {
+            this.fieldExtractor = fieldExtractor;
+            this.requiredDeclarations = requiredDeclarations;
+        }
+
+        public ContextEntry getNext() {
+            return this.entry;
+        }
+
+        public void setNext(final ContextEntry entry) {
+            this.entry = entry;
+        }
+
+        public void updateFromFactHandle(InternalWorkingMemory workingMemory,
+                                         InternalFactHandle handle) {
+            this.workingMemory = workingMemory;
+            this.object = handle.getObject();
+        }
+
+        public void updateFromTuple(InternalWorkingMemory workingMemory,
+                                    ReteTuple tuple) {
+            this.workingMemory = workingMemory;
+            this.leftTuple = tuple;
+        }
+
+        /* (non-Javadoc)
+         * @see org.drools.rule.ReturnValueContextEntry#getFieldExtractor()
+         */
+        public FieldExtractor getFieldExtractor() {
+            return this.fieldExtractor;
+        }
+
+        /* (non-Javadoc)
+         * @see org.drools.rule.ReturnValueContextEntry#getTuple()
+         */
+        public ReteTuple getTuple() {
+            return this.leftTuple;
+        }
+
+        /* (non-Javadoc)
+         * @see org.drools.rule.ReturnValueContextEntry#getObject()
+         */
+        public Object getObject() {
+            return this.object;
+        }
+
+        /* (non-Javadoc)
+         * @see org.drools.rule.ReturnValueContextEntry#getRequiredDeclarations()
+         */
+        public Declaration[] getRequiredDeclarations() {
+            return this.requiredDeclarations;
+        }
+
+        /* (non-Javadoc)
+         * @see org.drools.rule.ReturnValueContextEntry#getWorkingMemory()
+         */
+        public InternalWorkingMemory getWorkingMemory() {
+            return this.workingMemory;
+        }
+    }
+
 }
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/examples/manners/ReteooMannersTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/examples/manners/ReteooMannersTest.java	2006-10-22 21:11:12 UTC (rev 7009)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/examples/manners/ReteooMannersTest.java	2006-10-22 21:35:15 UTC (rev 7010)
@@ -87,8 +87,8 @@
         //            Thread.sleep( 2000 );
         //        }           
 
-        final MemoryVisitor visitor = new MemoryVisitor( (InternalWorkingMemory) workingMemory );
-        visitor.visit( ruleBase );
+//        final MemoryVisitor visitor = new MemoryVisitor( (InternalWorkingMemory) workingMemory );
+//        visitor.visit( ruleBase );
 
         //        final ReteooJungViewer viewer = new ReteooJungViewer(ruleBase); 
         //        




More information about the jboss-svn-commits mailing list