ohair@286: /*
alanb@368: * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
ohair@286: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ohair@286: *
ohair@286: * This code is free software; you can redistribute it and/or modify it
ohair@286: * under the terms of the GNU General Public License version 2 only, as
ohair@286: * published by the Free Software Foundation. Oracle designates this
ohair@286: * particular file as subject to the "Classpath" exception as provided
ohair@286: * by Oracle in the LICENSE file that accompanied this code.
ohair@286: *
ohair@286: * This code is distributed in the hope that it will be useful, but WITHOUT
ohair@286: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ohair@286: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ohair@286: * version 2 for more details (a copy is included in the LICENSE file that
ohair@286: * accompanied this code).
ohair@286: *
ohair@286: * You should have received a copy of the GNU General Public License version
ohair@286: * 2 along with this work; if not, write to the Free Software Foundation,
ohair@286: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ohair@286: *
ohair@286: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@286: * or visit www.oracle.com if you need additional information or have any
ohair@286: * questions.
ohair@286: */
ohair@286:
ohair@286: package com.sun.xml.internal.ws.developer;
ohair@286:
ohair@286: import com.sun.istack.internal.NotNull;
ohair@286: import com.sun.xml.internal.ws.addressing.v200408.MemberSubmissionAddressingConstants;
ohair@286: import com.sun.xml.internal.ws.wsdl.parser.WSDLConstants;
ohair@286: import org.w3c.dom.Element;
ohair@286:
ohair@286: import javax.xml.bind.JAXBContext;
ohair@286: import javax.xml.bind.JAXBException;
ohair@286: import javax.xml.bind.Marshaller;
ohair@286: import javax.xml.bind.Unmarshaller;
ohair@286: import javax.xml.bind.annotation.XmlAnyAttribute;
ohair@286: import javax.xml.bind.annotation.XmlAnyElement;
ohair@286: import javax.xml.bind.annotation.XmlAttribute;
ohair@286: import javax.xml.bind.annotation.XmlElement;
ohair@286: import javax.xml.bind.annotation.XmlRootElement;
ohair@286: import javax.xml.bind.annotation.XmlType;
ohair@286: import javax.xml.bind.annotation.XmlValue;
ohair@286: import javax.xml.namespace.QName;
ohair@286: import javax.xml.transform.Result;
ohair@286: import javax.xml.transform.Source;
ohair@286: import javax.xml.transform.dom.DOMSource;
ohair@286: import javax.xml.ws.EndpointReference;
ohair@286: import javax.xml.ws.WebServiceException;
ohair@286: import java.util.List;
ohair@286: import java.util.Map;
ohair@286:
ohair@286: /**
ohair@286: * Data model for Member Submission WS-Addressing specification. This is modeled after the
ohair@286: * member submission schema at:
ohair@286: *
ohair@286: * http://schemas.xmlsoap.org/ws/2004/08/addressing/
ohair@286: *
ohair@286: * @author Kathy Walsh
ohair@286: * @author Vivek Pandey
ohair@286: */
ohair@286:
ohair@286: @XmlRootElement(name = "EndpointReference", namespace = MemberSubmissionEndpointReference.MSNS)
ohair@286: @XmlType(name = "EndpointReferenceType", namespace = MemberSubmissionEndpointReference.MSNS)
ohair@286: public final class MemberSubmissionEndpointReference extends EndpointReference implements MemberSubmissionAddressingConstants {
ohair@286:
ohair@286: private final static JAXBContext msjc = MemberSubmissionEndpointReference.getMSJaxbContext();
ohair@286:
ohair@286: public MemberSubmissionEndpointReference() {
ohair@286: }
ohair@286:
ohair@286: /**
ohair@286: * construct an EPR from infoset representation
ohair@286: *
ohair@286: * @param source A source object containing valid XmlInfoset
ohair@286: * instance consistent with the Member Submission WS-Addressing
ohair@286: * @throws javax.xml.ws.WebServiceException
ohair@286: * if the source does not contain a valid W3C WS-Addressing
ohair@286: * EndpointReference.
ohair@286: * @throws WebServiceException if the null
source
value is given
ohair@286: */
ohair@286: public MemberSubmissionEndpointReference(@NotNull Source source) {
ohair@286:
alanb@368: if (source == null) {
ohair@286: throw new WebServiceException("Source parameter can not be null on constructor");
alanb@368: }
ohair@286:
ohair@286: try {
ohair@286: Unmarshaller unmarshaller = MemberSubmissionEndpointReference.msjc.createUnmarshaller();
ohair@286: MemberSubmissionEndpointReference epr = unmarshaller.unmarshal(source,MemberSubmissionEndpointReference.class).getValue();
ohair@286:
ohair@286: this.addr = epr.addr;
ohair@286: this.referenceProperties = epr.referenceProperties;
ohair@286: this.referenceParameters = epr.referenceParameters;
ohair@286: this.portTypeName = epr.portTypeName;
ohair@286: this.serviceName = epr.serviceName;
ohair@286: this.attributes = epr.attributes;
ohair@286: this.elements = epr.elements;
ohair@286: } catch (JAXBException e) {
ohair@286: throw new WebServiceException("Error unmarshalling MemberSubmissionEndpointReference ", e);
ohair@286: } catch (ClassCastException e) {
ohair@286: throw new WebServiceException("Source did not contain MemberSubmissionEndpointReference", e);
ohair@286: }
ohair@286: }
ohair@286:
alanb@368: @Override
ohair@286: public void writeTo(Result result) {
ohair@286: try {
ohair@286: Marshaller marshaller = MemberSubmissionEndpointReference.msjc.createMarshaller();
ohair@286: //marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
ohair@286: marshaller.marshal(this, result);
ohair@286: } catch (JAXBException e) {
ohair@286: throw new WebServiceException("Error marshalling W3CEndpointReference. ", e);
ohair@286: }
ohair@286: }
ohair@286:
ohair@286: /**
ohair@286: * Constructs a Source containing the wsdl from the MemberSubmissionEndpointReference
ohair@286: *
ohair@286: * @return Source A source object containing the wsdl in the MemeberSubmissionEndpointReference, if present.
ohair@286: */
ohair@286: public Source toWSDLSource() {
ohair@286: Element wsdlElement = null;
ohair@286:
ohair@286: for (Element elem : elements) {
ohair@286: if (elem.getNamespaceURI().equals(WSDLConstants.NS_WSDL) &&
ohair@286: elem.getLocalName().equals(WSDLConstants.QNAME_DEFINITIONS.getLocalPart())) {
ohair@286: wsdlElement = elem;
ohair@286: }
ohair@286: }
ohair@286:
ohair@286: return new DOMSource(wsdlElement);
ohair@286: }
ohair@286:
ohair@286:
ohair@286: private static JAXBContext getMSJaxbContext() {
ohair@286: try {
ohair@286: return JAXBContext.newInstance(MemberSubmissionEndpointReference.class);
ohair@286: } catch (JAXBException e) {
ohair@286: throw new WebServiceException("Error creating JAXBContext for MemberSubmissionEndpointReference. ", e);
ohair@286: }
ohair@286: }
ohair@286:
ohair@286: @XmlElement(name = "Address", namespace = MemberSubmissionEndpointReference.MSNS)
ohair@286: public Address addr;
ohair@286:
ohair@286: @XmlElement(name = "ReferenceProperties", namespace = MemberSubmissionEndpointReference.MSNS)
ohair@286: public Elements referenceProperties;
ohair@286:
ohair@286: @XmlElement(name = "ReferenceParameters", namespace = MemberSubmissionEndpointReference.MSNS)
ohair@286: public Elements referenceParameters;
ohair@286:
ohair@286: @XmlElement(name = "PortType", namespace = MemberSubmissionEndpointReference.MSNS)
ohair@286: public AttributedQName portTypeName;
ohair@286:
ohair@286: @XmlElement(name = "ServiceName", namespace = MemberSubmissionEndpointReference.MSNS)
ohair@286: public ServiceNameType serviceName;
ohair@286:
ohair@286: @XmlAnyAttribute
ohair@286: public Map attributes;
ohair@286:
ohair@286: @XmlAnyElement
ohair@286: public List elements;
ohair@286:
alanb@368: @XmlType(name="address", namespace=MemberSubmissionEndpointReference.MSNS)
ohair@286: public static class Address {
ohair@286: public Address() {
ohair@286: }
ohair@286:
ohair@286: @XmlValue
ohair@286: public String uri;
ohair@286: @XmlAnyAttribute
ohair@286: public Map attributes;
ohair@286: }
ohair@286:
alanb@368: @XmlType(name="elements", namespace=MemberSubmissionEndpointReference.MSNS)
ohair@286: public static class Elements {
ohair@286: public Elements() {}
ohair@286:
ohair@286: @XmlAnyElement
ohair@286: public List elements;
ohair@286: }
ohair@286:
ohair@286:
ohair@286: public static class AttributedQName {
ohair@286: public AttributedQName() {
ohair@286: }
ohair@286:
ohair@286: @XmlValue
ohair@286: public QName name;
ohair@286: @XmlAnyAttribute
ohair@286: public Map attributes;
ohair@286: }
ohair@286:
ohair@286: public static class ServiceNameType extends AttributedQName{
ohair@286: public ServiceNameType() {
ohair@286: }
ohair@286:
ohair@286: @XmlAttribute(name="PortName")
ohair@286: public String portName;
ohair@286: }
ohair@286:
ohair@286: protected static final String MSNS = "http://schemas.xmlsoap.org/ws/2004/08/addressing";
ohair@286: }