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