[re]-merged in Brians stuff
[org.ibex.js.git] / src / org / ibex / js / XMLRPC.java
index 6f50328..6db685c 100644 (file)
@@ -38,8 +38,8 @@ public class XMLRPC extends JS {
     }
     public XMLRPC(String url, String method, XMLRPC httpSource) {
         this.http = httpSource.http; this.url = url; this.method = method; }
-    public Object get(Object name) {
-        return new XMLRPC(url, (method.equals("") ? "" : method + ".") + name.toString(), this); }
+    public JS get(JS name) throws JSExn {
+        return new XMLRPC(url, (method.equals("") ? "" : method + ".") + JS.toString(name), this); }
 
 
     /** this holds character content as we read it in -- since there is only one per instance, we don't support mixed content */
@@ -84,7 +84,7 @@ public class XMLRPC extends JS {
             content.reset();
             //#switch(c.getLocalName())
             case "fault": fault = true;
-            case "struct": objects.setElementAt(new JS(), objects.size() - 1);
+            case "struct": objects.setElementAt(new JS.O(), objects.size() - 1);
             case "array": objects.setElementAt(null, objects.size() - 1);
             case "value": objects.addElement("");
             //#end
@@ -129,8 +129,8 @@ public class XMLRPC extends JS {
                                     "the server sent a <dateTime.iso8601> tag which was malformed: " + s);
                 }
             case "member":
-                Object memberValue = objects.elementAt(objects.size() - 1);
-                String memberName = (String)objects.elementAt(objects.size() - 2);
+                JS memberValue = (JS)objects.elementAt(objects.size() - 1);
+                JS memberName = (JS)objects.elementAt(objects.size() - 2);
                 JS struct = (JS)objects.elementAt(objects.size() - 3);
                 try {
                     struct.put(memberName, memberValue);
@@ -143,7 +143,7 @@ public class XMLRPC extends JS {
                 for(i=objects.size() - 1; objects.elementAt(i) != null; i--);
                 JSArray arr = new JSArray();
                 try {
-                    for(int j = i + 1; j<objects.size(); j++) arr.put(new Integer(j - i - 1), objects.elementAt(j));
+                    for(int j = i + 1; j<objects.size(); j++) arr.put(JS.N(j - i - 1), (JS)objects.elementAt(j));
                 } catch (JSExn e) {
                     throw new Error("this should never happen");
                 }
@@ -272,7 +272,7 @@ public class XMLRPC extends JS {
 
         } else if (o instanceof JSArray) {
             if (tracker.get(o) != null) throw new JSExn("attempted to send multi-ref data structure via XML-RPC");
-            tracker.put(o, Boolean.TRUE);
+            tracker.put(o, JS.B(true));
             sb.append("                <value><array><data>\n");
             JSArray a = (JSArray)o;
             for(int i=0; i<a.length(); i++) appendObject(a.elementAt(i), sb);
@@ -280,14 +280,14 @@ public class XMLRPC extends JS {
 
         } else if (o instanceof JS) {
             if (tracker.get(o) != null) throw new JSExn("attempted to send multi-ref data structure via XML-RPC");
-            tracker.put(o, Boolean.TRUE);
+            tracker.put(o, JS.B(true));
             JS j = (JS)o;
             sb.append("                <value><struct>\n");
             Enumeration e = j.keys();
             while(e.hasMoreElements()) {
                 Object key = e.nextElement();
                 sb.append("                <member><name>" + key + "</name>\n");
-                appendObject(j.get(key), sb);
+                appendObject(j.get((JS)key), sb);
                 sb.append("                </member>\n");
             }
             sb.append("                </struct></value>\n");
@@ -302,7 +302,7 @@ public class XMLRPC extends JS {
     // Call Sequence //////////////////////////////////////////////////////////////////////////
 
     /* FIXME this has been disabled to make XMLRPC usable without Scheduler
-    public final Object call(Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn {
+    public final Object call(JS a0, JS a1, JS a2, JS[] rest, int nargs) throws JSExn {
         JSArray args = new JSArray();
         for(int i=0; i<nargs; i++) args.addElement(i==0?a0:i==1?a1:i==2?a2:rest[i-3]);
         return call(args);
@@ -331,7 +331,8 @@ public class XMLRPC extends JS {
             BufferedReader br = new BufferedReader(new InputStreamReader(is));
             try {
                 new Helper().parse(br);
-                final Object result = fault ? new JSExn(objects.elementAt(0)) : objects.size() == 0 ? null : objects.elementAt(0);
+               if (fault) throw new JSExn((JS)objects.elementAt(0));
+                final JS result = (objects.size() == 0 ? (JS)null : ((JS)objects.elementAt(0)));
                 return (new Task() { public void perform() throws JSExn { callback.unpause(result); }});
             } finally {
                 tracker.clear();
@@ -339,13 +340,13 @@ public class XMLRPC extends JS {
             }
         } catch (final JSExn e) {
             final Exception e2 = e;
-            return (new Task() { public void perform() throws JSExn { callback.unpause(e2); }});
+            return (new Task() { public void perform() throws JSExn { callback.unpause((JSExn)e2); }});
         } catch (final IOException e) {
             final Exception e2 = e;
-            return (new Task() { public void perform() throws JSExn { callback.unpause(new JSExn(e2)); }});
+            return (new Task() { public void perform() throws JSExn { callback.unpause(new JSExn(e2.getMessage())); }});
         } catch (final XML.Exn e) {
             final Exception e2 = e;
-            return (new Task() { public void perform() throws JSExn { callback.unpause(new JSExn(e2)); }});
+            return (new Task() { public void perform() throws JSExn { callback.unpause(new JSExn(e2.getMessage())); }});
         }
     }
 }