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