001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.xml.ws.developer;
038:
039: import com.sun.istack.NotNull;
040: import com.sun.xml.ws.addressing.v200408.MemberSubmissionAddressingConstants;
041: import com.sun.xml.ws.wsdl.parser.WSDLConstants;
042: import org.w3c.dom.Element;
043:
044: import javax.xml.bind.JAXBContext;
045: import javax.xml.bind.JAXBException;
046: import javax.xml.bind.Marshaller;
047: import javax.xml.bind.Unmarshaller;
048: import javax.xml.bind.annotation.XmlAnyAttribute;
049: import javax.xml.bind.annotation.XmlAnyElement;
050: import javax.xml.bind.annotation.XmlAttribute;
051: import javax.xml.bind.annotation.XmlElement;
052: import javax.xml.bind.annotation.XmlRootElement;
053: import javax.xml.bind.annotation.XmlType;
054: import javax.xml.bind.annotation.XmlValue;
055: import javax.xml.namespace.QName;
056: import javax.xml.transform.Result;
057: import javax.xml.transform.Source;
058: import javax.xml.transform.dom.DOMSource;
059: import javax.xml.ws.EndpointReference;
060: import javax.xml.ws.WebServiceException;
061: import java.util.List;
062: import java.util.Map;
063:
064: /**
065: * Data model for Member Submission WS-Addressing specification. This is modeled after the
066: * member submission schema at:
067: *
068: * http://schemas.xmlsoap.org/ws/2004/08/addressing/
069: *
070: * @author Kathy Walsh
071: * @author Vivek Pandey
072: */
073:
074: @XmlRootElement(name="EndpointReference",namespace=MemberSubmissionEndpointReference.MSNS)
075: @XmlType(name="EndpointReferenceType",namespace=MemberSubmissionEndpointReference.MSNS)
076: public final class MemberSubmissionEndpointReference extends
077: EndpointReference implements
078: MemberSubmissionAddressingConstants {
079:
080: private final static JAXBContext msjc = MemberSubmissionEndpointReference
081: .getMSJaxbContext();
082:
083: public MemberSubmissionEndpointReference() {
084: }
085:
086: /**
087: * construct an EPR from infoset representation
088: *
089: * @param source A source object containing valid XmlInfoset
090: * instance consistent with the Member Submission WS-Addressing
091: * @throws javax.xml.ws.WebServiceException
092: * if the source does not contain a valid W3C WS-Addressing
093: * EndpointReference.
094: * @throws WebServiceException if the <code>null</code> <code>source</code> value is given
095: */
096: public MemberSubmissionEndpointReference(@NotNull
097: Source source) {
098:
099: if (source == null)
100: throw new WebServiceException(
101: "Source parameter can not be null on constructor");
102:
103: try {
104: Unmarshaller unmarshaller = MemberSubmissionEndpointReference.msjc
105: .createUnmarshaller();
106: MemberSubmissionEndpointReference epr = unmarshaller
107: .unmarshal(source,
108: MemberSubmissionEndpointReference.class)
109: .getValue();
110:
111: this .addr = epr.addr;
112: this .referenceProperties = epr.referenceProperties;
113: this .referenceParameters = epr.referenceParameters;
114: this .portTypeName = epr.portTypeName;
115: this .serviceName = epr.serviceName;
116: this .attributes = epr.attributes;
117: this .elements = epr.elements;
118: } catch (JAXBException e) {
119: throw new WebServiceException(
120: "Error unmarshalling MemberSubmissionEndpointReference ",
121: e);
122: } catch (ClassCastException e) {
123: throw new WebServiceException(
124: "Source did not contain MemberSubmissionEndpointReference",
125: e);
126: }
127: }
128:
129: public void writeTo(Result result) {
130: try {
131: Marshaller marshaller = MemberSubmissionEndpointReference.msjc
132: .createMarshaller();
133: marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
134: marshaller.marshal(this , result);
135: } catch (JAXBException e) {
136: throw new WebServiceException(
137: "Error marshalling W3CEndpointReference. ", e);
138: }
139: }
140:
141: /**
142: * Constructs a Source containing the wsdl from the MemberSubmissionEndpointReference
143: *
144: * @return Source A source object containing the wsdl in the MemeberSubmissionEndpointReference, if present.
145: */
146: public Source toWSDLSource() {
147: Element wsdlElement = null;
148:
149: for (Element elem : elements) {
150: if (elem.getNamespaceURI().equals(WSDLConstants.NS_WSDL)
151: && elem.getLocalName().equals(
152: WSDLConstants.QNAME_DEFINITIONS
153: .getLocalPart())) {
154: wsdlElement = elem;
155: }
156: }
157:
158: return new DOMSource(wsdlElement);
159: }
160:
161: private static JAXBContext getMSJaxbContext() {
162: try {
163: return JAXBContext
164: .newInstance(MemberSubmissionEndpointReference.class);
165: } catch (JAXBException e) {
166: throw new WebServiceException(
167: "Error creating JAXBContext for MemberSubmissionEndpointReference. ",
168: e);
169: }
170: }
171:
172: @XmlElement(name="Address",namespace=MemberSubmissionEndpointReference.MSNS)
173: public Address addr;
174:
175: @XmlElement(name="ReferenceProperties",namespace=MemberSubmissionEndpointReference.MSNS)
176: public Elements referenceProperties;
177:
178: @XmlElement(name="ReferenceParameters",namespace=MemberSubmissionEndpointReference.MSNS)
179: public Elements referenceParameters;
180:
181: @XmlElement(name="PortType",namespace=MemberSubmissionEndpointReference.MSNS)
182: public AttributedQName portTypeName;
183:
184: @XmlElement(name="ServiceName",namespace=MemberSubmissionEndpointReference.MSNS)
185: public ServiceNameType serviceName;
186:
187: @XmlAnyAttribute
188: public Map<QName, String> attributes;
189:
190: @XmlAnyElement
191: public List<Element> elements;
192:
193: public static class Address {
194: public Address() {
195: }
196:
197: @XmlValue
198: public String uri;
199: @XmlAnyAttribute
200: public Map<QName, String> attributes;
201: }
202:
203: public static class Elements {
204: public Elements() {
205: }
206:
207: @XmlAnyElement
208: public List<Element> elements;
209: }
210:
211: public static class AttributedQName {
212: public AttributedQName() {
213: }
214:
215: @XmlValue
216: public QName name;
217: @XmlAnyAttribute
218: public Map<QName, String> attributes;
219: }
220:
221: public static class ServiceNameType extends AttributedQName {
222: public ServiceNameType() {
223: }
224:
225: @XmlAttribute(name="PortName")
226: public String portName;
227: }
228:
229: protected static final String MSNS = "http://schemas.xmlsoap.org/ws/2004/08/addressing";
230: }
|