Spring Data Commmons

org.springframework.data.repository.util
Class ClassUtils

java.lang.Object
  extended by org.springframework.data.repository.util.ClassUtils

public abstract class ClassUtils
extends Object

Utility class to work with classes.

Author:
Oliver Gierke

Method Summary
static void assertReturnType(Method method, Class<?>... types)
          Asserts the given Method's return type to be one of the given types.
static Method getBaseClassMethodFor(Method method, Class<?> baseClass, Class<?> repositoryInterface)
          Returns the given base class' method if the given method (declared in the interface) was also declared at the base class.
static Class<?> getDomainClass(Class<?> clazz)
          Returns the domain class the given class is declared for.
static Class<? extends Serializable> getIdClass(Class<?> clazz)
          Returns the id class the given class is declared for.
static int getNumberOfOccurences(Method method, Class<?> type)
          Returns the number of occurences of the given type in the given Methods parameters.
static Class<?> getReturnedDomainClass(Method method)
          Returns the domain class returned by the given Method.
static boolean hasParameterOfType(Method method, Class<?> type)
          Returns whether the given Method has a parameter of the given type.
static boolean hasProperty(Class<?> type, String property)
          Returns whether the given class contains a property with the given name.
static boolean isGenericRepositoryInterface(Class<?> interfaze)
          Returns wthere the given type is the Repository interface.
static boolean isGenericRepositoryInterface(String interfaceName)
          Returns whether the given type name is a repository interface name.
static boolean isOfType(Object object, Collection<Class<?>> types)
          Returns whether the given object is of one of the given types.
static void unwrapReflectionException(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 Class<?> getDomainClass(Class<?> clazz)
Returns the domain class the given class is declared for. Will introspect the given class for extensions of Repository and retrieve the domain class type from its generics declaration.

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

getIdClass

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

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

getReturnedDomainClass

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

Parameters:
method -
Returns:

hasProperty

public static boolean hasProperty(Class<?> type,
                                  String property)
Returns whether the given class contains a property with the given name.

Parameters:
fieldName -
Returns:

isGenericRepositoryInterface

public static boolean isGenericRepositoryInterface(Class<?> interfaze)
Returns wthere the given type is the Repository interface.

Parameters:
interfaze -
Returns:

isGenericRepositoryInterface

public static boolean isGenericRepositoryInterface(String interfaceName)
Returns whether the given type name is a repository interface name.

Parameters:
interfaceName -
Returns:

getNumberOfOccurences

public static int getNumberOfOccurences(Method method,
                                        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(Method method,
                                    Class<?>... types)
Asserts the given Method's return type to be one of the given types.

Parameters:
method -
types -

isOfType

public static boolean isOfType(Object object,
                               Collection<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(Method method,
                                         Class<?> type)
Returns whether the given Method has a parameter of the given type.

Parameters:
method -
type -
Returns:

unwrapReflectionException

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

Parameters:
ex -
Throws:
Throwable

getBaseClassMethodFor

public static Method getBaseClassMethodFor(Method method,
                                           Class<?> baseClass,
                                           Class<?> repositoryInterface)
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 -
repositoryInterface -
Returns:

Spring Data Commmons

Copyright © 2011. All Rights Reserved.