Path: blob/aarch64-shenandoah-jdk8u272-b10/jaxp/src/javax/xml/stream/XMLInputFactory.java
48534 views
/*1* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.2*3* This code is free software; you can redistribute it and/or modify it4* under the terms of the GNU General Public License version 2 only, as5* published by the Free Software Foundation. Oracle designates this6* particular file as subject to the "Classpath" exception as provided7* by Oracle in the LICENSE file that accompanied this code.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*/2324/*25* Copyright (c) 2009, 2013, by Oracle Corporation. All Rights Reserved.26*/2728package javax.xml.stream;2930import javax.xml.stream.util.XMLEventAllocator;31import javax.xml.transform.Source;3233/**34* Defines an abstract implementation of a factory for getting streams.35*36* The following table defines the standard properties of this specification.37* Each property varies in the level of support required by each implementation.38* The level of support required is described in the 'Required' column.39*40* <table border="2" rules="all" cellpadding="4">41* <thead>42* <tr>43* <th align="center" colspan="5">44* Configuration parameters45* </th>46* </tr>47* </thead>48* <tbody>49* <tr>50* <th>Property Name</th>51* <th>Behavior</th>52* <th>Return type</th>53* <th>Default Value</th>54* <th>Required</th>55* </tr>56* <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>57* <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>58* <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>59* <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>60*<tr><td>javax.xml.stream.isSupportingExternalEntities</td><td>Resolve external parsed entities</td><td>Boolean</td><td>Unspecified</td><td>Yes</td></tr>61*<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>62*<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>63*<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>64*<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>65* </tbody>66* </table>67*68*69* @version 1.270* @author Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.71* @see XMLOutputFactory72* @see XMLEventReader73* @see XMLStreamReader74* @see EventFilter75* @see XMLReporter76* @see XMLResolver77* @see javax.xml.stream.util.XMLEventAllocator78* @since 1.679*/8081public abstract class XMLInputFactory {82/**83* The property used to turn on/off namespace support,84* this is to support XML 1.0 documents,85* only the true setting must be supported86*/87public static final String IS_NAMESPACE_AWARE=88"javax.xml.stream.isNamespaceAware";8990/**91* The property used to turn on/off implementation specific validation92*/93public static final String IS_VALIDATING=94"javax.xml.stream.isValidating";9596/**97* The property that requires the parser to coalesce adjacent character data sections98*/99public static final String IS_COALESCING=100"javax.xml.stream.isCoalescing";101102/**103* Requires the parser to replace internal104* entity references with their replacement105* text and report them as characters106*/107public static final String IS_REPLACING_ENTITY_REFERENCES=108"javax.xml.stream.isReplacingEntityReferences";109110/**111* The property that requires the parser to resolve external parsed entities112*/113public static final String IS_SUPPORTING_EXTERNAL_ENTITIES=114"javax.xml.stream.isSupportingExternalEntities";115116/**117* The property that requires the parser to support DTDs118*/119public static final String SUPPORT_DTD=120"javax.xml.stream.supportDTD";121122/**123* The property used to124* set/get the implementation of the XMLReporter interface125*/126public static final String REPORTER=127"javax.xml.stream.reporter";128129/**130* The property used to set/get the implementation of the XMLResolver131*/132public static final String RESOLVER=133"javax.xml.stream.resolver";134135/**136* The property used to set/get the implementation of the allocator137*/138public static final String ALLOCATOR=139"javax.xml.stream.allocator";140141static final String DEFAULIMPL = "com.sun.xml.internal.stream.XMLInputFactoryImpl";142143protected XMLInputFactory(){}144145/**146* Creates a new instance of the factory in exactly the same manner as the147* {@link #newFactory()} method.148* @throws FactoryConfigurationError if an instance of this factory cannot be loaded149*/150public static XMLInputFactory newInstance()151throws FactoryConfigurationError152{153return FactoryFinder.find(XMLInputFactory.class, DEFAULIMPL);154}155156/**157* Create a new instance of the factory.158* <p>159* This static method creates a new factory instance.160* This method uses the following ordered lookup procedure to determine161* the XMLInputFactory implementation class to load:162* </p>163* <ul>164* <li>165* Use the javax.xml.stream.XMLInputFactory system property.166* </li>167* <li>168* Use the properties file "lib/stax.properties" in the JRE directory.169* This configuration file is in standard java.util.Properties format170* and contains the fully qualified name of the implementation class171* with the key being the system property defined above.172* </li>173* <li>174* Use the service-provider loading facilities, defined by the175* {@link java.util.ServiceLoader} class, to attempt to locate and load an176* implementation of the service using the {@linkplain177* java.util.ServiceLoader#load(java.lang.Class) default loading mechanism}:178* the service-provider loading facility will use the {@linkplain179* java.lang.Thread#getContextClassLoader() current thread's context class loader}180* to attempt to load the service. If the context class181* loader is null, the {@linkplain182* ClassLoader#getSystemClassLoader() system class loader} will be used.183* </li>184* <li>185* Otherwise, the system-default implementation is returned.186* </li>187* </ul>188* <p>189* Once an application has obtained a reference to a XMLInputFactory it190* can use the factory to configure and obtain stream instances.191* </p>192* <p>193* Note that this is a new method that replaces the deprecated newInstance() method.194* No changes in behavior are defined by this replacement method relative to195* the deprecated method.196* </p>197* @throws FactoryConfigurationError in case of {@linkplain198* java.util.ServiceConfigurationError service configuration error} or if199* the implementation is not available or cannot be instantiated.200*/201public static XMLInputFactory newFactory()202throws FactoryConfigurationError203{204return FactoryFinder.find(XMLInputFactory.class, DEFAULIMPL);205}206207/**208* Create a new instance of the factory209*210* @param factoryId Name of the factory to find, same as211* a property name212* @param classLoader classLoader to use213* @return the factory implementation214* @throws FactoryConfigurationError if an instance of this factory cannot be loaded215*216* @deprecated This method has been deprecated to maintain API consistency.217* All newInstance methods have been replaced with corresponding218* newFactory methods. The replacement {@link219* #newFactory(java.lang.String, java.lang.ClassLoader)} method220* defines no changes in behavior.221*/222public static XMLInputFactory newInstance(String factoryId,223ClassLoader classLoader)224throws FactoryConfigurationError {225//do not fallback if given classloader can't find the class, throw exception226return FactoryFinder.find(XMLInputFactory.class, factoryId, classLoader, null);227}228229/**230* Create a new instance of the factory.231* If the classLoader argument is null, then the ContextClassLoader is used.232* <p>233* This method uses the following ordered lookup procedure to determine234* the XMLInputFactory implementation class to load:235* </p>236* <ul>237* <li>238* Use the value of the system property identified by {@code factoryId}.239* </li>240* <li>241* Use the properties file "lib/stax.properties" in the JRE directory.242* This configuration file is in standard java.util.Properties format243* and contains the fully qualified name of the implementation class244* with the key being the given {@code factoryId}.245* </li>246* <li>247* If {@code factoryId} is "javax.xml.stream.XMLInputFactory",248* use the service-provider loading facilities, defined by the249* {@link java.util.ServiceLoader} class, to attempt to {@linkplain250* java.util.ServiceLoader#load(java.lang.Class, java.lang.ClassLoader) locate and load}251* an implementation of the service using the specified {@code ClassLoader}.252* If {@code classLoader} is null, the {@linkplain253* java.util.ServiceLoader#load(java.lang.Class) default loading mechanism} will apply:254* That is, the service-provider loading facility will use the {@linkplain255* java.lang.Thread#getContextClassLoader() current thread's context class loader}256* to attempt to load the service. If the context class257* loader is null, the {@linkplain258* ClassLoader#getSystemClassLoader() system class loader} will be used.259* </li>260* <li>261* Otherwise, throws a {@link FactoryConfigurationError}.262* </li>263* </ul>264*265* <p>266* Note that this is a new method that replaces the deprecated267* {@link #newInstance(java.lang.String, java.lang.ClassLoader)268* newInstance(String factoryId, ClassLoader classLoader)} method.269* No changes in behavior are defined by this replacement method relative270* to the deprecated method.271* </p>272*273* @apiNote The parameter factoryId defined here is inconsistent with that274* of other JAXP factories where the first parameter is fully qualified275* factory class name that provides implementation of the factory.276*277* @param factoryId Name of the factory to find, same as278* a property name279* @param classLoader classLoader to use280* @return the factory implementation281* @throws FactoryConfigurationError in case of {@linkplain282* java.util.ServiceConfigurationError service configuration error} or if283* the implementation is not available or cannot be instantiated.284* @throws FactoryConfigurationError if an instance of this factory cannot be loaded285*/286public static XMLInputFactory newFactory(String factoryId,287ClassLoader classLoader)288throws FactoryConfigurationError {289//do not fallback if given classloader can't find the class, throw exception290return FactoryFinder.find(XMLInputFactory.class, factoryId, classLoader, null);291}292293/**294* Create a new XMLStreamReader from a reader295* @param reader the XML data to read from296* @throws XMLStreamException297*/298public abstract XMLStreamReader createXMLStreamReader(java.io.Reader reader)299throws XMLStreamException;300301/**302* Create a new XMLStreamReader from a JAXP source. This method is optional.303* @param source the source to read from304* @throws UnsupportedOperationException if this method is not305* supported by this XMLInputFactory306* @throws XMLStreamException307*/308public abstract XMLStreamReader createXMLStreamReader(Source source)309throws XMLStreamException;310311/**312* Create a new XMLStreamReader from a java.io.InputStream313* @param stream the InputStream to read from314* @throws XMLStreamException315*/316public abstract XMLStreamReader createXMLStreamReader(java.io.InputStream stream)317throws XMLStreamException;318319/**320* Create a new XMLStreamReader from a java.io.InputStream321* @param stream the InputStream to read from322* @param encoding the character encoding of the stream323* @throws XMLStreamException324*/325public abstract XMLStreamReader createXMLStreamReader(java.io.InputStream stream, String encoding)326throws XMLStreamException;327328/**329* Create a new XMLStreamReader from a java.io.InputStream330* @param systemId the system ID of the stream331* @param stream the InputStream to read from332*/333public abstract XMLStreamReader createXMLStreamReader(String systemId, java.io.InputStream stream)334throws XMLStreamException;335336/**337* Create a new XMLStreamReader from a java.io.InputStream338* @param systemId the system ID of the stream339* @param reader the InputStream to read from340*/341public abstract XMLStreamReader createXMLStreamReader(String systemId, java.io.Reader reader)342throws XMLStreamException;343344/**345* Create a new XMLEventReader from a reader346* @param reader the XML data to read from347* @throws XMLStreamException348*/349public abstract XMLEventReader createXMLEventReader(java.io.Reader reader)350throws XMLStreamException;351352/**353* Create a new XMLEventReader from a reader354* @param systemId the system ID of the input355* @param reader the XML data to read from356* @throws XMLStreamException357*/358public abstract XMLEventReader createXMLEventReader(String systemId, java.io.Reader reader)359throws XMLStreamException;360361/**362* Create a new XMLEventReader from an XMLStreamReader. After being used363* to construct the XMLEventReader instance returned from this method364* the XMLStreamReader must not be used.365* @param reader the XMLStreamReader to read from (may not be modified)366* @return a new XMLEventReader367* @throws XMLStreamException368*/369public abstract XMLEventReader createXMLEventReader(XMLStreamReader reader)370throws XMLStreamException;371372/**373* Create a new XMLEventReader from a JAXP source.374* Support of this method is optional.375* @param source the source to read from376* @throws UnsupportedOperationException if this method is not377* supported by this XMLInputFactory378*/379public abstract XMLEventReader createXMLEventReader(Source source)380throws XMLStreamException;381382/**383* Create a new XMLEventReader from a java.io.InputStream384* @param stream the InputStream to read from385* @throws XMLStreamException386*/387public abstract XMLEventReader createXMLEventReader(java.io.InputStream stream)388throws XMLStreamException;389390/**391* Create a new XMLEventReader from a java.io.InputStream392* @param stream the InputStream to read from393* @param encoding the character encoding of the stream394* @throws XMLStreamException395*/396public abstract XMLEventReader createXMLEventReader(java.io.InputStream stream, String encoding)397throws XMLStreamException;398399/**400* Create a new XMLEventReader from a java.io.InputStream401* @param systemId the system ID of the stream402* @param stream the InputStream to read from403* @throws XMLStreamException404*/405public abstract XMLEventReader createXMLEventReader(String systemId, java.io.InputStream stream)406throws XMLStreamException;407408/**409* Create a filtered reader that wraps the filter around the reader410* @param reader the reader to filter411* @param filter the filter to apply to the reader412* @throws XMLStreamException413*/414public abstract XMLStreamReader createFilteredReader(XMLStreamReader reader, StreamFilter filter)415throws XMLStreamException;416417/**418* Create a filtered event reader that wraps the filter around the event reader419* @param reader the event reader to wrap420* @param filter the filter to apply to the event reader421* @throws XMLStreamException422*/423public abstract XMLEventReader createFilteredReader(XMLEventReader reader, EventFilter filter)424throws XMLStreamException;425426/**427* The resolver that will be set on any XMLStreamReader or XMLEventReader created428* by this factory instance.429*/430public abstract XMLResolver getXMLResolver();431432/**433* The resolver that will be set on any XMLStreamReader or XMLEventReader created434* by this factory instance.435* @param resolver the resolver to use to resolve references436*/437public abstract void setXMLResolver(XMLResolver resolver);438439/**440* The reporter that will be set on any XMLStreamReader or XMLEventReader created441* by this factory instance.442*/443public abstract XMLReporter getXMLReporter();444445/**446* The reporter that will be set on any XMLStreamReader or XMLEventReader created447* by this factory instance.448* @param reporter the resolver to use to report non fatal errors449*/450public abstract void setXMLReporter(XMLReporter reporter);451452/**453* Allows the user to set specific feature/property on the underlying454* implementation. The underlying implementation is not required to support455* every setting of every property in the specification and may use456* IllegalArgumentException to signal that an unsupported property may not be457* set with the specified value.458* <p>459* All implementations that implement JAXP 1.5 or newer are required to460* support the {@link javax.xml.XMLConstants#ACCESS_EXTERNAL_DTD} property.461* </p>462* <ul>463* <li>464* <p>465* Access to external DTDs, external Entity References is restricted to the466* protocols specified by the property. If access is denied during parsing467* due to the restriction of this property, {@link javax.xml.stream.XMLStreamException}468* will be thrown by the {@link javax.xml.stream.XMLStreamReader#next()} or469* {@link javax.xml.stream.XMLEventReader#nextEvent()} method.470* </p>471* </li>472* </ul>473* @param name The name of the property (may not be null)474* @param value The value of the property475* @throws java.lang.IllegalArgumentException if the property is not supported476*/477public abstract void setProperty(java.lang.String name, Object value)478throws java.lang.IllegalArgumentException;479480/**481* Get the value of a feature/property from the underlying implementation482* @param name The name of the property (may not be null)483* @return The value of the property484* @throws IllegalArgumentException if the property is not supported485*/486public abstract Object getProperty(java.lang.String name)487throws java.lang.IllegalArgumentException;488489490/**491* Query the set of properties that this factory supports.492*493* @param name The name of the property (may not be null)494* @return true if the property is supported and false otherwise495*/496public abstract boolean isPropertySupported(String name);497498/**499* Set a user defined event allocator for events500* @param allocator the user defined allocator501*/502public abstract void setEventAllocator(XMLEventAllocator allocator);503504/**505* Gets the allocator used by streams created with this factory506*/507public abstract XMLEventAllocator getEventAllocator();508509}510511512