Package org.apache.tiles.request.reflect
Class ClassUtil
java.lang.Object
org.apache.tiles.request.reflect.ClassUtil
Utilities to work with dynamic class loading and instantiation.
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
collectBeanInfo
(Class<?> clazz, Map<String, PropertyDescriptor> name2descriptor) Collects bean infos from a class and filling a list.static <T> Class<? extends T>
Returns the class and casts it to the correct subclass.
It tries to use the thread's current classloader first and, if it does not succeed, uses the classloader of ClassUtil.static Object
instantiate
(String className) Returns an instance of the given class name, by calling the default constructor.static Object
instantiate
(String className, boolean returnNull) Returns an instance of the given class name, by calling the default constructor.
-
Method Details
-
getClass
public static <T> Class<? extends T> getClass(String className, Class<T> baseClass) throws ClassNotFoundException Returns the class and casts it to the correct subclass.
It tries to use the thread's current classloader first and, if it does not succeed, uses the classloader of ClassUtil.- Type Parameters:
T
- The subclass to use.- Parameters:
className
- The name of the class to load.baseClass
- The base class to subclass to.- Returns:
- The loaded class.
- Throws:
ClassNotFoundException
- If the class has not been found.
-
instantiate
Returns an instance of the given class name, by calling the default constructor.- Parameters:
className
- The class name to load and to instantiate.- Returns:
- The new instance of the class name.
- Throws:
CannotInstantiateObjectException
- If something goes wrong during instantiation.
-
instantiate
Returns an instance of the given class name, by calling the default constructor.- Parameters:
className
- The class name to load and to instantiate.returnNull
- Iftrue
, if the class is not found it returnstrue
, otherwise it throws aTilesException
.- Returns:
- The new instance of the class name.
- Throws:
CannotInstantiateObjectException
- If something goes wrong during instantiation.
-
collectBeanInfo
Collects bean infos from a class and filling a list.- Parameters:
clazz
- The class to be inspected.name2descriptor
- The map in the form: name of the property -> descriptor.
-