01: package org.objectweb.celtix.bus.jaxws.io;
02:
03: import java.lang.reflect.Constructor;
04:
05: import javax.xml.namespace.QName;
06: import javax.xml.soap.SOAPFault;
07: import javax.xml.ws.WebServiceException;
08: import javax.xml.ws.soap.SOAPFaultException;
09:
10: import org.w3c.dom.Node;
11: import org.w3c.dom.NodeList;
12:
13: import org.objectweb.celtix.bindings.DataReader;
14: import org.objectweb.celtix.bus.jaxws.JAXBDataBindingCallback;
15: import org.objectweb.celtix.bus.jaxws.JAXBEncoderDecoder;
16: import org.objectweb.celtix.context.ObjectMessageContext;
17:
18: public class SOAPFaultDataReader<T> implements DataReader<T> {
19: final JAXBDataBindingCallback callback;
20:
21: public SOAPFaultDataReader(JAXBDataBindingCallback cb) {
22: callback = cb;
23: }
24:
25: public Object read(QName name, int idx, T input) {
26: SOAPFault fault = (SOAPFault) input;
27: if (fault.getDetail() != null) {
28: NodeList list = fault.getDetail().getChildNodes();
29:
30: QName faultName;
31: for (int i = 0; i < list.getLength(); i++) {
32: Node entry = list.item(i);
33: if (entry.getNodeType() != Node.ELEMENT_NODE) {
34: continue;
35: }
36:
37: faultName = new QName(entry.getNamespaceURI(), entry
38: .getLocalName());
39:
40: Class<?> clazz = callback.getWebFault(faultName);
41: try {
42: if (clazz != null) {
43: Class<?> faultInfo = clazz.getMethod(
44: "getFaultInfo").getReturnType();
45: Object obj = JAXBEncoderDecoder.unmarshall(
46: callback.getJAXBContext(), callback
47: .getSchema(), entry, faultName,
48: faultInfo);
49: Constructor<?> ctor = clazz.getConstructor(
50: String.class, obj.getClass());
51: return ctor.newInstance(fault.getFaultString(),
52: obj);
53: }
54: } catch (Exception ex) {
55: throw new WebServiceException(
56: "error in unmarshal of SOAPFault", ex);
57: }
58: }
59: }
60: return new SOAPFaultException(fault);
61: }
62:
63: public Object read(int idx, T input) {
64: return read(null, idx, input);
65: }
66:
67: public void readWrapper(ObjectMessageContext objCtx,
68: boolean isOutBound, T input) {
69: throw new UnsupportedOperationException();
70: }
71: }
|