com.github.dandelion.datatables.core.util
Class ClassUtils

java.lang.Object
  extended by com.github.dandelion.datatables.core.util.ClassUtils

public class ClassUtils
extends Object

Helper class used for all reflection stuff.

Author:
Thibault Duchateau

Constructor Summary
ClassUtils()
           
 
Method Summary
static Boolean canBeUsed(String className)
           Test if a class exists in the classPath, trying to load it with its name.
static List<Class<?>> getAllClassesInPackage(String packageName)
           
static Class<?> getClass(String className)
           Tries to load a class from its name.
static Object getNewInstance(Class<?> klass)
           Instanciate a class.
static List<Class<?>> getSubClassesInPackage(String packageName, Class<?> superClass)
           
static Object invokeMethod(Object obj, String methodName, Object[] args)
           Invoke a method called methodName on the object obj, with arguments args.
static boolean isPresent(String className)
          Determine whether the Class identified by the supplied name is present and can be loaded.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassUtils

public ClassUtils()
Method Detail

getClass

public static Class<?> getClass(String className)
                         throws ClassNotFoundException

Tries to load a class from its name. If class is not found using the standard classloader, tries with the thread classloader.

Parameters:
className - class name
Returns:
the found class
Throws:
ClassNotFoundException - if none of the ClassLoaders is able to found the class.

getNewInstance

public static Object getNewInstance(Class<?> klass)
                             throws InstantiationException,
                                    IllegalAccessException

Instanciate a class.

Parameters:
klass - The class to instanciate.
Returns:
a new instance of the given class.
Throws:
IllegalAccessException
InstantiationException

invokeMethod

public static Object invokeMethod(Object obj,
                                  String methodName,
                                  Object[] args)
                           throws NoSuchMethodException,
                                  IllegalAccessException,
                                  InvocationTargetException

Invoke a method called methodName on the object obj, with arguments args.

Parameters:
obj - The object on which to invoke the method.
methodName - The method name to invoke.
args - The potential args used in the method.
Returns:
An object returned by the invoked method.
Throws:
InvocationTargetException
IllegalAccessException
NoSuchMethodException - if the methodName doesn't exist for the given object.

canBeUsed

public static Boolean canBeUsed(String className)

Test if a class exists in the classPath, trying to load it with its name.

Parameters:
className - The class to test.
Returns:
true if the class can be used, false otherwise.

isPresent

public static boolean isPresent(String className)
Determine whether the Class identified by the supplied name is present and can be loaded. Will return false if either the class or one of its dependencies is not present or cannot be loaded.

Parameters:
className - the name of the class to check
classLoader - the class loader to use (may be null, which indicates the default class loader)
Returns:
whether the specified class is present

getSubClassesInPackage

public static List<Class<?>> getSubClassesInPackage(String packageName,
                                                    Class<?> superClass)
                                             throws ClassNotFoundException,
                                                    IOException
Throws:
ClassNotFoundException
IOException

getAllClassesInPackage

public static List<Class<?>> getAllClassesInPackage(String packageName)
                                             throws ClassNotFoundException,
                                                    IOException
Throws:
ClassNotFoundException
IOException


Copyright © 2013–2014 Dandelion Project. All rights reserved.