[jboss-svn-commits] JBL Code SVN: r21304 - in labs/jbossrules/trunk/drools-decisiontables/src: main/java/org/drools/decisiontable/parser and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Jul 31 01:23:46 EDT 2008
Author: michael.neale at jboss.com
Date: 2008-07-31 01:23:45 -0400 (Thu, 31 Jul 2008)
New Revision: 21304
Modified:
labs/jbossrules/trunk/drools-decisiontables/src/main/java/org/drools/decisiontable/SpreadsheetCompiler.java
labs/jbossrules/trunk/drools-decisiontables/src/main/java/org/drools/decisiontable/parser/DefaultRuleSheetListener.java
labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/drools/decisiontable/SpreadsheetCompilerUnitTest.java
Log:
JBRULES-1702 DT with imports
Modified: labs/jbossrules/trunk/drools-decisiontables/src/main/java/org/drools/decisiontable/SpreadsheetCompiler.java
===================================================================
--- labs/jbossrules/trunk/drools-decisiontables/src/main/java/org/drools/decisiontable/SpreadsheetCompiler.java 2008-07-31 03:55:09 UTC (rev 21303)
+++ labs/jbossrules/trunk/drools-decisiontables/src/main/java/org/drools/decisiontable/SpreadsheetCompiler.java 2008-07-31 05:23:45 UTC (rev 21304)
@@ -2,13 +2,13 @@
/*
* 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.
@@ -32,7 +32,7 @@
/**
* @author <a href="mailto:michael.neale at gmail.com"> Michael Neale </a>
- *
+ *
* This class handles the input XLS and CSV and extracts the rule DRL, ready for
* pumping into drools.
*/
@@ -40,25 +40,25 @@
/**
* Generates DRL from the input stream containing the spreadsheet.
- *
- * @param pkg
- * Uses this package definition as the default definitions for the spreadsheet
+ *
+ * @param showPackageAndImports
+ * tells it to print or not print any package/import/global statements in the spreadsheet.
* @param xlsStream
* The stream to the spreadsheet. Uses the first worksheet found
* for the decision tables, ignores others.
* @return DRL xml, ready for use in drools.
*/
- public String compile(final org.drools.rule.Package pkg,
+ public String compile(boolean showPackageAndImports,
final InputStream xlsStream,
final InputType type) {
return compile( xlsStream,
type,
- new DefaultRuleSheetListener( pkg ) );
+ new DefaultRuleSheetListener( showPackageAndImports ) );
}
/**
* Generates DRL from the input stream containing the spreadsheet.
- *
+ *
* @param xlsStream
* The stream to the spreadsheet. Uses the first worksheet found
* for the decision tables, ignores others.
@@ -80,7 +80,7 @@
* @param type
* The type of the file - InputType.CSV or InputType.XLS
* @param listener
- *
+ *
* @return DRL xml, ready for use in drools.
*/
public String compile(final InputStream xlsStream,
@@ -98,7 +98,7 @@
* Convenience implementation, taking rules from the classpath. It is
* recommended to use the stream version, as you can then change rules
* dynamically. (that is a lot of the benefit of rule engines !).
- *
+ *
* @param classPathResource
* full class path to the spreadsheet you wish to convert to DRL.
* Uses the first worksheet for the decision tables.
@@ -119,7 +119,7 @@
/**
* Looks for a named worksheet to find the decision tables on. Only works
* with XLS format spreadsheets (as they have multiple worksheets).
- *
+ *
* @param stream
* The stream of the decision tables (spreadsheet) IN XLS format !!
* @param worksheetName
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 2008-07-31 03:55:09 UTC (rev 21303)
+++ labs/jbossrules/trunk/drools-decisiontables/src/main/java/org/drools/decisiontable/parser/DefaultRuleSheetListener.java 2008-07-31 05:23:45 UTC (rev 21304)
@@ -93,14 +93,14 @@
private final PropertiesSheetListener _propertiesListner = new PropertiesSheetListener();
- private final org.drools.rule.Package defaultPackage;
+ private boolean showPackage;
public DefaultRuleSheetListener() {
- this( null );
+ this( true );
}
- public DefaultRuleSheetListener(final org.drools.rule.Package pkg) {
- this.defaultPackage = pkg;
+ public DefaultRuleSheetListener(boolean showPackage) {
+ this.showPackage = showPackage;
}
/* (non-Javadoc)
@@ -130,23 +130,26 @@
}
private Package buildRuleSet() {
- final String defaultPackageName = this.defaultPackage != null ? this.defaultPackage.getName() : "rule_table";
+ final String defaultPackageName = "rule_table";
final String rulesetName = getProperties().getProperty( RULESET_TAG,
defaultPackageName );
- final Package ruleset = new Package( rulesetName );
+
+ final Package ruleset = new Package( (showPackage) ? rulesetName : null );
for ( Rule rule : this._ruleList ) {
ruleset.addRule( rule );
}
- final List<Import> importList = RuleSheetParserUtil.getImportList( getProperties().getProperty( IMPORT_TAG ) );
- for ( Import import1 : importList ) {
- ruleset.addImport( import1 );
+ if (showPackage) {
+ final List<Import> importList = RuleSheetParserUtil.getImportList( getProperties().getProperty( IMPORT_TAG ) );
+ for ( Import import1 : importList ) {
+ ruleset.addImport( import1 );
+ }
+ final List<Global> variableList = RuleSheetParserUtil.getVariableList( getProperties().getProperty( VARIABLES_TAG ) ); // Set the list of variables to
+ // be added to the
+ // application-data tags
+ for ( Global global : variableList ) {
+ ruleset.addVariable( global );
+ }
}
- final List<Global> variableList = RuleSheetParserUtil.getVariableList( getProperties().getProperty( VARIABLES_TAG ) ); // Set the list of variables to
- // be added to the
- // application-data tags
- for ( Global global : variableList ) {
- ruleset.addVariable( global );
- }
final String functions = getProperties().getProperty( FUNCTIONS_TAG );
ruleset.addFunctions( functions );
Modified: labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/drools/decisiontable/SpreadsheetCompilerUnitTest.java
===================================================================
--- labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/drools/decisiontable/SpreadsheetCompilerUnitTest.java 2008-07-31 03:55:09 UTC (rev 21303)
+++ labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/drools/decisiontable/SpreadsheetCompilerUnitTest.java 2008-07-31 05:23:45 UTC (rev 21304)
@@ -2,13 +2,13 @@
/*
* 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.
@@ -26,7 +26,7 @@
/**
* @author <a href="mailto:michael.neale at gmail.com"> Michael Neale</a>
- *
+ *
* Some basic unit tests for converter utility.
* Note that some of this may still use the drools 2.x syntax, as it is not compiled,
* only tested that it generates DRL in the correct structure (not that the DRL itself
@@ -36,7 +36,7 @@
public void testLoadFromClassPath() {
final SpreadsheetCompiler converter = new SpreadsheetCompiler();
- final String drl = converter.compile( "/data/MultiSheetDST.xls",
+ String drl = converter.compile( "/data/MultiSheetDST.xls",
InputType.XLS );
assertNotNull( drl );
@@ -44,6 +44,19 @@
assertTrue( drl.indexOf( "rule \"How cool am I_12\"" ) > drl.indexOf( "rule \"How cool am I_11\"" ) );
assertTrue( drl.indexOf( "import example.model.User;" ) > -1 );
assertTrue( drl.indexOf( "import example.model.Car;" ) > -1 );
+
+ InputStream ins = this.getClass().getResourceAsStream("/data/MultiSheetDST.xls");
+
+ drl = converter.compile( false, ins,
+ InputType.XLS );
+
+ assertNotNull( drl );
+
+ assertTrue( drl.indexOf( "rule \"How cool am I_12\"" ) > 0 );
+ assertTrue( drl.indexOf( "import example.model.User;" ) == -1 );
+ assertTrue( drl.indexOf( "import example.model.Car;" ) == -1 );
+ assertTrue( drl.indexOf("package ") == -1);
+
}
public void testLoadSpecificWorksheet() {
More information about the jboss-svn-commits
mailing list