1 25 package com.scalagent.ksoap; 26 27 import java.io.*; 28 import java.util.Vector ; 29 import java.util.Hashtable ; 30 import org.kxml.*; 31 import com.scalagent.ksoap.marshal.*; 32 33 34 public class ClassMap { 35 public static final Class OBJECT_CLASS = new Object ().getClass(); 36 public static final Class STRING_CLASS = "".getClass(); 37 public static final Class INTEGER_CLASS = new Integer (0).getClass(); 38 public static final Class LONG_CLASS = new Long (0).getClass(); 39 public static final Class BOOLEAN_CLASS = new Boolean (true).getClass(); 40 public static final Class VECTOR_CLASS = new java.util.Vector ().getClass(); 41 42 public static final String xsi = "http://www.w3.org/2001/XMLSchema-instance"; 43 public static final String xsd = "http://www.w3.org/2001/XMLSchema"; 44 public static final String env = "http://schemas.xmlsoap.org/soap/envelope/"; 45 public static final String enc = "http://schemas.xmlsoap.org/soap/encoding/"; 46 47 protected int cnt; 48 public PrefixMap prefixMap; 49 50 static final MarshalDefault DEFAULT_MARSHAL = new MarshalDefault(); 51 protected static Hashtable nameToClass = new Hashtable (); 52 protected static Hashtable classToName = new Hashtable (); 53 54 55 public ClassMap() { 56 PrefixMap basePrefixMap = new PrefixMap( 57 new PrefixMap(PrefixMap.DEFAULT,"SOAP-ENV",env), 58 "SOAP-ENC",enc); 59 prefixMap = new PrefixMap( 60 new PrefixMap(basePrefixMap,"xsd", xsd), 61 "xsi",xsi); 62 63 DEFAULT_MARSHAL.register(this); 64 } 65 66 public void addMapping(String namespace, String name, 67 Class clazz, Marshal marshal) { 68 SoapPrimitive sp = new SoapPrimitive(namespace,name,clazz,marshal); 69 nameToClass.put(sp,sp.getMarshal()); 70 classToName.put(clazz.getName(),sp); 71 if (prefixMap.getPrefix(namespace) == null) 72 prefixMap = new PrefixMap(prefixMap, "n"+(cnt++),namespace); 73 } 74 75 public static SoapPrimitive getSoapPrimitive(String className) { 76 if (KSoapTracing.dbg) 77 KSoapTracing.log(KSoapTracing.DEBUG, 78 "ClassMap.getSoapPrimitive(" + className + ")"); 79 return (SoapPrimitive) classToName.get(className); 80 } 81 82 public static Marshal getSoapMarshal(SoapPrimitive sp) { 83 if (KSoapTracing.dbg) 84 KSoapTracing.log(KSoapTracing.DEBUG, 85 "ClassMap.getSoapPrimitive(" + sp + ")"); 86 return (Marshal) nameToClass.get(sp); 87 } 88 } 89 | Popular Tags |