Tue, 06 Mar 2012 16:09:35 -0800
7150322: Stop using drop source bundles in jaxws
Reviewed-by: darcy, ohrstrom
1 /*
2 * Copyright (c) 1997, 2010, 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");
87 try {
88 Unmarshaller unmarshaller = MemberSubmissionEndpointReference.msjc.createUnmarshaller();
89 MemberSubmissionEndpointReference epr = unmarshaller.unmarshal(source,MemberSubmissionEndpointReference.class).getValue();
91 this.addr = epr.addr;
92 this.referenceProperties = epr.referenceProperties;
93 this.referenceParameters = epr.referenceParameters;
94 this.portTypeName = epr.portTypeName;
95 this.serviceName = epr.serviceName;
96 this.attributes = epr.attributes;
97 this.elements = epr.elements;
98 } catch (JAXBException e) {
99 throw new WebServiceException("Error unmarshalling MemberSubmissionEndpointReference ", e);
100 } catch (ClassCastException e) {
101 throw new WebServiceException("Source did not contain MemberSubmissionEndpointReference", e);
102 }
103 }
105 public void writeTo(Result result) {
106 try {
107 Marshaller marshaller = MemberSubmissionEndpointReference.msjc.createMarshaller();
108 //marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
109 marshaller.marshal(this, result);
110 } catch (JAXBException e) {
111 throw new WebServiceException("Error marshalling W3CEndpointReference. ", e);
112 }
113 }
115 /**
116 * Constructs a Source containing the wsdl from the MemberSubmissionEndpointReference
117 *
118 * @return Source A source object containing the wsdl in the MemeberSubmissionEndpointReference, if present.
119 */
120 public Source toWSDLSource() {
121 Element wsdlElement = null;
123 for (Element elem : elements) {
124 if (elem.getNamespaceURI().equals(WSDLConstants.NS_WSDL) &&
125 elem.getLocalName().equals(WSDLConstants.QNAME_DEFINITIONS.getLocalPart())) {
126 wsdlElement = elem;
127 }
128 }
130 return new DOMSource(wsdlElement);
131 }
134 private static JAXBContext getMSJaxbContext() {
135 try {
136 return JAXBContext.newInstance(MemberSubmissionEndpointReference.class);
137 } catch (JAXBException e) {
138 throw new WebServiceException("Error creating JAXBContext for MemberSubmissionEndpointReference. ", e);
139 }
140 }
142 @XmlElement(name = "Address", namespace = MemberSubmissionEndpointReference.MSNS)
143 public Address addr;
145 @XmlElement(name = "ReferenceProperties", namespace = MemberSubmissionEndpointReference.MSNS)
146 public Elements referenceProperties;
148 @XmlElement(name = "ReferenceParameters", namespace = MemberSubmissionEndpointReference.MSNS)
149 public Elements referenceParameters;
151 @XmlElement(name = "PortType", namespace = MemberSubmissionEndpointReference.MSNS)
152 public AttributedQName portTypeName;
154 @XmlElement(name = "ServiceName", namespace = MemberSubmissionEndpointReference.MSNS)
155 public ServiceNameType serviceName;
157 @XmlAnyAttribute
158 public Map<QName,String> attributes;
160 @XmlAnyElement
161 public List<Element> elements;
163 public static class Address {
164 public Address() {
165 }
167 @XmlValue
168 public String uri;
169 @XmlAnyAttribute
170 public Map<QName, String> attributes;
171 }
173 public static class Elements {
174 public Elements() {}
176 @XmlAnyElement
177 public List<Element> elements;
178 }
181 public static class AttributedQName {
182 public AttributedQName() {
183 }
185 @XmlValue
186 public QName name;
187 @XmlAnyAttribute
188 public Map<QName, String> attributes;
189 }
191 public static class ServiceNameType extends AttributedQName{
192 public ServiceNameType() {
193 }
195 @XmlAttribute(name="PortName")
196 public String portName;
197 }
199 protected static final String MSNS = "http://schemas.xmlsoap.org/ws/2004/08/addressing";
200 }