From 7aa8a8ac8752c351546e1e6e01ed384ae4f46cf1 Mon Sep 17 00:00:00 2001 From: hns Date: Thu, 10 Feb 2005 16:07:17 +0000 Subject: [PATCH] Added global getById() function which allows to retrieve any persistent HopObject by type name and id. --- src/helma/scripting/rhino/GlobalObject.java | 23 ++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/helma/scripting/rhino/GlobalObject.java b/src/helma/scripting/rhino/GlobalObject.java index c83b5a92..f419c3d7 100644 --- a/src/helma/scripting/rhino/GlobalObject.java +++ b/src/helma/scripting/rhino/GlobalObject.java @@ -65,7 +65,7 @@ public class GlobalObject extends ImporterTopLevel implements PropertyRecorder { "authenticate", "createSkin", "format", "encode", "encodeXml", "encodeForm", "stripTags", "formatParagraphs", "getXmlDocument", "getHtmlDocument", "seal", - "getDBConnection", "getURL", "write", "writeln" + "getDBConnection", "getURL", "write", "writeln", "getById" }; defineFunctionProperties(globalFuncs, GlobalObject.class, 0); @@ -96,6 +96,27 @@ public class GlobalObject extends ImporterTopLevel implements PropertyRecorder { 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); + } + /** * *