New smart classloading

This commit is contained in:
hns 2002-11-29 17:58:28 +00:00
parent 719959353e
commit 62c54ce820
5 changed files with 38 additions and 8 deletions

View file

@ -929,6 +929,14 @@ public final class Application implements IPathElement, Runnable {
} }
return null; return null;
} }
/**
* Return the application's classloader
*/
public ClassLoader getClassLoader () {
return typemgr.loader;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////
/// The following methods mimic the IPathElement interface. This allows us /// The following methods mimic the IPathElement interface. This allows us

View file

@ -72,9 +72,9 @@ public final class RequestEvaluator implements Runnable {
if (scriptingEngine == null) { if (scriptingEngine == null) {
String engineClassName = app.getProperty ( String engineClassName = app.getProperty (
"scriptingEngine", "scriptingEngine",
"helma.scripting.fesi.FesiEngine"); "helma.scripting.fesi.PhantomEngine");
try { try {
Class clazz = app.typemgr.loader.loadClass (engineClassName); Class clazz = app.getClassLoader().loadClass (engineClassName);
scriptingEngine = (ScriptingEngine) clazz.newInstance (); scriptingEngine = (ScriptingEngine) clazz.newInstance ();
scriptingEngine.init (app, this); scriptingEngine.init (app, this);
} catch (Exception x) { } catch (Exception x) {
@ -666,6 +666,7 @@ public final class RequestEvaluator implements Runnable {
if (rtx == null || !rtx.isAlive()) { if (rtx == null || !rtx.isAlive()) {
// app.logEvent ("Starting Thread"); // app.logEvent ("Starting Thread");
rtx = new Transactor (this, app.threadgroup, app.nmgr); rtx = new Transactor (this, app.threadgroup, app.nmgr);
rtx.setContextClassLoader (app.getClassLoader ());
rtx.start (); rtx.start ();
} else { } else {
notifyAll (); notifyAll ();

View file

@ -29,9 +29,7 @@ public class FilteredClassLoader extends URLClassLoader {
* Mask classes that implement the scripting engine(s) contained in helma.jar * Mask classes that implement the scripting engine(s) contained in helma.jar
*/ */
protected Class findClass (String name) throws ClassNotFoundException { protected Class findClass (String name) throws ClassNotFoundException {
if (name != null && (name.startsWith ("helma.scripting.fesi") || if (name != null && "helma.scripting.fesi.PhantomEngine".equals (name))
name.startsWith ("helma.doc") ||
name.startsWith ("FESI")))
throw new ClassNotFoundException (name); throw new ClassNotFoundException (name);
return super.findClass (name); return super.findClass (name);
} }

View file

@ -25,7 +25,7 @@ import FESI.Exceptions.*;
/** /**
* This is the implementation of ScriptingEnvironment for the FESI EcmaScript interpreter. * This is the implementation of ScriptingEnvironment for the FESI EcmaScript interpreter.
*/ */
public final class FesiEngine implements ScriptingEngine { public class FesiEngine implements ScriptingEngine {
// the application we're running in // the application we're running in
Application app; Application app;
@ -80,8 +80,7 @@ public final class FesiEngine implements ScriptingEngine {
wrappercache = new CacheMap (200, .75f); wrappercache = new CacheMap (200, .75f);
prototypes = new Hashtable (); prototypes = new Hashtable ();
try { try {
evaluator = new Evaluator(); evaluator = new Evaluator(this);
evaluator.engine = this;
global = evaluator.getGlobalObject(); global = evaluator.getGlobalObject();
for (int i=0; i<extensions.length; i++) for (int i=0; i<extensions.length; i++)
evaluator.addExtension (extensions[i]); evaluator.addExtension (extensions[i]);
@ -753,6 +752,13 @@ public final class FesiEngine implements ScriptingEngine {
wrappercache.put (n, esn); wrappercache.put (n, esn);
} }
/**
* Return the application's classloader
*/
public ClassLoader getClassLoader () {
return app.getClassLoader ();
}
/** /**
* Return the RequestEvaluator owning and driving this FESI evaluator. * Return the RequestEvaluator owning and driving this FESI evaluator.
*/ */

View file

@ -0,0 +1,17 @@
// PhantomEngine.java
// Copyright (c) Hannes Wallnöfer 2002
package helma.scripting.fesi;
import helma.scripting.ScriptingException;
public final class PhantomEngine extends FesiEngine {
/**
*
*/
public Object invoke (Object thisObject, String functionName, Object[] args, boolean xmlrpc) throws ScriptingException {
return super.invoke (thisObject, functionName, args, xmlrpc);
}
}