1 package com.thoughtworks.xstream.io.xml; 2 3 import javax.xml.namespace.QName ; 4 import java.util.Collections ; 5 import java.util.HashMap ; 6 import java.util.Map ; 7 8 15 public class QNameMap { 16 17 private Map qnameToJava; 19 private Map javaToQName; 20 private String defaultPrefix = ""; 21 private String defaultNamespace = ""; 22 23 28 public String getJavaClassName(QName qname) { 29 if (qnameToJava != null) { 30 String answer = (String ) qnameToJava.get(qname); 31 if (answer != null) { 32 return answer; 33 } 34 } 35 return qname.getLocalPart(); 36 } 37 38 43 public QName getQName(String javaClassName) { 44 if (javaToQName != null) { 45 QName answer = (QName ) javaToQName.get(javaClassName); 46 if (answer != null) { 47 return answer; 48 } 49 } 50 return new QName (defaultNamespace, javaClassName, defaultPrefix); 51 } 52 53 56 public synchronized void registerMapping(QName qname, String javaClassName) { 57 if (javaToQName == null) { 58 javaToQName = Collections.synchronizedMap(new HashMap ()); 59 } 60 if (qnameToJava == null) { 61 qnameToJava = Collections.synchronizedMap(new HashMap ()); 62 } 63 javaToQName.put(javaClassName, qname); 64 qnameToJava.put(qname, javaClassName); 65 } 66 67 70 public synchronized void registerMapping(QName qname, Class type) { 71 registerMapping(qname, type.getName()); 72 } 73 74 public String getDefaultNamespace() { 75 return defaultNamespace; 76 } 77 78 public void setDefaultNamespace(String defaultNamespace) { 79 this.defaultNamespace = defaultNamespace; 80 } 81 82 public String getDefaultPrefix() { 83 return defaultPrefix; 84 } 85 86 public void setDefaultPrefix(String defaultPrefix) { 87 this.defaultPrefix = defaultPrefix; 88 } 89 } 90 | Popular Tags |