/** * Get the information for a type * * @param type the type * @return the info */ @SuppressWarnings({"unchecked", "cast"}) public T get(Type type) { if (type == null) throw new IllegalArgumentException("Null type"); if (type instanceof ParameterizedType) return getParameterizedType((ParameterizedType) type); else if (type instanceof Class) return getClass((Class<?>) type); else if (type instanceof TypeVariable) // TODO Figure out why we need this cast with the Sun compiler? return (T) getTypeVariable((TypeVariable) type); else if (type instanceof GenericArrayType) return getGenericArrayType((GenericArrayType) type); else if (type instanceof WildcardType) return getWildcardType((WildcardType) type); else throw new UnsupportedOperationException("Unknown type: " + type + " class=" + type.getClass()); }
/** * Get the information for a parameterized type * * @param type the parameterized type * @return the info */ protected T getParameterizedType(ParameterizedType type) { // First check if we already have it T result = peek(type); if (result != null) return result; // Instantiate result = instantiate(type); // Put the perlimanary result into the cache put(type, result); // Generate the details generate(type, result); return result; }
/** * Get the information for an array type * * @param type the array type * @return the info */ protected T getGenericArrayType(GenericArrayType type) { // TODO JBMICROCONT-131 this needs implementing properly return get(Object[].class); }
protected <D extends GenericDeclaration> TypeInfo getTypeVariable(TypeVariable<D> type) { TypeInfo info = super.getTypeVariable(type); if (info instanceof TypeVariableAware) ((TypeVariableAware)info).setTypeVariable(type.getName()); return info; }
/** * Put a result into the cache * * @param type the type * @param result the value */ protected void put(ParameterizedType type, T result) { Class<?> rawType = (Class<?>) type.getRawType(); ClassLoader cl = SecurityActions.getClassLoader(rawType); Map<String, T> classLoaderCache = getClassLoaderCache(cl); synchronized (classLoaderCache) { // TODO JBMICROCONT-131 something better than toString()? classLoaderCache.put(type.toString(), result); } }
/** * Peek into the cache * * @param clazz the class * @return the value */ protected T peek(Class<?> clazz) { ClassLoader cl = SecurityActions.getClassLoader(clazz); Map<String, T> classLoaderCache = getClassLoaderCache(cl); synchronized (classLoaderCache) { return classLoaderCache.get(clazz.getName()); } }
/** * Get the information for a class * * @param clazz the class * @return the info */ protected T getClass(Class<?> clazz) { // First check if we already have it T result = peek(clazz); if (result != null) return result; // Instantiate result = instantiate(clazz); // Put the preliminary result into the cache put(clazz, result); // Generate the details generate(clazz, result); return result; }
/** * Get the information for a wildcard type * * @param type the paremeterized type * @return the info */ protected T getWildcardType(WildcardType type) { // TODO JBMICROCONT-131 improve this return get(type.getUpperBounds()[0]); }
/** * Put a result into the cache * * @param clazz the class * @param result the value */ protected void put(Class<?> clazz, T result) { ClassLoader cl = SecurityActions.getClassLoader(clazz); Map<String, T> classLoaderCache = getClassLoaderCache(cl); synchronized (classLoaderCache) { classLoaderCache.put(clazz.getName(), result); } }
/** * Get the information for a type variable * * @param <D> the declaration * @param type the type variable * @return the info */ protected <D extends GenericDeclaration> T getTypeVariable(TypeVariable<D> type) { // TODO JBMICROCONT-131 improve this return get(type.getBounds()[0]); }
/** * Peek into the cache * * @param type the type * @return the value */ protected T peek(ParameterizedType type) { Class<?> rawType = (Class<?>) type.getRawType(); ClassLoader cl = SecurityActions.getClassLoader(rawType); Map<String, T> classLoaderCache = getClassLoaderCache(cl); synchronized (classLoaderCache) { return classLoaderCache.get(type.toString()); } }
/** * 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); }