[jboss-svn-commits] JBL Code SVN: r15186 - labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Sep 17 22:23:46 EDT 2007
Author: michael.neale at jboss.com
Date: 2007-09-17 22:23:46 -0400 (Mon, 17 Sep 2007)
New Revision: 15186
Added:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/FileLoader.java
Modified:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/FileScanner.java
Log:
JBRULES-1201
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/FileLoader.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/FileLoader.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/FileLoader.java 2007-09-18 02:23:46 UTC (rev 15186)
@@ -0,0 +1,19 @@
+package org.drools.agent;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+
+
+/**
+ * This interface is mostly provided so a DRL provider can live in
+ * drools-compiler, without it, we would have circular references.
+ * @author Michael Neale
+ *
+ */
+public interface FileLoader {
+
+ public org.drools.rule.Package loadPackage(File drl) throws FileNotFoundException, IOException;
+
+}
Property changes on: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/FileLoader.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/FileScanner.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/FileScanner.java 2007-09-18 01:57:57 UTC (rev 15185)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/FileScanner.java 2007-09-18 02:23:46 UTC (rev 15186)
@@ -50,8 +50,8 @@
/**
* Perform the scan.
- * If there was an error reading the packages, this will not fail, it will
- * just do nothing (as there may be a temporary IO issue).
+ * If there was an error reading the packages, this will not fail, it will
+ * just do nothing (as there may be a temporary IO issue).
*/
Package[] loadPackageChanges() {
Package[] changes = getChangeSet();
@@ -64,9 +64,9 @@
/**
* Calculate a change set, based on last updated times.
* (keep a map of files).
- * @throws ClassNotFoundException
- * @throws IOException
- * @throws FileNotFoundException
+ * @throws ClassNotFoundException
+ * @throws IOException
+ * @throws FileNotFoundException
*/
private Package[] getChangeSet() {
if ( this.files == null ) return new Package[0];
@@ -90,23 +90,36 @@
*/
private Package readPackage(File pkgFile) {
- Package p1_ = null;
- ObjectInputStream in;
- try {
- in = new DroolsObjectInputStream( new FileInputStream( pkgFile ) );
- p1_ = (Package) in.readObject();
- in.close();
+ //use reflection to load if its DRL, the provider lives in drools compiler.
+ if (pkgFile.getName().endsWith(".drl")) {
+ try {
+ FileLoader fl = (FileLoader) Class.forName("org.drools.compiler.SourcePackageProvider").newInstance();
+ return fl.loadPackage(pkgFile);
+ } catch (Exception e) {
+ this.listener.exception(e);
+ return null;
+ }
- } catch ( FileNotFoundException e ) {
- this.listener.exception( e );
- this.listener.warning( "Was unable to find the file " + pkgFile.getPath() );
- } catch ( IOException e ) {
- this.listener.exception( e );
- } catch ( ClassNotFoundException e ) {
- this.listener.exception( e );
- this.listener.warning( "Was unable to load a class when loading a package. Perhaps it is missing from this application." );
- }
- return p1_;
+ } else {
+
+ Package p1_ = null;
+ ObjectInputStream in;
+ try {
+ in = new DroolsObjectInputStream( new FileInputStream( pkgFile ) );
+ p1_ = (Package) in.readObject();
+ in.close();
+
+ } catch ( FileNotFoundException e ) {
+ this.listener.exception( e );
+ this.listener.warning( "Was unable to find the file " + pkgFile.getPath() );
+ } catch ( IOException e ) {
+ this.listener.exception( e );
+ } catch ( ClassNotFoundException e ) {
+ this.listener.exception( e );
+ this.listener.warning( "Was unable to load a class when loading a package. Perhaps it is missing from this application." );
+ }
+ return p1_;
+ }
}
boolean hasChanged(String path,
More information about the jboss-svn-commits
mailing list