1/*
2 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package javax.xml.bind;
27
28import java.util.Map;
29
30/**
31 * <p>Factory that creates new <code>JAXBContext</code> instances.
32 *
33 * JAXBContextFactory can be located using {@link java.util.ServiceLoader#load(Class)}
34 *
35 * @since 9, JAXB 2.3
36 */
37public interface JAXBContextFactory {
38
39    /**
40     * <p>
41     * Create a new instance of a {@code JAXBContext} class.
42     *
43     * <p>
44     * For semantics see {@link javax.xml.bind.JAXBContext#newInstance(Class[], java.util.Map)}
45     *
46     * @param classesToBeBound
47     *      List of java classes to be recognized by the new {@link JAXBContext}.
48     *      Classes in {@code classesToBeBound} that are in named modules must be in a package
49     *      that is {@linkplain java.lang.Module#isOpen open} to at least the {@code java.xml.bind} module.
50     *      Can be empty, in which case a {@link JAXBContext} that only knows about
51     *      spec-defined classes will be returned.
52     * @param properties
53     *      provider-specific properties. Can be null, which means the same thing as passing
54     *      in an empty map.
55     *
56     * @return
57     *      A new instance of a {@code JAXBContext}.
58     *
59     * @throws JAXBException
60     *      if an error was encountered while creating the
61     *      {@code JAXBContext}, such as (but not limited to):
62     * <ol>
63     *  <li>No JAXB implementation was discovered
64     *  <li>Classes use JAXB annotations incorrectly
65     *  <li>Classes have colliding annotations (i.e., two classes with the same type name)
66     *  <li>The JAXB implementation was unable to locate
67     *      provider-specific out-of-band information (such as additional
68     *      files generated at the development time.)
69     *  <li>{@code classesToBeBound} are not open to {@code java.xml.bind} module
70     * </ol>
71     *
72     * @throws IllegalArgumentException
73     *      if the parameter contains {@code null} (i.e., {@code newInstance(null,someMap);})
74     *
75     * @since 9, JAXB 2.3
76     */
77    JAXBContext createContext(Class<?>[] classesToBeBound,
78                              Map<String, ?> properties ) throws JAXBException;
79
80    /**
81     * <p>
82     * Create a new instance of a {@code JAXBContext} class.
83     *
84     * <p>
85     * For semantics see {@link javax.xml.bind.JAXBContext#newInstance(String, ClassLoader, java.util.Map)}
86     *
87     * <p>
88     * The interpretation of properties is up to implementations. Implementations must
89     * throw {@code JAXBException} if it finds properties that it doesn't understand.
90     *
91     * @param contextPath
92     *      List of java package names that contain schema derived classes.
93     *      Classes in {@code classesToBeBound} that are in named modules must be in a package
94     *      that is {@linkplain java.lang.Module#isOpen open} to at least the {@code java.xml.bind} module.
95     * @param classLoader
96     *      This class loader will be used to locate the implementation classes.
97     * @param properties
98     *      provider-specific properties. Can be null, which means the same thing as passing
99     *      in an empty map.
100     *
101     * @return a new instance of a {@code JAXBContext}
102     * @throws JAXBException if an error was encountered while creating the
103     *                       {@code JAXBContext} such as
104     * <ol>
105     *   <li>failure to locate either ObjectFactory.class or jaxb.index in the packages</li>
106     *   <li>an ambiguity among global elements contained in the contextPath</li>
107     *   <li>failure to locate a value for the context factory provider property</li>
108     *   <li>mixing schema derived packages from different providers on the same contextPath</li>
109     *   <li>packages are not open to {@code java.xml.bind} module</li>
110     * </ol>
111     *
112     * @since 9, JAXB 2.3
113     */
114    JAXBContext createContext(String contextPath,
115                              ClassLoader classLoader,
116                              Map<String, ?> properties ) throws JAXBException;
117
118}
119