01: package org.objectweb.celtix.bus.jaxws.io;
02:
03: import java.lang.reflect.Method;
04:
05: import javax.xml.namespace.QName;
06: import javax.xml.soap.Detail;
07: import javax.xml.ws.WebFault;
08: import javax.xml.ws.WebServiceException;
09:
10: import org.objectweb.celtix.bindings.DataWriter;
11: import org.objectweb.celtix.bus.jaxws.JAXBDataBindingCallback;
12: import org.objectweb.celtix.bus.jaxws.JAXBEncoderDecoder;
13: import org.objectweb.celtix.context.ObjectMessageContext;
14:
15: public class DetailDataWriter<T> implements DataWriter<T> {
16: final JAXBDataBindingCallback callback;
17:
18: public DetailDataWriter(JAXBDataBindingCallback cb) {
19: callback = cb;
20: }
21:
22: public void write(Object obj, T output) {
23: WebFault wfAnnotation = obj.getClass().getAnnotation(
24: WebFault.class);
25: if (wfAnnotation != null) {
26: QName elName = new QName(wfAnnotation.targetNamespace(),
27: wfAnnotation.name());
28: write(obj, elName, output);
29: }
30: }
31:
32: public void write(Object obj, QName elName, T output) {
33: Object faultInfo = getFaultInfo((Throwable) obj);
34: if (faultInfo != null) {
35: JAXBEncoderDecoder.marshall(callback.getJAXBContext(),
36: callback.getSchema(), faultInfo, elName,
37: (Detail) output);
38: }
39: }
40:
41: public void writeWrapper(ObjectMessageContext objCtx,
42: boolean isOutbound, T output) {
43: throw new UnsupportedOperationException();
44: }
45:
46: private Object getFaultInfo(Throwable fault) {
47: try {
48: Method faultInfoMethod = fault.getClass().getMethod(
49: "getFaultInfo");
50: if (faultInfoMethod != null) {
51: return faultInfoMethod.invoke(fault);
52: }
53: } catch (Exception ex) {
54: throw new WebServiceException(
55: "Could not get faultInfo out of Exception", ex);
56: }
57:
58: return null;
59: }
60: }
|