ch.sahits.util
Class ClassChecker

java.lang.Object
  extended by ch.sahits.util.ClassChecker

public class ClassChecker
extends java.lang.Object

This class provides method to check whether some interface is implemented by the class or the class is the subclass of any class.

Author:
Andi Hotz

Constructor Summary
ClassChecker(java.lang.Class checkClass)
          Initialize the class to be checked
 
Method Summary
 boolean extendsClass(java.lang.Class superClass)
          Check whether the class extends a class.
 boolean extendsClass(java.lang.String superClassName)
          Load the class by its name and call extendsClass(Class)
 boolean hasConstructor(java.lang.Class[] types)
          Check whether the class implements a constructor with the given types.
 boolean hasMethod(java.lang.String name, java.lang.Class[] types)
          Check whether the class implements a method with the given name and types.
 boolean implementsInterface(java.lang.Class interfaceClass)
          Check whether the class implements a interface.
 boolean implementsInterface(java.lang.String interfaceName)
          Load the class by its name and call implementsInterface(Class)
 java.util.List<java.lang.Class> superClasses()
          Retrieve a list of all super classes of the class to be checked.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassChecker

public ClassChecker(java.lang.Class checkClass)
Initialize the class to be checked

Parameters:
checkClass -
Method Detail

implementsInterface

public boolean implementsInterface(java.lang.Class interfaceClass)
Check whether the class implements a interface. The interface must be declared as implemented in the class or the super class or the super class of the super class ...

Parameters:
interfaceClass - that should be implemented
Returns:
true if the interface is anywhere in the class hierarchy implemented.

extendsClass

public boolean extendsClass(java.lang.Class superClass)
Check whether the class extends a class. The super class must be declared as extending the class or the super class or the super class ...

Parameters:
superClass - that should be extended
Returns:
true if the class is extending the super class

extendsClass

public boolean extendsClass(java.lang.String superClassName)
Load the class by its name and call extendsClass(Class)

Parameters:
superClassName - name of the super class
Returns:
false if the superclass could not be loaded or the result from extendsClass(Class)

implementsInterface

public boolean implementsInterface(java.lang.String interfaceName)
Load the class by its name and call implementsInterface(Class)

Parameters:
interfaceName - name of the interface
Returns:
false if the interface could not be loaded or the result from implementsInterface(Class)

hasConstructor

public boolean hasConstructor(java.lang.Class[] types)
Check whether the class implements a constructor with the given types. Constructors that take a more general type as arguments are also accepted as long they extend the type explicitly. This excludes the type Object.

Parameters:
types - Array of argument types
Returns:
true if such a constructor exists

hasMethod

public boolean hasMethod(java.lang.String name,
                         java.lang.Class[] types)
Check whether the class implements a method with the given name and types. Constructors that take a more general type as arguments are also accepted as long they extend the type explicitly. This excludes the type Object.

Parameters:
name - of the method
types - Array of argument types
Returns:
true if such a method exists

superClasses

public java.util.List<java.lang.Class> superClasses()
Retrieve a list of all super classes of the class to be checked. The Object class is excluded.

Returns:
List of super classes