1 package org.objectweb.celtix.bus.jaxws.io; 2 3 import java.lang.reflect.Method ; 4 5 import javax.xml.namespace.QName ; 6 import javax.xml.soap.Detail ; 7 import javax.xml.ws.WebFault; 8 import javax.xml.ws.WebServiceException; 9 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 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 JAXBEncoderDecoder.marshall(callback.getJAXBContext(), 32 callback.getSchema(), faultInfo, elName, (Detail )output); 33 } 34 } 35 public void writeWrapper(ObjectMessageContext objCtx, boolean isOutbound, T output) { 36 throw new UnsupportedOperationException (); 37 } 38 private Object getFaultInfo(Throwable fault) { 39 try { 40 Method faultInfoMethod = fault.getClass().getMethod("getFaultInfo"); 41 if (faultInfoMethod != null) { 42 return faultInfoMethod.invoke(fault); 43 } 44 } catch (Exception ex) { 45 throw new WebServiceException("Could not get faultInfo out of Exception", ex); 46 } 47 48 return null; 49 } 50 } 51 | Popular Tags |