Tue, 09 Apr 2013 14:51:13 +0100
8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com
ohair@286 | 1 | /* |
alanb@368 | 2 | * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. |
ohair@286 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ohair@286 | 4 | * |
ohair@286 | 5 | * This code is free software; you can redistribute it and/or modify it |
ohair@286 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohair@286 | 7 | * published by the Free Software Foundation. Oracle designates this |
ohair@286 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@286 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
ohair@286 | 10 | * |
ohair@286 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
ohair@286 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ohair@286 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ohair@286 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
ohair@286 | 15 | * accompanied this code). |
ohair@286 | 16 | * |
ohair@286 | 17 | * You should have received a copy of the GNU General Public License version |
ohair@286 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
ohair@286 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ohair@286 | 20 | * |
ohair@286 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@286 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@286 | 23 | * questions. |
ohair@286 | 24 | */ |
ohair@286 | 25 | |
ohair@286 | 26 | package javax.xml.ws.wsaddressing; |
ohair@286 | 27 | |
ohair@286 | 28 | |
ohair@286 | 29 | import org.w3c.dom.Element; |
ohair@286 | 30 | |
ohair@286 | 31 | import javax.xml.bind.JAXBContext; |
ohair@286 | 32 | import javax.xml.bind.JAXBException; |
ohair@286 | 33 | import javax.xml.bind.Marshaller; |
ohair@286 | 34 | import javax.xml.bind.annotation.XmlAnyAttribute; |
ohair@286 | 35 | import javax.xml.bind.annotation.XmlAnyElement; |
ohair@286 | 36 | import javax.xml.bind.annotation.XmlElement; |
ohair@286 | 37 | import javax.xml.bind.annotation.XmlRootElement; |
ohair@286 | 38 | import javax.xml.bind.annotation.XmlType; |
ohair@286 | 39 | import javax.xml.bind.annotation.XmlValue; |
ohair@286 | 40 | import javax.xml.namespace.QName; |
ohair@286 | 41 | import javax.xml.transform.Result; |
ohair@286 | 42 | import javax.xml.transform.Source; |
ohair@286 | 43 | import javax.xml.ws.EndpointReference; |
ohair@286 | 44 | import javax.xml.ws.WebServiceException; |
ohair@286 | 45 | import java.util.List; |
ohair@286 | 46 | import java.util.Map; |
ohair@286 | 47 | |
ohair@286 | 48 | |
ohair@286 | 49 | /** |
ohair@286 | 50 | * This class represents a W3C Addressing EndpointReferece which is |
ohair@286 | 51 | * a remote reference to a web service endpoint that supports the |
ohair@286 | 52 | * W3C WS-Addressing 1.0 - Core Recommendation. |
ohair@286 | 53 | * <p> |
ohair@286 | 54 | * Developers should use this class in their SEIs if they want to |
ohair@286 | 55 | * pass/return endpoint references that represent the W3C WS-Addressing |
ohair@286 | 56 | * recommendation. |
ohair@286 | 57 | * <p> |
ohair@286 | 58 | * JAXB will use the JAXB annotations and bind this class to XML infoset |
ohair@286 | 59 | * that is consistent with that defined by WS-Addressing. See |
ohair@286 | 60 | * <a href="http://www.w3.org/TR/2006/REC-ws-addr-core-20060509/"> |
ohair@286 | 61 | * WS-Addressing</a> |
ohair@286 | 62 | * for more information on WS-Addressing EndpointReferences. |
ohair@286 | 63 | * |
ohair@286 | 64 | * @since JAX-WS 2.1 |
ohair@286 | 65 | */ |
ohair@286 | 66 | |
ohair@286 | 67 | // XmlRootElement allows this class to be marshalled on its own |
ohair@286 | 68 | @XmlRootElement(name="EndpointReference",namespace=W3CEndpointReference.NS) |
ohair@286 | 69 | @XmlType(name="EndpointReferenceType",namespace=W3CEndpointReference.NS) |
ohair@286 | 70 | public final class W3CEndpointReference extends EndpointReference { |
ohair@286 | 71 | |
ohair@286 | 72 | private final static JAXBContext w3cjc = getW3CJaxbContext(); |
ohair@286 | 73 | |
alanb@368 | 74 | // should be changed to package private, keeping original modifier to keep backwards compatibility |
alanb@368 | 75 | protected static final String NS = "http://www.w3.org/2005/08/addressing"; |
alanb@368 | 76 | |
alanb@368 | 77 | // default constructor forbidden ... |
alanb@368 | 78 | // should be private, keeping original modifier to keep backwards compatibility |
ohair@286 | 79 | protected W3CEndpointReference() { |
ohair@286 | 80 | } |
ohair@286 | 81 | |
ohair@286 | 82 | /** |
ohair@286 | 83 | * Creates an EPR from infoset representation |
ohair@286 | 84 | * |
ohair@286 | 85 | * @param source A source object containing valid XmlInfoset |
ohair@286 | 86 | * instance consistent with the W3C WS-Addressing Core |
ohair@286 | 87 | * recommendation. |
ohair@286 | 88 | * |
ohair@286 | 89 | * @throws WebServiceException |
ohair@286 | 90 | * If the source does NOT contain a valid W3C WS-Addressing |
ohair@286 | 91 | * EndpointReference. |
ohair@286 | 92 | * @throws NullPointerException |
ohair@286 | 93 | * If the <code>null</code> <code>source</code> value is given |
ohair@286 | 94 | */ |
ohair@286 | 95 | public W3CEndpointReference(Source source) { |
ohair@286 | 96 | try { |
ohair@286 | 97 | W3CEndpointReference epr = w3cjc.createUnmarshaller().unmarshal(source,W3CEndpointReference.class).getValue(); |
ohair@286 | 98 | this.address = epr.address; |
ohair@286 | 99 | this.metadata = epr.metadata; |
ohair@286 | 100 | this.referenceParameters = epr.referenceParameters; |
ohair@286 | 101 | this.elements = epr.elements; |
ohair@286 | 102 | this.attributes = epr.attributes; |
ohair@286 | 103 | } catch (JAXBException e) { |
ohair@286 | 104 | throw new WebServiceException("Error unmarshalling W3CEndpointReference " ,e); |
ohair@286 | 105 | } catch (ClassCastException e) { |
ohair@286 | 106 | throw new WebServiceException("Source did not contain W3CEndpointReference", e); |
ohair@286 | 107 | } |
ohair@286 | 108 | } |
ohair@286 | 109 | |
ohair@286 | 110 | /** |
ohair@286 | 111 | * {@inheritDoc} |
ohair@286 | 112 | */ |
ohair@286 | 113 | public void writeTo(Result result){ |
ohair@286 | 114 | try { |
ohair@286 | 115 | Marshaller marshaller = w3cjc.createMarshaller(); |
ohair@286 | 116 | marshaller.marshal(this, result); |
ohair@286 | 117 | } catch (JAXBException e) { |
ohair@286 | 118 | throw new WebServiceException("Error marshalling W3CEndpointReference. ", e); |
ohair@286 | 119 | } |
ohair@286 | 120 | } |
ohair@286 | 121 | |
ohair@286 | 122 | private static JAXBContext getW3CJaxbContext() { |
ohair@286 | 123 | try { |
ohair@286 | 124 | return JAXBContext.newInstance(W3CEndpointReference.class); |
ohair@286 | 125 | } catch (JAXBException e) { |
ohair@286 | 126 | throw new WebServiceException("Error creating JAXBContext for W3CEndpointReference. ", e); |
ohair@286 | 127 | } |
ohair@286 | 128 | } |
ohair@286 | 129 | |
ohair@286 | 130 | // private but necessary properties for databinding |
ohair@286 | 131 | @XmlElement(name="Address",namespace=NS) |
ohair@286 | 132 | private Address address; |
ohair@286 | 133 | @XmlElement(name="ReferenceParameters",namespace=NS) |
ohair@286 | 134 | private Elements referenceParameters; |
ohair@286 | 135 | @XmlElement(name="Metadata",namespace=NS) |
ohair@286 | 136 | private Elements metadata; |
ohair@286 | 137 | // attributes and elements are not private for performance reasons |
ohair@286 | 138 | // (JAXB can bypass reflection) |
ohair@286 | 139 | @XmlAnyAttribute |
ohair@286 | 140 | Map<QName,String> attributes; |
ohair@286 | 141 | @XmlAnyElement |
ohair@286 | 142 | List<Element> elements; |
ohair@286 | 143 | |
ohair@286 | 144 | |
alanb@368 | 145 | @XmlType(name="address", namespace=W3CEndpointReference.NS) |
ohair@286 | 146 | private static class Address { |
ohair@286 | 147 | protected Address() {} |
ohair@286 | 148 | @XmlValue |
ohair@286 | 149 | String uri; |
ohair@286 | 150 | @XmlAnyAttribute |
ohair@286 | 151 | Map<QName,String> attributes; |
ohair@286 | 152 | } |
ohair@286 | 153 | |
ohair@286 | 154 | |
alanb@368 | 155 | @XmlType(name="elements", namespace=W3CEndpointReference.NS) |
ohair@286 | 156 | private static class Elements { |
ohair@286 | 157 | protected Elements() {} |
ohair@286 | 158 | @XmlAnyElement |
ohair@286 | 159 | List<Element> elements; |
ohair@286 | 160 | @XmlAnyAttribute |
ohair@286 | 161 | Map<QName,String> attributes; |
ohair@286 | 162 | } |
ohair@286 | 163 | |
ohair@286 | 164 | } |