Remove global getById() in favor of Constructor.getById() which now takes

an optional second prototype argument.
This commit is contained in:
hns 2005-02-15 14:27:54 +00:00
parent 91136fed4c
commit 700f2b41ea
2 changed files with 8 additions and 23 deletions

View file

@ -65,7 +65,7 @@ public class GlobalObject extends ImporterTopLevel implements PropertyRecorder {
"authenticate", "createSkin", "format", "encode", "authenticate", "createSkin", "format", "encode",
"encodeXml", "encodeForm", "stripTags", "formatParagraphs", "encodeXml", "encodeForm", "stripTags", "formatParagraphs",
"getXmlDocument", "getHtmlDocument", "seal", "getXmlDocument", "getHtmlDocument", "seal",
"getDBConnection", "getURL", "write", "writeln", "getById" "getDBConnection", "getURL", "write", "writeln"
}; };
defineFunctionProperties(globalFuncs, GlobalObject.class, 0); defineFunctionProperties(globalFuncs, GlobalObject.class, 0);
@ -96,27 +96,6 @@ public class GlobalObject extends ImporterTopLevel implements PropertyRecorder {
super.put(name, start, value); super.put(name, start, value);
} }
/**
* Retrieve any persistent HopObject by type name and id.
*
* @param type the prototype name
* @param id the id
* @return the HopObject or null if it doesn't exist
*/
public Object getById(String type, String id) {
DbMapping dbmap = app.getDbMapping(type);
if (dbmap == null)
return null;
Object node = null;
try {
DbKey key = new DbKey(dbmap, id);
node = app.getNodeManager().getNode(key);
} catch (Exception x) {
return null;
}
return node == null ? null : Context.toObject(node, this);
}
/** /**
* *
* *

View file

@ -1088,7 +1088,13 @@ public final class RhinoCore {
* @return the HopObject or null if it doesn't exist * @return the HopObject or null if it doesn't exist
*/ */
public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) { public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) {
DbMapping dbmap = app.getDbMapping(typeName); if (args.length < 1 || args.length > 2)
throw new IllegalArgumentException("Wrong number of arguments in getById()");
// If second argument is provided, use it as type name.
// Otherwise, use our own type name.
String type = args.length == 1 ? typeName: Context.toString(args[1]);
DbMapping dbmap = app.getDbMapping(type);
if (dbmap == null) if (dbmap == null)
return null; return null;
Object node = null; Object node = null;