2003/12/22 02:32:04
[org.ibex.core.git] / src / org / xwt / SOAP.java
index 5b969b4..190d8b4 100644 (file)
@@ -29,7 +29,7 @@ class SOAP extends XMLRPC {
 
     /** 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) {
-        return new SOAP(url.toString(), (methodname.equals("") ? "" : methodname + ".") + name, http, action, nameSpace);
+        return new SOAP(url.toString(), (method.equals("") ? "" : method + ".") + name, http, action, nameSpace);
     }
 
 
@@ -41,9 +41,9 @@ class SOAP extends XMLRPC {
         if (name.equals("SOAP-ENV:Envelope")) return;
         if (name.equals("SOAP-ENV:Body")) return;
         if (name.equals("SOAP-ENV:Fault")) fault = true;
-
         // add a generic struct; we'll change this if our type is different
-        objects.addElement(new JS.Obj());
+        objects.addElement(new JS());
 
         for(int i=0; i<keys.length; i++) {
             String key = keys[i];
@@ -67,9 +67,9 @@ class SOAP extends XMLRPC {
                 } else if (value.endsWith("null")) {
                     objects.removeElementAt(objects.size() - 1);
                     objects.addElement(null);
-                } else if (value.endsWith("arrayType") || value.endsWith("JS.Array") || key.endsWith("arrayType")) {
+                } else if (value.endsWith("arrayType") || value.endsWith("JSArray") || key.endsWith("arrayType")) {
                     objects.removeElementAt(objects.size() - 1);
-                    objects.addElement(new JS.Array());
+                    objects.addElement(new JSArray());
                 }
             }
         }
@@ -90,13 +90,11 @@ class SOAP extends XMLRPC {
                 objects.addElement(new String(content.getBuf(), 0, content.size()).intern());
                 content.reset();
 
-                // FIXME
-                /*
             } else if (me instanceof byte[]) {
                 objects.removeElementAt(objects.size() - 1);
-                objects.addElement(new ByteStream(Base64.decode(new String(content.getBuf(), 0, content.size()))));
+                objects.addElement(new Res.ByteArray(Base64.decode(new String(content.getBuf(), 0, content.size())), null));
                 content.reset();                
-                */
+
             } else if (me instanceof Integer) {
                 objects.removeElementAt(objects.size() - 1);
                 objects.addElement(new Integer(new String(content.getBuf(), 0, content.size())));
@@ -149,20 +147,24 @@ class SOAP extends XMLRPC {
         if (objects.size() < 2) return;
 
         // our parent "should" be an aggregate type -- add ourselves to it.
-        if (parent != null && parent instanceof JS.Array) {
+        if (parent != null && parent instanceof JSArray) {
             objects.removeElementAt(objects.size() - 1);
-            ((JS.Array)parent).addElement(me);
+            ((JSArray)parent).addElement(me);
 
         } else if (parent != null && parent instanceof JS) {
             objects.removeElementAt(objects.size() - 1);
-            ((JS)parent).put(name, me);
+            try {
+                ((JS)parent).put(name, me);
+            } catch (JSExn e) {
+                throw new Error("this should never happen");
+            }
 
         }
 
     }
 
     /** Appends the SOAP representation of <code>o</code> to <code>sb</code> */
-    void appendObject(String name, Object o, StringBuffer sb) throws JS.Exn {
+    void appendObject(String name, Object o, StringBuffer sb) throws JSExn {
         if (o instanceof Number) {
             if ((double)((Number)o).intValue() == ((Number)o).doubleValue()) {
                 sb.append("                <" + name + " xsi:type=\"xsd:int\">");
@@ -179,11 +181,10 @@ class SOAP extends XMLRPC {
             sb.append(((Boolean)o).booleanValue() ? "true" : "false");
             sb.append("</" + name + ">\r\n");
 
-            /* FIXME
-        } else if (o instanceof ByteStream) {
+        } else if (o instanceof Res) {
             try {
                 sb.append("                <" + name + " xsi:type=\"SOAP-ENC:base64\">\r\n");
-                InputStream is = ((ByteStream)o).getInputStream();
+                InputStream is = ((Res)o).getInputStream();
                 byte[] buf = new byte[54];
                 while(true) {
                     int numread = is.read(buf, 0, 54);
@@ -202,9 +203,9 @@ class SOAP extends XMLRPC {
             } 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 JS.Exn("caught IOException while attempting to send a ByteStream via SOAP");
+                throw new JSExn("caught IOException while attempting to send a ByteStream via SOAP");
             }
-            */
+
         } else if (o instanceof String) {
             sb.append("                <" + name + " xsi:type=\"xsd:string\">");
             String s = (String)o;
@@ -224,8 +225,8 @@ class SOAP extends XMLRPC {
             }
             sb.append("</" + name + ">\r\n");
 
-        } else if (o instanceof JS.Array) {
-            JS.Array a = (JS.Array)o;
+        } else if (o instanceof JSArray) {
+            JSArray a = (JSArray)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");
@@ -233,13 +234,17 @@ class SOAP extends XMLRPC {
         } else if (o instanceof JS) {
             JS j = (JS)o;
             sb.append("                <" + name + ">");
-            Object[] ids = j.keys();
-            for(int i=0; i<ids.length; i++) appendObject(ids[i].toString(), j.get(ids[i].toString()), sb);
+            Enumeration e = j.keys();
+            while(e.hasMoreElements()) {
+                Object key = e.nextElement();
+                appendObject((String)key, j.get(key), sb);
+            }
             sb.append("</" + name + ">\r\n");
+
         }
     }
 
-    protected String send(JS.Array args, HTTP http) throws JS.Exn, IOException {
+    protected String buildRequest(JSArray args) throws JSExn, IOException {
         // build up the request
         StringBuffer content = new StringBuffer();
         content.append("SOAPAction: " + action + "\r\n\r\n");
@@ -251,19 +256,23 @@ class SOAP extends XMLRPC {
         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(method);
         content.append(nameSpace != null ? " xmlns=\"" + nameSpace + "\"" : "");
         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(), ((JS)args.elementAt(0)).get(o[i].toString()), content);
+            Enumeration e = ((JS)args.elementAt(0)).keys();
+            while(e.hasMoreElements()) {
+                Object key = e.nextElement();
+                appendObject((String)key, ((JS)args.elementAt(0)).get(key), content);
+            }
         }
-        content.append("    </" + methodname + "></SOAP-ENV:Body></SOAP-ENV:Envelope>\r\n");
+        content.append("    </" + method + "></SOAP-ENV:Body></SOAP-ENV:Envelope>\r\n");
         return content.toString();
     }
 
-    SOAP(String url, String methodname, String action, String nameSpace) { this(url, methodname, new HTTP(url), action, nameSpace); }
+    SOAP(String url, String methodname, String action, String nameSpace) {
+        this(url, methodname, new HTTP(url), action, nameSpace);
+    }
     SOAP(String url, String methodname, HTTP http, String action, String nameSpace) {
         super(url, methodname, http);
         this.action = action;