1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/developer/MemberSubmissionEndpointReference.java Wed Apr 27 01:27:09 2016 +0800 1.3 @@ -0,0 +1,209 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +package com.sun.xml.internal.ws.developer; 1.30 + 1.31 +import com.sun.istack.internal.NotNull; 1.32 +import com.sun.xml.internal.ws.addressing.v200408.MemberSubmissionAddressingConstants; 1.33 +import com.sun.xml.internal.ws.wsdl.parser.WSDLConstants; 1.34 +import org.w3c.dom.Element; 1.35 + 1.36 +import javax.xml.bind.JAXBContext; 1.37 +import javax.xml.bind.JAXBException; 1.38 +import javax.xml.bind.Marshaller; 1.39 +import javax.xml.bind.Unmarshaller; 1.40 +import javax.xml.bind.annotation.XmlAnyAttribute; 1.41 +import javax.xml.bind.annotation.XmlAnyElement; 1.42 +import javax.xml.bind.annotation.XmlAttribute; 1.43 +import javax.xml.bind.annotation.XmlElement; 1.44 +import javax.xml.bind.annotation.XmlRootElement; 1.45 +import javax.xml.bind.annotation.XmlType; 1.46 +import javax.xml.bind.annotation.XmlValue; 1.47 +import javax.xml.namespace.QName; 1.48 +import javax.xml.transform.Result; 1.49 +import javax.xml.transform.Source; 1.50 +import javax.xml.transform.dom.DOMSource; 1.51 +import javax.xml.ws.EndpointReference; 1.52 +import javax.xml.ws.WebServiceException; 1.53 +import java.util.List; 1.54 +import java.util.Map; 1.55 + 1.56 +/** 1.57 + * Data model for Member Submission WS-Addressing specification. This is modeled after the 1.58 + * member submission schema at: 1.59 + * 1.60 + * http://schemas.xmlsoap.org/ws/2004/08/addressing/ 1.61 + * 1.62 + * @author Kathy Walsh 1.63 + * @author Vivek Pandey 1.64 + */ 1.65 + 1.66 +@XmlRootElement(name = "EndpointReference", namespace = MemberSubmissionEndpointReference.MSNS) 1.67 +@XmlType(name = "EndpointReferenceType", namespace = MemberSubmissionEndpointReference.MSNS) 1.68 +public final class MemberSubmissionEndpointReference extends EndpointReference implements MemberSubmissionAddressingConstants { 1.69 + 1.70 + private final static ContextClassloaderLocal<JAXBContext> msjc = new ContextClassloaderLocal<JAXBContext>() { 1.71 + @Override 1.72 + protected JAXBContext initialValue() throws Exception { 1.73 + return MemberSubmissionEndpointReference.getMSJaxbContext(); 1.74 + } 1.75 + }; 1.76 + 1.77 + public MemberSubmissionEndpointReference() { 1.78 + } 1.79 + 1.80 + /** 1.81 + * construct an EPR from infoset representation 1.82 + * 1.83 + * @param source A source object containing valid XmlInfoset 1.84 + * instance consistent with the Member Submission WS-Addressing 1.85 + * @throws javax.xml.ws.WebServiceException 1.86 + * if the source does not contain a valid W3C WS-Addressing 1.87 + * EndpointReference. 1.88 + * @throws WebServiceException if the <code>null</code> <code>source</code> value is given 1.89 + */ 1.90 + public MemberSubmissionEndpointReference(@NotNull Source source) { 1.91 + 1.92 + if (source == null) { 1.93 + throw new WebServiceException("Source parameter can not be null on constructor"); 1.94 + } 1.95 + 1.96 + try { 1.97 + Unmarshaller unmarshaller = MemberSubmissionEndpointReference.msjc.get().createUnmarshaller(); 1.98 + MemberSubmissionEndpointReference epr = unmarshaller.unmarshal(source,MemberSubmissionEndpointReference.class).getValue(); 1.99 + 1.100 + this.addr = epr.addr; 1.101 + this.referenceProperties = epr.referenceProperties; 1.102 + this.referenceParameters = epr.referenceParameters; 1.103 + this.portTypeName = epr.portTypeName; 1.104 + this.serviceName = epr.serviceName; 1.105 + this.attributes = epr.attributes; 1.106 + this.elements = epr.elements; 1.107 + } catch (JAXBException e) { 1.108 + throw new WebServiceException("Error unmarshalling MemberSubmissionEndpointReference ", e); 1.109 + } catch (ClassCastException e) { 1.110 + throw new WebServiceException("Source did not contain MemberSubmissionEndpointReference", e); 1.111 + } 1.112 + } 1.113 + 1.114 + @Override 1.115 + public void writeTo(Result result) { 1.116 + try { 1.117 + Marshaller marshaller = MemberSubmissionEndpointReference.msjc.get().createMarshaller(); 1.118 + //marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); 1.119 + marshaller.marshal(this, result); 1.120 + } catch (JAXBException e) { 1.121 + throw new WebServiceException("Error marshalling W3CEndpointReference. ", e); 1.122 + } 1.123 + } 1.124 + 1.125 + /** 1.126 + * Constructs a Source containing the wsdl from the MemberSubmissionEndpointReference 1.127 + * 1.128 + * @return Source A source object containing the wsdl in the MemeberSubmissionEndpointReference, if present. 1.129 + */ 1.130 + public Source toWSDLSource() { 1.131 + Element wsdlElement = null; 1.132 + 1.133 + for (Element elem : elements) { 1.134 + if (elem.getNamespaceURI().equals(WSDLConstants.NS_WSDL) && 1.135 + elem.getLocalName().equals(WSDLConstants.QNAME_DEFINITIONS.getLocalPart())) { 1.136 + wsdlElement = elem; 1.137 + } 1.138 + } 1.139 + 1.140 + return new DOMSource(wsdlElement); 1.141 + } 1.142 + 1.143 + 1.144 + private static JAXBContext getMSJaxbContext() { 1.145 + try { 1.146 + return JAXBContext.newInstance(MemberSubmissionEndpointReference.class); 1.147 + } catch (JAXBException e) { 1.148 + throw new WebServiceException("Error creating JAXBContext for MemberSubmissionEndpointReference. ", e); 1.149 + } 1.150 + } 1.151 + 1.152 + @XmlElement(name = "Address", namespace = MemberSubmissionEndpointReference.MSNS) 1.153 + public Address addr; 1.154 + 1.155 + @XmlElement(name = "ReferenceProperties", namespace = MemberSubmissionEndpointReference.MSNS) 1.156 + public Elements referenceProperties; 1.157 + 1.158 + @XmlElement(name = "ReferenceParameters", namespace = MemberSubmissionEndpointReference.MSNS) 1.159 + public Elements referenceParameters; 1.160 + 1.161 + @XmlElement(name = "PortType", namespace = MemberSubmissionEndpointReference.MSNS) 1.162 + public AttributedQName portTypeName; 1.163 + 1.164 + @XmlElement(name = "ServiceName", namespace = MemberSubmissionEndpointReference.MSNS) 1.165 + public ServiceNameType serviceName; 1.166 + 1.167 + @XmlAnyAttribute 1.168 + public Map<QName,String> attributes; 1.169 + 1.170 + @XmlAnyElement 1.171 + public List<Element> elements; 1.172 + 1.173 + @XmlType(name="address", namespace=MemberSubmissionEndpointReference.MSNS) 1.174 + public static class Address { 1.175 + public Address() { 1.176 + } 1.177 + 1.178 + @XmlValue 1.179 + public String uri; 1.180 + @XmlAnyAttribute 1.181 + public Map<QName, String> attributes; 1.182 + } 1.183 + 1.184 + @XmlType(name="elements", namespace=MemberSubmissionEndpointReference.MSNS) 1.185 + public static class Elements { 1.186 + public Elements() {} 1.187 + 1.188 + @XmlAnyElement 1.189 + public List<Element> elements; 1.190 + } 1.191 + 1.192 + 1.193 + public static class AttributedQName { 1.194 + public AttributedQName() { 1.195 + } 1.196 + 1.197 + @XmlValue 1.198 + public QName name; 1.199 + @XmlAnyAttribute 1.200 + public Map<QName, String> attributes; 1.201 + } 1.202 + 1.203 + public static class ServiceNameType extends AttributedQName{ 1.204 + public ServiceNameType() { 1.205 + } 1.206 + 1.207 + @XmlAttribute(name="PortName") 1.208 + public String portName; 1.209 + } 1.210 + 1.211 + protected static final String MSNS = "http://schemas.xmlsoap.org/ws/2004/08/addressing"; 1.212 +}