1 5 6 package javax.xml.ws.wsaddressing; 7 8 9 import org.w3c.dom.Element ; 10 11 import javax.xml.bind.JAXBContext; 12 import javax.xml.bind.JAXBException; 13 import javax.xml.bind.Marshaller; 14 import javax.xml.bind.annotation.XmlAnyAttribute; 15 import javax.xml.bind.annotation.XmlAnyElement; 16 import javax.xml.bind.annotation.XmlElement; 17 import javax.xml.bind.annotation.XmlRootElement; 18 import javax.xml.bind.annotation.XmlType; 19 import javax.xml.bind.annotation.XmlValue; 20 import javax.xml.namespace.QName ; 21 import javax.xml.transform.Result ; 22 import javax.xml.transform.Source ; 23 import javax.xml.ws.EndpointReference; 24 import javax.xml.ws.WebServiceException; 25 import java.util.List ; 26 import java.util.Map ; 27 28 29 46 47 @XmlRootElement(name="EndpointReference",namespace=W3CEndpointReference.NS) 49 @XmlType(name="EndpointReferenceType",namespace=W3CEndpointReference.NS) 50 public final class W3CEndpointReference extends EndpointReference { 51 52 private final static JAXBContext w3cjc = getW3CJaxbContext(); 53 54 protected W3CEndpointReference() { 55 } 56 57 70 public W3CEndpointReference(Source source) { 71 try { 72 W3CEndpointReference epr = w3cjc.createUnmarshaller().unmarshal(source,W3CEndpointReference.class).getValue(); 73 this.address = epr.address; 74 this.metadata = epr.metadata; 75 this.referenceParameters = epr.referenceParameters; 76 } catch (JAXBException e) { 77 throw new WebServiceException("Error unmarshalling W3CEndpointReference " ,e); 78 } catch (ClassCastException e) { 79 throw new WebServiceException("Source did not contain W3CEndpointReference", e); 80 } 81 } 82 83 86 public void writeTo(Result result){ 87 try { 88 Marshaller marshaller = w3cjc.createMarshaller(); 89 marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); 90 marshaller.marshal(this, result); 91 } catch (JAXBException e) { 92 throw new WebServiceException("Error marshalling W3CEndpointReference. ", e); 93 } 94 } 95 96 private static JAXBContext getW3CJaxbContext() { 97 try { 98 return JAXBContext.newInstance(W3CEndpointReference.class); 99 } catch (JAXBException e) { 100 throw new WebServiceException("Error creating JAXBContext for W3CEndpointReference. ", e); 101 } 102 } 103 104 @XmlElement(name="Address",namespace=NS) 106 private Address address; 107 @XmlElement(name="ReferenceParameters",namespace=NS) 108 private Elements referenceParameters; 109 @XmlElement(name="Metadata",namespace=NS) 110 private Elements metadata; 111 @XmlAnyAttribute 112 Map <QName ,String > attributes; 113 @XmlAnyElement 114 List <Element > elements; 115 116 117 private static class Address { 118 protected Address() {} 119 @XmlValue 120 String uri; 121 @XmlAnyAttribute 122 Map <QName ,String > attributes; 123 } 124 125 126 private static class Elements { 127 protected Elements() {} 128 @XmlAnyElement 129 List <Element > elements; 130 @XmlAnyAttribute 131 Map <QName ,String > attributes; 132 } 133 134 protected static final String NS = "http://www.w3.org/2005/08/addressing"; 135 } 136 | Popular Tags |