Author: norman.richards(a)jboss.com
Date: 2009-06-24 16:51:19 -0400 (Wed, 24 Jun 2009)
New Revision: 11203
Added:
branches/community/Seam_2_2/src/main/org/jboss/seam/drools/SpreadsheetCompiler.java
Modified:
branches/community/Seam_2_2/src/main/org/jboss/seam/drools/RuleBase.java
Log:
JBSEAM-4266
Modified: branches/community/Seam_2_2/src/main/org/jboss/seam/drools/RuleBase.java
===================================================================
--- branches/community/Seam_2_2/src/main/org/jboss/seam/drools/RuleBase.java 2009-06-24
18:25:59 UTC (rev 11202)
+++ branches/community/Seam_2_2/src/main/org/jboss/seam/drools/RuleBase.java 2009-06-24
20:51:19 UTC (rev 11203)
@@ -11,8 +11,6 @@
import org.drools.compiler.PackageBuilder;
import org.drools.compiler.PackageBuilderConfiguration;
import org.drools.compiler.RuleBuildError;
-import org.drools.decisiontable.InputType;
-import org.drools.decisiontable.SpreadsheetCompiler;
import org.drools.spi.ConsequenceExceptionHandler;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Create;
@@ -61,16 +59,13 @@
if(isDecisionTable(ruleFile))
{
- log.debug("compiling decision table");
- SpreadsheetCompiler compiler = new SpreadsheetCompiler();
- String drl = compiler.compile(stream, InputType.XLS);
-
- log.debug("creating source");
- byte currentXMLBytes[] = drl.getBytes();
- InputStreamReader source = new InputStreamReader(new
ByteArrayInputStream(currentXMLBytes));
-
- builder.addPackageFromDrl(source);
- }
+ if (SpreadsheetCompiler.instance() != null) {
+ builder.addPackageFromDrl(SpreadsheetCompiler.instance().compile(stream));
+ } else {
+ throw new UnsupportedOperationException("Unable to compile decision table. You
need drools-decisiontables.jar in your classpath");
+
+ }
+ }
else if(isRuleFlow(ruleFile))
{
log.debug("adding ruleflow: " + ruleFile);
Added:
branches/community/Seam_2_2/src/main/org/jboss/seam/drools/SpreadsheetCompiler.java
===================================================================
--- branches/community/Seam_2_2/src/main/org/jboss/seam/drools/SpreadsheetCompiler.java
(rev 0)
+++
branches/community/Seam_2_2/src/main/org/jboss/seam/drools/SpreadsheetCompiler.java 2009-06-24
20:51:19 UTC (rev 11203)
@@ -0,0 +1,53 @@
+package org.jboss.seam.drools;
+
+import static org.jboss.seam.ScopeType.APPLICATION;
+import static org.jboss.seam.annotations.Install.BUILT_IN;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+import org.drools.decisiontable.InputType;
+import org.jboss.seam.Component;
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.Install;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.annotations.intercept.BypassInterceptors;
+import org.jboss.seam.contexts.Contexts;
+import org.jboss.seam.log.LogProvider;
+import org.jboss.seam.log.Logging;
+
+/**
+ * Compiles Drools DecisionTable.
+ *
+ * @author Tihomir Surdilovic
+ *
+ */
+
+(a)Name("org.jboss.seam.drools.spreadsheetComponent")
+@BypassInterceptors
+@Scope(APPLICATION)
+@Install(precedence = BUILT_IN, classDependencies =
"org.drools.decisiontable.SpreadsheetCompiler")
+public class SpreadsheetCompiler
+{
+ private static final LogProvider log =
Logging.getLogProvider(SpreadsheetCompiler.class);
+
+ public InputStreamReader compile(InputStream stream) {
+ org.drools.decisiontable.SpreadsheetCompiler compiler = new
org.drools.decisiontable.SpreadsheetCompiler();
+ String drl = compiler.compile(stream, InputType.XLS);
+
+ byte currentXMLBytes[] = drl.getBytes();
+ InputStreamReader source = new InputStreamReader(new
ByteArrayInputStream(currentXMLBytes));
+ return source;
+ }
+
+ public static SpreadsheetCompiler instance()
+ {
+ if (!Contexts.isApplicationContextActive()) {
+ return new SpreadsheetCompiler();
+ } else {
+ return (SpreadsheetCompiler) Component.getInstance(SpreadsheetCompiler.class,
ScopeType.APPLICATION);
+ }
+ }
+}
\ No newline at end of file
Show replies by date