src/share/jaxws_classes/com/sun/xml/internal/ws/developer/MemberSubmissionEndpointReference.java

Thu, 31 Aug 2017 15:18:52 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:18:52 +0800
changeset 637
9c07ef4934dd
parent 515
6cd506508147
parent 0
373ffda63c9a
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 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 com.sun.xml.internal.ws.developer;
aoqi@0 27
aoqi@0 28 import com.sun.istack.internal.NotNull;
aoqi@0 29 import com.sun.xml.internal.ws.addressing.v200408.MemberSubmissionAddressingConstants;
aoqi@0 30 import com.sun.xml.internal.ws.wsdl.parser.WSDLConstants;
aoqi@0 31 import org.w3c.dom.Element;
aoqi@0 32
aoqi@0 33 import javax.xml.bind.JAXBContext;
aoqi@0 34 import javax.xml.bind.JAXBException;
aoqi@0 35 import javax.xml.bind.Marshaller;
aoqi@0 36 import javax.xml.bind.Unmarshaller;
aoqi@0 37 import javax.xml.bind.annotation.XmlAnyAttribute;
aoqi@0 38 import javax.xml.bind.annotation.XmlAnyElement;
aoqi@0 39 import javax.xml.bind.annotation.XmlAttribute;
aoqi@0 40 import javax.xml.bind.annotation.XmlElement;
aoqi@0 41 import javax.xml.bind.annotation.XmlRootElement;
aoqi@0 42 import javax.xml.bind.annotation.XmlType;
aoqi@0 43 import javax.xml.bind.annotation.XmlValue;
aoqi@0 44 import javax.xml.namespace.QName;
aoqi@0 45 import javax.xml.transform.Result;
aoqi@0 46 import javax.xml.transform.Source;
aoqi@0 47 import javax.xml.transform.dom.DOMSource;
aoqi@0 48 import javax.xml.ws.EndpointReference;
aoqi@0 49 import javax.xml.ws.WebServiceException;
aoqi@0 50 import java.util.List;
aoqi@0 51 import java.util.Map;
aoqi@0 52
aoqi@0 53 /**
aoqi@0 54 * Data model for Member Submission WS-Addressing specification. This is modeled after the
aoqi@0 55 * member submission schema at:
aoqi@0 56 *
aoqi@0 57 * http://schemas.xmlsoap.org/ws/2004/08/addressing/
aoqi@0 58 *
aoqi@0 59 * @author Kathy Walsh
aoqi@0 60 * @author Vivek Pandey
aoqi@0 61 */
aoqi@0 62
aoqi@0 63 @XmlRootElement(name = "EndpointReference", namespace = MemberSubmissionEndpointReference.MSNS)
aoqi@0 64 @XmlType(name = "EndpointReferenceType", namespace = MemberSubmissionEndpointReference.MSNS)
aoqi@0 65 public final class MemberSubmissionEndpointReference extends EndpointReference implements MemberSubmissionAddressingConstants {
aoqi@0 66
aoqi@0 67 private final static ContextClassloaderLocal<JAXBContext> msjc = new ContextClassloaderLocal<JAXBContext>() {
aoqi@0 68 @Override
aoqi@0 69 protected JAXBContext initialValue() throws Exception {
aoqi@0 70 return MemberSubmissionEndpointReference.getMSJaxbContext();
aoqi@0 71 }
aoqi@0 72 };
aoqi@0 73
aoqi@0 74 public MemberSubmissionEndpointReference() {
aoqi@0 75 }
aoqi@0 76
aoqi@0 77 /**
aoqi@0 78 * construct an EPR from infoset representation
aoqi@0 79 *
aoqi@0 80 * @param source A source object containing valid XmlInfoset
aoqi@0 81 * instance consistent with the Member Submission WS-Addressing
aoqi@0 82 * @throws javax.xml.ws.WebServiceException
aoqi@0 83 * if the source does not contain a valid W3C WS-Addressing
aoqi@0 84 * EndpointReference.
aoqi@0 85 * @throws WebServiceException if the <code>null</code> <code>source</code> value is given
aoqi@0 86 */
aoqi@0 87 public MemberSubmissionEndpointReference(@NotNull Source source) {
aoqi@0 88
aoqi@0 89 if (source == null) {
aoqi@0 90 throw new WebServiceException("Source parameter can not be null on constructor");
aoqi@0 91 }
aoqi@0 92
aoqi@0 93 try {
aoqi@0 94 Unmarshaller unmarshaller = MemberSubmissionEndpointReference.msjc.get().createUnmarshaller();
aoqi@0 95 MemberSubmissionEndpointReference epr = unmarshaller.unmarshal(source,MemberSubmissionEndpointReference.class).getValue();
aoqi@0 96
aoqi@0 97 this.addr = epr.addr;
aoqi@0 98 this.referenceProperties = epr.referenceProperties;
aoqi@0 99 this.referenceParameters = epr.referenceParameters;
aoqi@0 100 this.portTypeName = epr.portTypeName;
aoqi@0 101 this.serviceName = epr.serviceName;
aoqi@0 102 this.attributes = epr.attributes;
aoqi@0 103 this.elements = epr.elements;
aoqi@0 104 } catch (JAXBException e) {
aoqi@0 105 throw new WebServiceException("Error unmarshalling MemberSubmissionEndpointReference ", e);
aoqi@0 106 } catch (ClassCastException e) {
aoqi@0 107 throw new WebServiceException("Source did not contain MemberSubmissionEndpointReference", e);
aoqi@0 108 }
aoqi@0 109 }
aoqi@0 110
aoqi@0 111 @Override
aoqi@0 112 public void writeTo(Result result) {
aoqi@0 113 try {
aoqi@0 114 Marshaller marshaller = MemberSubmissionEndpointReference.msjc.get().createMarshaller();
aoqi@0 115 //marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
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 /**
aoqi@0 123 * Constructs a Source containing the wsdl from the MemberSubmissionEndpointReference
aoqi@0 124 *
aoqi@0 125 * @return Source A source object containing the wsdl in the MemeberSubmissionEndpointReference, if present.
aoqi@0 126 */
aoqi@0 127 public Source toWSDLSource() {
aoqi@0 128 Element wsdlElement = null;
aoqi@0 129
aoqi@0 130 for (Element elem : elements) {
aoqi@0 131 if (elem.getNamespaceURI().equals(WSDLConstants.NS_WSDL) &&
aoqi@0 132 elem.getLocalName().equals(WSDLConstants.QNAME_DEFINITIONS.getLocalPart())) {
aoqi@0 133 wsdlElement = elem;
aoqi@0 134 }
aoqi@0 135 }
aoqi@0 136
aoqi@0 137 return new DOMSource(wsdlElement);
aoqi@0 138 }
aoqi@0 139
aoqi@0 140
aoqi@0 141 private static JAXBContext getMSJaxbContext() {
aoqi@0 142 try {
aoqi@0 143 return JAXBContext.newInstance(MemberSubmissionEndpointReference.class);
aoqi@0 144 } catch (JAXBException e) {
aoqi@0 145 throw new WebServiceException("Error creating JAXBContext for MemberSubmissionEndpointReference. ", e);
aoqi@0 146 }
aoqi@0 147 }
aoqi@0 148
aoqi@0 149 @XmlElement(name = "Address", namespace = MemberSubmissionEndpointReference.MSNS)
aoqi@0 150 public Address addr;
aoqi@0 151
aoqi@0 152 @XmlElement(name = "ReferenceProperties", namespace = MemberSubmissionEndpointReference.MSNS)
aoqi@0 153 public Elements referenceProperties;
aoqi@0 154
aoqi@0 155 @XmlElement(name = "ReferenceParameters", namespace = MemberSubmissionEndpointReference.MSNS)
aoqi@0 156 public Elements referenceParameters;
aoqi@0 157
aoqi@0 158 @XmlElement(name = "PortType", namespace = MemberSubmissionEndpointReference.MSNS)
aoqi@0 159 public AttributedQName portTypeName;
aoqi@0 160
aoqi@0 161 @XmlElement(name = "ServiceName", namespace = MemberSubmissionEndpointReference.MSNS)
aoqi@0 162 public ServiceNameType serviceName;
aoqi@0 163
aoqi@0 164 @XmlAnyAttribute
aoqi@0 165 public Map<QName,String> attributes;
aoqi@0 166
aoqi@0 167 @XmlAnyElement
aoqi@0 168 public List<Element> elements;
aoqi@0 169
aoqi@0 170 @XmlType(name="address", namespace=MemberSubmissionEndpointReference.MSNS)
aoqi@0 171 public static class Address {
aoqi@0 172 public Address() {
aoqi@0 173 }
aoqi@0 174
aoqi@0 175 @XmlValue
aoqi@0 176 public String uri;
aoqi@0 177 @XmlAnyAttribute
aoqi@0 178 public Map<QName, String> attributes;
aoqi@0 179 }
aoqi@0 180
aoqi@0 181 @XmlType(name="elements", namespace=MemberSubmissionEndpointReference.MSNS)
aoqi@0 182 public static class Elements {
aoqi@0 183 public Elements() {}
aoqi@0 184
aoqi@0 185 @XmlAnyElement
aoqi@0 186 public List<Element> elements;
aoqi@0 187 }
aoqi@0 188
aoqi@0 189
aoqi@0 190 public static class AttributedQName {
aoqi@0 191 public AttributedQName() {
aoqi@0 192 }
aoqi@0 193
aoqi@0 194 @XmlValue
aoqi@0 195 public QName name;
aoqi@0 196 @XmlAnyAttribute
aoqi@0 197 public Map<QName, String> attributes;
aoqi@0 198 }
aoqi@0 199
aoqi@0 200 public static class ServiceNameType extends AttributedQName{
aoqi@0 201 public ServiceNameType() {
aoqi@0 202 }
aoqi@0 203
aoqi@0 204 @XmlAttribute(name="PortName")
aoqi@0 205 public String portName;
aoqi@0 206 }
aoqi@0 207
aoqi@0 208 protected static final String MSNS = "http://schemas.xmlsoap.org/ws/2004/08/addressing";
aoqi@0 209 }

mercurial