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.client.dispatch;
038:
039: import com.sun.xml.ws.api.addressing.WSEndpointReference;
040: import com.sun.xml.ws.api.message.Message;
041: import com.sun.xml.ws.api.message.Messages;
042: import com.sun.xml.ws.api.message.Packet;
043: import com.sun.xml.ws.api.pipe.Tube;
044: import com.sun.xml.ws.binding.BindingImpl;
045: import com.sun.xml.ws.client.WSServiceDelegate;
046: import com.sun.xml.ws.message.source.PayloadSourceMessage;
047:
048: import javax.xml.namespace.QName;
049: import javax.xml.transform.Source;
050: import javax.xml.ws.Service.Mode;
051: import javax.xml.ws.WebServiceException;
052:
053: /**
054: * The <code>SOAPSourceDispatch</code> class provides support
055: * for the dynamic invocation of a service endpoint operation using XML
056: * constructs. The <code>javax.xml.ws.Service</code>
057: * interface acts as a factory for the creation of <code>SOAPSourceDispatch</code>
058: * instances.
059: *
060: * @author WS Development Team
061: * @version 1.0
062: * @see RESTSourceDispatch
063: */
064: final class SOAPSourceDispatch extends DispatchImpl<Source> {
065:
066: public SOAPSourceDispatch(QName port, Mode mode,
067: WSServiceDelegate owner, Tube pipe, BindingImpl binding,
068: WSEndpointReference epr) {
069: super (port, mode, owner, pipe, binding, epr);
070: assert !isXMLHttp(binding);
071: }
072:
073: Source toReturnValue(Packet response) {
074: Message msg = response.getMessage();
075:
076: switch (mode) {
077: case PAYLOAD:
078: return msg.readPayloadAsSource();
079: case MESSAGE:
080: return msg.readEnvelopeAsSource();
081: default:
082: throw new WebServiceException("Unrecognized dispatch mode");
083: }
084: }
085:
086: @Override
087: Packet createPacket(Source msg) {
088:
089: final Message message;
090:
091: if (msg == null)
092: message = Messages.createEmpty(soapVersion);
093: else {
094: switch (mode) {
095: case PAYLOAD:
096: message = new PayloadSourceMessage(null, msg,
097: setOutboundAttachments(), soapVersion);
098: break;
099: case MESSAGE:
100: message = Messages.create(msg, soapVersion);
101: break;
102: default:
103: throw new WebServiceException(
104: "Unrecognized message mode");
105: }
106: }
107:
108: return new Packet(message);
109: }
110:
111: }
|