1 16 17 package org.apache.axis.encoding.ser; 18 19 import org.apache.axis.utils.BeanUtils; 20 import org.apache.axis.utils.BeanPropertyDescriptor; 21 import org.apache.axis.utils.JavaUtils; 22 23 import javax.xml.namespace.QName ; 24 import javax.xml.rpc.JAXRPCException ; 25 import java.lang.reflect.Constructor ; 26 import java.io.IOException ; 27 28 37 public class SimpleDeserializerFactory extends BaseDeserializerFactory { 38 39 private static final Class [] STRING_STRING_CLASS = 40 new Class [] {String .class, String .class}; 41 42 private static final Class [] STRING_CLASS = 43 new Class [] {String .class}; 44 45 private transient Constructor constructor = null; 46 private boolean isBasicType = false; 47 51 public SimpleDeserializerFactory(Class javaType, QName xmlType) { 52 super(SimpleDeserializer.class, xmlType, javaType); 53 this.isBasicType = JavaUtils.isBasic(javaType); 54 initConstructor(javaType); 55 } 56 57 private void initConstructor(Class javaType) { 58 if (!this.isBasicType) { 59 try { 61 if (QName .class.isAssignableFrom(javaType)) { 62 constructor = 63 javaType.getDeclaredConstructor(STRING_STRING_CLASS); 64 } else { 65 constructor = 66 javaType.getDeclaredConstructor(STRING_CLASS); 67 } 68 } catch (NoSuchMethodException e) { 69 try { 70 constructor = 71 javaType.getDeclaredConstructor(new Class []{}); 72 BeanPropertyDescriptor[] pds = BeanUtils.getPd(javaType); 73 if(pds != null) { 74 if(BeanUtils.getSpecificPD(pds,"_value")!=null){ 75 return; 76 } 77 } 78 throw new IllegalArgumentException (e.toString()); 79 } catch (NoSuchMethodException ex) { 80 throw new IllegalArgumentException (ex.toString()); 81 } 82 } 83 } 84 } 85 86 90 public javax.xml.rpc.encoding.Deserializer getDeserializerAs(String mechanismType) 91 throws JAXRPCException { 92 if (javaType == java.lang.Object .class) { 93 return null; 94 } 95 if (this.isBasicType) { 96 return new SimpleDeserializer(javaType, xmlType); 97 } else { 98 SimpleDeserializer deser = 101 (SimpleDeserializer) super.getDeserializerAs(mechanismType); 102 if (deser != null) { 103 deser.setConstructor(constructor); 104 } 105 return deser; 106 } 107 } 108 109 private void readObject(java.io.ObjectInputStream in) throws IOException , ClassNotFoundException { 110 in.defaultReadObject(); 111 initConstructor(javaType); 112 } 113 114 } 115 | Popular Tags |