1 package org.objectweb.celtix.bus.jaxws.io; 2 3 import java.io.ByteArrayInputStream ; 4 import java.io.ByteArrayOutputStream ; 5 6 import javax.xml.namespace.QName ; 7 import javax.xml.soap.SOAPMessage ; 8 import javax.xml.transform.Source ; 9 import javax.xml.transform.dom.DOMSource ; 10 import javax.xml.transform.sax.SAXSource ; 11 import javax.xml.transform.stream.StreamSource ; 12 13 import org.xml.sax.InputSource ; 14 15 import org.objectweb.celtix.bindings.DataReader; 16 import org.objectweb.celtix.bus.jaxws.DynamicDataBindingCallback; 17 import org.objectweb.celtix.context.ObjectMessageContext; 18 19 public class SOAPMessageDataReader<T> implements DataReader<T> { 20 21 final DynamicDataBindingCallback callback; 22 23 public SOAPMessageDataReader(DynamicDataBindingCallback cb) { 24 callback = cb; 25 } 26 27 public Object read(int idx, T input) { 28 SOAPMessage src = (SOAPMessage )input; 29 Source obj = null; 30 try { 31 if (DOMSource .class.isAssignableFrom(callback.getSupportedFormats()[0])) { 32 33 obj = new DOMSource (src.getSOAPPart()); 34 35 } else if (SAXSource .class.isAssignableFrom(callback.getSupportedFormats()[0])) { 36 37 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 38 src.writeTo(baos); 39 ByteArrayInputStream bais = new ByteArrayInputStream (baos.toByteArray()); 40 InputSource inputSource = new InputSource (bais); 41 obj = new SAXSource (inputSource); 42 43 } else if (StreamSource .class.isAssignableFrom(callback.getSupportedFormats()[0])) { 44 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 45 src.writeTo(baos); 46 ByteArrayInputStream bais = new ByteArrayInputStream (baos.toByteArray()); 47 obj = new StreamSource (bais); 48 } 49 } catch (Exception ex) { 50 ex.printStackTrace(); 51 } 52 return obj; 53 } 54 55 public Object read(QName name, int idx, T input) { 56 return null; 57 } 58 59 public void readWrapper(ObjectMessageContext objCtx, boolean isOutBound, T input) { 60 } 62 63 } 64 | Popular Tags |