I don't think there's any reason not to just change the code to use
getResourceAsStream(); the standard implementation just defers to
getResource() anyway, and I can see how for some ClassLoaders,
implementing getResource() to return a URL might not be possible.
Thanks for the suggestion; we'll incorporate this in the next release.
On May 21, 2010, at 5:08 AM, Voigt, Michael wrote:
Hi,
For specific reasons we want to use a special classloader (JCL, http://jcloader.sourceforge.net
) to load jar files that contain fact classes and jessML files. We
use Rete.setClassLoader() to make Jess aware of this classloader.
One characteristic of JCL is that it loads the jar file as stream so
that it is not aware of the real location/URL of the underlying jar
file. Therefore it is not possible to return a proper URL when
jclClassLoader.getResource() is called for a jessML file that is
part of the jar file (it always returns null). On the other hand
jclClassLoader.getResourceAsStream() works fine.
Using this classloader with Jess works fine except that loading a
jessML file from the classloader fails. The reason is that
Rete.batch() internally uses classloader.getResource() to get the
URL of the given file (which in this case returns null). If that URL
is null an exception is thrown, if not a stream is opened; see
Batch.findDocument(Rete engine, String filename, String charset).
I wonder why Jess doesn’t try to use the
classloader.getResourceAsStream() as another alternative before
throwing the exception. I tried this and changed the lines to:
URL u = engine.getResource(filename);
InputStream is;
if (u != null) {
is = u.openStream();
} else {
try {
is =
engine.getClassLoader().getResourceAsStream(filename);
}
catch (Exception e2) {
throw new JessException("batch", "Cannot open
file", e);
}
}
fis = new PushbackReader(new InputStreamReader(is,
charset));
In my first simple tests this works very well. Do you see any
objections? Could this be integrated into the next release of Jess?
Or are there any other possibilities to achieve the described
functionality without changes in Jess source code?
Thanks!
Michael
---------------------------------------------------------
Ernest Friedman-Hill
Informatics & Decision Sciences, Sandia National Laboratories
PO Box 969, MS 9012, Livermore, CA 94550
http://www.jessrules.com
--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [email protected]'
in the BODY of a message to [email protected], NOT to the list
(use your own address!) List problems? Notify [email protected].
--------------------------------------------------------------------