Class ContextFinder


  • class ContextFinder
    extends java.lang.Object
    This class is package private and therefore is not exposed as part of the Jakarta XML Binding API. This code is designed to implement the XML Binding spec pluggability feature
    See Also:
    JAXBContext
    • Constructor Summary

      Constructors 
      Constructor Description
      ContextFinder()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static java.lang.String classNameFromSystemProperties()  
      (package private) static JAXBContext find​(java.lang.Class<?>[] classes, java.util.Map<java.lang.String,​?> properties)  
      (package private) static JAXBContext find​(java.lang.String factoryId, java.lang.String contextPath, java.lang.ClassLoader classLoader, java.util.Map<java.lang.String,​?> properties)  
      private static java.lang.ClassLoader getClassClassLoader​(java.lang.Class<?> c)  
      private static java.lang.ClassLoader getContextClassLoader()  
      private static java.lang.ClassLoader getSystemClassLoader()  
      private static java.lang.String getSystemProperty​(java.lang.String property)  
      private static JAXBException handleClassCastException​(java.lang.Class<?> originalType, java.lang.Class<?> targetType)
      Determine if two types (JAXBContext in this case) will generate a ClassCastException.
      private static java.lang.Throwable handleInvocationTargetException​(java.lang.reflect.InvocationTargetException x)
      If the InvocationTargetException wraps an exception that shouldn't be wrapped, throw the wrapped exception.
      private static java.lang.Object instantiateProviderIfNecessary​(java.lang.Class<?> implClass)  
      (package private) static JAXBContext newInstance​(java.lang.Class<?>[] classes, java.util.Map<java.lang.String,​?> properties, java.lang.Class<?> spFactory)  
      private static JAXBContext newInstance​(java.lang.Class<?>[] classes, java.util.Map<java.lang.String,​?> properties, java.lang.String className)
      Create an instance of a class using the thread context ClassLoader
      private static JAXBContext newInstance​(java.lang.Class<?>[] classes, java.util.Map<java.lang.String,​?> properties, java.lang.String className, java.lang.ClassLoader loader)
      Create an instance of a class using passed in ClassLoader
      (package private) static JAXBContext newInstance​(java.lang.String contextPath, java.lang.Class<?>[] contextPathClasses, java.lang.Class<?> spFactory, java.lang.ClassLoader classLoader, java.util.Map<java.lang.String,​?> properties)  
      (package private) static JAXBContext newInstance​(java.lang.String contextPath, java.lang.Class<?>[] contextPathClasses, java.lang.String className, java.lang.ClassLoader classLoader, java.util.Map<java.lang.String,​?> properties)
      Create an instance of a class using the specified ClassLoader
      (package private) static java.net.URL which​(java.lang.Class<?> clazz)
      Get the URL for the Class from it's ClassLoader.
      (package private) static java.net.URL which​(java.lang.Class<?> clazz, java.lang.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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • logger

        private static final java.util.logging.Logger logger
      • DEFAULT_FACTORY_CLASS

        static final java.lang.String DEFAULT_FACTORY_CLASS
        When JAXB is in J2SE, rt.jar has to have a JAXB implementation. However, rt.jar cannot have META-INF/services/jakarta.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 Jakarta XML Binding implementation, we'd like to use it, and we want the platform default to be used only when there's no other Jakarta XML Binding provider.

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

        See Also:
        Constant Field Values
    • Constructor Detail

      • ContextFinder

        ContextFinder()
    • Method Detail

      • handleInvocationTargetException

        private static java.lang.Throwable handleInvocationTargetException​(java.lang.reflect.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.
        Throws:
        JAXBException
      • handleClassCastException

        private static JAXBException handleClassCastException​(java.lang.Class<?> originalType,
                                                              java.lang.Class<?> targetType)
        Determine if two types (JAXBContext in this case) will generate a ClassCastException. For example, (targetType)originalType
        Parameters:
        originalType - The Class object of the type being cast
        targetType - The Class object of the type that is being cast to
        Returns:
        JAXBException to be thrown.
      • newInstance

        static JAXBContext newInstance​(java.lang.String contextPath,
                                       java.lang.Class<?>[] contextPathClasses,
                                       java.lang.String className,
                                       java.lang.ClassLoader classLoader,
                                       java.util.Map<java.lang.String,​?> properties)
                                throws JAXBException
        Create an instance of a class using the specified ClassLoader
        Throws:
        JAXBException
      • newInstance

        static JAXBContext newInstance​(java.lang.String contextPath,
                                       java.lang.Class<?>[] contextPathClasses,
                                       java.lang.Class<?> spFactory,
                                       java.lang.ClassLoader classLoader,
                                       java.util.Map<java.lang.String,​?> properties)
                                throws JAXBException
        Throws:
        JAXBException
      • instantiateProviderIfNecessary

        private static java.lang.Object instantiateProviderIfNecessary​(java.lang.Class<?> implClass)
                                                                throws JAXBException
        Throws:
        JAXBException
      • newInstance

        private static JAXBContext newInstance​(java.lang.Class<?>[] classes,
                                               java.util.Map<java.lang.String,​?> properties,
                                               java.lang.String className)
                                        throws JAXBException
        Create an instance of a class using the thread context ClassLoader
        Throws:
        JAXBException
      • newInstance

        private static JAXBContext newInstance​(java.lang.Class<?>[] classes,
                                               java.util.Map<java.lang.String,​?> properties,
                                               java.lang.String className,
                                               java.lang.ClassLoader loader)
                                        throws JAXBException
        Create an instance of a class using passed in ClassLoader
        Throws:
        JAXBException
      • newInstance

        static JAXBContext newInstance​(java.lang.Class<?>[] classes,
                                       java.util.Map<java.lang.String,​?> properties,
                                       java.lang.Class<?> spFactory)
                                throws JAXBException
        Throws:
        JAXBException
      • find

        static JAXBContext find​(java.lang.String factoryId,
                                java.lang.String contextPath,
                                java.lang.ClassLoader classLoader,
                                java.util.Map<java.lang.String,​?> properties)
                         throws JAXBException
        Throws:
        JAXBException
      • classNameFromSystemProperties

        private static java.lang.String classNameFromSystemProperties()
                                                               throws JAXBException
        Throws:
        JAXBException
      • getSystemProperty

        private static java.lang.String getSystemProperty​(java.lang.String property)
      • which

        static java.net.URL which​(java.lang.Class<?> clazz,
                                  java.lang.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 - The class to search for
        loader - The ClassLoader to search. If this parameter is null, then the system class loader will be searched
        Returns:
        the URL for the class or null if it wasn't found
      • which

        static java.net.URL which​(java.lang.Class<?> 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 - The class to search for
        Returns:
        the URL for the class or null if it wasn't found
      • getContextClassLoader

        private static java.lang.ClassLoader getContextClassLoader()
      • getClassClassLoader

        private static java.lang.ClassLoader getClassClassLoader​(java.lang.Class<?> c)
      • getSystemClassLoader

        private static java.lang.ClassLoader getSystemClassLoader()