X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2FXMLRPC.java;h=8368bf74a7129b37d866ea5b0f110a924131ffd9;hb=67eeff476179a91ae930ea89cbecde22132ca532;hp=e32f569de4fe6bdd6ee32aba00fcd889d8e14b75;hpb=9d07963a45f2147a62d8897e9c4245c224d98ccb;p=org.ibex.core.git diff --git a/src/org/xwt/XMLRPC.java b/src/org/xwt/XMLRPC.java index e32f569..8368bf7 100644 --- a/src/org/xwt/XMLRPC.java +++ b/src/org/xwt/XMLRPC.java @@ -30,9 +30,7 @@ import org.bouncycastle.util.encoders.Base64; * convert. * */ -class XMLRPC extends JS.Callable { - - public Object[] keys() { throw new Error("not implemented"); } +class XMLRPC extends JSCallable { /** the url to connect to */ protected String url = null; @@ -57,7 +55,7 @@ class XMLRPC extends JS.Callable { * * If an <array> tag is encountered, a null is pushed onto the * stack. When a </data> is encountered, we search back on the - * stack to the last null, replace it with a NativeJS.Array, and + * stack to the last null, replace it with a NativeJSArray, and * insert into it all elements above it on the stack. * * If a <struct> tag is encountered, a JSObject is pushed @@ -84,7 +82,7 @@ class XMLRPC extends JS.Callable { public void startElement(XML.Element c) { content.reset(); if (c.localName.equals("fault")) fault = true; - else if (c.localName.equals("struct")) objects.setElementAt(new JS.Obj(), objects.size() - 1); + else if (c.localName.equals("struct")) objects.setElementAt(new JSObj(), objects.size() - 1); else if (c.localName.equals("array")) objects.setElementAt(null, objects.size() - 1); else if (c.localName.equals("value")) objects.addElement(""); } @@ -121,8 +119,8 @@ class XMLRPC extends JS.Callable { if (i > 0) s = s.substring(i); try { - org.xwt.js.Date nd = new org.xwt.js.Date(); - double date = org.xwt.js.Date.date_msecFromDate(Double.valueOf(s.substring(0, 4)).doubleValue(), + JSDate nd = new JSDate(); + double date = JSDate.date_msecFromDate(Double.valueOf(s.substring(0, 4)).doubleValue(), Double.valueOf(s.substring(4, 6)).doubleValue() - 1, Double.valueOf(s.substring(6, 8)).doubleValue(), Double.valueOf(s.substring(9, 11)).doubleValue(), @@ -130,7 +128,7 @@ class XMLRPC extends JS.Callable { Double.valueOf(s.substring(15, 17)).doubleValue(), (double)0 ); - nd.jsFunction_setTime(org.xwt.js.Date.internalUTC(date)); + nd.jsJSFunction_setTime(JSDate.internalUTC(date)); objects.setElementAt(nd, objects.size() - 1); } catch (Exception e) { @@ -148,7 +146,7 @@ class XMLRPC extends JS.Callable { } else if (c.localName.equals("data")) { int i; for(i=objects.size() - 1; objects.elementAt(i) != null; i--); - JS.Array arr = new JS.Array(); + JSArray arr = new JSArray(); for(int j = i + 1; j\n"); - } else if (o instanceof org.xwt.js.Date) { + } else if (o instanceof JSDate) { sb.append(" "); - java.util.Date d = new java.util.Date(((org.xwt.js.Date)o).getRawTime()); + java.util.Date d = new java.util.Date(((JSDate)o).getRawTime()); sb.append(d.getYear() + 1900); if (d.getMonth() + 1 < 10) sb.append('0'); sb.append(d.getMonth() + 1); @@ -256,11 +254,11 @@ class XMLRPC extends JS.Callable { sb.append(d.getSeconds()); sb.append("\n"); - } else if (o instanceof JS.Array) { + } else if (o instanceof JSArray) { if (tracker.get(o) != null) throw new JS.Exn("attempted to send multi-ref data structure via XML-RPC"); tracker.put(o, Boolean.TRUE); sb.append(" \n"); - JS.Array a = (JS.Array)o; + JSArray a = (JSArray)o; for(int i=0; i\n"); @@ -269,10 +267,11 @@ class XMLRPC extends JS.Callable { tracker.put(o, Boolean.TRUE); JS j = (JS)o; sb.append(" \n"); - Object[] ids = j.keys(); - for(int i=0; i" + ids[i] + "\n"); - appendObject(j.get(ids[i].toString()), sb); + Enumeration e = j.keys(); + while(e.hasMoreElements()) { + Object key = e.nextElement(); + sb.append(" " + key + "\n"); + appendObject(j.get(key), sb); sb.append(" \n"); } sb.append(" \n"); @@ -283,9 +282,7 @@ class XMLRPC extends JS.Callable { } } - // this is synchronized in case multiple threads try to make a call on the same object... in the future, change this - // behavior to use pipelining. - public synchronized Object call2(JS.Array args) throws JS.Exn, IOException { + public Object call_(JSArray args) throws JS.Exn, IOException { if (Log.verbose) Log.log(this, "call to " + url + " : " + methodname); if (tracker == null) tracker = new Hash(); @@ -294,7 +291,7 @@ class XMLRPC extends JS.Callable { if (objects == null) objects = new Vec(); else objects.setSize(0); - String content = send(args, http); + final String content = send(args, http); if (Log.verbose) { String s; BufferedReader br2 = new BufferedReader(new StringReader(content)); @@ -320,13 +317,13 @@ class XMLRPC extends JS.Callable { return ret; } }); - return recieve(br); + return null; } finally { is.close(); } } - protected String send(JS.Array args, HTTP http) throws JS.Exn, IOException { + protected String send(JSArray args, HTTP http) throws JS.Exn, IOException { StringBuffer content = new StringBuffer(); content.append("\r\n"); content.append("\n"); @@ -359,19 +356,19 @@ class XMLRPC extends JS.Callable { return objects.elementAt(0); } - public final Object call(final JS.Array args) throws JS.Exn { - final JS.Context cx = JS.Context.current(); - Scheduler.add(new Scheduler.Task() { public void perform() { - Object ret; - try { - ret = call2(args); - } catch (IOException se) { - if (Log.on) Log.log(this, se); - throw new JS.Exn("socket exception: " + se); - } - cx.resume(ret); - } }); - return JS.Context.pause; + public final Object call(final JSArray args) throws JS.Exn { + final Callback callback = JSContext.pause(); + new java.lang.Thread() { + public void run() { + try { + final Object ret = call_(args); + Scheduler.add(new Scheduler.Task() { public void perform() { callback.call(ret); } }); + } catch (IOException se) { + if (Log.on) Log.log(this, se); + throw new JS.Exn("socket exception: " + se); + } + } }.start(); + return null; } /** When you get a property from an XMLRPC, it just returns another XMLRPC with the property name tacked onto methodname. */