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