001: /*
002: * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.xml.internal.bind.v2.runtime.output;
027:
028: import java.io.IOException;
029:
030: import javax.xml.stream.XMLStreamException;
031:
032: import com.sun.xml.internal.bind.v2.runtime.XMLSerializer;
033: import com.sun.xml.internal.bind.v2.runtime.Name;
034:
035: import org.xml.sax.SAXException;
036:
037: /**
038: * {@link XmlOutput} that writes to two {@link XmlOutput}s.
039: * @author Kohsuke Kawaguchi
040: */
041: public final class ForkXmlOutput extends XmlOutputAbstractImpl {
042: private final XmlOutput lhs;
043: private final XmlOutput rhs;
044:
045: public ForkXmlOutput(XmlOutput lhs, XmlOutput rhs) {
046: this .lhs = lhs;
047: this .rhs = rhs;
048: }
049:
050: @Override
051: public void startDocument(XMLSerializer serializer,
052: boolean fragment, int[] nsUriIndex2prefixIndex,
053: NamespaceContextImpl nsContext) throws IOException,
054: SAXException, XMLStreamException {
055: lhs.startDocument(serializer, fragment, nsUriIndex2prefixIndex,
056: nsContext);
057: rhs.startDocument(serializer, fragment, nsUriIndex2prefixIndex,
058: nsContext);
059: }
060:
061: @Override
062: public void endDocument(boolean fragment) throws IOException,
063: SAXException, XMLStreamException {
064: lhs.endDocument(fragment);
065: rhs.endDocument(fragment);
066: }
067:
068: @Override
069: public void beginStartTag(Name name) throws IOException,
070: XMLStreamException {
071: lhs.beginStartTag(name);
072: rhs.beginStartTag(name);
073: }
074:
075: @Override
076: public void attribute(Name name, String value) throws IOException,
077: XMLStreamException {
078: lhs.attribute(name, value);
079: rhs.attribute(name, value);
080: }
081:
082: @Override
083: public void endTag(Name name) throws IOException, SAXException,
084: XMLStreamException {
085: lhs.endTag(name);
086: rhs.endTag(name);
087: }
088:
089: @Override
090: public void flush() throws IOException, XMLStreamException {
091: lhs.flush();
092: rhs.flush();
093: }
094:
095: public void beginStartTag(int prefix, String localName)
096: throws IOException, XMLStreamException {
097: lhs.beginStartTag(prefix, localName);
098: rhs.beginStartTag(prefix, localName);
099: }
100:
101: public void attribute(int prefix, String localName, String value)
102: throws IOException, XMLStreamException {
103: lhs.attribute(prefix, localName, value);
104: rhs.attribute(prefix, localName, value);
105: }
106:
107: public void endStartTag() throws IOException, SAXException {
108: lhs.endStartTag();
109: rhs.endStartTag();
110: }
111:
112: public void endTag(int prefix, String localName)
113: throws IOException, SAXException, XMLStreamException {
114: lhs.endTag(prefix, localName);
115: rhs.endTag(prefix, localName);
116: }
117:
118: public void text(String value, boolean needsSeparatingWhitespace)
119: throws IOException, SAXException, XMLStreamException {
120: lhs.text(value, needsSeparatingWhitespace);
121: rhs.text(value, needsSeparatingWhitespace);
122: }
123:
124: public void text(Pcdata value, boolean needsSeparatingWhitespace)
125: throws IOException, SAXException, XMLStreamException {
126: lhs.text(value, needsSeparatingWhitespace);
127: rhs.text(value, needsSeparatingWhitespace);
128: }
129: }
|