01: package org.objectweb.celtix.bus.jaxws.io;
02:
03: import java.io.ByteArrayInputStream;
04: import java.io.ByteArrayOutputStream;
05:
06: import javax.xml.namespace.QName;
07: import javax.xml.soap.SOAPMessage;
08: import javax.xml.transform.Source;
09: 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
32: .getSupportedFormats()[0])) {
33:
34: obj = new DOMSource(src.getSOAPPart());
35:
36: } else if (SAXSource.class.isAssignableFrom(callback
37: .getSupportedFormats()[0])) {
38:
39: ByteArrayOutputStream baos = new ByteArrayOutputStream();
40: src.writeTo(baos);
41: ByteArrayInputStream bais = new ByteArrayInputStream(
42: baos.toByteArray());
43: InputSource inputSource = new InputSource(bais);
44: obj = new SAXSource(inputSource);
45:
46: } else if (StreamSource.class.isAssignableFrom(callback
47: .getSupportedFormats()[0])) {
48: ByteArrayOutputStream baos = new ByteArrayOutputStream();
49: src.writeTo(baos);
50: ByteArrayInputStream bais = new ByteArrayInputStream(
51: baos.toByteArray());
52: obj = new StreamSource(bais);
53: }
54: } catch (Exception ex) {
55: ex.printStackTrace();
56: }
57: return obj;
58: }
59:
60: public Object read(QName name, int idx, T input) {
61: return null;
62: }
63:
64: public void readWrapper(ObjectMessageContext objCtx,
65: boolean isOutBound, T input) {
66: //Complete
67: }
68:
69: }
|