001: /*
002: * $Id: BaseXMLEventFactory.java,v 1.1 2004/07/05 23:09:32 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 java.util.Iterator;
037:
038: import javax.xml.namespace.NamespaceContext;
039: import javax.xml.namespace.QName;
040: import javax.xml.stream.Location;
041: import javax.xml.stream.XMLEventFactory;
042: import javax.xml.stream.events.Attribute;
043: import javax.xml.stream.events.Characters;
044: import javax.xml.stream.events.Comment;
045: import javax.xml.stream.events.DTD;
046: import javax.xml.stream.events.EndDocument;
047: import javax.xml.stream.events.EndElement;
048: import javax.xml.stream.events.EntityDeclaration;
049: import javax.xml.stream.events.EntityReference;
050: import javax.xml.stream.events.Namespace;
051: import javax.xml.stream.events.ProcessingInstruction;
052: import javax.xml.stream.events.StartDocument;
053: import javax.xml.stream.events.StartElement;
054:
055: /**
056: * Abstract base class for {@link XMLEventFactory} implementations. This class
057: * makes it easier to implement by coalesing the various forms of each method into
058: * a single creation method, such as
059: * {@link #createAttribute(QName, String, Location, QName)}.
060: *
061: * @author Christian Niles
062: * @version $Revision: 1.1 $
063: */
064: public abstract class BaseXMLEventFactory extends XMLEventFactory {
065:
066: /** The current location registered with the factory. */
067: protected Location location;
068:
069: public void setLocation(Location location) {
070:
071: this .location = location;
072:
073: }
074:
075: public Attribute createAttribute(QName name, String value) {
076:
077: return createAttribute(name, value, location, null);
078:
079: }
080:
081: public Attribute createAttribute(String prefix,
082: String namespaceURI, String localName, String value) {
083:
084: return createAttribute(new QName(namespaceURI, localName,
085: prefix), value, location, null);
086:
087: }
088:
089: public Attribute createAttribute(String localName, String value) {
090:
091: return createAttribute(new QName(localName), value, location,
092: null);
093:
094: }
095:
096: public abstract Attribute createAttribute(QName name, String value,
097: Location location, QName schemaType);
098:
099: public Characters createCData(String content) {
100:
101: return createCData(content, location, null);
102:
103: }
104:
105: public abstract Characters createCData(String content,
106: Location location, QName schemaType);
107:
108: public Characters createCharacters(String content) {
109:
110: return createCharacters(content, location, null);
111:
112: }
113:
114: public abstract Characters createCharacters(String content,
115: Location location, QName schemaType);
116:
117: public Comment createComment(String text) {
118:
119: return createComment(text, location);
120:
121: }
122:
123: public abstract Comment createComment(String text, Location location);
124:
125: public DTD createDTD(String dtd) {
126:
127: return createDTD(dtd, location);
128:
129: }
130:
131: public abstract DTD createDTD(String dtd, Location location);
132:
133: public EndDocument createEndDocument() {
134:
135: return createEndDocument(location);
136:
137: }
138:
139: public abstract EndDocument createEndDocument(Location location);
140:
141: public EndElement createEndElement(QName name, Iterator namespaces) {
142:
143: return createEndElement(name, namespaces, location, null);
144:
145: }
146:
147: public EndElement createEndElement(String prefix,
148: String namespaceUri, String localName, Iterator namespaces) {
149:
150: return createEndElement(new QName(namespaceUri, localName,
151: prefix), namespaces, location, null);
152:
153: }
154:
155: public EndElement createEndElement(String prefix,
156: String namespaceUri, String localName) {
157:
158: return createEndElement(new QName(namespaceUri, localName,
159: prefix), null, location, null);
160:
161: }
162:
163: public abstract EndElement createEndElement(QName name,
164: Iterator namespaces, Location location, QName schemaType);
165:
166: public EntityReference createEntityReference(String name,
167: EntityDeclaration declaration) {
168:
169: return createEntityReference(name, declaration, location);
170:
171: }
172:
173: public abstract EntityReference createEntityReference(String name,
174: EntityDeclaration declaration, Location location);
175:
176: public Characters createIgnorableSpace(String content) {
177:
178: return createIgnorableSpace(content, location);
179:
180: }
181:
182: public abstract Characters createIgnorableSpace(String content,
183: Location location);
184:
185: public Namespace createNamespace(String prefix, String namespaceUri) {
186:
187: return createNamespace(prefix, namespaceUri, location);
188:
189: }
190:
191: public Namespace createNamespace(String namespaceUri) {
192:
193: return createNamespace("", namespaceUri, location);
194:
195: }
196:
197: public abstract Namespace createNamespace(String prefix,
198: String namespaceUri, Location location);
199:
200: public ProcessingInstruction createProcessingInstruction(
201: String target, String data) {
202:
203: return createProcessingInstruction(target, data, location);
204:
205: }
206:
207: public abstract ProcessingInstruction createProcessingInstruction(
208: String target, String data, Location location);
209:
210: public Characters createSpace(String content) {
211:
212: return createSpace(content, location);
213:
214: }
215:
216: public abstract Characters createSpace(String content,
217: Location location);
218:
219: public StartDocument createStartDocument() {
220:
221: return createStartDocument(null, null, null, location, null);
222:
223: }
224:
225: public StartDocument createStartDocument(String encoding,
226: String version, boolean standalone) {
227:
228: return createStartDocument(encoding, version, Boolean
229: .valueOf(standalone), location, null);
230:
231: }
232:
233: public StartDocument createStartDocument(String encoding,
234: String version) {
235:
236: return createStartDocument(encoding, version, null, location,
237: null);
238:
239: }
240:
241: public StartDocument createStartDocument(String encoding) {
242:
243: return createStartDocument(encoding, null, null, location, null);
244:
245: }
246:
247: public abstract StartDocument createStartDocument(String encoding,
248: String version, Boolean standalone, Location location,
249: QName schemaType);
250:
251: public StartElement createStartElement(QName name,
252: Iterator attributes, Iterator namespaces) {
253:
254: return createStartElement(name, attributes, namespaces, null,
255: location, null);
256:
257: }
258:
259: public StartElement createStartElement(String prefix,
260: String namespaceUri, String localName, Iterator attributes,
261: Iterator namespaces, NamespaceContext context) {
262:
263: return createStartElement(new QName(namespaceUri, localName,
264: prefix), attributes, namespaces, context, location,
265: null);
266:
267: }
268:
269: public StartElement createStartElement(String prefix,
270: String namespaceUri, String localName, Iterator attributes,
271: Iterator namespaces) {
272:
273: return createStartElement(new QName(namespaceUri, localName,
274: prefix), attributes, namespaces, null, location, null);
275:
276: }
277:
278: public StartElement createStartElement(String prefix,
279: String namespaceUri, String localName) {
280:
281: return createStartElement(new QName(namespaceUri, localName,
282: prefix), null, null, null, location, null);
283:
284: }
285:
286: public abstract StartElement createStartElement(QName name,
287: Iterator attributes, Iterator namespaces,
288: NamespaceContext namespaceCtx, Location location,
289: QName schemaType);
290:
291: }
|