1 57 58 package org.apache.wsif.providers; 59 60 import java.io.Serializable ; 61 import java.util.ArrayList ; 62 import java.util.Iterator ; 63 import java.util.Vector ; 64 65 import javax.xml.namespace.QName ; 66 67 import org.apache.wsif.logging.Trc; 68 import org.apache.wsif.util.WSIFUtils; 69 70 76 public class WSIFDynamicTypeMap implements Serializable { 77 78 private static final long serialVersionUID = 1L; 79 80 protected Vector typeMapList = new Vector (); 81 protected Vector xmlTypes = new Vector (); 83 protected ArrayList allTypes; 84 85 88 public WSIFDynamicTypeMap() { 89 Trc.entry(this); 90 allTypes = new ArrayList (); 91 Trc.exit(); 92 } 93 94 98 public WSIFDynamicTypeMap(ArrayList aList) { 99 Trc.entry(this, aList); 100 allTypes = aList; 101 Trc.exit(); 102 } 103 104 111 public void mapType(QName xmlType, Class javaType) { 112 Trc.entry(this, xmlType, javaType); 113 int i = xmlTypes.indexOf(xmlType); 114 if (i == -1) { 115 typeMapList.add(new WSIFDynamicTypeMapping(xmlType, javaType)); 117 xmlTypes.add(xmlType); 118 } else { 119 typeMapList.setElementAt(new WSIFDynamicTypeMapping(xmlType, javaType), i); 121 } 122 Trc.exit(); 123 } 124 125 132 public void mapType(QName xmlType, Class javaType, boolean force) { 133 Trc.entry(this, xmlType, javaType); 134 int i = xmlTypes.indexOf(xmlType); 135 if (force || (i == -1)) { 138 if (i == -1) { 139 typeMapList.add(new WSIFDynamicTypeMapping(xmlType, javaType)); 141 xmlTypes.add(xmlType); 142 } else { 143 typeMapList.setElementAt(new WSIFDynamicTypeMapping(xmlType, javaType), i); 145 } 146 } 147 Trc.exit(); 148 } 149 150 155 public void mapPackage(String namespace, String packageName) { 156 Trc.entry(this, namespace, packageName); 157 Iterator it = allTypes.iterator(); 158 while (it.hasNext()) { 159 QName qname = (QName ) it.next(); 160 String ns = qname.getNamespaceURI(); 161 if (ns != null && ns.equals(namespace)) { 162 resolveMapping(qname, packageName); 163 } 164 } 165 Trc.exit(); 166 } 167 168 protected void resolveMapping(QName qn, String pn) { 169 Trc.entry(this, qn, pn); 170 try { 171 String xmlName = qn.getLocalPart(); 172 if (xmlName != null) { 173 String javaName = WSIFUtils.getJavaClassNameFromXMLName(xmlName); 174 String classname = pn + "." + javaName; 175 Class cl = 176 Class.forName(classname, true, Thread.currentThread().getContextClassLoader()); 177 mapType(qn, cl); 178 } 179 } catch (Exception e) { 180 Trc.ignoredException(e); 181 } 183 Trc.exit(); 184 } 185 186 190 public void setAllTypes(ArrayList aList) { 191 Trc.entry(this, aList); 192 allTypes = aList; 193 Trc.exit(); 194 } 195 196 200 public Iterator iterator() { 201 Trc.entry(this); 202 Trc.exit(); 203 return typeMapList.iterator(); 204 } 205 212 public WSIFDynamicTypeMap copy() { 213 synchronized (typeMapList) { 215 WSIFDynamicTypeMap tm = new WSIFDynamicTypeMap(); 216 synchronized (allTypes) { 217 tm.setAllTypes((ArrayList ) allTypes.clone()); 218 } 219 Iterator it = typeMapList.iterator(); 220 while (it.hasNext()) { 222 WSIFDynamicTypeMapping temp = 223 (WSIFDynamicTypeMapping) it.next(); 224 tm.mapType(temp.getXmlType(), temp.getJavaType()); 225 } 226 return tm; 227 } 228 }} | Popular Tags |