1 25 package com.scalagent.ksoap; 26 27 import java.io.*; 28 import java.util.*; 29 30 import org.kxml.*; 31 import org.kxml.io.*; 32 33 import com.scalagent.ksoap.marshal.Marshal; 34 35 public class SoapWriter { 36 37 public AbstractXmlWriter writer; 38 public ClassMap classMap; 39 40 public SoapWriter(AbstractXmlWriter writer, 41 ClassMap classMap) { 42 this.writer = writer; 43 this.classMap = classMap; 44 } 45 46 public void write(SoapObject obj) throws IOException { 47 if (KSoapTracing.dbgWriter) 48 KSoapTracing.log(KSoapTracing.DEBUG,"SoapWriter.write(" + obj + ")"); 49 50 writer.startTag(classMap.prefixMap, 51 obj.getNamespace(), 52 obj.getName()); 53 54 if (KSoapTracing.dbgWriter) 55 KSoapTracing.log(KSoapTracing.DEBUG,"SoapWriter.write : nameSpace=" + 56 obj.getNamespace() + ", action=" + obj.getName()); 57 writer.attribute("id","o0"); 58 writer.attribute(classMap.enc,"root","1"); 59 writeObjectBody(obj); 60 writer.endTag(); 61 } 62 63 public void writeObjectBody(SoapObject obj) throws IOException { 64 if (KSoapTracing.dbgWriter) 65 KSoapTracing.log(KSoapTracing.DEBUG,"SoapWriter.writeObjectBody(" + obj + ")"); 66 PropertyInfo info = null; 67 int cnt = obj.getPropertyCount(); 68 for (int i = 0; i < cnt; i++) { 69 info = obj.getPropertyInfo(i); 70 if (info != null) { 71 writer.startTag(info.name); 72 writeProperty(obj.getProperty(i),info); 73 writer.endTag(); 74 } 75 } 76 } 77 78 public void writeProperty(Object obj, 79 PropertyInfo propertyInfo) throws IOException { 80 if (KSoapTracing.dbgWriter) 81 KSoapTracing.log(KSoapTracing.DEBUG,"SoapWriter.writeProperty(" + obj + 82 "," + propertyInfo + ")"); 83 if (obj == null) { 84 writer.attribute(classMap.xsi,"null","true"); 85 return; 86 } 87 88 if (obj instanceof SoapObject) 89 writeObjectBody((SoapObject) obj); 90 else { 91 SoapPrimitive sp = ClassMap.getSoapPrimitive(obj.getClass().getName()); 92 if (sp != null) { 93 Marshal marshal = sp.getMarshal(); 94 if (marshal != null) { 95 String prefix = writer.getPrefixMap().getPrefix(sp.getNameSpace()); 96 writer.attribute(classMap.xsi,"type",prefix+":"+sp.getName()); 97 marshal.writeInstance(this,obj); 98 } else { 99 KSoapTracing.log(KSoapTracing.ERROR, 100 "can't writeProperty (undefined)."); 101 throw new IOException("can't writeProperty (undefined)."); 102 } 103 } 104 } 105 } 106 } 107 | Popular Tags |