[jboss-svn-commits] JBL Code SVN: r12787 - in labs/jbossrules/trunk/drools-compiler/src: main/java/org/drools/xml and 3 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sat Jun 23 05:17:39 EDT 2007


Author: fmeyer
Date: 2007-06-23 05:17:39 -0400 (Sat, 23 Jun 2007)
New Revision: 12787

Added:
   labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_from.drl
   labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_simplerule.drl
Modified:
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/DrlDumper.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/XmlDumper.java
   labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/xml/DumperTest.java
   labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/xml/DumperTestHelper.java
   labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_Forall.drl
   labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_exists.drl
Log:
JBRULES-880
	- Updated DRL dumper to handle with new language features

Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/DrlDumper.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/DrlDumper.java	2007-06-23 08:29:28 UTC (rev 12786)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/DrlDumper.java	2007-06-23 09:17:39 UTC (rev 12787)
@@ -130,7 +130,7 @@
     public void visitExistsDescr(final ExistsDescr descr) {
         this.template = new String();
         if ( !descr.getDescrs().isEmpty() ) {
-            this.template = "\t\texists " + processDescrList( descr.getDescrs() );
+            this.template = "\t\texists " + processDescrList( descr.getDescrs() ) + ";";
         } else {
             this.template = "";
         }
@@ -145,22 +145,38 @@
         this.template = tmpstr + ");";
     }
     
-    //TODO FM: FIXME
     public void visitAccumulateDescr(final AccumulateDescr descr) {
-        System.out.println( "Accumulate DRL" );
+        String tmpstr = new String();
+        visitPatternDescr( descr.getResultPattern() );
+        tmpstr += this.template + " from accumulate (";
+        visitPatternDescr( descr.getSourcePattern() );
+        tmpstr += this.template.substring( 2 );
+        tmpstr += ", init(" + descr.getInitCode() + "), "; 
+        tmpstr += "action(" + descr.getActionCode() + "), "; 
+        tmpstr += "result(" + descr.getResultCode() + ")"; 
+        this.template = tmpstr + ");";
     }
     
-    //TODO FM: FIXME
     public void visitFromDescr(final FromDescr descr) {
-        System.out.println( "From DRL" );
+        visitPatternDescr( descr.getReturnedPattern() );
+        this.template += " from (";
+        this.template += descr.getDataSource().getText().trim();
+        this.template += ")";
     }
 
 
     public void visitForallDescr(final ForallDescr descr) {
-        this.template = new String();
-        this.template += "\t\tforall ( ";
-        this.template += DrlDumper.eol;
-        this.template += processDescrList( descr.getDescrs() );
+        String localstr = new String();
+        localstr += "\t\tforall ( ";
+        localstr += DrlDumper.eol;
+        
+        for ( final Iterator ite = descr.getDescrs().iterator(); ite.hasNext(); ) {
+            Object obj = ite.next();
+            visit( obj );
+            localstr += this.template + ",";
+        }
+        
+        this.template = localstr.substring( 0, localstr.lastIndexOf( "," ) );
         this.template += "\t\t)";
         this.template += DrlDumper.eol;
     }

Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/XmlDumper.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/XmlDumper.java	2007-06-23 08:29:28 UTC (rev 12786)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/XmlDumper.java	2007-06-23 09:17:39 UTC (rev 12787)
@@ -124,7 +124,6 @@
         this.template += "</pattern>";
     }
 
-    //TODO FM: FIXME
     public void visitAccumulateDescr(final AccumulateDescr descr) {
         String tmpstr = new String();
         visit( descr.getResultPattern() );
@@ -141,6 +140,7 @@
     }
 
     //TODO FM: FIXME
+    
     public void visitFromDescr(final FromDescr descr) {
 
         String tmpstr = new String();
@@ -154,7 +154,6 @@
         this.template += "</pattern>";
     }
 
-    //TODO FM: FIXME
     public void visitForallDescr(final ForallDescr descr) {
         this.template = "<forall>" + processDescrList( descr.getDescrs() ) + "</forall>";
     }

Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/xml/DumperTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/xml/DumperTest.java	2007-06-23 08:29:28 UTC (rev 12786)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/xml/DumperTest.java	2007-06-23 09:17:39 UTC (rev 12787)
@@ -52,24 +52,24 @@
         DumperTestHelper.DrlFile( "../integrationtests/test_Collect.drl" );
     }
     
-    //FIXME: FM Correct Drl Dumper 
-//    public void testRoundTripAccumulateDrl() throws Exception {
-//        DumperTestHelper.DrlFile( "../integrationtests/test_Accumulate.drl" );
-//    }
-//    
-//    public void testRoundTripExistsDrl() throws Exception {
-//        DumperTestHelper.DrlFile( "../integrationtests/test_exists.drl" );
-//    }
-//
-//    public void testRoundTripForallDrl() throws Exception {
-//        DumperTestHelper.DrlFile( "../integrationtests/test_Forall.drl" );
-//    }
-//
-//    public void testRoundTripFromDrl() throws Exception {
-//        DumperTestHelper.DrlFile( "../integrationtests/test_From.drl" );
-//    }
-//
-//    public void testRoundTripSimpleRuleDrl() throws Exception {
-//        DumperTestHelper.DrlFile( "../lang/simple_rule.drl" );
-//    }
+    public void testRoundTripAccumulateDrl() throws Exception {
+        DumperTestHelper.DrlFile( "../integrationtests/test_Accumulate.drl" );
+    }
+    
+    public void testRoundTripExistsDrl() throws Exception {
+        DumperTestHelper.DrlFile( "../integrationtests/test_exists.drl" );
+    }
+
+    public void testRoundTripForallDrl() throws Exception {
+        DumperTestHelper.DrlFile( "../integrationtests/test_Forall.drl" );
+    }
+
+    //FM: FIXME
+    public void FIXME_testRoundTripFromDrl() throws Exception {
+        DumperTestHelper.DrlFile( "test_from.drl" );
+    }
+
+    public void testRoundTripSimpleRuleDrl() throws Exception {
+        DumperTestHelper.DrlFile( "test_simplerule.drl" );
+    }
 }
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/xml/DumperTestHelper.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/xml/DumperTestHelper.java	2007-06-23 08:29:28 UTC (rev 12786)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/xml/DumperTestHelper.java	2007-06-23 09:17:39 UTC (rev 12787)
@@ -27,14 +27,8 @@
 
         final XmlDumper dumper = new XmlDumper();
         final String result = dumper.dump( pkgOriginal );
-        
-        
-        System.out.println(result);
 
         String buffer = readFile( filename );
-        
-        System.out.println( buffer);
-
         assertEqualsIgnoreWhitespace( buffer,
                                       result );
         assertNotNull( result );

Modified: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_Forall.drl
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_Forall.drl	2007-06-23 08:29:28 UTC (rev 12786)
+++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_Forall.drl	2007-06-23 09:17:39 UTC (rev 12787)
@@ -1,6 +1,6 @@
 package org.drools;
 
-global java.util.List results
+global java.util.List results;
 
 rule "test nested CEs"	
 	when

Modified: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_exists.drl
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_exists.drl	2007-06-23 08:29:28 UTC (rev 12786)
+++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_exists.drl	2007-06-23 09:17:39 UTC (rev 12787)
@@ -7,7 +7,7 @@
 
 rule "Buy cheese"
 when
-  $cheese: Cheese($type : type);
+  $cheese: Cheese($type : type)
   exists Person(likes == $type);
 then
   list.add($cheese);

Added: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_from.drl
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_from.drl	                        (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_from.drl	2007-06-23 09:17:39 UTC (rev 12787)
@@ -0,0 +1,24 @@
+package org.drools.test;
+ 
+import org.drools.Cheese;
+import org.drools.Cheesery;
+import java.util.List;
+
+global List list1;
+global List list2;
+global List list3;
+global Cheesery cheesery;
+
+rule "test from using a global"
+	when
+		$cheese : Cheese() from cheesery.getCheeses()		
+	then
+		list1.add( $cheese );
+end
+
+rule "test from using a global against a map lookup"
+	when
+		$cheese : Cheese( type == "stilton" ) from cheesery.getCheeseMap["stilton"]	
+	then
+		list1.add( $cheese );
+end
\ No newline at end of file

Added: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_simplerule.drl
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_simplerule.drl	                        (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_simplerule.drl	2007-06-23 09:17:39 UTC (rev 12787)
@@ -0,0 +1,15 @@
+package foo;
+
+rule "simple_rule" 
+  when
+    foo3 : Bar(a==3)
+    foo4 : Bar(a4:a==4)
+    Baz()
+  then
+  if ( a == b ) {
+    assert( foo3 );
+  } else {
+    retract( foo4 );
+  } 
+  System.out.println( a4 );
+end
\ No newline at end of file




More information about the jboss-svn-commits mailing list