/** * Get the information for a class * * @param name the name * @param cl the classloader * @return the info * @throws ClassNotFoundException when the class cannot be found */ public T get(String name, ClassLoader cl) throws ClassNotFoundException { if (name == null) throw new IllegalArgumentException("Null name"); if (cl == null) throw new IllegalArgumentException("Null classloader"); Class<?> clazz = cl.loadClass(name); return get(clazz); }
/** * Get the information for a class * * @param clazz the class * @return the info */ public T get(Class<?> clazz) { if (clazz == null) throw new IllegalArgumentException("Null class"); Map<String, WeakReference<T>> classLoaderCache = getClassLoaderCache(clazz.getClassLoader()); WeakReference<T> weak = classLoaderCache.get(clazz.getName()); if (weak != null) { T result = weak.get(); if (result != null) return result; } T result = instantiate(clazz); weak = new WeakReference<T>(result); classLoaderCache.put(clazz.getName(), weak); generate(clazz, result); return result; }
/** * Gets the classloader cache for the passed in classloader. * * @param cl the classloader. If null is used, the Thread context classloader will be used instead * @return the cache of type infos by name */ @Override protected Map<String, WeakReference<TypeInfo>> getClassLoaderCache(ClassLoader cl) { if (cl == null) cl = SecurityActions.getContextClassLoader(); return super.getClassLoaderCache(cl); }
/** * Gets the classloader cache for the passed in classloader. * * @param cl the classloader. If null is used, the Thread context classloader will be used instead * @return the cache of type infos by name */ @Override protected Map<String, WeakReference<TypeInfo>> getClassLoaderCache(ClassLoader cl) { if (cl == null) cl = SecurityActions.getContextClassLoader(); return super.getClassLoaderCache(cl); }