--- old/src/java.xml.bind/share/classes/javax/xml/bind/JAXBContext.java 2015-05-26 17:38:00.000000000 +0200 +++ new/src/java.xml.bind/share/classes/javax/xml/bind/JAXBContext.java 2015-05-26 17:38:00.000000000 +0200 @@ -45,29 +45,20 @@ * specialized forms of the method available: * * * - *

- * SPEC REQUIREMENT: the provider must supply an implementation - * class containing the following method signatures: - * - *

{@code
- * public static JAXBContext createContext( String contextPath, ClassLoader classLoader, Map properties ) throws JAXBException
- * public static JAXBContext createContext( Class[] classes, Map properties ) throws JAXBException
- * }
- * *

* The following JAXB 1.0 requirement is only required for schema to * java interface/implementation binding. It does not apply to JAXB annotated @@ -109,11 +100,11 @@ * any of the schemas listed in the contextPath. For example: * *

- *        JAXBContext jc = JAXBContext.newInstance( "com.acme.foo:com.acme.bar" );
- *        Unmarshaller u = jc.createUnmarshaller();
- *        FooObject fooObj = (FooObject)u.unmarshal( new File( "foo.xml" ) ); // ok
- *        BarObject barObj = (BarObject)u.unmarshal( new File( "bar.xml" ) ); // ok
- *        BazObject bazObj = (BazObject)u.unmarshal( new File( "baz.xml" ) ); // error, "com.acme.baz" not in contextPath
+ *      JAXBContext jc = JAXBContext.newInstance( "com.acme.foo:com.acme.bar" );
+ *      Unmarshaller u = jc.createUnmarshaller();
+ *      FooObject fooObj = (FooObject)u.unmarshal( new File( "foo.xml" ) ); // ok
+ *      BarObject barObj = (BarObject)u.unmarshal( new File( "bar.xml" ) ); // ok
+ *      BazObject bazObj = (BazObject)u.unmarshal( new File( "baz.xml" ) ); // error, "com.acme.baz" not in contextPath
  * 
* *

@@ -146,7 +137,7 @@ * Section 4.2 Java Package of the specification. * *

- * SPEC REQUIREMENT: the provider must generate a class in each + * The provider must generate a class in each * package that contains all of the necessary object factory methods for that * package named ObjectFactory as well as the static * newInstance( javaContentInterface ) method @@ -214,6 +205,7 @@ * by the following steps. * *

    + * *
  1. * For each package/class explicitly passed in to the {@link #newInstance} method, in the order they are specified, * jaxb.properties file is looked up in its package, by using the associated classloader — @@ -223,7 +215,7 @@ *

    * If such a file is discovered, it is {@link Properties#load(InputStream) loaded} as a property file, and * the value of the {@link #JAXB_CONTEXT_FACTORY} key will be assumed to be the provider factory class. - * This class is then loaded by the associated classloader discussed above. + * This class is then loaded by the associated class loader discussed above. * *

    * This phase of the look up allows some packages to force the use of a certain JAXB implementation. @@ -234,10 +226,36 @@ * factory class. This phase of the look up enables per-JVM override of the JAXB implementation. * *

  2. - * Look for /META-INF/services/javax.xml.bind.JAXBContext file in the associated classloader. - * This file follows the standard service descriptor convention, and if such a file exists, its content - * is assumed to be the provider factory class. This phase of the look up is for automatic discovery. - * It allows users to just put a JAXB implementation in a classpath and use it without any furhter configuration. + * Provider of {@link javax.xml.bind.JAXBContextFactory} is loaded using the service-provider loading + * facilities, defined by the {@link java.util.ServiceLoader} class, to attempt + * to locate and load an implementation of the service using the {@linkplain + * java.util.ServiceLoader#load(java.lang.Class) default loading mechanism}: the service-provider loading facility + * will use the {@linkplain java.lang.Thread#getContextClassLoader() current thread's context class loader} + * to attempt to load the context factory. If the context class loader is null, the + * {@linkplain ClassLoader#getSystemClassLoader() system class loader} will be used. + *
    + * In case of {@link java.util.ServiceConfigurationError service + * configuration error} a {@link javax.xml.bind.JAXBException} will be thrown. + *
  3. + * + *
  4. + * Look for resource {@code /META-INF/services/javax.xml.bind.JAXBContext} using provided class loader. + * Methods without class loader parameter use {@code Thread.currentThread().getContextClassLoader()}. + * If such a resource exists, its content is assumed to be the provider factory class and must supply + * an implementation class containing the following method signatures: + * + *
    + *
    + * public static JAXBContext createContext(
    + *                                      String contextPath,
    + *                                      ClassLoader classLoader,
    + *                                      Map<String,Object> properties throws JAXBException
    + *
    + * public static JAXBContext createContext(
    + *                                      Class[] classes,
    + *                                      Map<String,Object> properties ) throws JAXBException
    + * 
    + * This configuration method is deprecated. * *
  5. * Finally, if all the steps above fail, then the rest of the look up is unspecified. That said, @@ -246,17 +264,30 @@ *
* *

- * Once the provider factory class is discovered, its - * public static JAXBContext createContext(String,ClassLoader,Map) method - * (see {@link #newInstance(String, ClassLoader, Map)} for the parameter semantics.) - * or public static JAXBContext createContet(Class[],Map) method - * (see {@link #newInstance(Class[], Map)} for the parameter semantics) are invoked + * Once the provider factory class {@link javax.xml.bind.JAXBContextFactory} is discovered, one of its methods + * {@link javax.xml.bind.JAXBContextFactory#createContext(String, ClassLoader, java.util.Map)} or + * {@link javax.xml.bind.JAXBContextFactory#createContext(Class[], java.util.Map)} is invoked * to create a {@link JAXBContext}. * - * @author

+ *

+ * + * @apiNote + *

Service discovery method using file /META-INF/services/javax.xml.bind.JAXBContext (described in step 4) + * and leveraging provider's static methods is supported only to allow backwards compatibility, but it is strongly + * recommended to migrate to standard ServiceLoader mechanism (described in step 3). + * + * @implNote + * Within the last step, if Glassfish AS environment detected, its specific service loader is used to find factory class. + * + * @author

+ * * @see Marshaller * @see Unmarshaller - * @see S 7.4.1 "Named Packages" in Java Language Specification + * @see S 7.4.1 "Named Packages" + * in Java Language Specification + * * @since 1.6, JAXB 1.0 */ public abstract class JAXBContext { @@ -265,9 +296,7 @@ * The name of the property that contains the name of the class capable * of creating new JAXBContext objects. */ - public static final String JAXB_CONTEXT_FACTORY = - "javax.xml.bind.context.factory"; - + public static final String JAXB_CONTEXT_FACTORY = "javax.xml.bind.JAXBContextFactory"; protected JAXBContext() { } @@ -275,7 +304,7 @@ /** *

- * Obtain a new instance of a JAXBContext class. + * Create a new instance of a JAXBContext class. * *

* This is a convenience method to invoke the @@ -300,7 +329,7 @@ /** *

- * Obtain a new instance of a JAXBContext class. + * Create a new instance of a JAXBContext class. * *

* The client application must supply a context path which is a list of @@ -396,7 +425,7 @@ /** *

- * Obtain a new instance of a JAXBContext class. + * Create a new instance of a JAXBContext class. * *

* This is mostly the same as {@link JAXBContext#newInstance(String, ClassLoader)}, @@ -425,8 +454,9 @@ * * @since 1.6, JAXB 2.0 */ - public static JAXBContext newInstance( String contextPath, ClassLoader classLoader, Map properties ) - throws JAXBException { + public static JAXBContext newInstance( String contextPath, + ClassLoader classLoader, + Map properties ) throws JAXBException { return ContextFinder.find( /* The default property name according to the JAXB spec */ @@ -443,7 +473,7 @@ // TODO: resurrect this once we introduce external annotations // /** // *

-// * Obtain a new instance of a JAXBContext class. +// * Create a new instance of a JAXBContext class. // * // *

// * The client application must supply a list of classes that the new @@ -479,7 +509,7 @@ // * spec-defined classes will be returned. // * // * @return -// * A new instance of a JAXBContext. Always non-null valid object. +// * A new instance of a JAXBContext. // * // * @throws JAXBException // * if an error was encountered while creating the @@ -517,7 +547,7 @@ /** *

- * Obtain a new instance of a JAXBContext class. + * Create a new instance of a JAXBContext class. * *

* The client application must supply a list of classes that the new @@ -559,7 +589,7 @@ * spec-defined classes will be returned. * * @return - * A new instance of a JAXBContext. Always non-null valid object. + * A new instance of a JAXBContext. * * @throws JAXBException * if an error was encountered while creating the @@ -578,7 +608,7 @@ * * @since 1.6, JAXB 2.0 */ - public static JAXBContext newInstance( Class... classesToBeBound ) + public static JAXBContext newInstance( Class ... classesToBeBound ) throws JAXBException { return newInstance(classesToBeBound,Collections.emptyMap()); @@ -586,7 +616,7 @@ /** *

- * Obtain a new instance of a JAXBContext class. + * Create a new instance of a JAXBContext class. * *

* An overloading of {@link JAXBContext#newInstance(Class...)} @@ -605,7 +635,7 @@ * in an empty map. * * @return - * A new instance of a JAXBContext. Always non-null valid object. + * A new instance of a JAXBContext. * * @throws JAXBException * if an error was encountered while creating the @@ -624,7 +654,7 @@ * * @since 1.6, JAXB 2.0 */ - public static JAXBContext newInstance( Class[] classesToBeBound, Map properties ) + public static JAXBContext newInstance( Class[] classesToBeBound, Map properties ) throws JAXBException { if (classesToBeBound == null) { @@ -756,9 +786,9 @@ if (System.getSecurityManager() == null) { return Thread.currentThread().getContextClassLoader(); } else { - return (ClassLoader) java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public java.lang.Object run() { + return java.security.AccessController.doPrivileged( + new java.security.PrivilegedAction() { + public ClassLoader run() { return Thread.currentThread().getContextClassLoader(); } });