jaxp/src/javax/xml/stream/XMLInputFactory.java
changeset 17264 3aff554ad461
parent 12457 c348e06f0e82
child 17534 21dc0b2762da
equal deleted inserted replaced
16954:c9f8ddb618be 17264:3aff554ad461
    21  * or visit www.oracle.com if you need additional information or have any
    21  * or visit www.oracle.com if you need additional information or have any
    22  * questions.
    22  * questions.
    23  */
    23  */
    24 
    24 
    25 /*
    25 /*
    26  * Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
    26  * Copyright (c) 2009, 2013, by Oracle Corporation. All Rights Reserved.
    27  */
    27  */
    28 
    28 
    29 package javax.xml.stream;
    29 package javax.xml.stream;
    30 
    30 
       
    31 import javax.xml.stream.util.XMLEventAllocator;
    31 import javax.xml.transform.Source;
    32 import javax.xml.transform.Source;
    32 import javax.xml.stream.util.XMLEventAllocator;
       
    33 
    33 
    34 /**
    34 /**
    35  * Defines an abstract implementation of a factory for getting streams.
    35  * Defines an abstract implementation of a factory for getting streams.
    36  *
    36  *
    37  * The following table defines the standard properties of this specification.
    37  * The following table defines the standard properties of this specification.
   142   static final String DEFAULIMPL = "com.sun.xml.internal.stream.XMLInputFactoryImpl";
   142   static final String DEFAULIMPL = "com.sun.xml.internal.stream.XMLInputFactoryImpl";
   143 
   143 
   144   protected XMLInputFactory(){}
   144   protected XMLInputFactory(){}
   145 
   145 
   146   /**
   146   /**
   147    * Create a new instance of the factory.
   147    * Creates a new instance of the factory in exactly the same manner as the
       
   148    * {@link #newFactory()} method.
   148    * @throws FactoryConfigurationError if an instance of this factory cannot be loaded
   149    * @throws FactoryConfigurationError if an instance of this factory cannot be loaded
   149    */
   150    */
   150   public static XMLInputFactory newInstance()
   151   public static XMLInputFactory newInstance()
   151     throws FactoryConfigurationError
   152     throws FactoryConfigurationError
   152   {
   153   {
   153     return (XMLInputFactory) FactoryFinder.find(
   154     return FactoryFinder.find(XMLInputFactory.class, DEFAULIMPL);
   154       "javax.xml.stream.XMLInputFactory",
       
   155       DEFAULIMPL);
       
   156   }
   155   }
   157 
   156 
   158   /**
   157   /**
   159    * Create a new instance of the factory.
   158    * Create a new instance of the factory.
       
   159    * <p>
   160    * This static method creates a new factory instance.
   160    * This static method creates a new factory instance.
   161    * This method uses the following ordered lookup procedure to determine
   161    * This method uses the following ordered lookup procedure to determine
   162    * the XMLInputFactory implementation class to load:
   162    * the XMLInputFactory implementation class to load:
       
   163    * </p>
       
   164    * <ul>
       
   165    * <li>
   163    *   Use the javax.xml.stream.XMLInputFactory system property.
   166    *   Use the javax.xml.stream.XMLInputFactory system property.
       
   167    * </li>
       
   168    * <li>
   164    *   Use the properties file "lib/stax.properties" in the JRE directory.
   169    *   Use the properties file "lib/stax.properties" in the JRE directory.
   165    *     This configuration file is in standard java.util.Properties format
   170    *     This configuration file is in standard java.util.Properties format
   166    *     and contains the fully qualified name of the implementation class
   171    *     and contains the fully qualified name of the implementation class
   167    *     with the key being the system property defined above.
   172    *     with the key being the system property defined above.
   168    *   Use the Services API (as detailed in the JAR specification), if available,
   173    * </li>
   169    *     to determine the classname. The Services API will look for a classname
   174    * <li>
   170    *     in the file META-INF/services/javax.xml.stream.XMLInputFactory in jars
   175    *   Use the service-provider loading facilities, defined by the
   171    *     available to the runtime.
   176    *   {@link java.util.ServiceLoader} class, to attempt to locate and load an
   172    *   Platform default XMLInputFactory instance.
   177    *   implementation of the service.
   173    *
   178    * </li>
       
   179    * <li>
       
   180    * Otherwise, the system-default implementation is returned.
       
   181    * </li>
       
   182    * </ul>
       
   183    * <p>
   174    *   Once an application has obtained a reference to a XMLInputFactory it
   184    *   Once an application has obtained a reference to a XMLInputFactory it
   175    *   can use the factory to configure and obtain stream instances.
   185    *   can use the factory to configure and obtain stream instances.
   176    *
   186    * </p>
       
   187    * <p>
   177    *   Note that this is a new method that replaces the deprecated newInstance() method.
   188    *   Note that this is a new method that replaces the deprecated newInstance() method.
   178    *     No changes in behavior are defined by this replacement method relative to
   189    *     No changes in behavior are defined by this replacement method relative to
   179    *     the deprecated method.
   190    *     the deprecated method.
   180    *
   191    * </p>
   181    * @throws FactoryConfigurationError if an instance of this factory cannot be loaded
   192    * @throws FactoryConfigurationError in case of {@linkplain
       
   193    *   java.util.ServiceConfigurationError service configuration error} or if
       
   194    *   the implementation is not available or cannot be instantiated.
   182    */
   195    */
   183   public static XMLInputFactory newFactory()
   196   public static XMLInputFactory newFactory()
   184     throws FactoryConfigurationError
   197     throws FactoryConfigurationError
   185   {
   198   {
   186     return (XMLInputFactory) FactoryFinder.find(
   199     return FactoryFinder.find(XMLInputFactory.class, DEFAULIMPL);
   187       "javax.xml.stream.XMLInputFactory",
       
   188       DEFAULIMPL);
       
   189   }
   200   }
   190 
   201 
   191   /**
   202   /**
   192    * Create a new instance of the factory
   203    * Create a new instance of the factory
   193    *
   204    *
   204    *              defines no changes in behavior.
   215    *              defines no changes in behavior.
   205    */
   216    */
   206   public static XMLInputFactory newInstance(String factoryId,
   217   public static XMLInputFactory newInstance(String factoryId,
   207           ClassLoader classLoader)
   218           ClassLoader classLoader)
   208           throws FactoryConfigurationError {
   219           throws FactoryConfigurationError {
   209       try {
   220       //do not fallback if given classloader can't find the class, throw exception
   210           //do not fallback if given classloader can't find the class, throw exception
   221       return FactoryFinder.find(XMLInputFactory.class, factoryId, classLoader, null);
   211           return (XMLInputFactory) FactoryFinder.find(factoryId, classLoader, null);
       
   212       } catch (FactoryFinder.ConfigurationError e) {
       
   213           throw new FactoryConfigurationError(e.getException(),
       
   214                   e.getMessage());
       
   215       }
       
   216   }
   222   }
   217 
   223 
   218   /**
   224   /**
   219    * Create a new instance of the factory.
   225    * Create a new instance of the factory.
   220    * If the classLoader argument is null, then the ContextClassLoader is used.
   226    * If the classLoader argument is null, then the ContextClassLoader is used.
       
   227    * <p>
       
   228    * This method uses the following ordered lookup procedure to determine
       
   229    * the XMLInputFactory implementation class to load:
       
   230    * </p>
       
   231    * <ul>
       
   232    * <li>
       
   233    *   Use the value of the system property identified by {@code factoryId}.
       
   234    * </li>
       
   235    * <li>
       
   236    *   Use the properties file "lib/stax.properties" in the JRE directory.
       
   237    *     This configuration file is in standard java.util.Properties format
       
   238    *     and contains the fully qualified name of the implementation class
       
   239    *     with the key being the given {@code factoryId}.
       
   240    * </li>
       
   241    * <li>
       
   242    *   If {@code factoryId} is "javax.xml.stream.XMLInputFactory",
       
   243    *   use the service-provider loading facilities, defined by the
       
   244    *   {@link java.util.ServiceLoader} class, to attempt to locate and load an
       
   245    *   implementation of the service.
       
   246    * </li>
       
   247    * <li>
       
   248    *   Otherwise, throws a {@link FactoryConfigurationError}.
       
   249    * </li>
       
   250    * </ul>
   221    *
   251    *
       
   252    * <p>
   222    * Note that this is a new method that replaces the deprecated
   253    * Note that this is a new method that replaces the deprecated
   223    *   newInstance(String factoryId, ClassLoader classLoader) method.
   254    *   {@link #newInstance(java.lang.String, java.lang.ClassLoader)
       
   255    *   newInstance(String factoryId, ClassLoader classLoader)} method.
   224    * No changes in behavior are defined by this replacement method relative
   256    * No changes in behavior are defined by this replacement method relative
   225    * to the deprecated method.
   257    * to the deprecated method.
       
   258    * </p>
   226    *
   259    *
   227    * @param factoryId             Name of the factory to find, same as
   260    * @param factoryId             Name of the factory to find, same as
   228    *                              a property name
   261    *                              a property name
   229    * @param classLoader           classLoader to use
   262    * @param classLoader           classLoader to use
   230    * @return the factory implementation
   263    * @return the factory implementation
       
   264    * @throws FactoryConfigurationError in case of {@linkplain
       
   265    *   java.util.ServiceConfigurationError service configuration error} or if
       
   266    *   the implementation is not available or cannot be instantiated.
   231    * @throws FactoryConfigurationError if an instance of this factory cannot be loaded
   267    * @throws FactoryConfigurationError if an instance of this factory cannot be loaded
   232    */
   268    */
   233   public static XMLInputFactory newFactory(String factoryId,
   269   public static XMLInputFactory newFactory(String factoryId,
   234           ClassLoader classLoader)
   270           ClassLoader classLoader)
   235           throws FactoryConfigurationError {
   271           throws FactoryConfigurationError {
   236       try {
   272       //do not fallback if given classloader can't find the class, throw exception
   237           //do not fallback if given classloader can't find the class, throw exception
   273       return FactoryFinder.find(XMLInputFactory.class, factoryId, classLoader, null);
   238           return (XMLInputFactory) FactoryFinder.find(factoryId, classLoader, null);
       
   239       } catch (FactoryFinder.ConfigurationError e) {
       
   240           throw new FactoryConfigurationError(e.getException(),
       
   241                   e.getMessage());
       
   242       }
       
   243   }
   274   }
   244 
   275 
   245   /**
   276   /**
   246    * Create a new XMLStreamReader from a reader
   277    * Create a new XMLStreamReader from a reader
   247    * @param reader the XML data to read from
   278    * @param reader the XML data to read from