1/*
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package com.sun.xml.internal.ws.message;
27
28import com.sun.istack.internal.NotNull;
29import com.sun.xml.internal.ws.api.SOAPVersion;
30import com.sun.xml.internal.ws.api.message.AttachmentSet;
31import com.sun.xml.internal.ws.api.message.HeaderList;
32import com.sun.xml.internal.ws.api.message.Message;
33import com.sun.xml.internal.ws.api.message.MessageHeaders;
34
35import org.xml.sax.ContentHandler;
36import org.xml.sax.ErrorHandler;
37import org.xml.sax.SAXException;
38
39import javax.xml.stream.XMLStreamException;
40import javax.xml.stream.XMLStreamReader;
41import javax.xml.stream.XMLStreamWriter;
42import javax.xml.transform.Source;
43
44/**
45 * {@link Message} that has no body.
46 *
47 * @author Kohsuke Kawaguchi
48 */
49public class EmptyMessageImpl extends AbstractMessageImpl {
50
51    /**
52     * If a message has no payload, it's more likely to have
53     * some header, so we create it eagerly here.
54     */
55    private final MessageHeaders headers;
56    private final AttachmentSet attachmentSet;
57
58    public EmptyMessageImpl(SOAPVersion version) {
59        super(version);
60        this.headers = new HeaderList(version);
61        this.attachmentSet = new AttachmentSetImpl();
62    }
63
64    public EmptyMessageImpl(MessageHeaders headers, @NotNull AttachmentSet attachmentSet, SOAPVersion version){
65        super(version);
66        if(headers==null)
67            headers = new HeaderList(version);
68        this.attachmentSet = attachmentSet;
69        this.headers = headers;
70    }
71
72    /**
73     * Copy constructor.
74     */
75    private EmptyMessageImpl(EmptyMessageImpl that) {
76        super(that);
77        this.headers = new HeaderList(that.headers);
78        this.attachmentSet = that.attachmentSet;
79        this.copyFrom(that);
80    }
81
82    public boolean hasHeaders() {
83        return headers.hasHeaders();
84    }
85
86    public MessageHeaders getHeaders() {
87        return headers;
88    }
89
90    public String getPayloadLocalPart() {
91        return null;
92    }
93
94    public String getPayloadNamespaceURI() {
95        return null;
96    }
97
98    public boolean hasPayload() {
99        return false;
100    }
101
102    public Source readPayloadAsSource() {
103        return null;
104    }
105
106    public XMLStreamReader readPayload() throws XMLStreamException {
107        return null;
108    }
109
110    public void writePayloadTo(XMLStreamWriter sw) throws XMLStreamException {
111        // noop
112    }
113
114    public void writePayloadTo(ContentHandler contentHandler, ErrorHandler errorHandler, boolean fragment) throws SAXException {
115        // noop
116    }
117
118    public Message copy() {
119        return new EmptyMessageImpl(this).copyFrom(this);
120    }
121
122}
123