2003/11/29 03:06:09
[org.ibex.core.git] / src / org / xwt / XWT.java
index d3c53fd..a987d9e 100644 (file)
@@ -23,10 +23,10 @@ public final class XWT extends JS {
         public String toString() { return "XWTSUB " + key; }
         public void put(Object key, Object val) { XWT.this.put(this.key + "." + key, val); }
         public Object get(Object key) { return XWT.this.get(this.key + "." + key); }
-        public Object call(Object a0, Object a1, Object a2, Object[] rest, int nargs) {
+        public Object call(Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn {
             return XWT.this.callMethod(this.key, a0, a1, a2, rest, nargs);
         }
-        public Object callMethod(Object method, Object a0, Object a1, Object a2, Object[] rest, int nargs) {
+        public Object callMethod(Object method, Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn {
             return XWT.this.callMethod(this.key + "." + method, a0, a1, a2, rest, nargs);
         }
     }
@@ -99,7 +99,7 @@ public final class XWT extends JS {
         //#switch(name)
         case "thread":
             Scheduler.add(new Scheduler.Task() {
-                    public void perform() {
+                    public void perform() throws JSExn {
                         try {
                             JS.invokePauseable((JSFunction)value);
                         } catch (JS.PausedException pe) {
@@ -164,7 +164,7 @@ public final class XWT extends JS {
         return null;
     }
 
-    public static void sleep(final int i) {
+    public static void sleep(final int i) throws JSExn {
         try {
             final JS.UnpauseCallback callback = JS.pause();
             final long currentTime = System.currentTimeMillis();
@@ -172,7 +172,7 @@ public final class XWT extends JS {
                 public void run() {
                     try { Thread.sleep(i); } catch (InterruptedException e) { }
                     Scheduler.add(new Scheduler.Task() {
-                            public void perform() {
+                            public void perform() throws JSExn {
                                 try {
                                     callback.unpause(null);
                                 } catch (JS.PausedException pe) {
@@ -190,7 +190,7 @@ public final class XWT extends JS {
     public static final JSMath xwtMath = new JSMath() {
             private JS gs = new JSScope.Global();
             public String toString() { return "XWTMATH"; }
-            public Object get(Object key) {
+            public Object get(Object key) throws JSExn {
                 //#switch(key)
                 case "isNaN": return gs.get("isNaN");
                 case "isFinite": return gs.get("isFinite");
@@ -204,7 +204,7 @@ public final class XWT extends JS {
     public static final JS xwtString = new JS() {
             private JS gs = new JSScope.Global();
             public void put(Object key, Object val) { }
-            public Object get(Object key) {
+            public Object get(Object key) throws JSExn {
                 //#switch(key)
                 case "parseInt": return gs.get("parseInt");
                 case "parseFloat": return gs.get("parseFloat");
@@ -224,31 +224,43 @@ public final class XWT extends JS {
         Vector obStack = new Vector();
         public XMLHelper() { super(BUFFER_SIZE); }
         public void startElement(XML.Element c) throws XML.SchemaException {
-            JS o = new JS();
-            o.put("$name", c.localName);
-            for(int i=0; i<c.len; i++) o.put(c.keys[i], c.vals[i]);
-            o.put("$numchildren", new Integer(0));
-            obStack.addElement(o);
+            try {
+                JS o = new JS();
+                o.put("$name", c.localName);
+                for(int i=0; i<c.len; i++) o.put(c.keys[i], c.vals[i]);
+                o.put("$numchildren", new Integer(0));
+                obStack.addElement(o);
+            } catch (JSExn jse) {
+                throw new Error("this should never happen");
+            }
         }
         public void endElement(XML.Element c) throws XML.SchemaException {
-            if (obStack.size() == 1) return;
-            JS me = (JS)obStack.lastElement();
-            obStack.setSize(obStack.size() - 1);
-            JS parent = (JS)obStack.lastElement();
-            int numchildren = ((Integer)parent.get("$numchildren")).intValue();
-            parent.put("$numchildren", new Integer(numchildren + 1));
-            parent.put(new Integer(numchildren), me);
+            try {
+                if (obStack.size() == 1) return;
+                JS me = (JS)obStack.lastElement();
+                obStack.setSize(obStack.size() - 1);
+                JS parent = (JS)obStack.lastElement();
+                int numchildren = ((Integer)parent.get("$numchildren")).intValue();
+                parent.put("$numchildren", new Integer(numchildren + 1));
+                parent.put(new Integer(numchildren), me);
+            } catch (JSExn jse) {
+                throw new Error("this should never happen");
+            }
         }
         public void characters(char[] ch, int start, int length) throws XML.SchemaException {
-            String s = new String(ch, start, length);
-            JS parent = (JS)obStack.lastElement();
-            int numchildren = ((Integer)parent.get("$numchildren")).intValue();
-            Object lastChild = parent.get(new Integer(numchildren - 1));
-            if (lastChild instanceof String) {
-                parent.put(new Integer(numchildren - 1), lastChild + s);
-            } else {
-                parent.put("$numchildren", new Integer(numchildren + 1));
-                parent.put(new Integer(numchildren), s);
+            try {
+                String s = new String(ch, start, length);
+                JS parent = (JS)obStack.lastElement();
+                int numchildren = ((Integer)parent.get("$numchildren")).intValue();
+                Object lastChild = parent.get(new Integer(numchildren - 1));
+                if (lastChild instanceof String) {
+                    parent.put(new Integer(numchildren - 1), lastChild + s);
+                } else {
+                    parent.put("$numchildren", new Integer(numchildren + 1));
+                    parent.put(new Integer(numchildren), s);
+                }
+            } catch (JSExn jse) {
+                throw new Error("this should never happen");
             }
         }
         public void whitespace(char[] ch, int start, int length) {}