src/javax/xml/stream/XMLInputFactory.java

Print this page




 231    * Create a new instance of the factory.
 232    * If the classLoader argument is null, then the ContextClassLoader is used.
 233    * <p>
 234    * This method uses the following ordered lookup procedure to determine
 235    * the XMLInputFactory implementation class to load:
 236    * </p>
 237    * <ul>
 238    * <li>
 239    *   Use the value of the system property identified by {@code factoryId}.
 240    * </li>
 241    * <li>
 242    *   Use the properties file "lib/stax.properties" in the JRE directory.
 243    *     This configuration file is in standard java.util.Properties format
 244    *     and contains the fully qualified name of the implementation class
 245    *     with the key being the given {@code factoryId}.
 246    * </li>
 247    * <li>
 248    *   If {@code factoryId} is "javax.xml.stream.XMLInputFactory",
 249    *   use the service-provider loading facilities, defined by the
 250    *   {@link java.util.ServiceLoader} class, to attempt to locate and load an
 251    *   implementation of the service using the {@linkplain
 252    *   java.util.ServiceLoader#load(java.lang.Class) default loading mechanism}:
 253    *   the service-provider loading facility will use the {@linkplain

 254    *   java.lang.Thread#getContextClassLoader() current thread's context class loader}
 255    *   to attempt to load the service. If the context class
 256    *   loader is null, the {@linkplain
 257    *   ClassLoader#getSystemClassLoader() system class loader} will be used.
 258    * </li>
 259    * <li>
 260    *   Otherwise, throws a {@link FactoryConfigurationError}.
 261    * </li>
 262    * </ul>
 263    *
 264    * <p>
 265    * Note that this is a new method that replaces the deprecated
 266    *   {@link #newInstance(java.lang.String, java.lang.ClassLoader)
 267    *   newInstance(String factoryId, ClassLoader classLoader)} method.
 268    * No changes in behavior are defined by this replacement method relative
 269    * to the deprecated method.
 270    * </p>
 271    *




 272    * @param factoryId             Name of the factory to find, same as
 273    *                              a property name
 274    * @param classLoader           classLoader to use
 275    * @return the factory implementation
 276    * @throws FactoryConfigurationError in case of {@linkplain
 277    *   java.util.ServiceConfigurationError service configuration error} or if
 278    *   the implementation is not available or cannot be instantiated.
 279    * @throws FactoryConfigurationError if an instance of this factory cannot be loaded
 280    */
 281   public static XMLInputFactory newFactory(String factoryId,
 282           ClassLoader classLoader)
 283           throws FactoryConfigurationError {
 284       //do not fallback if given classloader can't find the class, throw exception
 285       return FactoryFinder.find(XMLInputFactory.class, factoryId, classLoader, null);
 286   }
 287 
 288   /**
 289    * Create a new XMLStreamReader from a reader
 290    * @param reader the XML data to read from
 291    * @throws XMLStreamException




 231    * Create a new instance of the factory.
 232    * If the classLoader argument is null, then the ContextClassLoader is used.
 233    * <p>
 234    * This method uses the following ordered lookup procedure to determine
 235    * the XMLInputFactory implementation class to load:
 236    * </p>
 237    * <ul>
 238    * <li>
 239    *   Use the value of the system property identified by {@code factoryId}.
 240    * </li>
 241    * <li>
 242    *   Use the properties file "lib/stax.properties" in the JRE directory.
 243    *     This configuration file is in standard java.util.Properties format
 244    *     and contains the fully qualified name of the implementation class
 245    *     with the key being the given {@code factoryId}.
 246    * </li>
 247    * <li>
 248    *   If {@code factoryId} is "javax.xml.stream.XMLInputFactory",
 249    *   use the service-provider loading facilities, defined by the
 250    *   {@link java.util.ServiceLoader} class, to attempt to locate and load an
 251    *   implementation of the service using the specified {@code ClassLoader}.
 252    *   If {@code classLoader} is null, the {@linkplain
 253    *   java.util.ServiceLoader#load(java.lang.Class) default loading mechanism} will apply:
 254    *   That is, the service-provider loading facility will use the {@linkplain
 255    *   java.lang.Thread#getContextClassLoader() current thread's context class loader}
 256    *   to attempt to load the service. If the context class
 257    *   loader is null, the {@linkplain
 258    *   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 deprecated
 267    *   {@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 relative
 270    * to the deprecated method.
 271    * </p>
 272    *
 273    * @apiNote The parameter factoryId defined here is inconsistent with that
 274    * of other JAXP factories where the first parameter is fully qualified
 275    * factory class name that provides implementation of the factory.
 276    *
 277    * @param factoryId             Name of the factory to find, same as
 278    *                              a property name
 279    * @param classLoader           classLoader to use
 280    * @return the factory implementation
 281    * @throws FactoryConfigurationError in case of {@linkplain
 282    *   java.util.ServiceConfigurationError service configuration error} or if
 283    *   the implementation is not available or cannot be instantiated.
 284    * @throws FactoryConfigurationError if an instance of this factory cannot be loaded
 285    */
 286   public static XMLInputFactory newFactory(String factoryId,
 287           ClassLoader classLoader)
 288           throws FactoryConfigurationError {
 289       //do not fallback if given classloader can't find the class, throw exception
 290       return FactoryFinder.find(XMLInputFactory.class, factoryId, classLoader, null);
 291   }
 292 
 293   /**
 294    * Create a new XMLStreamReader from a reader
 295    * @param reader the XML data to read from
 296    * @throws XMLStreamException