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:
parent
84e4c9361d
commit
4b594414ed
3 changed files with 34 additions and 14 deletions
|
@ -48,14 +48,19 @@ public class GlobalObject extends ScriptableObject {
|
|||
*
|
||||
* @param core ...
|
||||
* @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 ...
|
||||
*/
|
||||
public GlobalObject(RhinoCore core, Application app, Context cx)
|
||||
throws PropertyException {
|
||||
this.core = core;
|
||||
this.app = app;
|
||||
|
||||
public void init() throws PropertyException {
|
||||
String[] globalFuncs = {
|
||||
"renderSkin", "renderSkinAsString", "getProperty",
|
||||
"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 ...
|
||||
* @return a parsed skin object
|
||||
*/
|
||||
public Skin createSkin(String str) {
|
||||
public Object createSkin(String str) {
|
||||
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)
|
||||
throw new RuntimeException ("Wrong number of arguments in getDBConnection(dbsource)");
|
||||
DbSource dbsrc = app.getDbSource (dbsource.toLowerCase ());
|
||||
if (dbsrc == null)
|
||||
throw new RuntimeException ("DbSource "+dbsource+" does not exist");
|
||||
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) {
|
||||
if (location == null) {
|
||||
return null;
|
||||
|
|
|
@ -81,7 +81,8 @@ public final class RhinoCore {
|
|||
context.setOptimizationLevel(optLevel);
|
||||
|
||||
try {
|
||||
GlobalObject g = new GlobalObject(this, app, context);
|
||||
GlobalObject g = new GlobalObject(this, app);
|
||||
g.init();
|
||||
|
||||
global = (GlobalObject) context.initStandardObjects(g);
|
||||
ScriptableObject.defineClass(global, HopObject.class);
|
||||
|
|
|
@ -84,7 +84,7 @@ public class RhinoEngine implements ScriptingEngine {
|
|||
context.setCompileFunctionsWithDynamicScope(true);
|
||||
|
||||
try {
|
||||
global = context.newObject(core.global);
|
||||
global = new GlobalObject(core, app); // context.newObject(core.global);
|
||||
global.setPrototype(core.global);
|
||||
global.setParentScope(null);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue