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.message;
038:
039: import com.sun.istack.NotNull;
040: import com.sun.xml.ws.api.SOAPVersion;
041: import com.sun.xml.ws.api.message.AttachmentSet;
042: import com.sun.xml.ws.api.message.Header;
043: import com.sun.xml.ws.api.message.HeaderList;
044: import com.sun.xml.ws.api.message.Message;
045: import org.xml.sax.ContentHandler;
046: import org.xml.sax.ErrorHandler;
047: import org.xml.sax.SAXException;
048:
049: import javax.xml.soap.SOAPException;
050: import javax.xml.soap.SOAPMessage;
051: import javax.xml.stream.XMLStreamException;
052: import javax.xml.stream.XMLStreamReader;
053: import javax.xml.stream.XMLStreamWriter;
054: import javax.xml.transform.Source;
055:
056: /**
057: * {@link Message} that has no body.
058: *
059: * @author Kohsuke Kawaguchi
060: */
061: public class EmptyMessageImpl extends AbstractMessageImpl {
062:
063: /**
064: * If a message has no payload, it's more likely to have
065: * some header, so we create it eagerly here.
066: */
067: private final HeaderList headers;
068: private final AttachmentSet attachmentSet;
069:
070: public EmptyMessageImpl(SOAPVersion version) {
071: super (version);
072: this .headers = new HeaderList();
073: this .attachmentSet = new AttachmentSetImpl();
074: }
075:
076: public EmptyMessageImpl(HeaderList headers, @NotNull
077: AttachmentSet attachmentSet, SOAPVersion version) {
078: super (version);
079: if (headers == null)
080: headers = new HeaderList();
081: this .attachmentSet = attachmentSet;
082: this .headers = headers;
083: }
084:
085: /**
086: * Copy constructor.
087: */
088: private EmptyMessageImpl(EmptyMessageImpl that) {
089: super (that);
090: this .headers = new HeaderList(that.headers);
091: this .attachmentSet = that.attachmentSet;
092: }
093:
094: public boolean hasHeaders() {
095: return !headers.isEmpty();
096: }
097:
098: @Override
099: public @NotNull
100: AttachmentSet getAttachments() {
101: return attachmentSet;
102: }
103:
104: public HeaderList getHeaders() {
105: return headers;
106: }
107:
108: public String getPayloadLocalPart() {
109: return null;
110: }
111:
112: public String getPayloadNamespaceURI() {
113: return null;
114: }
115:
116: public boolean hasPayload() {
117: return false;
118: }
119:
120: public Source readPayloadAsSource() {
121: return null;
122: }
123:
124: public XMLStreamReader readPayload() throws XMLStreamException {
125: return null;
126: }
127:
128: public void writePayloadTo(XMLStreamWriter sw)
129: throws XMLStreamException {
130: // noop
131: }
132:
133: public void writePayloadTo(ContentHandler contentHandler,
134: ErrorHandler errorHandler, boolean fragment)
135: throws SAXException {
136: // noop
137: }
138:
139: public Message copy() {
140: return new EmptyMessageImpl(this);
141: }
142: }
|