--- /dev/null
+// Copyright 2002 Adam Megacz, see the COPYING file for licensing [GPL]
+package org.xwt;
+
+import org.xwt.util.*;
+import org.mozilla.javascript.*;
+
+/** implements objects in the xwt.static.* namespace */
+public class Static extends JSObject {
+
+ public static Static getStatic(String resourcename) {
+ Static ret = (Static)cache.get(resourcename);
+ if (ret == null) {
+ Template t = Template.getTemplate(resourcename, null);
+ if (t == null) return null;
+ ret = new Static(resourcename, false);
+ t.link();
+ return ret;
+ }
+ return ret;
+ }
+
+ private static Hash cache = new Hash();
+
+ /** the resource name that this Static object corresponds to */
+ private String resourcename = null;
+
+ /** true iff this represents a directory (rather than an actual xwt) */
+ public boolean ispackage = false;
+
+ private Static(String resourcename, boolean ispackage) {
+ super(true);
+ cache.put(resourcename, this);
+ this.resourcename = resourcename;
+ this.ispackage = ispackage;
+ setSeal(ispackage);
+ }
+
+ /** creates a new static representing a package */
+ public Static(String resourcename) {
+ this(resourcename, true);
+ }
+
+ public Object get(String name, Scriptable start) {
+ if (name == null) return null;
+
+ // hack since Rhino needs to be able to grab these functions to create new objects
+ if (name.equals("Object")) return JSObject.defaultObjects.get("Object", null);
+ if (name.equals("Array")) return JSObject.defaultObjects.get("Array", null);
+ if (name.equals("Function")) return JSObject.defaultObjects.get("Function", null);
+ if (name.equals("TypeError")) return JSObject.defaultObjects.get("TypeError", null);
+
+ if ("xwt".equals(name)) return XWT.singleton;
+ if (!ispackage) return super.get(name, start);
+ return getStatic(resourcename + (resourcename.length() == 0 ? "" : ".") + name);
+ }
+
+}