* convert.
* </ol>
*/
-class XMLRPC extends JSCallable {
+class XMLRPC extends JS {
/** the url to connect to */
protected String url = null;
* 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
+ * If a <struct> tag is encountered, a JSect is pushed
* onto the stack. If a <name> tag is encountered, its CDATA is
* pushed onto the stack. When a </member> is encountered, the
* name (second element on stack) and value (top of stack) are
public void startElement(XML.Element c) {
content.reset();
- if (c.localName.equals("fault")) fault = true;
- 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("");
+ //#switch(c.localName)
+ case "fault": fault = true;
+ case "struct": objects.setElementAt(new JS(), objects.size() - 1);
+ case "array": objects.setElementAt(null, objects.size() - 1);
+ case "value": objects.addElement("");
+ //#end
}
public void endElement(XML.Element c) {
-
- if (c.localName.equals("int") || c.localName.equals("i4"))
- objects.setElementAt(new Integer(new String(content.getBuf(), 0, content.size())), objects.size() - 1);
-
- else if (c.localName.equals("boolean"))
- objects.setElementAt(content.getBuf()[0] == '1' ? Boolean.TRUE : Boolean.FALSE, objects.size() - 1);
-
- else if (c.localName.equals("string"))
+ //#switch(c.localName)
+ case "int": objects.setElementAt(new Integer(new String(content.getBuf(), 0, content.size())), objects.size() - 1);
+ case "i4": objects.setElementAt(new Integer(new String(content.getBuf(), 0, content.size())), objects.size() - 1);
+ case "boolean": objects.setElementAt(content.getBuf()[0] == '1' ? Boolean.TRUE : Boolean.FALSE, objects.size() - 1);
+ case "string": objects.setElementAt(new String(content.getBuf(), 0, content.size()), objects.size() - 1);
+ case "double": objects.setElementAt(new Double(new String(content.getBuf(), 0, content.size())), objects.size() - 1);
+ case "base64": objects.setElementAt(new Res.ByteArray(Base64.decode(new String(content.getBuf(), 0, content.size())),
+ null), objects.size() - 1);
+ case "name": objects.addElement(new String(content.getBuf(), 0, content.size()));
+ case "value": if ("".equals(objects.lastElement()))
objects.setElementAt(new String(content.getBuf(), 0, content.size()), objects.size() - 1);
-
- else if (c.localName.equals("double"))
- objects.setElementAt(new Double(new String(content.getBuf(), 0, content.size())), objects.size() - 1);
-
- else if (c.localName.equals("base64"))
- objects.setElementAt(new Res.ByteArray(Base64.decode(new String(content.getBuf(), 0, content.size())), null), objects.size() - 1);
-
- else if (c.localName.equals("name"))
- objects.addElement(new String(content.getBuf(), 0, content.size()));
-
- else if (c.localName.equals("value") && "".equals(objects.lastElement()))
- objects.setElementAt(new String(content.getBuf(), 0, content.size()), objects.size() - 1);
-
- else if (c.localName.equals("dateTime.iso8601")) {
+ case "dateTime.iso8601":
String s = new String(content.getBuf(), 0, content.size());
// strip whitespace
Double.valueOf(s.substring(15, 17)).doubleValue(),
(double)0
);
- nd.jsJSFunction_setTime(JSDate.internalUTC(date));
+ nd.setTime(JSDate.internalUTC(date));
objects.setElementAt(nd, objects.size() - 1);
} catch (Exception e) {
if (Log.on) Log.log(this, "error parsing date : " + s);
if (Log.on) Log.log(this, e);
}
-
- } else if (c.localName.equals("member")) {
+ case "member":
Object memberValue = objects.elementAt(objects.size() - 1);
String memberName = (String)objects.elementAt(objects.size() - 2);
JS struct = (JS)objects.elementAt(objects.size() - 3);
struct.put(memberName, memberValue);
objects.setSize(objects.size() - 2);
-
- } else if (c.localName.equals("data")) {
+ case "data":
int i;
for(i=objects.size() - 1; objects.elementAt(i) != null; i--);
JSArray arr = new JSArray();
for(int j = i + 1; j<objects.size(); j++) arr.put(new Integer(j - i - 1), objects.elementAt(j));
objects.setElementAt(arr, i);
objects.setSize(i + 1);
-
- }
-
+ //#end
content.reset();
}
// Methods to make outbound XML-RPC request ///////////////////////////////////////////////////
/** Appends the XML-RPC representation of <code>o</code> to <code>sb</code> */
- void appendObject(Object o, StringBuffer sb) throws JS.Exn {
+ void appendObject(Object o, StringBuffer sb) throws JSExn {
if (o == null) {
- throw new JS.Exn("attempted to send a null value via XML-RPC");
+ throw new JSExn("attempted to send a null value via XML-RPC");
} else if (o instanceof Number) {
if ((double)((Number)o).intValue() == ((Number)o).doubleValue()) {
} catch (IOException e) {
if (Log.on) Log.log(this, "caught IOException while attempting to send a ByteStream via XML-RPC");
if (Log.on) Log.log(this, e);
- throw new JS.Exn("caught IOException while attempting to send a ByteStream via XML-RPC");
+ throw new JSExn("caught IOException while attempting to send a ByteStream via XML-RPC");
}
} else if (o instanceof String) {
sb.append("</dateTime.iso8601></value>\n");
} else if (o instanceof JSArray) {
- if (tracker.get(o) != null) throw new JS.Exn("attempted to send multi-ref data structure via XML-RPC");
+ if (tracker.get(o) != null) throw new JSExn("attempted to send multi-ref data structure via XML-RPC");
tracker.put(o, Boolean.TRUE);
sb.append(" <value><array><data>\n");
JSArray a = (JSArray)o;
sb.append(" </data></array></value>\n");
} else if (o instanceof JS) {
- if (tracker.get(o) != null) throw new JS.Exn("attempted to send multi-ref data structure via XML-RPC");
+ if (tracker.get(o) != null) throw new JSExn("attempted to send multi-ref data structure via XML-RPC");
tracker.put(o, Boolean.TRUE);
JS j = (JS)o;
sb.append(" <value><struct>\n");
sb.append(" </struct></value>\n");
} else {
- throw new JS.Exn("attempt to send object of type " + o.getClass().getName() + " via XML-RPC");
+ throw new JSExn("attempt to send object of type " + o.getClass().getName() + " via XML-RPC");
}
}
- public Object call_(JSArray args) throws JS.Exn, IOException {
+ public Object call_(JSArray args) throws JSExn, IOException {
if (Log.verbose) Log.log(this, "call to " + url + " : " + methodname);
if (tracker == null) tracker = new Hash();
}
}
- protected String send(JSArray args, HTTP http) throws JS.Exn, IOException {
+ protected String send(JSArray args, HTTP http) throws JSExn, IOException {
StringBuffer content = new StringBuffer();
content.append("\r\n");
content.append("<?xml version=\"1.0\"?>\n");
return content.toString();
}
- protected Object recieve(BufferedReader br) throws JS.Exn, IOException {
+ protected Object recieve(BufferedReader br) throws JSExn, IOException {
// parse XML reply
try {
new Helper().parse(br);
} catch (XML.XMLException e) {
if (Log.on) Log.log(this, "reply from server was not well-formed XML: " + e);
- throw new JS.Exn("reply from server was not well-formed XML: " + e);
+ throw new JSExn("reply from server was not well-formed XML: " + e);
}
- if (fault) throw new JS.Exn(objects.elementAt(0));
+ if (fault) throw new JSExn(objects.elementAt(0));
if (objects.size() == 0) return null;
return objects.elementAt(0);
}
- 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;
+ public final Object call(Object a0, Object a1, Object a2, Object[] 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);
+ }
+ public final Object call(final JSArray args) throws JSExn {
+ try {
+ final JS.UnpauseCallback callback = JS.pause();
+ new java.lang.Thread() {
+ public void run() {
+ try {
+ final Object ret = call_(args);
+ Scheduler.add(new Scheduler.Task() {
+ public void perform() {
+ try {
+ callback.unpause(null);
+ } catch (JS.PausedException pe) {
+ // okay
+ }
+ }
+ });
+ } catch (IOException se) {
+ if (Log.on) Log.log(this, se);
+ throw new JSExn("socket exception: " + se);
+ }
+ } }.start();
+ return null;
+ } catch (NotPauseableException npe) {
+ throw new JSExn("cannot invoke an XML-RPC call in the foreground thread");
+ }
}
/** When you get a property from an XMLRPC, it just returns another XMLRPC with the property name tacked onto methodname. */