public static JAXBContext find()

in jaxb-api-2.1/src/main/java/javax/xml/bind/ContextFinder.java [33:76]


    public static JAXBContext find(String contextPath, ClassLoader classLoader, Map properties) throws JAXBException {
        String className = null;
        // Patch for bug https://issues.apache.org/activemq/browse/SMX4-329
        if (contextPath == null || contextPath.length() == 0) {
            throw new JAXBException("Invalid contextPath (empty or null)");
  	    }
        String[] packages = contextPath.split(":");
        if (packages == null || packages.length == 0) {
            throw new JAXBException("Invalid contextPath (no packages)");
        }
        for (String pkg : packages) {
            String url = pkg.replace('.', '/') + "/jaxb.properties";
            className = loadClassNameFromProperties(url, classLoader);
            if (className != null) {
                break;
            }
        }
        if (className == null) {
            className = System.getProperty(JAXB_CONTEXT_PROPERTY);
        }
        if (className == null) {
            String url = "META-INF/services/" + JAXB_CONTEXT_PROPERTY;
            className = loadClassName(url, classLoader);
        }
        if (className == null) {
            className = PLATFORM_DEFAULT_FACTORY_CLASS;
        }
        Class spi = loadSpi(className, classLoader);
        try {
            Method m = spi.getMethod("createContext", new Class[] { String.class, ClassLoader.class, Map.class });
            return (JAXBContext) m.invoke(null, new Object[] { contextPath, classLoader, properties });
        } catch (NoSuchMethodException e) {
            // ignore
        } catch (Throwable t) {
            throw new JAXBException("Unable to create context", t);
        } 
        // Fallback for JAXB 1.0 compatibility (at least JAXB TCK tests are using that feature)
        try {
            Method m = spi.getMethod("createContext", new Class[] { String.class, ClassLoader.class, });
            return (JAXBContext) m.invoke(null, new Object[] { contextPath, classLoader });
        } catch (Throwable t) {
            throw new JAXBException("Unable to create context", t);
        }
    }