Tue, 09 Apr 2013 14:51:13 +0100
8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com
1 /*
2 * Copyright (c) 1997, 2013, 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 JAXBContext msjc = MemberSubmissionEndpointReference.getMSJaxbContext();
69 public MemberSubmissionEndpointReference() {
70 }
72 /**
73 * construct an EPR from infoset representation
74 *
75 * @param source A source object containing valid XmlInfoset
76 * instance consistent with the Member Submission WS-Addressing
77 * @throws javax.xml.ws.WebServiceException
78 * if the source does not contain a valid W3C WS-Addressing
79 * EndpointReference.
80 * @throws WebServiceException if the <code>null</code> <code>source</code> value is given
81 */
82 public MemberSubmissionEndpointReference(@NotNull Source source) {
84 if (source == null) {
85 throw new WebServiceException("Source parameter can not be null on constructor");
86 }
88 try {
89 Unmarshaller unmarshaller = MemberSubmissionEndpointReference.msjc.createUnmarshaller();
90 MemberSubmissionEndpointReference epr = unmarshaller.unmarshal(source,MemberSubmissionEndpointReference.class).getValue();
92 this.addr = epr.addr;
93 this.referenceProperties = epr.referenceProperties;
94 this.referenceParameters = epr.referenceParameters;
95 this.portTypeName = epr.portTypeName;
96 this.serviceName = epr.serviceName;
97 this.attributes = epr.attributes;
98 this.elements = epr.elements;
99 } catch (JAXBException e) {
100 throw new WebServiceException("Error unmarshalling MemberSubmissionEndpointReference ", e);
101 } catch (ClassCastException e) {
102 throw new WebServiceException("Source did not contain MemberSubmissionEndpointReference", e);
103 }
104 }
106 @Override
107 public void writeTo(Result result) {
108 try {
109 Marshaller marshaller = MemberSubmissionEndpointReference.msjc.createMarshaller();
110 //marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
111 marshaller.marshal(this, result);
112 } catch (JAXBException e) {
113 throw new WebServiceException("Error marshalling W3CEndpointReference. ", e);
114 }
115 }
117 /**
118 * Constructs a Source containing the wsdl from the MemberSubmissionEndpointReference
119 *
120 * @return Source A source object containing the wsdl in the MemeberSubmissionEndpointReference, if present.
121 */
122 public Source toWSDLSource() {
123 Element wsdlElement = null;
125 for (Element elem : elements) {
126 if (elem.getNamespaceURI().equals(WSDLConstants.NS_WSDL) &&
127 elem.getLocalName().equals(WSDLConstants.QNAME_DEFINITIONS.getLocalPart())) {
128 wsdlElement = elem;
129 }
130 }
132 return new DOMSource(wsdlElement);
133 }
136 private static JAXBContext getMSJaxbContext() {
137 try {
138 return JAXBContext.newInstance(MemberSubmissionEndpointReference.class);
139 } catch (JAXBException e) {
140 throw new WebServiceException("Error creating JAXBContext for MemberSubmissionEndpointReference. ", e);
141 }
142 }
144 @XmlElement(name = "Address", namespace = MemberSubmissionEndpointReference.MSNS)
145 public Address addr;
147 @XmlElement(name = "ReferenceProperties", namespace = MemberSubmissionEndpointReference.MSNS)
148 public Elements referenceProperties;
150 @XmlElement(name = "ReferenceParameters", namespace = MemberSubmissionEndpointReference.MSNS)
151 public Elements referenceParameters;
153 @XmlElement(name = "PortType", namespace = MemberSubmissionEndpointReference.MSNS)
154 public AttributedQName portTypeName;
156 @XmlElement(name = "ServiceName", namespace = MemberSubmissionEndpointReference.MSNS)
157 public ServiceNameType serviceName;
159 @XmlAnyAttribute
160 public Map<QName,String> attributes;
162 @XmlAnyElement
163 public List<Element> elements;
165 @XmlType(name="address", namespace=MemberSubmissionEndpointReference.MSNS)
166 public static class Address {
167 public Address() {
168 }
170 @XmlValue
171 public String uri;
172 @XmlAnyAttribute
173 public Map<QName, String> attributes;
174 }
176 @XmlType(name="elements", namespace=MemberSubmissionEndpointReference.MSNS)
177 public static class Elements {
178 public Elements() {}
180 @XmlAnyElement
181 public List<Element> elements;
182 }
185 public static class AttributedQName {
186 public AttributedQName() {
187 }
189 @XmlValue
190 public QName name;
191 @XmlAnyAttribute
192 public Map<QName, String> attributes;
193 }
195 public static class ServiceNameType extends AttributedQName{
196 public ServiceNameType() {
197 }
199 @XmlAttribute(name="PortName")
200 public String portName;
201 }
203 protected static final String MSNS = "http://schemas.xmlsoap.org/ws/2004/08/addressing";
204 }