Changed constructor/init method for GlobalObject

Use a GlobalObject for the per-thread scope in RhinoEngine
Modified getDBConnection() to wrap its return value
Some minor changes
Added JavaDoc comments to GlobalObject
This commit is contained in:
hns 2003-07-31 12:33:54 +00:00
parent 84e4c9361d
commit 4b594414ed
3 changed files with 34 additions and 14 deletions

View file

@ -48,14 +48,19 @@ public class GlobalObject extends ScriptableObject {
* *
* @param core ... * @param core ...
* @param app ... * @param app ...
*/
public GlobalObject(RhinoCore core, Application app) {
this.core = core;
this.app = app;
}
/**
* Initializes the global object. This is only done for the shared
* global objects not the per-thread ones.
* *
* @throws PropertyException ... * @throws PropertyException ...
*/ */
public GlobalObject(RhinoCore core, Application app, Context cx) public void init() throws PropertyException {
throws PropertyException {
this.core = core;
this.app = app;
String[] globalFuncs = { String[] globalFuncs = {
"renderSkin", "renderSkinAsString", "getProperty", "renderSkin", "renderSkinAsString", "getProperty",
"authenticate", "createSkin", "format", "encode", "authenticate", "createSkin", "format", "encode",
@ -167,27 +172,41 @@ public class GlobalObject extends ScriptableObject {
} }
/** /**
* Create a Skin object from a string
* *
* @param str the source string to parse
* *
* @param str ... * @return a parsed skin object
*
* @return ...
*/ */
public Skin createSkin(String str) { public Object createSkin(String str) {
return new Skin(str, app); return new Skin(str, app);
} }
public DatabaseObject getDBConnection(String dbsource) throws Exception { /**
* Get a Helma DB connection specified in db.properties
*
* @param str the db source name
*
* @return a DatabaseObject for the specified DbConnection
*/
public Object getDBConnection(String dbsource) throws Exception {
if (dbsource == null) if (dbsource == null)
throw new RuntimeException ("Wrong number of arguments in getDBConnection(dbsource)"); throw new RuntimeException ("Wrong number of arguments in getDBConnection(dbsource)");
DbSource dbsrc = app.getDbSource (dbsource.toLowerCase ()); DbSource dbsrc = app.getDbSource (dbsource.toLowerCase ());
if (dbsrc == null) if (dbsrc == null)
throw new RuntimeException ("DbSource "+dbsource+" does not exist"); throw new RuntimeException ("DbSource "+dbsource+" does not exist");
DatabaseObject db = new DatabaseObject (dbsrc, 0); DatabaseObject db = new DatabaseObject (dbsrc, 0);
return db; return Context.toObject(db, this);
} }
/**
* Retrieve a Document from the specified URL.
*
* @param location the URL to retrieve
* @param opt either a LastModified date or an ETag string for conditional GETs
*
* @return a wrapped MIME object
*/
public Object getURL(String location, Object opt) { public Object getURL(String location, Object opt) {
if (location == null) { if (location == null) {
return null; return null;

View file

@ -81,7 +81,8 @@ public final class RhinoCore {
context.setOptimizationLevel(optLevel); context.setOptimizationLevel(optLevel);
try { try {
GlobalObject g = new GlobalObject(this, app, context); GlobalObject g = new GlobalObject(this, app);
g.init();
global = (GlobalObject) context.initStandardObjects(g); global = (GlobalObject) context.initStandardObjects(g);
ScriptableObject.defineClass(global, HopObject.class); ScriptableObject.defineClass(global, HopObject.class);

View file

@ -84,7 +84,7 @@ public class RhinoEngine implements ScriptingEngine {
context.setCompileFunctionsWithDynamicScope(true); context.setCompileFunctionsWithDynamicScope(true);
try { try {
global = context.newObject(core.global); global = new GlobalObject(core, app); // context.newObject(core.global);
global.setPrototype(core.global); global.setPrototype(core.global);
global.setParentScope(null); global.setParentScope(null);