public static InputStream getResourceAsStream(String resource) { InputStream stream = getContextClassLoader().getResourceAsStream(resource); if (stream == null) { // fallback stream = _ClassUtils.class.getClassLoader().getResourceAsStream(resource); } return stream; }
/** * Gets the ClassLoader associated with the current thread. Returns the class loader associated with the specified * default object if no context loader is associated with the current thread. * * @param defaultObject * The default object to use to determine the class loader (if none associated with current thread.) * @return ClassLoader */ protected static ClassLoader getCurrentLoader(Object defaultObject) { ClassLoader loader = getContextClassLoader(); if (loader == null) { loader = defaultObject.getClass().getClassLoader(); } return loader; }
/** * Tries a Class.loadClass with the context class loader of the current thread first and automatically falls back to * the ClassUtils class loader (i.e. the loader of the myfaces.jar lib) if necessary. * * @param type * fully qualified name of a non-primitive non-array class * @return the corresponding Class * @throws NullPointerException * if type is null * @throws ClassNotFoundException */ public static Class<?> classForName(String type) throws ClassNotFoundException { if (type == null) { throw new NullPointerException("type"); } try { // Try WebApp ClassLoader first return Class.forName(type, false, // do not initialize for faster startup getContextClassLoader()); } catch (ClassNotFoundException ignore) { // fallback: Try ClassLoader for ClassUtils (i.e. the myfaces.jar lib) return Class.forName(type, false, // do not initialize for faster startup _ClassUtils.class.getClassLoader()); } }
_ClassUtils.getContextClassLoader());