001: /*
002: * The contents of this file are subject to the terms
003: * of the Common Development and Distribution License
004: * (the "License"). You may not use this file except
005: * in compliance with the License.
006: *
007: * You can obtain a copy of the license at
008: * https://jwsdp.dev.java.net/CDDLv1.0.html
009: * See the License for the specific language governing
010: * permissions and limitations under the License.
011: *
012: * When distributing Covered Code, include this CDDL
013: * HEADER in each file and include the License file at
014: * https://jwsdp.dev.java.net/CDDLv1.0.html If applicable,
015: * add the following below this CDDL HEADER, with the
016: * fields enclosed by brackets "[]" replaced with your
017: * own identifying information: Portions Copyright [yyyy]
018: * [name of copyright owner]
019: */
020: package com.sun.xml.stream.buffer;
021:
022: import com.sun.xml.stream.buffer.sax.SAXBufferCreator;
023: import javax.xml.transform.sax.SAXResult;
024: import org.xml.sax.ContentHandler;
025: import org.xml.sax.ext.LexicalHandler;
026:
027: /**
028: * A JAXP Result implementation that supports the serialization to an
029: * {@link MutableXMLStreamBuffer} for use by applications that expect a Result.
030: *
031: * <p>
032: * Reuse of a XMLStreamBufferResult more than once will require that the
033: * MutableXMLStreamBuffer is reset by called
034: * {@link #.getXMLStreamBuffer()}.reset(), or by calling
035: * {@link #.setXMLStreamBuffer()} with a new instance of
036: * {@link MutableXMLStreamBuffer}.
037: *
038: * <p>
039: * The derivation of XMLStreamBufferResult from SAXResult is an implementation
040: * detail.
041: *
042: * <p>General applications shall not call the following methods:
043: * <ul>
044: * <li>setHandler</li>
045: * <li>setLexicalHandler</li>
046: * <li>setSystemId</li>
047: * </ul>
048: */
049: public class XMLStreamBufferResult extends SAXResult {
050: protected MutableXMLStreamBuffer _buffer;
051: protected SAXBufferCreator _bufferCreator;
052:
053: /**
054: * The default XMLStreamBufferResult constructor.
055: *
056: * <p>
057: * A {@link MutableXMLStreamBuffer} is instantiated and used.
058: */
059: public XMLStreamBufferResult() {
060: setXMLStreamBuffer(new MutableXMLStreamBuffer());
061: }
062:
063: /**
064: * XMLStreamBufferResult constructor.
065: *
066: * @param buffer the {@link MutableXMLStreamBuffer} to use.
067: */
068: public XMLStreamBufferResult(MutableXMLStreamBuffer buffer) {
069: setXMLStreamBuffer(buffer);
070: }
071:
072: /**
073: * Get the {@link MutableXMLStreamBuffer} that is used.
074: *
075: * @return the {@link MutableXMLStreamBuffer}.
076: */
077: public MutableXMLStreamBuffer getXMLStreamBuffer() {
078: return _buffer;
079: }
080:
081: /**
082: * Set the {@link MutableXMLStreamBuffer} to use.
083: *
084: * @param buffer the {@link MutableXMLStreamBuffer}.
085: */
086: public void setXMLStreamBuffer(MutableXMLStreamBuffer buffer) {
087: if (buffer == null) {
088: throw new NullPointerException("buffer cannot be null");
089: }
090: _buffer = buffer;
091: setSystemId(_buffer.getSystemId());
092:
093: if (_bufferCreator != null) {
094: _bufferCreator.setXMLStreamBuffer(_buffer);
095: }
096: }
097:
098: public ContentHandler getHandler() {
099: if (_bufferCreator == null) {
100: _bufferCreator = new SAXBufferCreator(_buffer);
101: setHandler(_bufferCreator);
102: } else if (super .getHandler() == null) {
103: setHandler(_bufferCreator);
104: }
105:
106: return _bufferCreator;
107: }
108:
109: public LexicalHandler getLexicalHandler() {
110: return (LexicalHandler) getHandler();
111: }
112: }
|