List of usage examples for java.lang Class getClassLoader
@CallerSensitive
@ForceInline
public ClassLoader getClassLoader()
From source file:ezbake.deployer.utilities.Utilities.java
public static List<String> getResourcesFromClassPath(final Class clazz, final String classpath) { Reflections reflections = new Reflections( new ConfigurationBuilder().setUrls(ClasspathHelper.forPackage(classpath, clazz.getClassLoader())) .setScanners(new ResourcesScanner()).filterInputsBy(new Predicate<String>() { @Override public boolean apply(String input) { return input.startsWith(classpath); }//from w w w . ja v a2 s . c om })); return Lists.newArrayList(reflections.getResources(Predicates.<String>alwaysTrue())); }
From source file:org.hopen.framework.rewrite.CachedIntrospectionResults.java
/** * Clear the introspection cache for the given ClassLoader, removing the * introspection results for all classes underneath that ClassLoader, * and deregistering the ClassLoader (and any of its children) from the * acceptance list./*from w ww . j av a2s. co m*/ * @param classLoader the ClassLoader to clear the cache for */ public static void clearClassLoader(ClassLoader classLoader) { if (classLoader == null) { return; } synchronized (classCache) { for (Iterator<Class> it = classCache.keySet().iterator(); it.hasNext();) { Class beanClass = it.next(); if (isUnderneathClassLoader(beanClass.getClassLoader(), classLoader)) { it.remove(); } } } synchronized (acceptedClassLoaders) { for (Iterator<ClassLoader> it = acceptedClassLoaders.iterator(); it.hasNext();) { ClassLoader registeredLoader = it.next(); if (isUnderneathClassLoader(registeredLoader, classLoader)) { it.remove(); } } } }
From source file:TypeUtil.java
public static void dump(Class c) { System.err.println("Dump: " + c); dump(c.getClassLoader()); }
From source file:com.amazonaws.services.lambda.invoke.LambdaInvokerFactory.java
/** * Creates a new Lambda invoker implementing the given interface and wrapping the given * {@code AWSLambda} client./* w w w . j av a 2 s .c om*/ * * @param interfaceClass * the interface to implement * @param awsLambda * the lambda client to use for making remote calls */ public static <T> T build(Class<T> interfaceClass, AWSLambda awsLambda) { Object proxy = Proxy.newProxyInstance(interfaceClass.getClassLoader(), new Class<?>[] { interfaceClass }, new LambdaInvocationHandler(interfaceClass, awsLambda)); return interfaceClass.cast(proxy); }
From source file:com.ibm.team.build.internal.hjplugin.RTCFacadeFactory.java
/** * @return The URL for the jar containing the facade. *///from w w w. j a v a 2 s. c o m public synchronized static URL getFacadeJarURL(PrintStream debugLog) { // if we already have a cached facade for the toolkit requested, get the path from there. // otherwise find it without creating a facade. if (fgHJPlugin_rtcJar != null) { return fgHJPlugin_rtcJar; } // Find the jar from our class loader Class<?> originalClass = RTCFacadeFactory.class; ClassLoader originalClassLoader = originalClass.getClassLoader(); debug(debugLog, "Original class loader: " + originalClassLoader); //$NON-NLS-1$ // Get the jar for the hjplugin-rtc jar. fgHJPlugin_rtcJar = getHjplugin_rtcJar(originalClassLoader, "com.ibm.team.build.internal.hjplugin.rtc.RTCFacade", debugLog); //$NON-NLS-1$ return fgHJPlugin_rtcJar; }
From source file:lite.log.intercept.Modifier.java
@SuppressWarnings("unchecked") static public <T> Modifier<T> addLoggingBusiness(Class<T> clazz, ExecutionContext executionContext, LogFactory logFactory) {//from w ww .j a v a 2 s . c o m Class<T> dynamicType = (Class<T>) new ByteBuddy().subclass(clazz).method(ElementMatchers.named("tranform")) .intercept(MethodDelegation.to(new InterceptorBusiness(executionContext, logFactory))) .make().load(clazz.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER).getLoaded(); return new Modifier<T>(dynamicType); }
From source file:ClassLoaderUtils.java
/** * Load a given resource.//from www.ja v a 2 s. c o m * <p/> * This method will try to load the resource using the following methods (in order): * <ul> * <li>From {@link Thread#getContextClassLoader() Thread.currentThread().getContextClassLoader()} * <li>From {@link Class#getClassLoader() ClassLoaderUtil.class.getClassLoader()} * <li>From the {@link Class#getClassLoader() callingClass.getClassLoader() } * </ul> * * @param resourceName The name of the resource to load * @param callingClass The Class object of the calling object */ public static URL getResource(String resourceName, Class callingClass) { URL url = null; url = Thread.currentThread().getContextClassLoader().getResource(resourceName); if (url == null) { url = ClassLoaderUtils.class.getClassLoader().getResource(resourceName); } if (url == null) { url = callingClass.getClassLoader().getResource(resourceName); } return url; }
From source file:com.yahoo.storm.yarn.StormOnYarn.java
/** * Find a jar that contains a class of the same name, if any. * It will return a jar file, even if that is not the first thing * on the class path that has a class with the same name. * /*ww w . j a v a 2 s . co m*/ * @param my_class the class to find. * @return a jar file that contains the class, or null. * @throws IOException on any error */ public static String findContainingJar(Class<?> my_class) throws IOException { ClassLoader loader = my_class.getClassLoader(); String class_file = my_class.getName().replaceAll("\\.", "/") + ".class"; for (Enumeration<URL> itr = loader.getResources(class_file); itr.hasMoreElements();) { URL url = itr.nextElement(); if ("jar".equals(url.getProtocol())) { String toReturn = url.getPath(); if (toReturn.startsWith("file:")) { toReturn = toReturn.substring("file:".length()); } // URLDecoder is a misnamed class, since it actually decodes // x-www-form-urlencoded MIME type rather than actual // URL encoding (which the file path has). Therefore it would // decode +s to ' 's which is incorrect (spaces are actually // either unencoded or encoded as "%20"). Replace +s first, so // that they are kept sacred during the decoding process. toReturn = toReturn.replaceAll("\\+", "%2B"); toReturn = URLDecoder.decode(toReturn, "UTF-8"); return toReturn.replaceAll("!.*$", ""); } } throw new IOException("Fail to locat a JAR for class: " + my_class.getName()); }
From source file:ReflectionHelper.java
public static Class<?> classForName(String name, Class<?> caller) throws ClassNotFoundException { try {/*from ww w.j a v a2 s . com*/ ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); if (contextClassLoader != null) { return contextClassLoader.loadClass(name); } } catch (Throwable e) { // ignore } return Class.forName(name, true, caller.getClassLoader()); }
From source file:com.link_intersystems.lang.reflect.ThreadLocalProxy.java
@SuppressWarnings("unchecked") public static <T, TC> T createProxy(ThreadLocal<T> threadLocal, T nullInstance, Class<TC> targetClass) { List<Class<?>> allInterfaces = new ArrayList<Class<?>>(ClassUtils.getAllInterfaces(targetClass)); if (targetClass.isInterface()) { allInterfaces.add(targetClass);/*www. ja va 2 s.co m*/ } Class<?>[] interfaces = (Class<?>[]) allInterfaces.toArray(new Class<?>[allInterfaces.size()]); T proxy = (T) Proxy.newProxyInstance(targetClass.getClassLoader(), interfaces, new ThreadLocalProxy(threadLocal, nullInstance)); return proxy; }