|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.basedb.util.ClassUtil
public class ClassUtil
Utility class for Class
objects.
Constructor Summary | |
---|---|
ClassUtil()
|
Method Summary | ||
---|---|---|
static Class<?> |
checkAndLoadClass(ClassLoader loader,
String name,
boolean publicNoArgConstructor,
Class<?>... interfaces)
Check if a specified class exists and, optionally, if it has public no-argument constructor and implements a set of specific interfaces or superclasses. |
|
static void |
checkClass(Class<?> clazz,
boolean publicNoArgConstructor,
Class<?>... interfaces)
Check if a specified class has public no-argument constructor and implements a set of specific interfaces or superclasses. |
|
static
|
findConstructor(Class<I> clazz,
Object[] parameters)
Find a constructor for the specified class which takes parameters of the specified types taking superclasses and interfaces into account. |
|
static Method |
findMethod(Class<?> clazz,
String name,
Class<?>... arguments)
Find a method in a clazz with the given name
that takes the given list of arguments . |
|
static Set<Class> |
getInterfaces(Class clazz)
Get all interfaces a class implements, including those implemented by superclasses. |
|
static boolean |
isAssignable(Class<?>[] classes,
Object[] values)
Check if one array of class objects is assignment compatible with values in another array. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ClassUtil()
Method Detail |
---|
public static <I> Constructor<I> findConstructor(Class<I> clazz, Object[] parameters)
clazz
- The class to find a constructor forparameters
- The parameters that are going to be sent to the
constructor's Constructor.newInstance(Object[])
method
public static boolean isAssignable(Class<?>[] classes, Object[] values)
Class.isAssignableFrom(Class)
method returns
true for each element in the classes
array with respect to the class
of the corresponding value in the values
array.
Null elements in the values
array are ignored.
classes
- The class objects representing the parameters we want to assign values tovalues
- The parameter values to assign
public static Set<Class> getInterfaces(Class clazz)
clazz
- The Class
to check
Set
containing the Class
objects
for the interfacespublic static Class<?> checkAndLoadClass(ClassLoader loader, String name, boolean publicNoArgConstructor, Class<?>... interfaces) throws ClassNotFoundException, NoSuchMethodException, ClassCastException
loader
- The classloader used to load the class, or null
to use the default classloadername
- The fully qualified name of class to checkpublicNoArgConstructor
- TRUE to check if a public no-argument constructor existsinterfaces
- An array of class objects representing interfaces or superclasses
that the class to check must implement or extend
Class
object for the named class
ClassNotFoundException
- If a class with the specified name isn't found
NoSuchMethodException
- If a public no-argument constructor isn't found
ClassCastException
- If the class doesn't implement or extend all of
the interfaces/superclassespublic static void checkClass(Class<?> clazz, boolean publicNoArgConstructor, Class<?>... interfaces) throws NoSuchMethodException, ClassCastException
clazz
- The clazz to checkpublicNoArgConstructor
- TRUE to check if a public no-argument constructor existsinterfaces
- An array of class objects representing interfaces or superclasses
that the class to check must implement or extend
NoSuchMethodException
- If a public no-argument constructor isn't found
ClassCastException
- If the class doesn't implement or extend all of
the interfaces/superclassespublic static Method findMethod(Class<?> clazz, String name, Class<?>... arguments)
clazz
with the given name
that takes the given list of arguments
. This method is
just calling Class.getMethod(String, Class...)
but returns
null instead of throwing an exception in case the method is not found.
clazz
- The class to look for the method inname
- The name of the methodarguments
- The class types of the arguments
|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |