1 25 package com.scalagent.ksoap; 26 27 import java.io.*; 28 29 import org.kxml.*; 30 import org.kxml.io.*; 31 import org.kxml.parser.*; 32 33 import com.scalagent.ksoap.marshal.*; 34 35 public class SoapEnvelope { 36 37 Object body; 38 ClassMap classMap; 39 String encodingStyle; 40 41 public SoapEnvelope() { 42 classMap = new ClassMap(); 43 new MarshalBase64().register(classMap); 44 new MarshalHashtable().register(classMap); 45 new MarshalVector().register(classMap); 46 } 47 48 public void setEncodingStyle(String encodingStyle) { 49 this.encodingStyle = encodingStyle; 50 } 51 52 public void setBody(SoapObject body) { 53 this.body = body; 54 } 55 56 public Object getBody() { 57 return body; 58 } 59 60 public void read(AbstractXmlParser parser) throws IOException { 61 if (KSoapTracing.dbgReader) 62 KSoapTracing.log(KSoapTracing.DEBUG, 63 "SoapEnvelope.read(" + parser + ")"); 64 65 readHead(parser); 66 readBody(parser); 67 readTail(parser); 68 } 69 70 public void readHead(AbstractXmlParser parser) throws IOException { 71 if (KSoapTracing.dbgReader) 72 KSoapTracing.log(KSoapTracing.DEBUG, 73 "SoapEnvelope.readHead(" + parser + ")"); 74 75 parser.skip(); 76 StartTag tag = null; 77 Attribute attr = null; 78 try { 79 tag = (StartTag) parser.read(Xml.START_TAG, classMap.env,"Envelope"); 80 attr = tag.getAttribute(classMap.env,"encodingStyle"); 81 } catch (ParseException exc) { 82 parser.read(); 85 parser.skip(); 86 tag = (StartTag) parser.read(Xml.START_TAG, classMap.env,"Envelope"); 87 attr = tag.getAttribute(classMap.env,"encodingStyle"); 88 } 89 if (attr != null) encodingStyle = attr.getValue(); 90 91 parser.skip(); 92 93 if (parser.peek(Xml.START_TAG,classMap.env,"Header")) { 94 parser.read(); 95 parser.skip(); 96 97 while (parser.peek().getType() != Xml.END_TAG) { 98 parser.ignoreTree(); 99 parser.skip(); 100 } 101 102 parser.read(Xml.END_TAG,classMap.env,"Header"); 103 } 104 105 parser.skip(); 106 tag = (StartTag) parser.read(Xml.START_TAG,classMap.env,"Body"); 107 attr = tag.getAttribute(classMap.env,"encodingStyle"); 108 if (attr != null) encodingStyle = attr.getValue(); 109 } 110 111 112 public void readBody(AbstractXmlParser parser) throws IOException { 113 if (KSoapTracing.dbgReader) 114 KSoapTracing.log(KSoapTracing.DEBUG, 115 "SoapEnvelope.readBody(" + parser + ")"); 116 117 parser.skip(); 118 119 if (parser.peek(Xml.START_TAG,classMap.env,"Fault")) { 120 SoapFault fault = new SoapFault(); 121 fault.parse(parser); 122 body = fault; 123 if (KSoapTracing.dbgReader) 124 KSoapTracing.log(KSoapTracing.DEBUG, 125 "SoapEnvelope.readBody : Fault = " + fault); 126 } else { 127 if (KSoapTracing.dbgReader) 128 KSoapTracing.log(KSoapTracing.DEBUG, 129 "SoapEnvelope.readBody befor SoapReader(...).read()"); 130 body = new SoapReader(parser,classMap).read(); 131 } 132 } 133 134 public void readTail(AbstractXmlParser parser) throws IOException { 135 if (KSoapTracing.dbgReader) 136 KSoapTracing.log(KSoapTracing.DEBUG, 137 "SoapEnvelope.readdTail(" + parser + ")"); 138 parser.skip(); 139 parser.read(Xml.END_TAG,classMap.env,"Body"); 140 parser.skip(); 141 parser.read(Xml.END_TAG,classMap.env,"Envelope"); 142 } 143 144 public void write(AbstractXmlWriter writer) throws IOException { 145 if (KSoapTracing.dbgWriter) 146 KSoapTracing.log(KSoapTracing.DEBUG, 147 "SoapEnvelope.write(" + writer + ")"); 148 writer.startTag(classMap.prefixMap,classMap.env,"Envelope"); 149 writer.startTag(classMap.env,"Body"); 150 writer.attribute(classMap.env,"encodingStyle", 151 encodingStyle == null ? classMap.enc : encodingStyle); 152 new SoapWriter(writer,classMap).write((SoapObject) body); 153 writer.endTag(); 154 writer.endTag(); 155 } 156 } 157 | Popular Tags |