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

Fri, 14 Feb 2014 11:13:45 +0100

author
mkos
date
Fri, 14 Feb 2014 11:13:45 +0100
changeset 515
6cd506508147
parent 368
0989ad8c0860
child 637
9c07ef4934dd
permissions
-rw-r--r--

8026188: Enhance envelope factory
Summary: Avoiding caching data initialized via TCCL in static context; fix also reviewed by Alexander Fomin
Reviewed-by: ahgross, mgrebac, skoivu

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

mercurial