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 Tue Mar 06 16:09:35 2012 -0800 1.3 @@ -0,0 +1,200 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2010, 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 JAXBContext msjc = MemberSubmissionEndpointReference.getMSJaxbContext(); 1.71 + 1.72 + public MemberSubmissionEndpointReference() { 1.73 + } 1.74 + 1.75 + /** 1.76 + * construct an EPR from infoset representation 1.77 + * 1.78 + * @param source A source object containing valid XmlInfoset 1.79 + * instance consistent with the Member Submission WS-Addressing 1.80 + * @throws javax.xml.ws.WebServiceException 1.81 + * if the source does not contain a valid W3C WS-Addressing 1.82 + * EndpointReference. 1.83 + * @throws WebServiceException if the <code>null</code> <code>source</code> value is given 1.84 + */ 1.85 + public MemberSubmissionEndpointReference(@NotNull Source source) { 1.86 + 1.87 + if (source == null) 1.88 + throw new WebServiceException("Source parameter can not be null on constructor"); 1.89 + 1.90 + try { 1.91 + Unmarshaller unmarshaller = MemberSubmissionEndpointReference.msjc.createUnmarshaller(); 1.92 + MemberSubmissionEndpointReference epr = unmarshaller.unmarshal(source,MemberSubmissionEndpointReference.class).getValue(); 1.93 + 1.94 + this.addr = epr.addr; 1.95 + this.referenceProperties = epr.referenceProperties; 1.96 + this.referenceParameters = epr.referenceParameters; 1.97 + this.portTypeName = epr.portTypeName; 1.98 + this.serviceName = epr.serviceName; 1.99 + this.attributes = epr.attributes; 1.100 + this.elements = epr.elements; 1.101 + } catch (JAXBException e) { 1.102 + throw new WebServiceException("Error unmarshalling MemberSubmissionEndpointReference ", e); 1.103 + } catch (ClassCastException e) { 1.104 + throw new WebServiceException("Source did not contain MemberSubmissionEndpointReference", e); 1.105 + } 1.106 + } 1.107 + 1.108 + public void writeTo(Result result) { 1.109 + try { 1.110 + Marshaller marshaller = MemberSubmissionEndpointReference.msjc.createMarshaller(); 1.111 + //marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); 1.112 + marshaller.marshal(this, result); 1.113 + } catch (JAXBException e) { 1.114 + throw new WebServiceException("Error marshalling W3CEndpointReference. ", e); 1.115 + } 1.116 + } 1.117 + 1.118 + /** 1.119 + * Constructs a Source containing the wsdl from the MemberSubmissionEndpointReference 1.120 + * 1.121 + * @return Source A source object containing the wsdl in the MemeberSubmissionEndpointReference, if present. 1.122 + */ 1.123 + public Source toWSDLSource() { 1.124 + Element wsdlElement = null; 1.125 + 1.126 + for (Element elem : elements) { 1.127 + if (elem.getNamespaceURI().equals(WSDLConstants.NS_WSDL) && 1.128 + elem.getLocalName().equals(WSDLConstants.QNAME_DEFINITIONS.getLocalPart())) { 1.129 + wsdlElement = elem; 1.130 + } 1.131 + } 1.132 + 1.133 + return new DOMSource(wsdlElement); 1.134 + } 1.135 + 1.136 + 1.137 + private static JAXBContext getMSJaxbContext() { 1.138 + try { 1.139 + return JAXBContext.newInstance(MemberSubmissionEndpointReference.class); 1.140 + } catch (JAXBException e) { 1.141 + throw new WebServiceException("Error creating JAXBContext for MemberSubmissionEndpointReference. ", e); 1.142 + } 1.143 + } 1.144 + 1.145 + @XmlElement(name = "Address", namespace = MemberSubmissionEndpointReference.MSNS) 1.146 + public Address addr; 1.147 + 1.148 + @XmlElement(name = "ReferenceProperties", namespace = MemberSubmissionEndpointReference.MSNS) 1.149 + public Elements referenceProperties; 1.150 + 1.151 + @XmlElement(name = "ReferenceParameters", namespace = MemberSubmissionEndpointReference.MSNS) 1.152 + public Elements referenceParameters; 1.153 + 1.154 + @XmlElement(name = "PortType", namespace = MemberSubmissionEndpointReference.MSNS) 1.155 + public AttributedQName portTypeName; 1.156 + 1.157 + @XmlElement(name = "ServiceName", namespace = MemberSubmissionEndpointReference.MSNS) 1.158 + public ServiceNameType serviceName; 1.159 + 1.160 + @XmlAnyAttribute 1.161 + public Map<QName,String> attributes; 1.162 + 1.163 + @XmlAnyElement 1.164 + public List<Element> elements; 1.165 + 1.166 + public static class Address { 1.167 + public Address() { 1.168 + } 1.169 + 1.170 + @XmlValue 1.171 + public String uri; 1.172 + @XmlAnyAttribute 1.173 + public Map<QName, String> attributes; 1.174 + } 1.175 + 1.176 + public static class Elements { 1.177 + public Elements() {} 1.178 + 1.179 + @XmlAnyElement 1.180 + public List<Element> elements; 1.181 + } 1.182 + 1.183 + 1.184 + public static class AttributedQName { 1.185 + public AttributedQName() { 1.186 + } 1.187 + 1.188 + @XmlValue 1.189 + public QName name; 1.190 + @XmlAnyAttribute 1.191 + public Map<QName, String> attributes; 1.192 + } 1.193 + 1.194 + public static class ServiceNameType extends AttributedQName{ 1.195 + public ServiceNameType() { 1.196 + } 1.197 + 1.198 + @XmlAttribute(name="PortName") 1.199 + public String portName; 1.200 + } 1.201 + 1.202 + protected static final String MSNS = "http://schemas.xmlsoap.org/ws/2004/08/addressing"; 1.203 +}