1 22 package org.apache.axis.encoding.ser.xbeans; 23 24 import org.apache.axis.encoding.DeserializationContext; 25 import org.apache.axis.encoding.DeserializerImpl; 26 import org.apache.axis.message.MessageElement; 27 import org.apache.xmlbeans.QNameSet; 28 import org.apache.xmlbeans.SchemaType; 29 import org.apache.xmlbeans.XmlObject; 30 import org.apache.xmlbeans.XmlOptions; 31 import org.xml.sax.Attributes ; 32 import org.xml.sax.SAXException ; 33 34 import javax.xml.namespace.QName ; 35 36 40 public class XmlBeanDeserializer extends DeserializerImpl { 41 42 private Class mJavaType; 43 private QName mXmlType; 44 45 public XmlBeanDeserializer(Class javaType, QName xmlType) { 46 mJavaType = javaType; 47 mXmlType = xmlType; 48 } 49 50 public void onStartElement(String namespace, String localName, 51 String prefix, Attributes attributes, 52 DeserializationContext context) 53 throws SAXException { 54 try { 55 MessageElement me = context.getCurElement(); 56 XmlOptions opts = new XmlOptions() 57 .setLoadReplaceDocumentElement(null); 58 XmlObject xObj = XmlObject.Factory.parse(me, opts); 59 SchemaType st = xObj.schemaType(); 60 SchemaType jt = (SchemaType) mJavaType.getField("type").get(null); 61 XmlObject converted = xObj.changeType(jt); 62 if (converted != null) { 63 setValue(converted); 64 } else { 65 XmlObject[] children = xObj.selectChildren(QNameSet.ALL); 66 for (int j = 0; j < children.length; j++) { 67 st = children[j].schemaType(); 68 converted = xObj.changeType(jt); 69 if (converted != null) { 70 setValue(converted); 71 break; 72 } 73 } 74 } 75 } catch (Exception xe) { 76 throw new SAXException (xe); 77 } 78 } 79 } 80 | Popular Tags |