1/*
2 * Copyright (c) 1997, 2013, 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.util.xml;
27
28import com.sun.xml.internal.ws.api.streaming.XMLStreamWriterFactory;
29import com.sun.xml.internal.ws.api.streaming.XMLStreamWriterFactory.RecycleAware;
30
31import javax.xml.namespace.NamespaceContext;
32import javax.xml.stream.XMLStreamException;
33import javax.xml.stream.XMLStreamWriter;
34
35/**
36 * {@link XMLStreamWriter} that delegates to another {@link XMLStreamWriter}.
37 *
38 * <p>
39 * This class isn't very useful by itself, but works as a base class
40 * for {@link XMLStreamWriter} filtering.
41 *
42 * @author Kohsuke Kawaguchi
43 */
44public class XMLStreamWriterFilter implements XMLStreamWriter, RecycleAware {
45    protected XMLStreamWriter writer;
46
47    public XMLStreamWriterFilter(XMLStreamWriter writer) {
48        this.writer = writer;
49    }
50
51    public void close() throws XMLStreamException {
52        writer.close();
53    }
54
55    public void flush() throws XMLStreamException {
56        writer.flush();
57    }
58
59    public void writeEndDocument() throws XMLStreamException {
60        writer.writeEndDocument();
61    }
62
63    public void writeEndElement() throws XMLStreamException {
64        writer.writeEndElement();
65    }
66
67    public void writeStartDocument() throws XMLStreamException {
68        writer.writeStartDocument();
69    }
70
71    public void writeCharacters(char[] text, int start, int len) throws XMLStreamException {
72        writer.writeCharacters(text, start, len);
73    }
74
75    public void setDefaultNamespace(String uri) throws XMLStreamException {
76        writer.setDefaultNamespace(uri);
77    }
78
79    public void writeCData(String data) throws XMLStreamException {
80        writer.writeCData(data);
81    }
82
83    public void writeCharacters(String text) throws XMLStreamException {
84        writer.writeCharacters(text);
85    }
86
87    public void writeComment(String data) throws XMLStreamException {
88        writer.writeComment(data);
89    }
90
91    public void writeDTD(String dtd) throws XMLStreamException {
92        writer.writeDTD(dtd);
93    }
94
95    public void writeDefaultNamespace(String namespaceURI) throws XMLStreamException {
96        writer.writeDefaultNamespace(namespaceURI);
97    }
98
99    public void writeEmptyElement(String localName) throws XMLStreamException {
100        writer.writeEmptyElement(localName);
101    }
102
103    public void writeEntityRef(String name) throws XMLStreamException {
104        writer.writeEntityRef(name);
105    }
106
107    public void writeProcessingInstruction(String target) throws XMLStreamException {
108        writer.writeProcessingInstruction(target);
109    }
110
111    public void writeStartDocument(String version) throws XMLStreamException {
112        writer.writeStartDocument(version);
113    }
114
115    public void writeStartElement(String localName) throws XMLStreamException {
116        writer.writeStartElement(localName);
117    }
118
119    public NamespaceContext getNamespaceContext() {
120        return writer.getNamespaceContext();
121    }
122
123    public void setNamespaceContext(NamespaceContext context) throws XMLStreamException {
124        writer.setNamespaceContext(context);
125    }
126
127    public Object getProperty(String name) throws IllegalArgumentException {
128        return writer.getProperty(name);
129    }
130
131    public String getPrefix(String uri) throws XMLStreamException {
132        return writer.getPrefix(uri);
133    }
134
135    public void setPrefix(String prefix, String uri) throws XMLStreamException {
136        writer.setPrefix(prefix, uri);
137    }
138
139    public void writeAttribute(String localName, String value) throws XMLStreamException {
140        writer.writeAttribute(localName, value);
141    }
142
143    public void writeEmptyElement(String namespaceURI, String localName) throws XMLStreamException {
144        writer.writeEmptyElement(namespaceURI, localName);
145    }
146
147    public void writeNamespace(String prefix, String namespaceURI) throws XMLStreamException {
148        writer.writeNamespace(prefix, namespaceURI);
149    }
150
151    public void writeProcessingInstruction(String target, String data) throws XMLStreamException {
152        writer.writeProcessingInstruction(target, data);
153    }
154
155    public void writeStartDocument(String encoding, String version) throws XMLStreamException {
156        writer.writeStartDocument(encoding, version);
157    }
158
159    public void writeStartElement(String namespaceURI, String localName) throws XMLStreamException {
160        writer.writeStartElement(namespaceURI, localName);
161    }
162
163    public void writeAttribute(String namespaceURI, String localName, String value) throws XMLStreamException {
164        writer.writeAttribute(namespaceURI, localName, value);
165    }
166
167    public void writeEmptyElement(String prefix, String localName, String namespaceURI) throws XMLStreamException {
168        writer.writeEmptyElement(prefix, localName, namespaceURI);
169    }
170
171    public void writeStartElement(String prefix, String localName, String namespaceURI) throws XMLStreamException {
172        writer.writeStartElement(prefix, localName, namespaceURI);
173    }
174
175    public void writeAttribute(String prefix, String namespaceURI, String localName, String value) throws XMLStreamException {
176        writer.writeAttribute(prefix, namespaceURI, localName, value);
177    }
178
179    public void onRecycled() {
180        XMLStreamWriterFactory.recycle(writer);
181        writer = null;
182    }
183}
184