org.synyx.hades.util
Class ClassUtils

java.lang.Object
  extended by org.synyx.hades.util.ClassUtils

public abstract class ClassUtils
extends java.lang.Object

Utility class to work with classes.

Author:
Oliver Gierke - gierke@synyx.de

Method Summary
static void assertReturnType(java.lang.reflect.Method method, java.lang.Class<?>... types)
          Asserts the given Method's return type to be one of the given types.
static java.lang.Class<?> getDomainClass(java.lang.Class<?> clazz)
          Returns the domain class the given class is declared for.
static java.lang.String getEntityName(java.lang.Class<?> domainClass)
          Returns the name ot the entity represented by this class.
static java.lang.Class<? extends java.io.Serializable> getIdClass(java.lang.Class<?> clazz)
          Returns the id class the given class is declared for.
static int getNumberOfOccurences(java.lang.reflect.Method method, java.lang.Class<?> type)
          Returns the number of occurences of the given type in the given Methods parameters.
static java.lang.Class<?> getReturnedDomainClass(java.lang.reflect.Method method)
          Returns the domain class returned by the given Method.
static boolean hasParameterOfType(java.lang.reflect.Method method, java.lang.Class<?> type)
          Returns whether the given Method has a parameter of the given type.
static boolean isEntityManagerOfType(javax.persistence.EntityManager em, java.lang.String type)
          Returns whether the given EntityManager is of the given type.
static boolean isExtendedDaoInterface(java.lang.Class<?> daoInterface)
          Returns if the DAO bean to be created shall implement ExtendedGenericDao.
static boolean isHadesDaoInterface(java.lang.Class<?> interfaze)
          Returns wthere the given type is a Hades DAO interface.
static boolean isHadesDaoInterface(java.lang.String interfaceName)
          Returns whether the given type name is a Hades DAO interface name.
static boolean isOfType(java.lang.Object object, java.util.Collection<java.lang.Class<?>> types)
          Returns whether the given object is of one of the given types.
static void unwrapReflectionException(java.lang.Exception ex)
          Helper method to extract the original exception that can possibly occur during a reflection call.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getDomainClass

public static java.lang.Class<?> getDomainClass(java.lang.Class<?> clazz)
Returns the domain class the given class is declared for. Will introspect the given class for extensions of GenericDao or ExtendedGenericDao and retrieve the domain class type from its generics declaration.

Parameters:
clazz -
Returns:
the domain class the given class is DAO for or null if none found.

getIdClass

public static java.lang.Class<? extends java.io.Serializable> getIdClass(java.lang.Class<?> clazz)
Returns the id class the given class is declared for. Will introspect the given class for extensions of GenericDao or ExtendedGenericDao and retrieve the Serializable type from its generics declaration.

Parameters:
clazz -
Returns:
the id class the given class is DAO for or null if none found.

getReturnedDomainClass

public static java.lang.Class<?> getReturnedDomainClass(java.lang.reflect.Method method)
Returns the domain class returned by the given Method. Will extract the type from Collections and Page as well.

Parameters:
method -
Returns:

isHadesDaoInterface

public static boolean isHadesDaoInterface(java.lang.Class<?> interfaze)
Returns wthere the given type is a Hades DAO interface.

Parameters:
interfaze -
Returns:

isHadesDaoInterface

public static boolean isHadesDaoInterface(java.lang.String interfaceName)
Returns whether the given type name is a Hades DAO interface name.

Parameters:
interfaceName -
Returns:

isEntityManagerOfType

public static boolean isEntityManagerOfType(javax.persistence.EntityManager em,
                                            java.lang.String type)
Returns whether the given EntityManager is of the given type.

Parameters:
em -
type - the fully qualified expected EntityManager type.
Returns:

isExtendedDaoInterface

public static boolean isExtendedDaoInterface(java.lang.Class<?> daoInterface)
Returns if the DAO bean to be created shall implement ExtendedGenericDao.

Returns:

getNumberOfOccurences

public static int getNumberOfOccurences(java.lang.reflect.Method method,
                                        java.lang.Class<?> type)
Returns the number of occurences of the given type in the given Methods parameters.

Parameters:
method -
type -
Returns:

assertReturnType

public static void assertReturnType(java.lang.reflect.Method method,
                                    java.lang.Class<?>... types)
Asserts the given Method's return type to be one of the given types.

Parameters:
method -
types -

isOfType

public static boolean isOfType(java.lang.Object object,
                               java.util.Collection<java.lang.Class<?>> types)
Returns whether the given object is of one of the given types. Will return false for null.

Parameters:
object -
types -
Returns:

hasParameterOfType

public static boolean hasParameterOfType(java.lang.reflect.Method method,
                                         java.lang.Class<?> type)
Returns whether the given Method has a parameter of the given type.

Parameters:
method -
type -
Returns:

getEntityName

public static java.lang.String getEntityName(java.lang.Class<?> domainClass)
Returns the name ot the entity represented by this class. Used to build queries for that class.

Parameters:
domainClass -
Returns:

unwrapReflectionException

public static void unwrapReflectionException(java.lang.Exception ex)
                                      throws java.lang.Throwable
Helper method to extract the original exception that can possibly occur during a reflection call.

Parameters:
ex -
Throws:
java.lang.Throwable


Copyright © 2009-2010 Synyx GmbH & Co. KG. All Rights Reserved.