1 20 package org.apache.beehive.wsm.axis.registration; 21 22 import java.io.File ; 23 import java.lang.reflect.Constructor ; 24 import java.lang.reflect.InvocationTargetException ; 25 import java.lang.reflect.Type ; 26 import java.rmi.Remote ; 27 import java.util.Collection ; 28 import java.util.HashMap ; 29 import java.util.Map ; 30 31 import javax.jws.soap.SOAPBinding; 32 import javax.xml.namespace.QName ; 33 34 import org.apache.axis.Constants; 35 import org.apache.axis.description.ElementDesc; 36 import org.apache.axis.description.FieldDesc; 37 import org.apache.axis.description.TypeDesc; 38 import org.apache.axis.encoding.DeserializerFactory; 39 import org.apache.axis.encoding.SerializerFactory; 40 import org.apache.axis.encoding.TypeMapping; 41 import org.apache.axis.encoding.XMLType; 42 import org.apache.axis.encoding.ser.ArrayDeserializerFactory; 43 import org.apache.axis.encoding.ser.ArraySerializerFactory; 44 import org.apache.axis.encoding.ser.BeanDeserializerFactory; 45 import org.apache.axis.encoding.ser.BeanSerializerFactory; 46 import org.apache.axis.types.HexBinary; 47 import org.apache.axis.utils.BeanPropertyDescriptor; 48 import org.apache.beehive.wsm.axis.ant.AxisTypeGeneratorTask; 49 import org.apache.beehive.wsm.axis.databinding.AxisTypeLookup; 50 import org.apache.beehive.wsm.axis.util.encoding.XmlBeanDeserializerFactory; 51 import org.apache.beehive.wsm.axis.util.encoding.XmlBeanSerializerFactory; 52 import org.apache.beehive.wsm.databinding.BindingLookupService; 53 import org.apache.beehive.wsm.util.InvalidTypeMappingException; 54 import org.apache.beehive.wsm.registration.TypeRegistrar; 55 import org.apache.log4j.Logger; 56 import org.apache.xmlbeans.XmlObject; 57 58 public class AxisTypeRegistrar extends TypeRegistrar { 59 static Logger logger = Logger.getLogger(AxisTypeRegistrar.class); 60 61 public AxisTypeRegistrar(TypeMapping tm, BindingLookupService lookupService) { 62 super(tm, lookupService); 63 64 } 65 66 67 71 protected boolean isBuiltInType(Class cls) { 72 return (AxisTypeMappingMetaData.isBuiltInType(cls)); 73 } 74 75 76 80 protected void registerClassAsWithDefaultSearialization(Class cls, QName q, SOAPBinding.Style style, 81 SOAPBinding.Use use) { 82 try { 83 logger.debug("Assigned Default Serialization to class: " + cls.getCanonicalName() 84 + " qname:" + q); 85 TypeDesc td = TypeDesc.getTypeDescForClass(cls); TypeDesc superTd = null; 90 BeanPropertyDescriptor[] superPd = null; 91 boolean shoudRegisterFields = false; 92 if (null == td) { 93 shoudRegisterFields = true; 94 td = new TypeDesc(cls); 95 Class supa = cls.getSuperclass(); 96 if ((supa != null) && (supa != java.lang.Object .class) 97 && (supa != java.lang.Exception .class) 98 && (supa != java.lang.Throwable .class) 99 && (supa != java.rmi.RemoteException .class) 100 && (supa != org.apache.axis.AxisFault.class)) { 101 registerType(supa, style, use); 102 superTd = TypeDesc.getTypeDescForClass(supa); 103 if (superTd != null) { 104 superPd = superTd.getPropertyDescriptors(); 105 } 106 } 107 td.setXmlType(q); 108 TypeDesc.registerTypeDescForClass(cls, td); 109 } 110 mTypeMapping.register(cls, q, new BeanSerializerFactory(cls, q), 111 116 new BeanDeserializerFactory(cls, q)); 117 Map serProps = BeanDeserializerFactory.getProperties(cls, null); 118 for (BeanPropertyDescriptor beanProps : (Collection <BeanPropertyDescriptor>) serProps 119 .values()) { 120 Class subType = beanProps.getType(); 121 if (!(subType.isPrimitive() 122 || subType.getName().startsWith("java.") || subType 123 .getName().startsWith("javax."))) { 124 registerType(subType, style, use); 125 } 126 if (shoudRegisterFields) { 127 String ns = q.getNamespaceURI(); 128 if (superTd != null && superPd != null) { 129 for (int j = 0; j < superPd.length; j++) { 130 if (beanProps.getName() 131 .equals(superPd[j].getName())) { 132 ns = superTd.getXmlType().getNamespaceURI(); 133 break; 134 } 135 } 136 } 137 FieldDesc fd = new ElementDesc(); 138 fd.setJavaType(subType); 139 fd.setFieldName(beanProps.getName()); 140 fd.setXmlName(new QName (ns, beanProps.getName())); 141 fd.setXmlType(getRegisteredQName(subType)); 145 ((ElementDesc) fd).setNillable(true); 146 151 td.addFieldDesc(fd); 152 } 153 } 154 } catch (RuntimeException e) { 155 logger.error("Error in registering class: " 156 + cls.getCanonicalName() + " qname:" + q); 157 e.printStackTrace(); 158 throw e; 159 } 160 } 161 162 166 protected void registerClassAsXMLBeans(Class cls, QName q) { 167 logger.debug("Assigned XMLBeans Serialization to class: " + cls.getCanonicalName() 168 + " qname:" + q); mTypeMapping.register(cls, q, new XmlBeanSerializerFactory(cls, q), 169 new XmlBeanDeserializerFactory(cls, q)); 170 } 171 172 181 protected void registerClassAsDataHandler(Class cls, QName q) 182 throws ClassNotFoundException , NoSuchMethodException , 183 InstantiationException , IllegalAccessException , 184 InvocationTargetException { 185 logger.debug("Assigned DataHandler to class: " + cls.getCanonicalName() 186 + " qname:" + q); 190 ClassLoader cl = getClass().getClassLoader(); 191 Class <SerializerFactory> sfClass = (Class <SerializerFactory>) cl 192 .loadClass("org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory"); 193 Class <DeserializerFactory> dsfClass = (Class <DeserializerFactory>) cl 194 .loadClass("org.apache.axis.encoding.ser.JAFDataHandlerDeserializerFactory"); 195 Constructor <SerializerFactory> sfCon = sfClass.getConstructor( 196 Class .class, QName .class); 197 Constructor <DeserializerFactory> dsfCon = dsfClass.getConstructor( 198 Class .class, QName .class); 199 SerializerFactory sf = sfCon.newInstance(cls, q); 200 DeserializerFactory dsf = dsfCon.newInstance(cls, q); 201 mTypeMapping.register(cls, q, sf, dsf); 202 } 203 204 208 protected void registerClassAsSoapEncodedArray(Class cls, QName q) { 209 logger.debug("Assigned Array Serialization to class: " + cls.getCanonicalName() 210 + " qname:" + q + " Array element qname: " + lookupService.class2qname(cls.getComponentType())); 211 212 213 mTypeMapping.register(cls, q, new ArraySerializerFactory(lookupService.class2qname(cls.getComponentType())), 214 new ArrayDeserializerFactory()); 215 } 216 217 222 protected boolean classIsRegistered(Class cls, QName q) { 223 return mTypeMapping.isRegistered(cls, q); 224 } 225 226 230 protected QName getRegisteredQName(Class cls) { 231 QName currentQName = ((org.apache.axis.encoding.TypeMapping) mTypeMapping) 232 .getTypeQName(cls); 233 return currentQName; 234 } 235 236 239 public QName getVoidType() { 240 return XMLType.AXIS_VOID; 241 242 } 243 244 245 246 247 250 protected QName getBuiltInTypeQname(Class cls) { 251 return AxisTypeMappingMetaData.getBuiltInTypeQname(cls); 252 } 253 } 254 | Popular Tags |