/** * Gets the ClassLoader associated with the current thread. Includes a check for priviledges * against java2 security to ensure no security related exceptions are encountered. * * @since 3.0.6 * @return ClassLoader */ public static ClassLoader getContextClassLoader() { // call into the same method on ClassLoaderUtils. no need for duplicate code maintenance. return ClassLoaderUtils.getContextClassLoader(); }
/** * Gets the ClassLoader associated with the current thread. Includes a check for priviledges * against java2 security to ensure no security related exceptions are encountered. * * @since 3.0.6 * @return ClassLoader */ public static ClassLoader getContextClassLoader() { // call into the same method on ClassLoaderUtils. no need for duplicate code maintenance. return ClassLoaderUtils.getContextClassLoader(); }
private static ClassLoader getContextClassLoaderFailsafe() { ClassLoader contextClassLoader = ClassLoaderUtils.getContextClassLoader(); if (contextClassLoader == null) { // fall back to the ClassLoader of this class if the current Thread has no ContextClassLoader contextClassLoader = MyFacesClassLoader.class.getClassLoader(); } return contextClassLoader; }
private static ClassLoader getContextClassLoaderFailsafe() { ClassLoader contextClassLoader = ClassLoaderUtils.getContextClassLoader(); if (contextClassLoader == null) { // fall back to the ClassLoader of this class if the current Thread has no ContextClassLoader contextClassLoader = MyFacesClassLoader.class.getClassLoader(); } return contextClassLoader; }
ClassLoader loader = getContextClassLoader();
ClassLoader loader = getContextClassLoader();
/** * Locates the resource with the specified name. For Java 2 callers, the * current thread's context class loader is preferred, falling back on the * class loader of the caller when the current thread's context is not set, * or the caller is pre Java 2. If the callerClassLoader is null, then * fall back on the system class loader. * * @param name the name of the resource * @param callerClassLoader the calling class loader context * @return the resulting <code>URL</code> object */ public static URL getResource( String name, ClassLoader callerClassLoader) { _checkResourceName(name); URL url = null; ClassLoader loader = getContextClassLoader(); if (loader != null) url = loader.getResource(name); if (url == null) { if (callerClassLoader != null) url = callerClassLoader.getResource(name); else url = ClassLoader.getSystemResource(name); } return url; }
/** * Locates the resource stream with the specified name. For Java 2 callers, * the current thread's context class loader is preferred, falling back on * the class loader of the caller when the current thread's context is not * set, or the caller is pre Java 2. If the callerClassLoader is null, then * fall back on the system class loader. * * @param name the name of the resource * @param callerClassLoader the calling class loader context * @return the resulting <code>InputStream</code> object */ public static InputStream getResourceAsStream( String name, ClassLoader callerClassLoader) { _checkResourceName(name); InputStream stream = null; ClassLoader loader = getContextClassLoader(); if (loader != null) stream = loader.getResourceAsStream(name); if (stream == null) { if (callerClassLoader != null) stream = callerClassLoader.getResourceAsStream(name); else stream = ClassLoader.getSystemResourceAsStream(name); } return stream; }
/** * Locates the resource with the specified name. For Java 2 callers, the * current thread's context class loader is preferred, falling back on the * class loader of the caller when the current thread's context is not set, * or the caller is pre Java 2. If the callerClassLoader is null, then * fall back on the system class loader. * * @param name the name of the resource * @param callerClassLoader the calling class loader context * @return the resulting <code>URL</code> object */ public static URL getResource( String name, ClassLoader callerClassLoader) { _checkResourceName(name); URL url = null; ClassLoader loader = getContextClassLoader(); if (loader != null) url = loader.getResource(name); if (url == null) { if (callerClassLoader != null) url = callerClassLoader.getResource(name); else url = ClassLoader.getSystemResource(name); } return url; }
/** * Locates the resource stream with the specified name. For Java 2 callers, * the current thread's context class loader is preferred, falling back on * the class loader of the caller when the current thread's context is not * set, or the caller is pre Java 2. If the callerClassLoader is null, then * fall back on the system class loader. * * @param name the name of the resource * @param callerClassLoader the calling class loader context * @return the resulting <code>InputStream</code> object */ public static InputStream getResourceAsStream( String name, ClassLoader callerClassLoader) { _checkResourceName(name); InputStream stream = null; ClassLoader loader = getContextClassLoader(); if (loader != null) stream = loader.getResourceAsStream(name); if (stream == null) { if (callerClassLoader != null) stream = callerClassLoader.getResourceAsStream(name); else stream = ClassLoader.getSystemResourceAsStream(name); } return stream; }