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