[jboss-svn-commits] JBL Code SVN: r29075 - in labs/jbossrules/trunk: drools-templates/src/main/java/org/drools/template/model and 1 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Aug 26 10:09:42 EDT 2009


Author: salaboy21
Date: 2009-08-26 10:09:41 -0400 (Wed, 26 Aug 2009)
New Revision: 29075

Added:
   labs/jbossrules/trunk/drools-templates/src/main/java/org/drools/template/model/Queries.java
   labs/jbossrules/trunk/drools-templates/src/test/java/org/drools/template/model/QueriesRenderTest1.java
Modified:
   labs/jbossrules/trunk/drools-decisiontables/src/main/java/org/drools/decisiontable/parser/DefaultRuleSheetListener.java
   labs/jbossrules/trunk/drools-templates/src/main/java/org/drools/template/model/Package.java
Log:
JBRULES-2259: Support for Queries inside XLS Decision Tables
	- queries now supported inside a Queries row
	

Modified: labs/jbossrules/trunk/drools-decisiontables/src/main/java/org/drools/decisiontable/parser/DefaultRuleSheetListener.java
===================================================================
--- labs/jbossrules/trunk/drools-decisiontables/src/main/java/org/drools/decisiontable/parser/DefaultRuleSheetListener.java	2009-08-26 14:06:46 UTC (rev 29074)
+++ labs/jbossrules/trunk/drools-decisiontables/src/main/java/org/drools/decisiontable/parser/DefaultRuleSheetListener.java	2009-08-26 14:09:41 UTC (rev 29075)
@@ -63,6 +63,7 @@
     RuleSheetListener {
 
     //keywords
+    public static final String            QUERIES_TAG          = "Queries";
     public static final String            FUNCTIONS_TAG          = "Functions";
     public static final String            IMPORT_TAG             = "Import";
     public static final String            SEQUENTIAL_FLAG        = "Sequential";
@@ -151,6 +152,10 @@
 
         final String functions = getProperties().getProperty( FUNCTIONS_TAG );
         ruleset.addFunctions( functions );
+
+        final String queries = getProperties().getProperty( QUERIES_TAG );
+        ruleset.addQueries(queries);
+
         return ruleset;
     }
 

Modified: labs/jbossrules/trunk/drools-templates/src/main/java/org/drools/template/model/Package.java
===================================================================
--- labs/jbossrules/trunk/drools-templates/src/main/java/org/drools/template/model/Package.java	2009-08-26 14:06:46 UTC (rev 29074)
+++ labs/jbossrules/trunk/drools-templates/src/main/java/org/drools/template/model/Package.java	2009-08-26 14:09:41 UTC (rev 29075)
@@ -40,12 +40,15 @@
 
     private Functions _functions;
 
+    private Queries _queries;
+
     public Package(final String name) {
         this._name = name;
         this._imports = new LinkedList<Import>();
         this._variables = new LinkedList<Global>();
         this._rules = new LinkedList<Rule>();
         this._functions = new Functions();
+        this._queries = new Queries();
     }
 
     public void addImport(final Import imp) {
@@ -63,6 +66,9 @@
     public void addFunctions(final String listing) {
         this._functions.setFunctionsListing( listing );
     }
+    public void addQueries(final String listing) {
+        this._queries.setQueriesListing( listing );
+    }
 
     public String getName() {
         return this._name;
@@ -91,6 +97,7 @@
         renderDRL( this._variables,
                    out );
         this._functions.renderDRL( out );
+        this._queries.renderDRL(out);
         renderDRL( this._rules,
                    out );
 

Added: labs/jbossrules/trunk/drools-templates/src/main/java/org/drools/template/model/Queries.java
===================================================================
--- labs/jbossrules/trunk/drools-templates/src/main/java/org/drools/template/model/Queries.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-templates/src/main/java/org/drools/template/model/Queries.java	2009-08-26 14:09:41 UTC (rev 29075)
@@ -0,0 +1,41 @@
+package org.drools.template.model;
+
+/*
+ * Copyright 2005 JBoss Inc
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Wrapper for queries. Queries must be written in the appropriate style, no
+ * formatting is contributed here.
+ * 
+ * @author salaboy
+ */
+public class Queries
+    implements
+    DRLJavaEmitter {
+
+    private String queriesListing;
+
+    public void setQueriesListing(final String queriesListing) {
+        this.queriesListing = queriesListing;
+    }
+
+    public void renderDRL(final DRLOutput out) {
+        if ( this.queriesListing != null ) {
+            out.writeLine( this.queriesListing );
+        }
+    }
+
+}

Added: labs/jbossrules/trunk/drools-templates/src/test/java/org/drools/template/model/QueriesRenderTest1.java
===================================================================
--- labs/jbossrules/trunk/drools-templates/src/test/java/org/drools/template/model/QueriesRenderTest1.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-templates/src/test/java/org/drools/template/model/QueriesRenderTest1.java	2009-08-26 14:09:41 UTC (rev 29075)
@@ -0,0 +1,43 @@
+package org.drools.template.model;
+
+/*
+ * Copyright 2005 JBoss Inc
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * @author: salaboy
+ */
+import junit.framework.TestCase;
+
+public class QueriesRenderTest1 extends TestCase {
+
+    public void testQueriesRender() {
+        final Queries queries = new Queries();
+
+        DRLOutput out = new DRLOutput();
+        queries.renderDRL( out );
+
+        assertEquals( "",
+                      out.toString() );
+
+        queries.setQueriesListing( "query myQuery(String value) Person() end" );
+        out = new DRLOutput();
+        queries.renderDRL( out );
+        final String s = out.toString();
+        assertEquals( "query myQuery(String value) Person() end\n",
+                      s );
+    }
+
+}



More information about the jboss-svn-commits mailing list