diff --git a/src/helma/extensions/HelmaExtension.java b/src/helma/extensions/HelmaExtension.java
index 5c4757e2..5750e65c 100644
--- a/src/helma/extensions/HelmaExtension.java
+++ b/src/helma/extensions/HelmaExtension.java
@@ -1,5 +1,7 @@
package helma.extensions;
+import java.util.HashMap;
+
import helma.framework.core.Application;
import helma.main.Server;
import helma.scripting.ScriptingEngine;
@@ -19,26 +21,25 @@ public abstract class HelmaExtension {
public abstract void init (Server server) throws ConfigurationException;
/**
- * called when an Application is started.
- * This should be synchronized. Every application starting calls this method. Otherwise this could
- * lead to problems when more than one application starts at the same time.
+ * called when an Application is started. This should be synchronized when
+ * any self-initialization is performed.
*/
public abstract void applicationStarted (Application app) throws ConfigurationException;
/**
* called when an Application is stopped.
- * This should be synchronized. Otherwise this could lead to problems when more than one
- * application gets stopped.
+ * This should be synchronized when any self-destruction is performed.
*/
public abstract void applicationStopped (Application app);
/**
- * called by the ScriptingEngine when it is initizalized. throws a ConfigurationException
- * when this type of ScriptingEngine is not supported.
- * This should be synchronized. Every application starting calls this method. Otherwise this could
- * lead to problems when more than one application starts at the same time.
+ * called by the ScriptingEngine when it is initizalized. Throws a ConfigurationException
+ * when this type of ScriptingEngine is not supported. New methods and prototypes can be
+ * added to the scripting environment. New global vars should be returned in a HashMap
+ * with pairs of varname and ESObjects. This method should be synchronized, if it
+ * performs any other self-initialization outside the scripting environment.
*/
- public abstract void initScripting (Application app, ScriptingEngine engine) throws ConfigurationException;
+ public abstract HashMap initScripting (Application app, ScriptingEngine engine) throws ConfigurationException;
public abstract String getName ();
diff --git a/src/helma/extensions/demo/DemoExtension.java b/src/helma/extensions/demo/DemoExtension.java
index ed4e4755..de7038a5 100644
--- a/src/helma/extensions/demo/DemoExtension.java
+++ b/src/helma/extensions/demo/DemoExtension.java
@@ -1,5 +1,7 @@
package helma.extensions.demo;
+import java.util.HashMap;
+
import helma.extensions.HelmaExtension;
import helma.extensions.ConfigurationException;
import helma.framework.core.Application;
@@ -41,29 +43,22 @@ public class DemoExtension extends HelmaExtension {
app.logEvent ("DemoExtension stopped on app " + app.getName () );
}
- public void initScripting (Application app, ScriptingEngine engine) throws ConfigurationException {
- if (engine instanceof FesiEvaluator) {
- try {
- initFesi (app, engine);
- app.logEvent("initScripting DemoExtension with " + app.getName () + " and " + engine.toString() );
- } catch (EcmaScriptException ecma) {
- throw new ConfigurationException (ecma.getMessage());
- }
- } else {
+ public HashMap initScripting (Application app, ScriptingEngine engine) throws ConfigurationException {
+ if (!(engine instanceof FesiEvaluator))
throw new ConfigurationException ("scripting engine " + engine.toString () + " not supported in DemoExtension");
- }
+ app.logEvent("initScripting DemoExtension with " + app.getName () + " and " + engine.toString() );
+ // fesi-specific code:
+ Evaluator evaluator = ((FesiEvaluator)engine).getEvaluator ();
+ // initialize prototypes and global vars here, but don't add them to fesi's global object
+ ESWrapper demo = new ESWrapper(Server.getServer (), evaluator);
+ HashMap globals = new HashMap ();
+ globals.put ("demo",demo);
+ return globals;
}
public String getName () {
return "DemoExtension";
}
- private void initFesi (Application app, ScriptingEngine engine) throws EcmaScriptException {
- Evaluator evaluator = ((FesiEvaluator)engine).getEvaluator ();
- ESObject demo = new ESWrapper(Server.getServer (), evaluator);
- GlobalObject go = evaluator.getGlobalObject();
- go.putHiddenProperty ("demo", demo);
- }
-
}
diff --git a/src/helma/scripting/fesi/FesiEvaluator.java b/src/helma/scripting/fesi/FesiEvaluator.java
index 3e7b89e7..58c0c664 100644
--- a/src/helma/scripting/fesi/FesiEvaluator.java
+++ b/src/helma/scripting/fesi/FesiEvaluator.java
@@ -60,6 +60,8 @@ public final class FesiEvaluator implements ScriptingEngine {
// do lazy cleanup
Map lastGlobals = null;
+ // the global vars set by extensions
+ HashMap extensionGlobals;
public FesiEvaluator (Application app, RequestEvaluator reval) {
this.app = app;
@@ -78,13 +80,15 @@ public final class FesiEvaluator implements ScriptingEngine {
mailx.setProperties (app.getProperties ());
Database dbx = (Database) evaluator.addExtension ("helma.scripting.fesi.extensions.Database");
dbx.setApplication (app);
-
- // load extensions defined in server.properties
+ // load extensions defined in server.properties:
+ extensionGlobals = new HashMap ();
Vector extVec = Server.getServer ().getExtensions ();
for (int i=0; i