[seam-commits] Seam SVN: r11204 - tags/JBoss_Seam_2_2_0_CR1/src/main/org/jboss/seam/drools.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Wed Jun 24 17:13:28 EDT 2009


Author: norman.richards at jboss.com
Date: 2009-06-24 17:13:27 -0400 (Wed, 24 Jun 2009)
New Revision: 11204

Added:
   tags/JBoss_Seam_2_2_0_CR1/src/main/org/jboss/seam/drools/SpreadsheetCompiler.java
Modified:
   tags/JBoss_Seam_2_2_0_CR1/src/main/org/jboss/seam/drools/RuleBase.java
Log:
JBSEAM-4266

Modified: tags/JBoss_Seam_2_2_0_CR1/src/main/org/jboss/seam/drools/RuleBase.java
===================================================================
--- tags/JBoss_Seam_2_2_0_CR1/src/main/org/jboss/seam/drools/RuleBase.java	2009-06-24 20:51:19 UTC (rev 11203)
+++ tags/JBoss_Seam_2_2_0_CR1/src/main/org/jboss/seam/drools/RuleBase.java	2009-06-24 21:13:27 UTC (rev 11204)
@@ -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,15 +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 {             
                // read in the source
                Reader drlReader = new InputStreamReader(stream);

Added: tags/JBoss_Seam_2_2_0_CR1/src/main/org/jboss/seam/drools/SpreadsheetCompiler.java
===================================================================
--- tags/JBoss_Seam_2_2_0_CR1/src/main/org/jboss/seam/drools/SpreadsheetCompiler.java	                        (rev 0)
+++ tags/JBoss_Seam_2_2_0_CR1/src/main/org/jboss/seam/drools/SpreadsheetCompiler.java	2009-06-24 21:13:27 UTC (rev 11204)
@@ -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
+ *
+ */
+
+ at Name("org.jboss.seam.drools.spreadsheetComponent")
+ at BypassInterceptors
+ at Scope(APPLICATION)
+ at 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




More information about the seam-commits mailing list