Wed, 27 Apr 2016 01:27:09 +0800
Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/jaxws/
changeset: 657:d47a47f961ee
tag: jdk8u25-b17
1 /*
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
26 package com.sun.xml.internal.ws.developer;
28 import com.sun.istack.internal.NotNull;
29 import com.sun.xml.internal.ws.addressing.v200408.MemberSubmissionAddressingConstants;
30 import com.sun.xml.internal.ws.wsdl.parser.WSDLConstants;
31 import org.w3c.dom.Element;
33 import javax.xml.bind.JAXBContext;
34 import javax.xml.bind.JAXBException;
35 import javax.xml.bind.Marshaller;
36 import javax.xml.bind.Unmarshaller;
37 import javax.xml.bind.annotation.XmlAnyAttribute;
38 import javax.xml.bind.annotation.XmlAnyElement;
39 import javax.xml.bind.annotation.XmlAttribute;
40 import javax.xml.bind.annotation.XmlElement;
41 import javax.xml.bind.annotation.XmlRootElement;
42 import javax.xml.bind.annotation.XmlType;
43 import javax.xml.bind.annotation.XmlValue;
44 import javax.xml.namespace.QName;
45 import javax.xml.transform.Result;
46 import javax.xml.transform.Source;
47 import javax.xml.transform.dom.DOMSource;
48 import javax.xml.ws.EndpointReference;
49 import javax.xml.ws.WebServiceException;
50 import java.util.List;
51 import java.util.Map;
53 /**
54 * Data model for Member Submission WS-Addressing specification. This is modeled after the
55 * member submission schema at:
56 *
57 * http://schemas.xmlsoap.org/ws/2004/08/addressing/
58 *
59 * @author Kathy Walsh
60 * @author Vivek Pandey
61 */
63 @XmlRootElement(name = "EndpointReference", namespace = MemberSubmissionEndpointReference.MSNS)
64 @XmlType(name = "EndpointReferenceType", namespace = MemberSubmissionEndpointReference.MSNS)
65 public final class MemberSubmissionEndpointReference extends EndpointReference implements MemberSubmissionAddressingConstants {
67 private final static ContextClassloaderLocal<JAXBContext> msjc = new ContextClassloaderLocal<JAXBContext>() {
68 @Override
69 protected JAXBContext initialValue() throws Exception {
70 return MemberSubmissionEndpointReference.getMSJaxbContext();
71 }
72 };
74 public MemberSubmissionEndpointReference() {
75 }
77 /**
78 * construct an EPR from infoset representation
79 *
80 * @param source A source object containing valid XmlInfoset
81 * instance consistent with the Member Submission WS-Addressing
82 * @throws javax.xml.ws.WebServiceException
83 * if the source does not contain a valid W3C WS-Addressing
84 * EndpointReference.
85 * @throws WebServiceException if the <code>null</code> <code>source</code> value is given
86 */
87 public MemberSubmissionEndpointReference(@NotNull Source source) {
89 if (source == null) {
90 throw new WebServiceException("Source parameter can not be null on constructor");
91 }
93 try {
94 Unmarshaller unmarshaller = MemberSubmissionEndpointReference.msjc.get().createUnmarshaller();
95 MemberSubmissionEndpointReference epr = unmarshaller.unmarshal(source,MemberSubmissionEndpointReference.class).getValue();
97 this.addr = epr.addr;
98 this.referenceProperties = epr.referenceProperties;
99 this.referenceParameters = epr.referenceParameters;
100 this.portTypeName = epr.portTypeName;
101 this.serviceName = epr.serviceName;
102 this.attributes = epr.attributes;
103 this.elements = epr.elements;
104 } catch (JAXBException e) {
105 throw new WebServiceException("Error unmarshalling MemberSubmissionEndpointReference ", e);
106 } catch (ClassCastException e) {
107 throw new WebServiceException("Source did not contain MemberSubmissionEndpointReference", e);
108 }
109 }
111 @Override
112 public void writeTo(Result result) {
113 try {
114 Marshaller marshaller = MemberSubmissionEndpointReference.msjc.get().createMarshaller();
115 //marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
116 marshaller.marshal(this, result);
117 } catch (JAXBException e) {
118 throw new WebServiceException("Error marshalling W3CEndpointReference. ", e);
119 }
120 }
122 /**
123 * Constructs a Source containing the wsdl from the MemberSubmissionEndpointReference
124 *
125 * @return Source A source object containing the wsdl in the MemeberSubmissionEndpointReference, if present.
126 */
127 public Source toWSDLSource() {
128 Element wsdlElement = null;
130 for (Element elem : elements) {
131 if (elem.getNamespaceURI().equals(WSDLConstants.NS_WSDL) &&
132 elem.getLocalName().equals(WSDLConstants.QNAME_DEFINITIONS.getLocalPart())) {
133 wsdlElement = elem;
134 }
135 }
137 return new DOMSource(wsdlElement);
138 }
141 private static JAXBContext getMSJaxbContext() {
142 try {
143 return JAXBContext.newInstance(MemberSubmissionEndpointReference.class);
144 } catch (JAXBException e) {
145 throw new WebServiceException("Error creating JAXBContext for MemberSubmissionEndpointReference. ", e);
146 }
147 }
149 @XmlElement(name = "Address", namespace = MemberSubmissionEndpointReference.MSNS)
150 public Address addr;
152 @XmlElement(name = "ReferenceProperties", namespace = MemberSubmissionEndpointReference.MSNS)
153 public Elements referenceProperties;
155 @XmlElement(name = "ReferenceParameters", namespace = MemberSubmissionEndpointReference.MSNS)
156 public Elements referenceParameters;
158 @XmlElement(name = "PortType", namespace = MemberSubmissionEndpointReference.MSNS)
159 public AttributedQName portTypeName;
161 @XmlElement(name = "ServiceName", namespace = MemberSubmissionEndpointReference.MSNS)
162 public ServiceNameType serviceName;
164 @XmlAnyAttribute
165 public Map<QName,String> attributes;
167 @XmlAnyElement
168 public List<Element> elements;
170 @XmlType(name="address", namespace=MemberSubmissionEndpointReference.MSNS)
171 public static class Address {
172 public Address() {
173 }
175 @XmlValue
176 public String uri;
177 @XmlAnyAttribute
178 public Map<QName, String> attributes;
179 }
181 @XmlType(name="elements", namespace=MemberSubmissionEndpointReference.MSNS)
182 public static class Elements {
183 public Elements() {}
185 @XmlAnyElement
186 public List<Element> elements;
187 }
190 public static class AttributedQName {
191 public AttributedQName() {
192 }
194 @XmlValue
195 public QName name;
196 @XmlAnyAttribute
197 public Map<QName, String> attributes;
198 }
200 public static class ServiceNameType extends AttributedQName{
201 public ServiceNameType() {
202 }
204 @XmlAttribute(name="PortName")
205 public String portName;
206 }
208 protected static final String MSNS = "http://schemas.xmlsoap.org/ws/2004/08/addressing";
209 }