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.bind.v2.runtime.output;
038:
039: import java.io.IOException;
040:
041: import javax.xml.stream.XMLStreamException;
042:
043: import com.sun.xml.bind.v2.runtime.XMLSerializer;
044: import com.sun.xml.bind.v2.runtime.Name;
045:
046: import org.xml.sax.SAXException;
047:
048: /**
049: * {@link XmlOutput} that writes to two {@link XmlOutput}s.
050: * @author Kohsuke Kawaguchi
051: */
052: public final class ForkXmlOutput extends XmlOutputAbstractImpl {
053: private final XmlOutput lhs;
054: private final XmlOutput rhs;
055:
056: public ForkXmlOutput(XmlOutput lhs, XmlOutput rhs) {
057: this .lhs = lhs;
058: this .rhs = rhs;
059: }
060:
061: @Override
062: public void startDocument(XMLSerializer serializer,
063: boolean fragment, int[] nsUriIndex2prefixIndex,
064: NamespaceContextImpl nsContext) throws IOException,
065: SAXException, XMLStreamException {
066: lhs.startDocument(serializer, fragment, nsUriIndex2prefixIndex,
067: nsContext);
068: rhs.startDocument(serializer, fragment, nsUriIndex2prefixIndex,
069: nsContext);
070: }
071:
072: @Override
073: public void endDocument(boolean fragment) throws IOException,
074: SAXException, XMLStreamException {
075: lhs.endDocument(fragment);
076: rhs.endDocument(fragment);
077: }
078:
079: @Override
080: public void beginStartTag(Name name) throws IOException,
081: XMLStreamException {
082: lhs.beginStartTag(name);
083: rhs.beginStartTag(name);
084: }
085:
086: @Override
087: public void attribute(Name name, String value) throws IOException,
088: XMLStreamException {
089: lhs.attribute(name, value);
090: rhs.attribute(name, value);
091: }
092:
093: @Override
094: public void endTag(Name name) throws IOException, SAXException,
095: XMLStreamException {
096: lhs.endTag(name);
097: rhs.endTag(name);
098: }
099:
100: public void beginStartTag(int prefix, String localName)
101: throws IOException, XMLStreamException {
102: lhs.beginStartTag(prefix, localName);
103: rhs.beginStartTag(prefix, localName);
104: }
105:
106: public void attribute(int prefix, String localName, String value)
107: throws IOException, XMLStreamException {
108: lhs.attribute(prefix, localName, value);
109: rhs.attribute(prefix, localName, value);
110: }
111:
112: public void endStartTag() throws IOException, SAXException {
113: lhs.endStartTag();
114: rhs.endStartTag();
115: }
116:
117: public void endTag(int prefix, String localName)
118: throws IOException, SAXException, XMLStreamException {
119: lhs.endTag(prefix, localName);
120: rhs.endTag(prefix, localName);
121: }
122:
123: public void text(String value, boolean needsSeparatingWhitespace)
124: throws IOException, SAXException, XMLStreamException {
125: lhs.text(value, needsSeparatingWhitespace);
126: rhs.text(value, needsSeparatingWhitespace);
127: }
128:
129: public void text(Pcdata value, boolean needsSeparatingWhitespace)
130: throws IOException, SAXException, XMLStreamException {
131: lhs.text(value, needsSeparatingWhitespace);
132: rhs.text(value, needsSeparatingWhitespace);
133: }
134: }
|