001: package javax.xml.stream;
002:
003: import javax.xml.transform.Source;
004: import javax.xml.stream.util.XMLEventAllocator;
005:
006: /**
007: * Defines an abstract implementation of a factory for getting streams.
008: *
009: * The following table defines the standard properties of this specification.
010: * Each property varies in the level of support required by each implementation.
011: * The level of support required is described in the 'Required' column.
012: *
013: * <table border="2" rules="all" cellpadding="4">
014: * <thead>
015: * <tr>
016: * <th align="center" colspan="5">
017: * Configuration parameters
018: * </th>
019: * </tr>
020: * </thead>
021: * <tbody>
022: * <tr>
023: * <th>Property Name</th>
024: * <th>Behavior</th>
025: * <th>Return type</th>
026: * <th>Default Value</th>
027: * <th>Required</th>
028: * </tr>
029: * <tr><td>javax.xml.stream.isValidating</td><td>Turns on/off implementation specific DTD validation</td><td>Boolean</td><td>False</td><td>No</td></tr>
030: * <tr><td>javax.xml.stream.isNamespaceAware</td><td>Turns on/off namespace processing for XML 1.0 support</td><td>Boolean</td><td>True</td><td>True (required) / False (optional)</td></tr>
031: * <tr><td>javax.xml.stream.isCoalescing</td><td>Requires the processor to coalesce adjacent character data</td><td>Boolean</td><td>False</td><td>Yes</td></tr>
032: * <tr><td>javax.xml.stream.isReplacingEntityReferences</td><td>replace internal entity references with their replacement text and report them as characters</td><td>Boolean</td><td>True</td><td>Yes</td></tr>
033: *<tr><td>javax.xml.stream.isSupportingExternalEntities</td><td>Resolve external parsed entities</td><td>Boolean</td><td>Unspecified</td><td>Yes</td></tr>
034: *<tr><td>javax.xml.stream.supportDTD</td><td>Use this property to request processors that do not support DTDs</td><td>Boolean</td><td>True</td><td>Yes</td></tr>
035: *<tr><td>javax.xml.stream.reporter</td><td>sets/gets the impl of the XMLReporter </td><td>javax.xml.stream.XMLReporter</td><td>Null</td><td>Yes</td></tr>
036: *<tr><td>javax.xml.stream.resolver</td><td>sets/gets the impl of the XMLResolver interface</td><td>javax.xml.stream.XMLResolver</td><td>Null</td><td>Yes</td></tr>
037: *<tr><td>javax.xml.stream.allocator</td><td>sets/gets the impl of the XMLEventAllocator interface</td><td>javax.xml.stream.util.XMLEventAllocator</td><td>Null</td><td>Yes</td></tr>
038: * </tbody>
039: * </table>
040: *
041: *
042: * @version 1.0
043: * @author Copyright (c) 2003 by BEA Systems. All Rights Reserved.
044: * @see XMLOutputFactory
045: * @see XMLEventReader
046: * @see XMLStreamReader
047: * @see EventFilter
048: * @see XMLReporter
049: * @see XMLResolver
050: * @see javax.xml.stream.util.XMLEventAllocator
051: */
052:
053: public abstract class XMLInputFactory {
054: /**
055: * The property used to turn on/off namespace support,
056: * this is to support XML 1.0 documents,
057: * only the true setting must be supported
058: */
059: public static final String IS_NAMESPACE_AWARE = "javax.xml.stream.isNamespaceAware";
060:
061: /**
062: * The property used to turn on/off implementation specific validation
063: */
064: public static final String IS_VALIDATING = "javax.xml.stream.isValidating";
065:
066: /**
067: * The property that requires the parser to coalesce adjacent character data sections
068: */
069: public static final String IS_COALESCING = "javax.xml.stream.isCoalescing";
070:
071: /**
072: * Requires the parser to replace internal
073: * entity references with their replacement
074: * text and report them as characters
075: */
076: public static final String IS_REPLACING_ENTITY_REFERENCES = "javax.xml.stream.isReplacingEntityReferences";
077:
078: /**
079: * The property that requires the parser to resolve external parsed entities
080: */
081: public static final String IS_SUPPORTING_EXTERNAL_ENTITIES = "javax.xml.stream.isSupportingExternalEntities";
082:
083: /**
084: * The property that requires the parser to support DTDs
085: */
086: public static final String SUPPORT_DTD = "javax.xml.stream.supportDTD";
087:
088: /**
089: * The property used to
090: * set/get the implementation of the XMLReporter interface
091: */
092: public static final String REPORTER = "javax.xml.stream.reporter";
093:
094: /**
095: * The property used to set/get the implementation of the XMLResolver
096: */
097: public static final String RESOLVER = "javax.xml.stream.resolver";
098:
099: /**
100: * The property used to set/get the implementation of the allocator
101: */
102: public static final String ALLOCATOR = "javax.xml.stream.allocator";
103:
104: protected XMLInputFactory() {
105: }
106:
107: /**
108: * Create a new instance of the factory.
109: * This static method creates a new factory instance.
110: * This method uses the following ordered lookup procedure to determine
111: * the XMLInputFactory implementation class to load:
112: * Use the javax.xml.stream.XMLInputFactory system property.
113: * Use the properties file "lib/stax.properties" in the JRE directory.
114: * This configuration file is in standard java.util.Properties format and contains
115: * the fully qualified name of the implementation class with the key being the system property defined above.
116: * Use the Services API (as detailed in the JAR specification), if available, to determine the classname.
117: * The Services API will look for a classname in the file META-INF/services/javax.xml.stream.XMLInputFactory
118: * in jars available to the runtime.
119: * Platform default XMLInputFactory instance.
120: * Once an application has obtained a reference to a XMLInputFactory
121: * it can use the factory to configure and obtain stream instances.
122: *
123: * @throws FactoryConfigurationError if an instance of this factory cannot be loaded
124: */
125: public static XMLInputFactory newInstance()
126: throws FactoryConfigurationError {
127: return (XMLInputFactory) FactoryFinder.find(
128: "javax.xml.stream.XMLInputFactory",
129: "com.bea.xml.stream.MXParserFactory");
130: }
131:
132: /**
133: * Create a new instance of the factory
134: *
135: * @param factoryId Name of the factory to find, same as
136: * a property name
137: * @param classLoader classLoader to use
138: * @return the factory implementation
139: * @throws FactoryConfigurationError if an instance of this factory cannot be loaded
140: */
141:
142: public static XMLInputFactory newInstance(String factoryId,
143: ClassLoader classLoader) throws FactoryConfigurationError {
144: return (XMLInputFactory) FactoryFinder.find(factoryId,
145: "com.bea.xml.stream.MXParserFactory", classLoader);
146: }
147:
148: /**
149: * Create a new XMLStreamReader from a reader
150: * @param reader the XML data to read from
151: * @throws XMLStreamException
152: */
153: public abstract XMLStreamReader createXMLStreamReader(
154: java.io.Reader reader) throws XMLStreamException;
155:
156: /**
157: * Create a new XMLStreamReader from a JAXP source. This method is optional.
158: * @param source the source to read from
159: * @throws UnsupportedOperationException if this method is not
160: * supported by this XMLInputFactory
161: * @throws XMLStreamException
162: */
163: public abstract XMLStreamReader createXMLStreamReader(Source source)
164: throws XMLStreamException;
165:
166: /**
167: * Create a new XMLStreamReader from a java.io.InputStream
168: * @param stream the InputStream to read from
169: * @throws XMLStreamException
170: */
171: public abstract XMLStreamReader createXMLStreamReader(
172: java.io.InputStream stream) throws XMLStreamException;
173:
174: /**
175: * Create a new XMLStreamReader from a java.io.InputStream
176: * @param stream the InputStream to read from
177: * @param encoding the character encoding of the stream
178: * @throws XMLStreamException
179: */
180: public abstract XMLStreamReader createXMLStreamReader(
181: java.io.InputStream stream, String encoding)
182: throws XMLStreamException;
183:
184: /**
185: * Create a new XMLStreamReader from a java.io.InputStream
186: * @param systemId the system ID of the stream
187: * @param stream the InputStream to read from
188: */
189: public abstract XMLStreamReader createXMLStreamReader(
190: String systemId, java.io.InputStream stream)
191: throws XMLStreamException;
192:
193: /**
194: * Create a new XMLStreamReader from a java.io.InputStream
195: * @param systemId the system ID of the stream
196: * @param reader the InputStream to read from
197: */
198: public abstract XMLStreamReader createXMLStreamReader(
199: String systemId, java.io.Reader reader)
200: throws XMLStreamException;
201:
202: /**
203: * Create a new XMLEventReader from a reader
204: * @param reader the XML data to read from
205: * @throws XMLStreamException
206: */
207: public abstract XMLEventReader createXMLEventReader(
208: java.io.Reader reader) throws XMLStreamException;
209:
210: /**
211: * Create a new XMLEventReader from a reader
212: * @param systemId the system ID of the input
213: * @param reader the XML data to read from
214: * @throws XMLStreamException
215: */
216: public abstract XMLEventReader createXMLEventReader(
217: String systemId, java.io.Reader reader)
218: throws XMLStreamException;
219:
220: /**
221: * Create a new XMLEventReader from an XMLStreamReader. After being used
222: * to construct the XMLEventReader instance returned from this method
223: * the XMLStreamReader must not be used.
224: * @param reader the XMLStreamReader to read from (may not be modified)
225: * @return a new XMLEventReader
226: * @throws XMLStreamException
227: */
228: public abstract XMLEventReader createXMLEventReader(
229: XMLStreamReader reader) throws XMLStreamException;
230:
231: /**
232: * Create a new XMLEventReader from a JAXP source.
233: * Support of this method is optional.
234: * @param source the source to read from
235: * @throws UnsupportedOperationException if this method is not
236: * supported by this XMLInputFactory
237: */
238: public abstract XMLEventReader createXMLEventReader(Source source)
239: throws XMLStreamException;
240:
241: /**
242: * Create a new XMLEventReader from a java.io.InputStream
243: * @param stream the InputStream to read from
244: * @throws XMLStreamException
245: */
246: public abstract XMLEventReader createXMLEventReader(
247: java.io.InputStream stream) throws XMLStreamException;
248:
249: /**
250: * Create a new XMLEventReader from a java.io.InputStream
251: * @param stream the InputStream to read from
252: * @param encoding the character encoding of the stream
253: * @throws XMLStreamException
254: */
255: public abstract XMLEventReader createXMLEventReader(
256: java.io.InputStream stream, String encoding)
257: throws XMLStreamException;
258:
259: /**
260: * Create a new XMLEventReader from a java.io.InputStream
261: * @param systemId the system ID of the stream
262: * @param stream the InputStream to read from
263: * @throws XMLStreamException
264: */
265: public abstract XMLEventReader createXMLEventReader(
266: String systemId, java.io.InputStream stream)
267: throws XMLStreamException;
268:
269: /**
270: * Create a filtered reader that wraps the filter around the reader
271: * @param reader the reader to filter
272: * @param filter the filter to apply to the reader
273: * @throws XMLStreamException
274: */
275: public abstract XMLStreamReader createFilteredReader(
276: XMLStreamReader reader, StreamFilter filter)
277: throws XMLStreamException;
278:
279: /**
280: * Create a filtered event reader that wraps the filter around the event reader
281: * @param reader the event reader to wrap
282: * @param filter the filter to apply to the event reader
283: * @throws XMLStreamException
284: */
285: public abstract XMLEventReader createFilteredReader(
286: XMLEventReader reader, EventFilter filter)
287: throws XMLStreamException;
288:
289: /**
290: * The resolver that will be set on any XMLStreamReader or XMLEventReader created
291: * by this factory instance.
292: */
293: public abstract XMLResolver getXMLResolver();
294:
295: /**
296: * The resolver that will be set on any XMLStreamReader or XMLEventReader created
297: * by this factory instance.
298: * @param resolver the resolver to use to resolve references
299: */
300: public abstract void setXMLResolver(XMLResolver resolver);
301:
302: /**
303: * The reporter that will be set on any XMLStreamReader or XMLEventReader created
304: * by this factory instance.
305: */
306: public abstract XMLReporter getXMLReporter();
307:
308: /**
309: * The reporter that will be set on any XMLStreamReader or XMLEventReader created
310: * by this factory instance.
311: * @param reporter the resolver to use to report non fatal errors
312: */
313: public abstract void setXMLReporter(XMLReporter reporter);
314:
315: /**
316: * Allows the user to set specific feature/property on the underlying implementation. The underlying implementation
317: * is not required to support every setting of every property in the specification and may use IllegalArgumentException
318: * to signal that an unsupported property may not be set with the specified value.
319: * @param name The name of the property (may not be null)
320: * @param value The value of the property
321: * @throws java.lang.IllegalArgumentException if the property is not supported
322: */
323: public abstract void setProperty(java.lang.String name, Object value)
324: throws java.lang.IllegalArgumentException;
325:
326: /**
327: * Get the value of a feature/property from the underlying implementation
328: * @param name The name of the property (may not be null)
329: * @return The value of the property
330: * @throws IllegalArgumentException if the property is not supported
331: */
332: public abstract Object getProperty(java.lang.String name)
333: throws java.lang.IllegalArgumentException;
334:
335: /**
336: * Query the set of properties that this factory supports.
337: *
338: * @param name The name of the property (may not be null)
339: * @return true if the property is supported and false otherwise
340: */
341: public abstract boolean isPropertySupported(String name);
342:
343: /**
344: * Set a user defined event allocator for events
345: * @param allocator the user defined allocator
346: */
347: public abstract void setEventAllocator(XMLEventAllocator allocator);
348:
349: /**
350: * Gets the allocator used by streams created with this factory
351: */
352: public abstract XMLEventAllocator getEventAllocator();
353:
354: }
|