src/share/jaxws_classes/javax/xml/ws/wsaddressing/W3CEndpointReference.java

changeset 0
373ffda63c9a
child 637
9c07ef4934dd
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/javax/xml/ws/wsaddressing/W3CEndpointReference.java	Wed Apr 27 01:27:09 2016 +0800
     1.3 @@ -0,0 +1,164 @@
     1.4 +/*
     1.5 + * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package javax.xml.ws.wsaddressing;
    1.30 +
    1.31 +
    1.32 +import org.w3c.dom.Element;
    1.33 +
    1.34 +import javax.xml.bind.JAXBContext;
    1.35 +import javax.xml.bind.JAXBException;
    1.36 +import javax.xml.bind.Marshaller;
    1.37 +import javax.xml.bind.annotation.XmlAnyAttribute;
    1.38 +import javax.xml.bind.annotation.XmlAnyElement;
    1.39 +import javax.xml.bind.annotation.XmlElement;
    1.40 +import javax.xml.bind.annotation.XmlRootElement;
    1.41 +import javax.xml.bind.annotation.XmlType;
    1.42 +import javax.xml.bind.annotation.XmlValue;
    1.43 +import javax.xml.namespace.QName;
    1.44 +import javax.xml.transform.Result;
    1.45 +import javax.xml.transform.Source;
    1.46 +import javax.xml.ws.EndpointReference;
    1.47 +import javax.xml.ws.WebServiceException;
    1.48 +import java.util.List;
    1.49 +import java.util.Map;
    1.50 +
    1.51 +
    1.52 +/**
    1.53 + * This class represents a W3C Addressing EndpointReferece which is
    1.54 + * a remote reference to a web service endpoint that supports the
    1.55 + * W3C WS-Addressing 1.0 - Core Recommendation.
    1.56 + * <p>
    1.57 + * Developers should use this class in their SEIs if they want to
    1.58 + * pass/return endpoint references that represent the W3C WS-Addressing
    1.59 + * recommendation.
    1.60 + * <p>
    1.61 + * JAXB will use the JAXB annotations and bind this class to XML infoset
    1.62 + * that is consistent with that defined by WS-Addressing.  See
    1.63 + * <a href="http://www.w3.org/TR/2006/REC-ws-addr-core-20060509/">
    1.64 + * WS-Addressing</a>
    1.65 + * for more information on WS-Addressing EndpointReferences.
    1.66 + *
    1.67 + * @since JAX-WS 2.1
    1.68 + */
    1.69 +
    1.70 +// XmlRootElement allows this class to be marshalled on its own
    1.71 +@XmlRootElement(name="EndpointReference",namespace=W3CEndpointReference.NS)
    1.72 +@XmlType(name="EndpointReferenceType",namespace=W3CEndpointReference.NS)
    1.73 +public final class W3CEndpointReference extends EndpointReference {
    1.74 +
    1.75 +    private final JAXBContext w3cjc = getW3CJaxbContext();
    1.76 +
    1.77 +    // should be changed to package private, keeping original modifier to keep backwards compatibility
    1.78 +    protected static final String NS = "http://www.w3.org/2005/08/addressing";
    1.79 +
    1.80 +    // default constructor forbidden ...
    1.81 +    // should be private, keeping original modifier to keep backwards compatibility
    1.82 +    protected W3CEndpointReference() {
    1.83 +    }
    1.84 +
    1.85 +    /**
    1.86 +     * Creates an EPR from infoset representation
    1.87 +     *
    1.88 +     * @param source A source object containing valid XmlInfoset
    1.89 +     * instance consistent with the W3C WS-Addressing Core
    1.90 +     * recommendation.
    1.91 +     *
    1.92 +     * @throws WebServiceException
    1.93 +     *   If the source does NOT contain a valid W3C WS-Addressing
    1.94 +     *   EndpointReference.
    1.95 +     * @throws NullPointerException
    1.96 +     *   If the <code>null</code> <code>source</code> value is given
    1.97 +     */
    1.98 +    public W3CEndpointReference(Source source) {
    1.99 +        try {
   1.100 +            W3CEndpointReference epr = w3cjc.createUnmarshaller().unmarshal(source,W3CEndpointReference.class).getValue();
   1.101 +            this.address = epr.address;
   1.102 +            this.metadata = epr.metadata;
   1.103 +            this.referenceParameters = epr.referenceParameters;
   1.104 +            this.elements = epr.elements;
   1.105 +            this.attributes = epr.attributes;
   1.106 +        } catch (JAXBException e) {
   1.107 +            throw new WebServiceException("Error unmarshalling W3CEndpointReference " ,e);
   1.108 +        } catch (ClassCastException e) {
   1.109 +            throw new WebServiceException("Source did not contain W3CEndpointReference", e);
   1.110 +        }
   1.111 +    }
   1.112 +
   1.113 +    /**
   1.114 +     * {@inheritDoc}
   1.115 +     */
   1.116 +    public void writeTo(Result result){
   1.117 +        try {
   1.118 +            Marshaller marshaller = w3cjc.createMarshaller();
   1.119 +            marshaller.marshal(this, result);
   1.120 +        } catch (JAXBException e) {
   1.121 +            throw new WebServiceException("Error marshalling W3CEndpointReference. ", e);
   1.122 +        }
   1.123 +    }
   1.124 +
   1.125 +    private static JAXBContext getW3CJaxbContext() {
   1.126 +        try {
   1.127 +            return JAXBContext.newInstance(W3CEndpointReference.class);
   1.128 +        } catch (JAXBException e) {
   1.129 +            throw new WebServiceException("Error creating JAXBContext for W3CEndpointReference. ", e);
   1.130 +        }
   1.131 +    }
   1.132 +
   1.133 +    // private but necessary properties for databinding
   1.134 +    @XmlElement(name="Address",namespace=NS)
   1.135 +    private Address address;
   1.136 +    @XmlElement(name="ReferenceParameters",namespace=NS)
   1.137 +    private Elements referenceParameters;
   1.138 +    @XmlElement(name="Metadata",namespace=NS)
   1.139 +    private Elements metadata;
   1.140 +    // attributes and elements are not private for performance reasons
   1.141 +    // (JAXB can bypass reflection)
   1.142 +    @XmlAnyAttribute
   1.143 +    Map<QName,String> attributes;
   1.144 +    @XmlAnyElement
   1.145 +    List<Element> elements;
   1.146 +
   1.147 +
   1.148 +    @XmlType(name="address", namespace=W3CEndpointReference.NS)
   1.149 +    private static class Address {
   1.150 +        protected Address() {}
   1.151 +        @XmlValue
   1.152 +        String uri;
   1.153 +        @XmlAnyAttribute
   1.154 +        Map<QName,String> attributes;
   1.155 +    }
   1.156 +
   1.157 +
   1.158 +    @XmlType(name="elements", namespace=W3CEndpointReference.NS)
   1.159 +    private static class Elements {
   1.160 +        protected Elements() {}
   1.161 +        @XmlAnyElement
   1.162 +        List<Element> elements;
   1.163 +        @XmlAnyAttribute
   1.164 +        Map<QName,String> attributes;
   1.165 +    }
   1.166 +
   1.167 +}

mercurial