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

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.reflect.Method getBaseClassMethodFor(java.lang.reflect.Method method, java.lang.Class<?> baseClass, java.lang.Class<?> daoInterface)
          Returns the given base class' method if the given method (declared in the interface) was also declared at the base class.
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 isGenericDaoInterface(java.lang.Class<?> interfaze)
          Returns wthere the given type is the GenericDao 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:

isGenericDaoInterface

public static boolean isGenericDaoInterface(java.lang.Class<?> interfaze)
Returns wthere the given type is the GenericDao 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:

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

getBaseClassMethodFor

public static java.lang.reflect.Method getBaseClassMethodFor(java.lang.reflect.Method method,
                                                             java.lang.Class<?> baseClass,
                                                             java.lang.Class<?> daoInterface)
Returns the given base class' method if the given method (declared in the interface) was also declared at the base class. Returns the given method if the given base class does not declare the method given. Takes generics into account.

Parameters:
method -
baseClass -
daoInterface -
Returns:


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