import java.io.*;
import java.net.*;
import java.util.*;
-import org.mozilla.javascript.*;
+import org.xwt.js.*;
import org.xwt.util.*;
import org.bouncycastle.util.encoders.Base64;
String nameSpace = null;
/** When you get a property from an SOAP, it just returns another SOAP with the property name tacked onto methodname. */
- public Object get(String name, Scriptable start) {
+ public Object get(String name) {
return new SOAP(url.toString(), (methodname.equals("") ? "" : methodname + ".") + name, http, action, nameSpace);
}
if (name.equals("SOAP-ENV:Fault")) fault = true;
// add a generic struct; we'll change this if our type is different
- objects.addElement(new JSObject(false));
+ objects.addElement(new JS.Obj());
for(int i=0; i<keys.length; i++) {
String key = keys[i];
objects.addElement(null);
} else if (value.endsWith("arrayType") || value.endsWith("Array") || key.endsWith("arrayType")) {
objects.removeElementAt(objects.size() - 1);
- objects.addElement(Context.enter().newArray(org.xwt.util.JSObject.defaultObjects, new Object[] { } ));
+ objects.addElement(new Array());
}
}
}
if (objects.size() < 2) return;
// our parent "should" be an aggregate type -- add ourselves to it.
- if (parent != null && parent instanceof NativeArray) {
+ if (parent != null && parent instanceof Array) {
objects.removeElementAt(objects.size() - 1);
- ((NativeArray)parent).put((int)((NativeArray)parent).jsGet_length(), (NativeArray)parent, me);
+ ((Array)parent).addElement(me);
- } else if (parent != null && parent instanceof Scriptable) {
+ } else if (parent != null && parent instanceof JS) {
objects.removeElementAt(objects.size() - 1);
- ((Scriptable)parent).put(name, (Scriptable)parent, me);
+ ((JS)parent).put(name, me);
}
}
/** Appends the SOAP representation of <code>o</code> to <code>sb</code> */
- void appendObject(String name, Object o, StringBuffer sb) throws JavaScriptException {
+ void appendObject(String name, Object o, StringBuffer sb) throws JS.Exn {
if (o instanceof Number) {
if ((double)((Number)o).intValue() == ((Number)o).doubleValue()) {
sb.append(" <" + name + " xsi:type=\"xsd:int\">");
sb.append(((Number)o).intValue());
- sb.append("</" + name + ">\n");
+ sb.append("</" + name + ">\r\n");
} else {
sb.append(" <" + name + " xsi:type=\"xsd:double\">");
sb.append(o);
- sb.append("</" + name + ">\n");
+ sb.append("</" + name + ">\r\n");
}
} else if (o instanceof Boolean) {
sb.append(" <" + name + " xsi:type=\"xsd:boolean\">");
sb.append(((Boolean)o).booleanValue() ? "true" : "false");
- sb.append("</" + name + ">\n");
+ sb.append("</" + name + ">\r\n");
} else if (o instanceof ByteStream) {
try {
- sb.append(" <" + name + " xsi:type=\"SOAP-ENC:base64\">\n");
+ sb.append(" <" + name + " xsi:type=\"SOAP-ENC:base64\">\r\n");
InputStream is = ((ByteStream)o).getInputStream();
byte[] buf = new byte[54];
while(true) {
}
sb.append(" ");
sb.append(new String(Base64.encode(writebuf)));
- sb.append("\n");
+ sb.append("\r\n");
}
sb.append(((Boolean)o).booleanValue() ? "1" : "0");
- sb.append("</" + name + ">\n");
+ sb.append("</" + name + ">\r\n");
} catch (IOException e) {
if (Log.on) Log.log(this, "caught IOException while attempting to send a ByteStream via SOAP");
if (Log.on) Log.log(this, e);
- throw new JavaScriptException("caught IOException while attempting to send a ByteStream via SOAP");
+ throw new JS.Exn("caught IOException while attempting to send a ByteStream via SOAP");
}
} else if (o instanceof String) {
i = oldi = i + 1;
}
}
- sb.append("</" + name + ">\n");
+ sb.append("</" + name + ">\r\n");
- } else if (o instanceof NativeArray) {
- NativeArray na = (NativeArray)o;
- sb.append(" <" + name + " SOAP-ENC:arrayType=\"xsd:ur-type[" + na.jsGet_length() + "]\">");
- for(int i=0; i<na.jsGet_length(); i++)
- appendObject("item", na.get(i, na), sb);
- sb.append("</" + name + ">\n");
+ } else if (o instanceof Array) {
+ Array a = (Array)o;
+ sb.append(" <" + name + " SOAP-ENC:arrayType=\"xsd:ur-type[" + a.length() + "]\">");
+ for(int i=0; i<a.length(); i++) appendObject("item", a.elementAt(i), sb);
+ sb.append("</" + name + ">\r\n");
- } else if (o instanceof Scriptable && !(o instanceof Undefined)) {
- Scriptable s = (Scriptable)o;
+ } else if (o instanceof JS) {
+ JS j = (JS)o;
sb.append(" <" + name + ">");
- Object[] ids = s.getIds();
- for(int i=0; i<ids.length; i++)
- appendObject(ids[i].toString(), s.get(ids[i].toString(), s), sb);
- sb.append("</" + name + ">\n");
+ Object[] ids = j.keys();
+ for(int i=0; i<ids.length; i++) appendObject(ids[i].toString(), j.get(ids[i].toString()), sb);
+ sb.append("</" + name + ">\r\n");
}
}
- protected String send(Object[] args, HTTP http) throws JavaScriptException, IOException {
+ protected String send(Array args, HTTP http) throws JS.Exn, IOException {
// build up the request
StringBuffer content = new StringBuffer();
content.append("SOAPAction: " + action + "\r\n\r\n");
- content.append("<?xml version=\"1.0\"?>\n");
- content.append("<SOAP-ENV:Envelope SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"\n");
- content.append(" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\"\n");
- content.append(" xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"\n");
- content.append(" xmlns:xsd=\"http://www.w3.org/1999/XMLSchema\"\n");
- content.append(" xmlns:xsi=\"http://www.w3.org/1999/XMLSchema-instance\">\n");
- content.append("<SOAP-ENV:Body>\n");
+ content.append("<?xml version=\"1.0\"?>\r\n");
+ content.append("<SOAP-ENV:Envelope SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"\r\n");
+ content.append(" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\"\r\n");
+ content.append(" xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"\r\n");
+ content.append(" xmlns:xsd=\"http://www.w3.org/1999/XMLSchema\"\r\n");
+ content.append(" xmlns:xsi=\"http://www.w3.org/1999/XMLSchema-instance\">\r\n");
+ content.append("<SOAP-ENV:Body>\r\n");
content.append(" <");
content.append(methodname);
content.append(nameSpace != null ? " xmlns=\"" + nameSpace + "\"" : "");
- content.append(">\n");
- if (args.length > 0) {
- Object[] o = ((Scriptable)args[0]).getIds();
+ content.append(">\r\n");
+ if (args.length() > 0) {
+ Object[] o = ((JS)args.elementAt(0)).keys();
for(int i=0; i<o.length; i++)
- appendObject(o[i].toString(), ((Scriptable)args[0]).get(o[i].toString(), (Scriptable)args[0]), content);
+ appendObject(o[i].toString(), ((JS)args.elementAt(0)).get(o[i].toString()), content);
}
- content.append(" </" + methodname + "></SOAP-ENV:Body></SOAP-ENV:Envelope>");
+ content.append(" </" + methodname + "></SOAP-ENV:Body></SOAP-ENV:Envelope>\r\n");
return content.toString();
}