1/*
2 * Copyright (c) 1997, 2012, 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.bind.v2.runtime.output;
27
28import java.io.IOException;
29
30import javax.xml.stream.XMLStreamException;
31
32import com.sun.xml.internal.bind.v2.runtime.XMLSerializer;
33import com.sun.xml.internal.bind.v2.runtime.Name;
34
35import org.xml.sax.SAXException;
36
37/**
38 * {@link XmlOutput} that writes to two {@link XmlOutput}s.
39 * @author Kohsuke Kawaguchi
40 */
41public final class ForkXmlOutput extends XmlOutputAbstractImpl {
42    private final XmlOutput lhs;
43    private final XmlOutput rhs;
44
45    public ForkXmlOutput(XmlOutput lhs, XmlOutput rhs) {
46        this.lhs = lhs;
47        this.rhs = rhs;
48    }
49
50    @Override
51    public void startDocument(XMLSerializer serializer, boolean fragment, int[] nsUriIndex2prefixIndex, NamespaceContextImpl nsContext) throws IOException, SAXException, XMLStreamException {
52        lhs.startDocument(serializer, fragment, nsUriIndex2prefixIndex, nsContext);
53        rhs.startDocument(serializer, fragment, nsUriIndex2prefixIndex, nsContext);
54    }
55
56    @Override
57    public void endDocument(boolean fragment) throws IOException, SAXException, XMLStreamException {
58        lhs.endDocument(fragment);
59        rhs.endDocument(fragment);
60    }
61
62    @Override
63    public void beginStartTag(Name name) throws IOException, XMLStreamException {
64        lhs.beginStartTag(name);
65        rhs.beginStartTag(name);
66    }
67
68    @Override
69    public void attribute(Name name, String value) throws IOException, XMLStreamException {
70        lhs.attribute(name, value);
71        rhs.attribute(name, value);
72    }
73
74    @Override
75    public void endTag(Name name) throws IOException, SAXException, XMLStreamException {
76        lhs.endTag(name);
77        rhs.endTag(name);
78    }
79
80    public void beginStartTag(int prefix, String localName) throws IOException, XMLStreamException {
81        lhs.beginStartTag(prefix,localName);
82        rhs.beginStartTag(prefix,localName);
83    }
84
85    public void attribute(int prefix, String localName, String value) throws IOException, XMLStreamException {
86        lhs.attribute(prefix,localName,value);
87        rhs.attribute(prefix,localName,value);
88    }
89
90    public void endStartTag() throws IOException, SAXException {
91        lhs.endStartTag();
92        rhs.endStartTag();
93    }
94
95    public void endTag(int prefix, String localName) throws IOException, SAXException, XMLStreamException {
96        lhs.endTag(prefix,localName);
97        rhs.endTag(prefix,localName);
98    }
99
100    public void text(String value, boolean needsSeparatingWhitespace) throws IOException, SAXException, XMLStreamException {
101        lhs.text(value,needsSeparatingWhitespace);
102        rhs.text(value,needsSeparatingWhitespace);
103    }
104
105    public void text(Pcdata value, boolean needsSeparatingWhitespace) throws IOException, SAXException, XMLStreamException {
106        lhs.text(value,needsSeparatingWhitespace);
107        rhs.text(value,needsSeparatingWhitespace);
108    }
109}
110