001: /*
002: * $Id: BaseXMLEventAllocator.java,v 1.1 2004/07/05 23:09:31 cniles Exp $
003: *
004: * Copyright (c) 2004, Christian Niles, unit12.net
005: * All rights reserved.
006: *
007: * Redistribution and use in source and binary forms, with or without
008: * modification, are permitted provided that the following conditions are met:
009: *
010: * * Redistributions of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * * Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in the
015: * documentation and/or other materials provided with the distribution.
016: *
017: * * Neither the name of Christian Niles, Unit12, nor the names of its
018: * contributors may be used to endorse or promote products derived from
019: * this software without specific prior written permission.
020: *
021: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
022: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
023: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
024: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
025: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
026: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
027: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
028: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
029: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
030: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
031: * POSSIBILITY OF SUCH DAMAGE.
032: *
033: */
034: package javanet.staxutils.events;
035:
036: import javax.xml.namespace.NamespaceContext;
037: import javax.xml.stream.Location;
038: import javax.xml.stream.XMLStreamException;
039: import javax.xml.stream.XMLStreamReader;
040: import javax.xml.stream.events.*;
041: import javax.xml.stream.util.XMLEventAllocator;
042: import javax.xml.stream.util.XMLEventConsumer;
043:
044: /**
045: * Abstract base class for {@link XMLEventAllocator} implementations.
046: *
047: * @author Christian Niles
048: * @version $Revision: 1.1 $
049: */
050: public abstract class BaseXMLEventAllocator implements
051: XMLEventAllocator {
052:
053: public void allocate(XMLStreamReader reader,
054: XMLEventConsumer consumer) throws XMLStreamException {
055:
056: consumer.add(allocate(reader));
057:
058: }
059:
060: /**
061: * Delegates allocation to the appropriate <code>allocateXXX</code> method.
062: */
063: public XMLEvent allocate(XMLStreamReader reader)
064: throws XMLStreamException {
065:
066: int eventType = reader.getEventType();
067: switch (eventType) {
068:
069: case XMLEvent.START_ELEMENT:
070: return allocateStartElement(reader);
071:
072: case XMLEvent.END_ELEMENT:
073: return allocateEndElement(reader);
074:
075: case XMLEvent.CHARACTERS:
076: return allocateCharacters(reader);
077:
078: case XMLEvent.CDATA:
079: return allocateCData(reader);
080:
081: case XMLEvent.SPACE:
082: return allocateIgnorableSpace(reader);
083:
084: case XMLEvent.COMMENT:
085: return allocateComment(reader);
086:
087: case XMLEvent.DTD:
088: return allocateDTD(reader);
089:
090: case XMLEvent.ENTITY_REFERENCE:
091: return allocateEntityReference(reader);
092:
093: case XMLEvent.PROCESSING_INSTRUCTION:
094: return allocateProcessingInstruction(reader);
095:
096: case XMLEvent.START_DOCUMENT:
097: return allocateStartDocument(reader);
098:
099: case XMLEvent.END_DOCUMENT:
100: return allocateEndDocument(reader);
101:
102: default:
103: throw new XMLStreamException("Unexpected reader state: "
104: + eventType);
105:
106: }
107:
108: }
109:
110: public abstract StartElement allocateStartElement(
111: XMLStreamReader reader) throws XMLStreamException;
112:
113: public abstract EndElement allocateEndElement(XMLStreamReader reader)
114: throws XMLStreamException;
115:
116: public abstract Characters allocateCharacters(XMLStreamReader reader)
117: throws XMLStreamException;
118:
119: public abstract Characters allocateCData(XMLStreamReader reader)
120: throws XMLStreamException;
121:
122: public abstract Characters allocateIgnorableSpace(
123: XMLStreamReader reader) throws XMLStreamException;
124:
125: public abstract EntityReference allocateEntityReference(
126: XMLStreamReader reader) throws XMLStreamException;
127:
128: public abstract Comment allocateComment(XMLStreamReader reader)
129: throws XMLStreamException;
130:
131: public abstract DTD allocateDTD(XMLStreamReader reader)
132: throws XMLStreamException;
133:
134: public abstract StartDocument allocateStartDocument(
135: XMLStreamReader reader) throws XMLStreamException;
136:
137: public abstract EndDocument allocateEndDocument(
138: XMLStreamReader reader) throws XMLStreamException;
139:
140: public abstract ProcessingInstruction allocateProcessingInstruction(
141: XMLStreamReader reader) throws XMLStreamException;
142:
143: public abstract NamespaceContext createStableNamespaceContext(
144: XMLStreamReader reader);
145:
146: public abstract Location createStableLocation(XMLStreamReader reader);
147:
148: }
|