2003/09/07 03:04:31
[org.ibex.core.git] / src / org / xwt / Static.java
index 035a4ed..4d6fe81 100644 (file)
@@ -1,24 +1,24 @@
 // Copyright 2002 Adam Megacz, see the COPYING file for licensing [GPL]
 package org.xwt;
 
+import org.xwt.js.*;
 import org.xwt.util.*;
-import org.mozilla.javascript.*;
 
 /** implements objects in the xwt.static.* namespace */
-public class Static extends JSObject {
+public class Static extends JS.Scope {
 
     public static Static getStatic(String resourcename) {
-        Static ret = (Static)cache.get(resourcename);
-        if (ret == null) {
-            Template t = Template.getTemplate(resourcename, null);
-
-            // FIXME: ugly
-            if (t == null) return new Static(resourcename, true);
+        Template t = Template.getTemplate(resourcename, null);
+        if (t != null) t.link();
+        return (Static)cache.get(resourcename);
+    }
 
-            ret = new Static(resourcename, false);
-            t.link();
-            return ret;
-        }
+    public static Static createStatic(String resourcename, boolean isPackage) {
+        Static ret = (Static)cache.get(resourcename);
+        if (ret != null) return ret;
+        if (resourcename.indexOf('.') != -1)
+            createStatic(resourcename.substring(0, resourcename.lastIndexOf('.')), true);
+        ret = new Static(resourcename, isPackage);
         return ret;
     }
 
@@ -31,7 +31,7 @@ public class Static extends JSObject {
     public boolean ispackage = false;
 
     private Static(String resourcename, boolean ispackage) {
-        super(true);
+        super(null);
         cache.put(resourcename, this);
         this.resourcename = resourcename;
         this.ispackage = ispackage;
@@ -41,21 +41,12 @@ public class Static extends JSObject {
     /** 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))
-            for(Scriptable cur = Context.enter().currentFunction; cur != null; cur = cur.getParentScope())
-                if (cur == this) return XWT.singleton;
-
-        if (!ispackage) return super.get(name, start);
+    public Object get(Object name_) {
+        String name = name_.toString();
+        if (!ispackage) return super.get(name);
         return getStatic(resourcename + (resourcename.length() == 0 ? "" : ".") + name);
     }
 
+    static { createStatic("", true); }
+
 }