Top Description Fields Constructors Methods
javax.xml.bind

pack-priv Class ContextFinder

extends Object
Class Inheritance
Imports
java.io.BufferedReader, .IOException, .InputStream, .InputStreamReader, java.lang.reflect.InvocationTargetException, .Method, java.net.URL, java.security.AccessController, .PrivilegedActionException, .PrivilegedExceptionAction, java.util.Map, .Properties, .StringTokenizer, java.util.logging.ConsoleHandler, .Level, .Logger

This class is package private and therefore is not exposed as part of the JAXB API. This code is designed to implement the JAXB 1.0 spec pluggability feature
Author
See Also
JAXBContext

Field Summary

Modifier and TypeField and Description
private static ServiceLoaderUtil.ExceptionHandler<JAXBException>
private static final String
private static final Logger
private static final String
PLATFORM_DEFAULT_FACTORY_CLASS

When JAXB is in J2SE, rt.jar has to have a JAXB implementation.

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private static String
classNameFromPackageProperties(URL packagePropertiesUrl, String... factoryIds)

first factoryId should be the preferred one, more of those can be provided to support backwards compatibility

private static String
pack-priv static JAXBContext
find(String factoryId, String contextPath, ClassLoader classLoader, Map<K, V> properties)

pack-priv static JAXBContext
find(Class<?>[] classes, Map<String, ?> properties)

pack-priv static String
firstByServiceLoaderDeprecated(Class<T> spiClass, ClassLoader classLoader)

Deprecated
private static ClassLoader
private static ClassLoader
private static String
private static URL

Returns:

resource url if found
getResourceUrl
(ClassLoader
classloader to load resource with
classLoader
,
String
qualified name of the resource
resourceName
)

If run on JPMS package containing resource must be open unconditionally.

private static URL
getResourceUrl(Class<?> clazz, String resourceName)

private static ClassLoader
private static String
private static JAXBException

Returns:

JAXBException to be thrown.
handleClassCastException
(Class<T>
The Class object of the type being cast
originalType
,
Class<T>
The Class object of the type that is being cast to
targetType
)

Determine if two types (JAXBContext in this case) will generate a ClassCastException.

private static Throwable
handleInvocationTargetException(InvocationTargetException x)

If the InvocationTargetException wraps an exception that shouldn't be wrapped, throw the wrapped exception.

private static Object
private static String
jaxbProperties(String contextPath, ClassLoader classLoader, String factoryId)

private static String
jaxbProperties(Class<T>[] classesFromContextPath, String factoryId)

private static Properties
pack-priv static JAXBContext
newInstance(String contextPath, Class<T>[] contextPathClasses, String className, ClassLoader classLoader, Map<K, V> properties)

Create an instance of a class using the specified ClassLoader

pack-priv static JAXBContext
newInstance(String contextPath, Class<T>[] contextPathClasses, Class<T> spFactory, ClassLoader classLoader, Map<K, V> properties)

pack-priv static JAXBContext
newInstance(Class<T>[] classes, Map<K, V> properties, String className)

Create an instance of a class using the thread context ClassLoader

pack-priv static JAXBContext
newInstance(Class<T>[] classes, Map<K, V> properties, Class<T> spFactory)

pack-priv static URL

Returns:

the URL for the class or null if it wasn't found
which
(Class<T>
The class to search for
clazz
,
ClassLoader
The ClassLoader to search. If this parameter is null, then the system class loader will be searched
loader
)

Search the given ClassLoader for an instance of the specified class and return a string representation of the URL that points to the resource.

pack-priv static URL

Returns:

the URL for the class or null if it wasn't found
which
(Class<T>
The class to search for
clazz
)

Get the URL for the Class from it's ClassLoader.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

EXCEPTION_HANDLERback to summary
private static ServiceLoaderUtil.ExceptionHandler<JAXBException> EXCEPTION_HANDLER
JAXB_CONTEXT_FACTORY_DEPRECATEDback to summary
private static final String JAXB_CONTEXT_FACTORY_DEPRECATED
loggerback to summary
private static final Logger logger
PLATFORM_DEFAULT_FACTORY_CLASSback to summary
private static final String PLATFORM_DEFAULT_FACTORY_CLASS

When JAXB is in J2SE, rt.jar has to have a JAXB implementation. However, rt.jar cannot have META-INF/services/javax.xml.bind.JAXBContext because if it has, it will take precedence over any file that applications have in their jar files.

When the user bundles his own JAXB implementation, we'd like to use it, and we want the platform default to be used only when there's no other JAXB provider.

For this reason, we have to hard-code the class name into the API.

Constructor Detail

ContextFinderback to summary
pack-priv ContextFinder()

Method Detail

classNameFromPackagePropertiesback to summary
private static String classNameFromPackageProperties(URL packagePropertiesUrl, String... factoryIds) throws JAXBException

first factoryId should be the preferred one, more of those can be provided to support backwards compatibility

classNameFromSystemPropertiesback to summary
private static String classNameFromSystemProperties() throws JAXBException
findback to summary
pack-priv static JAXBContext find(String factoryId, String contextPath, ClassLoader classLoader, Map<K, V> properties) throws JAXBException
findback to summary
pack-priv static JAXBContext find(Class<?>[] classes, Map<String, ?> properties) throws JAXBException
firstByServiceLoaderDeprecatedback to summary
pack-priv static String firstByServiceLoaderDeprecated(Class<T> spiClass, ClassLoader classLoader) throws JAXBException

Deprecated

Annotations
@Deprecated
getClassClassLoaderback to summary
private static ClassLoader getClassClassLoader(final Class<T> c)
Annotations
@SuppressWarnings:unchecked
getContextClassLoaderback to summary
private static ClassLoader getContextClassLoader()
Annotations
@SuppressWarnings:unchecked
getDeprecatedSystemPropertyback to summary
private static String getDeprecatedSystemProperty(String property)
getResourceUrlback to summary
private static URL getResourceUrl(ClassLoader classLoader, String resourceName)

If run on JPMS package containing resource must be open unconditionally.

Parameters
classLoader:ClassLoader

classloader to load resource with

resourceName:String

qualified name of the resource

Returns:URL

resource url if found

getResourceUrlback to summary
private static URL getResourceUrl(Class<?> clazz, String resourceName)
getSystemClassLoaderback to summary
private static ClassLoader getSystemClassLoader()
getSystemPropertyback to summary
private static String getSystemProperty(String property)
handleClassCastExceptionback to summary
private static JAXBException handleClassCastException(Class<T> originalType, Class<T> targetType)

Determine if two types (JAXBContext in this case) will generate a ClassCastException. For example, (targetType)originalType

Parameters
originalType:Class<T>

The Class object of the type being cast

targetType:Class<T>

The Class object of the type that is being cast to

Returns:JAXBException

JAXBException to be thrown.

handleInvocationTargetExceptionback to summary
private static Throwable handleInvocationTargetException(InvocationTargetException x) throws JAXBException

If the InvocationTargetException wraps an exception that shouldn't be wrapped, throw the wrapped exception. Otherwise returns exception to be wrapped for further processing.

instantiateProviderIfNecessaryback to summary
private static Object instantiateProviderIfNecessary(final Class<?> implClass) throws JAXBException
jaxbPropertiesback to summary
private static String jaxbProperties(String contextPath, ClassLoader classLoader, String factoryId) throws JAXBException
jaxbPropertiesback to summary
private static String jaxbProperties(Class<T>[] classesFromContextPath, String factoryId) throws JAXBException
loadJAXBPropertiesback to summary
private static Properties loadJAXBProperties(URL url) throws JAXBException
newInstanceback to summary
pack-priv static JAXBContext newInstance(String contextPath, Class<T>[] contextPathClasses, String className, ClassLoader classLoader, Map<K, V> properties) throws JAXBException

Create an instance of a class using the specified ClassLoader

newInstanceback to summary
pack-priv static JAXBContext newInstance(String contextPath, Class<T>[] contextPathClasses, Class<T> spFactory, ClassLoader classLoader, Map<K, V> properties) throws JAXBException
newInstanceback to summary
pack-priv static JAXBContext newInstance(Class<T>[] classes, Map<K, V> properties, String className) throws JAXBException

Create an instance of a class using the thread context ClassLoader

newInstanceback to summary
pack-priv static JAXBContext newInstance(Class<T>[] classes, Map<K, V> properties, Class<T> spFactory) throws JAXBException
whichback to summary
pack-priv static URL which(Class<T> clazz, ClassLoader loader)

Search the given ClassLoader for an instance of the specified class and return a string representation of the URL that points to the resource.

Parameters
clazz:Class<T>

The class to search for

loader:ClassLoader

The ClassLoader to search. If this parameter is null, then the system class loader will be searched

Returns:URL

the URL for the class or null if it wasn't found

whichback to summary
pack-priv static URL which(Class<T> clazz)

Get the URL for the Class from it's ClassLoader. Convenience method for which(Class, ClassLoader). Equivalent to calling: which(clazz, clazz.getClassLoader())

Parameters
clazz:Class<T>

The class to search for

Returns:URL

the URL for the class or null if it wasn't found