1 20 21 package org.apache.beehive.wsm.axis.databinding; 22 23 import javax.xml.namespace.QName ; 24 25 import org.apache.axis.description.TypeDesc; 26 import org.apache.axis.utils.ClassUtils; 27 import org.apache.axis.wsdl.fromJava.Namespaces; 28 import org.apache.axis.wsdl.fromJava.Types; 29 import org.apache.axis.wsdl.toJava.Utils; 30 import org.apache.beehive.wsm.axis.registration.AxisTypeMappingMetaData; 31 import org.apache.beehive.wsm.databinding.BindingLookupService; 32 import org.apache.log4j.Logger; 33 34 public class AxisTypeLookup implements BindingLookupService { 35 static Logger logger = Logger.getLogger(AxisTypeLookup.class); 36 37 40 public AxisTypeLookup() { 41 super(); 42 } 43 44 49 public QName class2qname(Class cls) { 50 if (cls.isArray()) 51 cls = cls.getComponentType(); 52 TypeDesc td = TypeDesc.getTypeDescForClass(cls); if (null != td) { 54 return td.getXmlType(); 55 } else { 56 String namespace = Namespaces.makeNamespace(cls.getName()); 57 if (namespace == null || namespace.endsWith("DefaultNamespace")) { 58 namespace = "http://no.namespace.specified"; 59 } 60 return class2qname(cls, namespace); 61 } 62 63 } 64 65 70 public QName class2qname(Class cls, String namespace) { 71 if (AxisTypeMappingMetaData.isBuiltInType(cls)) 72 return AxisTypeMappingMetaData.getBuiltInTypeQname(cls); 73 return new QName (namespace, Types.getLocalNameFromFullName(cls 74 .getName())); 75 } 76 77 public Class qname2class(QName qType) { 78 79 if (qType == null) { 80 return null; 81 } 82 83 String packageName = getPackageNameFromQName(qType); 84 String className; 85 if (packageName != null && packageName.length() > 0) { 86 className = packageName + "." 87 + Utils.xmlNameToJavaClass(qType.getLocalPart()); 88 } else { 89 className = Utils.xmlNameToJavaClass(qType.getLocalPart()); 90 } 91 92 Class javaType = null; 93 94 try { 95 javaType = ClassUtils.forName(className); 96 97 } catch (ClassNotFoundException e) { 98 System.out.println("Failed to find the class: " + className 99 + " No Axis generated classes was found for qname: " 100 + qType); 101 } 102 103 if (null != javaType) 104 System.out.println("Found an Axis generated type for qname: " 105 + qType + " class: " + javaType.getCanonicalName()); 106 107 return javaType; 108 } 109 110 private String getPackageNameFromQName(QName qType) { 111 112 String packageName = Utils.makePackageName(qType.getNamespaceURI()); 116 packageName = normalizePackageName(packageName, '.'); 117 return packageName; 118 } 119 120 private static final char[] pkgSeparators = { '.', ':' }; 121 122 private static String normalizePackageName(String pkg, char separator) { 123 124 for (int i = 0; i < pkgSeparators.length; i++) { 125 pkg = pkg.replace(pkgSeparators[i], separator); 126 } 127 128 return pkg; 129 } 130 131 } 132 | Popular Tags |