001 package javax.xml.stream;
002
003 import javax.xml.stream.events.*;
004 import javax.xml.namespace.NamespaceContext;
005 import javax.xml.namespace.QName;
006 import java.util.Iterator;
007
008 /**
009 * This interface defines a utility class for creating instances of
010 * XMLEvents
011 * @version 1.0
012 * @author Copyright (c) 2003 by BEA Systems. All Rights Reserved.
013 * @see javax.xml.stream.events.StartElement
014 * @see javax.xml.stream.events.EndElement
015 * @see javax.xml.stream.events.ProcessingInstruction
016 * @see javax.xml.stream.events.Comment
017 * @see javax.xml.stream.events.Characters
018 * @see javax.xml.stream.events.StartDocument
019 * @see javax.xml.stream.events.EndDocument
020 * @see javax.xml.stream.events.DTD
021 * @since 1.6
022 */
023 public abstract class XMLEventFactory {
024 protected XMLEventFactory() {
025 }
026
027 /**
028 * Create a new instance of the factory
029 * @throws FactoryConfigurationError if an instance of this factory cannot be loaded
030 */
031 public static XMLEventFactory newInstance()
032 throws FactoryConfigurationError {
033 return (XMLEventFactory) FactoryFinder
034 .find("javax.xml.stream.XMLEventFactory",
035 "com.sun.xml.internal.stream.events.XMLEventFactoryImpl");
036 }
037
038 /**
039 * Create a new instance of the factory
040 *
041 * @param factoryId Name of the factory to find, same as
042 * a property name
043 * @param classLoader classLoader to use
044 * @return the factory implementation
045 * @throws FactoryConfigurationError if an instance of this factory cannot be loaded
046 */
047 public static XMLEventFactory newInstance(String factoryId,
048 ClassLoader classLoader) throws FactoryConfigurationError {
049 try {
050 //do not fallback if given classloader can't find the class, throw exception
051 return (XMLEventFactory) FactoryFinder.newInstance(
052 factoryId, classLoader, false);
053 } catch (FactoryFinder.ConfigurationError e) {
054 throw new FactoryConfigurationError(e.getException(), e
055 .getMessage());
056 }
057 }
058
059 /**
060 * This method allows setting of the Location on each event that
061 * is created by this factory. The values are copied by value into
062 * the events created by this factory. To reset the location
063 * information set the location to null.
064 * @param location the location to set on each event created
065 */
066 public abstract void setLocation(Location location);
067
068 /**
069 * Create a new Attribute
070 * @param prefix the prefix of this attribute, may not be null
071 * @param namespaceURI the attribute value is set to this value, may not be null
072 * @param localName the local name of the XML name of the attribute, localName cannot be null
073 * @param value the attribute value to set, may not be null
074 * @return the Attribute with specified values
075 */
076 public abstract Attribute createAttribute(String prefix,
077 String namespaceURI, String localName, String value);
078
079 /**
080 * Create a new Attribute
081 * @param localName the local name of the XML name of the attribute, localName cannot be null
082 * @param value the attribute value to set, may not be null
083 * @return the Attribute with specified values
084 */
085 public abstract Attribute createAttribute(String localName,
086 String value);
087
088 /**
089 * Create a new Attribute
090 * @param name the qualified name of the attribute, may not be null
091 * @param value the attribute value to set, may not be null
092 * @return the Attribute with specified values
093 */
094 public abstract Attribute createAttribute(QName name, String value);
095
096 /**
097 * Create a new default Namespace
098 * @param namespaceURI the default namespace uri
099 * @return the Namespace with the specified value
100 */
101 public abstract Namespace createNamespace(String namespaceURI);
102
103 /**
104 * Create a new Namespace
105 * @param prefix the prefix of this namespace, may not be null
106 * @param namespaceUri the attribute value is set to this value, may not be null
107 * @return the Namespace with the specified values
108 */
109 public abstract Namespace createNamespace(String prefix,
110 String namespaceUri);
111
112 /**
113 * Create a new StartElement. Namespaces can be added to this StartElement
114 * by passing in an Iterator that walks over a set of Namespace interfaces.
115 * Attributes can be added to this StartElement by passing an iterator
116 * that walks over a set of Attribute interfaces.
117 *
118 * @param name the qualified name of the attribute, may not be null
119 * @param attributes an optional unordered set of objects that
120 * implement Attribute to add to the new StartElement, may be null
121 * @param namespaces an optional unordered set of objects that
122 * implement Namespace to add to the new StartElement, may be null
123 * @return an instance of the requested StartElement
124 */
125 public abstract StartElement createStartElement(QName name,
126 Iterator attributes, Iterator namespaces);
127
128 /**
129 * Create a new StartElement. This defaults the NamespaceContext to
130 * an empty NamespaceContext. Querying this event for its namespaces or
131 * attributes will result in an empty iterator being returned.
132 *
133 * @param namespaceUri the uri of the QName of the new StartElement
134 * @param localName the local name of the QName of the new StartElement
135 * @param prefix the prefix of the QName of the new StartElement
136 * @return an instance of the requested StartElement
137 */
138 public abstract StartElement createStartElement(String prefix,
139 String namespaceUri, String localName);
140
141 /**
142 * Create a new StartElement. Namespaces can be added to this StartElement
143 * by passing in an Iterator that walks over a set of Namespace interfaces.
144 * Attributes can be added to this StartElement by passing an iterator
145 * that walks over a set of Attribute interfaces.
146 *
147 * @param namespaceUri the uri of the QName of the new StartElement
148 * @param localName the local name of the QName of the new StartElement
149 * @param prefix the prefix of the QName of the new StartElement
150 * @param attributes an unordered set of objects that implement
151 * Attribute to add to the new StartElement
152 * @param namespaces an unordered set of objects that implement
153 * Namespace to add to the new StartElement
154 * @return an instance of the requested StartElement
155 */
156 public abstract StartElement createStartElement(String prefix,
157 String namespaceUri, String localName, Iterator attributes,
158 Iterator namespaces);
159
160 /**
161 * Create a new StartElement. Namespaces can be added to this StartElement
162 * by passing in an Iterator that walks over a set of Namespace interfaces.
163 * Attributes can be added to this StartElement by passing an iterator
164 * that walks over a set of Attribute interfaces.
165 *
166 * @param namespaceUri the uri of the QName of the new StartElement
167 * @param localName the local name of the QName of the new StartElement
168 * @param prefix the prefix of the QName of the new StartElement
169 * @param attributes an unordered set of objects that implement
170 * Attribute to add to the new StartElement, may be null
171 * @param namespaces an unordered set of objects that implement
172 * Namespace to add to the new StartElement, may be null
173 * @param context the namespace context of this element
174 * @return an instance of the requested StartElement
175 */
176 public abstract StartElement createStartElement(String prefix,
177 String namespaceUri, String localName, Iterator attributes,
178 Iterator namespaces, NamespaceContext context);
179
180 /**
181 * Create a new EndElement
182 * @param name the qualified name of the EndElement
183 * @param namespaces an optional unordered set of objects that
184 * implement Namespace that have gone out of scope, may be null
185 * @return an instance of the requested EndElement
186 */
187 public abstract EndElement createEndElement(QName name,
188 Iterator namespaces);
189
190 /**
191 * Create a new EndElement
192 * @param namespaceUri the uri of the QName of the new StartElement
193 * @param localName the local name of the QName of the new StartElement
194 * @param prefix the prefix of the QName of the new StartElement
195 * @return an instance of the requested EndElement
196 */
197 public abstract EndElement createEndElement(String prefix,
198 String namespaceUri, String localName);
199
200 /**
201 * Create a new EndElement
202 * @param namespaceUri the uri of the QName of the new StartElement
203 * @param localName the local name of the QName of the new StartElement
204 * @param prefix the prefix of the QName of the new StartElement
205 * @param namespaces an unordered set of objects that implement
206 * Namespace that have gone out of scope, may be null
207 * @return an instance of the requested EndElement
208 */
209 public abstract EndElement createEndElement(String prefix,
210 String namespaceUri, String localName, Iterator namespaces);
211
212 /**
213 * Create a Characters event, this method does not check if the content
214 * is all whitespace. To create a space event use #createSpace(String)
215 * @param content the string to create
216 * @return a Characters event
217 */
218 public abstract Characters createCharacters(String content);
219
220 /**
221 * Create a Characters event with the CData flag set to true
222 * @param content the string to create
223 * @return a Characters event
224 */
225 public abstract Characters createCData(String content);
226
227 /**
228 * Create a Characters event with the isSpace flag set to true
229 * @param content the content of the space to create
230 * @return a Characters event
231 */
232 public abstract Characters createSpace(String content);
233
234 /**
235 * Create an ignorable space
236 * @param content the space to create
237 * @return a Characters event
238 */
239 public abstract Characters createIgnorableSpace(String content);
240
241 /**
242 * Creates a new instance of a StartDocument event
243 * @return a StartDocument event
244 */
245 public abstract StartDocument createStartDocument();
246
247 /**
248 * Creates a new instance of a StartDocument event
249 *
250 * @param encoding the encoding style
251 * @param version the XML version
252 * @param standalone the status of standalone may be set to "true" or "false"
253 * @return a StartDocument event
254 */
255 public abstract StartDocument createStartDocument(String encoding,
256 String version, boolean standalone);
257
258 /**
259 * Creates a new instance of a StartDocument event
260 *
261 * @param encoding the encoding style
262 * @param version the XML version
263 * @return a StartDocument event
264 */
265 public abstract StartDocument createStartDocument(String encoding,
266 String version);
267
268 /**
269 * Creates a new instance of a StartDocument event
270 *
271 * @param encoding the encoding style
272 * @return a StartDocument event
273 */
274 public abstract StartDocument createStartDocument(String encoding);
275
276 /**
277 * Creates a new instance of an EndDocument event
278 * @return an EndDocument event
279 */
280 public abstract EndDocument createEndDocument();
281
282 /** Creates a new instance of a EntityReference event
283 *
284 * @param name The name of the reference
285 * @param declaration the declaration for the event
286 * @return an EntityReference event
287 */
288 public abstract EntityReference createEntityReference(String name,
289 EntityDeclaration declaration);
290
291 /**
292 * Create a comment
293 * @param text The text of the comment
294 * a Comment event
295 */
296 public abstract Comment createComment(String text);
297
298 /**
299 * Create a processing instruction
300 * @param target The target of the processing instruction
301 * @param data The text of the processing instruction
302 * @return a ProcessingInstruction event
303 */
304 public abstract ProcessingInstruction createProcessingInstruction(
305 String target, String data);
306
307 /**
308 * Create a document type definition event
309 * This string contains the entire document type declaration that matches
310 * the doctypedecl in the XML 1.0 specification
311 * @param dtd the text of the document type definition
312 * @return a DTD event
313 */
314 public abstract DTD createDTD(String dtd);
315 }
|