1 package org.objectweb.celtix.bus.jaxws.io; 2 3 import java.lang.reflect.Method ; 4 import javax.xml.namespace.QName ; 5 import javax.xml.ws.WebFault; 6 import javax.xml.ws.WebServiceException; 7 import org.w3c.dom.*; 8 9 import org.objectweb.celtix.bindings.DataWriter; 10 import org.objectweb.celtix.bus.bindings.xml.XMLFault; 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 XMLFaultWriter<T> implements DataWriter<T> { 16 final JAXBDataBindingCallback callback; 17 18 public XMLFaultWriter(JAXBDataBindingCallback cb) { 19 callback = cb; 20 } 21 public void write(Object obj, T output) { 22 WebFault wfAnnotation = obj.getClass().getAnnotation(WebFault.class); 23 if (wfAnnotation != null) { 24 QName elName = new QName (wfAnnotation.targetNamespace(), wfAnnotation.name()); 25 write(obj, elName, output); 26 } 27 } 28 public void write(Object obj, QName elName, T output) { 29 Object faultInfo = getFaultInfo((Throwable )obj); 30 if (faultInfo != null) { 31 XMLFault fault = (XMLFault)output; 32 Node detail = fault.addFaultDetail(); 33 JAXBEncoderDecoder.marshall(callback.getJAXBContext(), 34 callback.getSchema(), faultInfo, elName, detail); 35 fault.setFaultDetail(detail); 36 } 37 } 38 public void writeWrapper(ObjectMessageContext objCtx, boolean isOutbound, T output) { 39 throw new UnsupportedOperationException (); 40 } 41 private Object getFaultInfo(Throwable fault) { 42 try { 43 Method faultInfoMethod = fault.getClass().getMethod("getFaultInfo"); 44 if (faultInfoMethod != null) { 45 return faultInfoMethod.invoke(fault); 46 } 47 } catch (Exception ex) { 48 throw new WebServiceException("Could not get faultInfo out of Exception", ex); 49 } 50 51 return null; 52 } 53 } 54 | Popular Tags |