1 25 package com.scalagent.ksoap.marshal; 26 27 import java.io.*; 28 import org.kxml.parser.*; 29 import com.scalagent.ksoap.*; 30 31 public class MarshalDefault implements Marshal { 32 33 public Object readInstance(SoapReader reader, 34 String namespace, 35 String name, 36 PropertyInfo expected) throws IOException { 37 if (KSoapTracing.dbg) 38 KSoapTracing.log(KSoapTracing.DEBUG, 39 "MarshalDefault.readInstance(" + reader + "," + 40 namespace + "," + 41 name + "," + 42 expected + ")"); 43 44 reader.parser.read(); 45 String text = reader.parser.readText(); 46 reader.parser.read(); 47 switch (name.charAt(0)) { 48 case 's': return text; 49 case 'i': return new Integer (Integer.parseInt(text)); 50 case 'l': return new Long (Long.parseLong(text)); 51 case 'b': return new Boolean (stringToBoolean(text)); 52 default: 53 KSoapTracing.log(KSoapTracing.ERROR, 54 "MarshalDefault.readInstance(...) EXCEPTION"); 55 throw new RuntimeException (); 56 } 57 } 58 59 public void writeInstance(SoapWriter writer, 60 Object instance) throws IOException { 61 if (KSoapTracing.dbg) 62 KSoapTracing.log(KSoapTracing.DEBUG, 63 "MarshalDefault.writeInstance(" + writer + 64 "," + instance + ")"); 65 writer.writer.write(instance.toString()); 66 } 67 68 public void register(ClassMap cm) { 69 cm.addMapping(cm.xsd,"int",ClassMap.INTEGER_CLASS,this); 70 cm.addMapping(cm.xsd,"long",ClassMap.LONG_CLASS,this); 71 cm.addMapping(cm.xsd,"string",ClassMap.STRING_CLASS,this); 72 cm.addMapping(cm.xsd,"boolean",ClassMap.BOOLEAN_CLASS,this); 73 } 74 75 static boolean stringToBoolean(String s) { 76 if (s == null) return false; 77 s = s.trim().toLowerCase(); 78 return (s.equals("1") || s.equals("true")); 79 } 80 } 81 | Popular Tags |