org.apache.webbeans.util
Class ClassUtil

java.lang.Object
  extended by org.apache.webbeans.util.ClassUtil

public final class ClassUtil
extends Object

Utility classes with respect to the class operations.

Since:
1.0
Author:
Gurkan Erdogdu

Field Summary
static Object[] OBJECT_EMPTY
           
static Map<Class<?>,Object> PRIMITIVE_CLASS_DEFAULT_VALUES
           
static Map<Class<?>,Class<?>> PRIMITIVE_TO_WRAPPERS_MAP
           
static Set<Class<?>> VALUE_TYPES
           
static String WEBBEANS_DATE_FORMAT
           
 
Method Summary
static Object callInstanceMethod(Method method, Object instance, Object[] args)
          Call method on the instance with given arguments.
static boolean checkBeanAndRequiredTypeisParametrized(Type beanTypeArg, Type requiredTypeArg)
          Check parametrized bean type and parametrized required types.
static boolean checkBeanTypeAndRequiredIsTypeVariable(Type beanTypeArg, Type requiredTypeArg)
           
static boolean checkEqual(TypeVariable<?>[] variables, Type[] types)
          Check the parametrized type actual arguments equals with the class type variables at the injection point.
static boolean checkEventTypeAssignability(Type eventType, Type observerType)
          Checks that event is applicable for the given observer type.
static boolean checkForTypeArguments(Class<?> src, Type[] typeArguments, Class<?> target)
           
static boolean checkParametrizedType(ParameterizedType pType)
          Return true if it does not contain type variable for wildcard type false otherwise.
static boolean checkRequiredTypeIsClassAndBeanTypeIsVariable(Type beanTypeArg, Type requiredTypeArg)
          Checking bean type and required type.
static boolean checkRequiredTypeIsTypeVariableAndBeanTypeIsClass(Type beanTypeArg, Type requiredTypeArg)
           
static boolean checkRequiredTypeisWildCard(Type beanTypeArg, Type requiredTypeArg)
          Check bean type and required type.
static boolean classHasFieldWithName(Class<?> clazz, String fieldName)
           
static boolean classHasMoreThanOneFieldWithName(Class<?> clazz, String fieldName)
           
static
<T> T
defaultJavaValues(Class<T> clazz)
          Gets the Java Standart Class default value.
static Type[] getActualTypeArguements(Class<?> clazz)
           
static Type[] getActualTypeArguements(Type type)
           
static Class<?> getClass(Type type)
          Gets the class of the given type arguments.
static Class<?> getClassFromName(String name)
           
static List<Method> getClassMethodsWithTypes(Class<?> clazz, String methodName, List<Class<?>> parameterTypes)
           
static Method getClassMethodWithTypes(Class<?> clazz, String methodName, List<Class<?>> parameterTypes)
           
static Class<?> getClazz(Type type)
          Return raw class type for given type.
static Constructor<?> getConstructor(Class<?> clazz, Class<?>[] parameterTypes)
           
static
<T> Constructor<T>[]
getConstructors(Class<T> clazz)
          Returns class constructor array.
static Method getDeclaredMethod(Class<?> clazz, String methodName, Class<?>[] parameters)
           
static Method[] getDeclaredMethods(Class<?> clazz)
          Gets the declared methods of the given class.
static Field[] getFieldsWithType(Class<?> clazz, Type type)
           
static Field getFieldWithAnnotation(Class<?> clazz, Class<? extends Annotation> annotation)
           
static Field getFieldWithName(Class<?> clazz, String fieldName)
           
static Class<?> getFirstRawType(Type type)
           
static Type[] getGenericSuperClassTypeArguments(Class<?> clazz)
           
static List<Type[]> getGenericSuperInterfacesTypeArguments(Class<?> clazz)
           
static Class<?>[] getMethodParameterTypes(Method method)
           
static List<String> getObjectMethodNames()
           
 Package getPackage(String packageName)
          Gets java package if exist.
static Class<?> getPrimitiveWrapper(Class<?> clazz)
           
static Class<?> getRawTypeForInjectionPoint(InjectionPoint injectionPoint)
          Returns injection point raw type.
static Class<?> getReturnType(Method method)
          Gets the return type of the method.
static Throwable getRootException(Throwable throwable)
           
static List<Class<?>> getSuperClasses(Class<?> clazz, List<Class<?>> list)
           
static TypeVariable<?>[] getTypeVariables(Class<?> clazz)
           
static Class<?> getWrapperPrimitive(Class<?> clazz)
           
static
<T> boolean
hasDefaultConstructor(Class<T> clazz)
          Returns true if class has a default constructor.
static boolean hasFinalMethod(Class<?> clazz)
          Check for class that has a final method or not.
static boolean hasMethodWithName(Class<?> clazz, String methodName)
           
static boolean isAbstract(Integer modifier)
          Check abstract modifier.
static boolean isArray(Class<?> clazz)
           
static boolean isAssignable(Type beanType, Type requiredType)
          See specification 5.2.3.
static boolean isAssignableForParametrized(ParameterizedType beanType, ParameterizedType requiredType)
          Returns true if given bean's api type is injectable to injection point required type.
static boolean isClassAssignable(Class<?> lhs, Class<?> rhs)
          Returns true if rhs is assignable type to the lhs, false otherwise.
static boolean isConcrete(Class<?> clazz)
          Returna true if the class is not abstract and interface.
static
<T> Constructor<T>
isContaintNoArgConstructor(Class<T> clazz)
           
static boolean isDefinitionConstainsTypeVariables(Class<?> clazz)
           
static boolean isEnum(Class<?> clazz)
           
static boolean isFinal(Integer modifier)
          Check final modifier.
static boolean isFirstParametricTypeArgGeneric(ParameterizedType type)
           
static boolean isInnerClazz(Class<?> clazz)
          Check the class is inner or not
static boolean isInterface(Integer modifier)
          Check interface modifier.
static boolean isInValueTypes(Class<?> clazz)
           
static boolean isMethodHasCheckedException(Method method)
          Check method throws checked exception or not.
static boolean isMethodHasException(Method method)
          Check method throws Exception or not.
static boolean isMethodHasParameter(Method method)
          Check that method has any formal arguments.
static boolean isMoreThanOneMethodWithName(String methodName, Class<?> clazz)
           
static boolean isObjectMethod(String methodName)
           
static boolean isOverriden(Method subClassMethod, Method superClassMethod)
           
static boolean isParametrizedType(Type type)
          Returns true if type is an instance of ParameterizedType else otherwise.
static boolean isPrimitive(Class<?> clazz)
           
static boolean isPrimitiveWrapper(Class<?> clazz)
           
static boolean isPrivate(Integer modifier)
          Check the modifier contains static keyword.
static boolean isPublic(int modifs)
          Check the modifiers contains the public keyword.
static boolean isPublic(Integer modifier)
          Check the modifier contains static keyword.
static boolean isStatic(Integer modifier)
          Check the modifier contains static keyword.
static boolean isTypeVariable(Type type)
          Returns true if type is an instance of TypeVariable else otherwise.
static boolean isUnboundedTypeVariable(Type type)
           
static Object isValueOkForBigDecimalOrInteger(Class<?> type, String value)
           
static Calendar isValueOkForCalendar(String value)
           
static Date isValueOkForDate(String value)
           
static Enum isValueOkForEnum(Class clazz, String value)
           
static Object isValueOkForPrimitiveOrWrapper(Class<?> type, String value)
          Gets the primitive/wrapper value of the parsed String parameter.
static boolean isWildCardType(Type type)
          Returns true if type is an instance of WildcardType else otherwise.
static Object newInstance(Class<?> clazz)
           
static Set<Type> setClassTypeHierarchy(Set<Type> set, Class<?> clazz)
           
static void setField(Object instance, Field field, Object value)
           
static Set<Type> setInterfaceTypeHierarchy(Set<Type> set, Class<?> clazz)
           
static Set<Type> setTypeHierarchy(Set<Type> set, Type clazz)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PRIMITIVE_CLASS_DEFAULT_VALUES

public static final Map<Class<?>,Object> PRIMITIVE_CLASS_DEFAULT_VALUES

VALUE_TYPES

public static final Set<Class<?>> VALUE_TYPES

PRIMITIVE_TO_WRAPPERS_MAP

public static final Map<Class<?>,Class<?>> PRIMITIVE_TO_WRAPPERS_MAP

WEBBEANS_DATE_FORMAT

public static final String WEBBEANS_DATE_FORMAT
See Also:
Constant Field Values

OBJECT_EMPTY

public static final Object[] OBJECT_EMPTY
Method Detail

checkEqual

public static boolean checkEqual(TypeVariable<?>[] variables,
                                 Type[] types)
Check the parametrized type actual arguments equals with the class type variables at the injection point.

Parameters:
variables - type variable
types - type
Returns:

newInstance

public static Object newInstance(Class<?> clazz)

getClassFromName

public static Class<?> getClassFromName(String name)

isFinal

public static boolean isFinal(Integer modifier)
Check final modifier.

Parameters:
modifier - modifier
Returns:
true or false

isAbstract

public static boolean isAbstract(Integer modifier)
Check abstract modifier.

Parameters:
modifier - modifier
Returns:
true or false

isInterface

public static boolean isInterface(Integer modifier)
Check interface modifier.

Parameters:
modifier - modifier
Returns:
true or false

hasFinalMethod

public static boolean hasFinalMethod(Class<?> clazz)
Check for class that has a final method or not.

Parameters:
clazz - check methods of it
Returns:
true or false

isInnerClazz

public static boolean isInnerClazz(Class<?> clazz)
Check the class is inner or not

Parameters:
modifier - modifier
Returns:
true or false

isStatic

public static boolean isStatic(Integer modifier)
Check the modifier contains static keyword.

Parameters:
modifier - modifier
Returns:
true or false

isPublic

public static boolean isPublic(Integer modifier)
Check the modifier contains static keyword.

Parameters:
modifier - modifier
Returns:
true or false

isPrivate

public static boolean isPrivate(Integer modifier)
Check the modifier contains static keyword.

Parameters:
modifier - modifier
Returns:
true or false

defaultJavaValues

public static <T> T defaultJavaValues(Class<T> clazz)
Gets the Java Standart Class default value.

Type Parameters:
T - parametrized type
Parameters:
clazz - class instance
Returns:
default value of the class

getPrimitiveWrapper

public static Class<?> getPrimitiveWrapper(Class<?> clazz)

getWrapperPrimitive

public static Class<?> getWrapperPrimitive(Class<?> clazz)

getClass

public static Class<?> getClass(Type type)
Gets the class of the given type arguments.

If the given type Type parameters is an instance of the ParameterizedType, it returns the raw type otherwise it return the casted Class of the type argument.

Parameters:
type - class or parametrized type
Returns:

getDeclaredMethods

public static Method[] getDeclaredMethods(Class<?> clazz)
Gets the declared methods of the given class.

Parameters:
clazz - class instance
Returns:
the declared methods

isMethodHasParameter

public static boolean isMethodHasParameter(Method method)
Check that method has any formal arguments.

Parameters:
method - method instance
Returns:
true or false

getReturnType

public static Class<?> getReturnType(Method method)
Gets the return type of the method.

Parameters:
method - method instance
Returns:
return type

isMethodHasCheckedException

public static boolean isMethodHasCheckedException(Method method)
Check method throws checked exception or not.

Parameters:
method - method instance
Returns:
trur or false

isMethodHasException

public static boolean isMethodHasException(Method method)
Check method throws Exception or not.

Parameters:
method - method instance
Returns:
trur or false

callInstanceMethod

public static Object callInstanceMethod(Method method,
                                        Object instance,
                                        Object[] args)
Call method on the instance with given arguments.

Parameters:
method - method instance
instance - object instance
args - arguments
Returns:
the method result

getSuperClasses

public static List<Class<?>> getSuperClasses(Class<?> clazz,
                                             List<Class<?>> list)

getMethodParameterTypes

public static Class<?>[] getMethodParameterTypes(Method method)

getObjectMethodNames

public static List<String> getObjectMethodNames()

isObjectMethod

public static boolean isObjectMethod(String methodName)

isMoreThanOneMethodWithName

public static boolean isMoreThanOneMethodWithName(String methodName,
                                                  Class<?> clazz)

isContaintNoArgConstructor

public static <T> Constructor<T> isContaintNoArgConstructor(Class<T> clazz)

isPublic

public static boolean isPublic(int modifs)
Check the modifiers contains the public keyword.

Parameters:
modifs - modifiers
Returns:
true or false

getPackage

public Package getPackage(String packageName)
Gets java package if exist.

Parameters:
packageName - package name
Returns:
the package with given name

isParametrizedType

public static boolean isParametrizedType(Type type)
Returns true if type is an instance of ParameterizedType else otherwise.

Parameters:
type - type of the artifact
Returns:
true if type is an instance of ParameterizedType

isWildCardType

public static boolean isWildCardType(Type type)
Returns true if type is an instance of WildcardType else otherwise.

Parameters:
type - type of the artifact
Returns:
true if type is an instance of WildcardType

isUnboundedTypeVariable

public static boolean isUnboundedTypeVariable(Type type)

isTypeVariable

public static boolean isTypeVariable(Type type)
Returns true if type is an instance of TypeVariable else otherwise.

Parameters:
type - type of the artifact
Returns:
true if type is an instance of TypeVariable

isConcrete

public static boolean isConcrete(Class<?> clazz)
Returna true if the class is not abstract and interface.

Parameters:
clazz - class type
Returns:
true if the class is not abstract and interface

getConstructors

public static <T> Constructor<T>[] getConstructors(Class<T> clazz)
Returns class constructor array.

Type Parameters:
T - class type arfument
Parameters:
clazz - class that is searched for constructor.
Returns:
class constructor array

hasDefaultConstructor

public static <T> boolean hasDefaultConstructor(Class<T> clazz)
Returns true if class has a default constructor.

Type Parameters:
T - type argument of class
Parameters:
clazz - class type
Returns:
true if class has a default constructor.

isAssignable

public static boolean isAssignable(Type beanType,
                                   Type requiredType)
See specification 5.2.3.

Parameters:
beanType - bean type
requiredType - required type
Returns:
true if assignable

checkEventTypeAssignability

public static boolean checkEventTypeAssignability(Type eventType,
                                                  Type observerType)
Checks that event is applicable for the given observer type.

Parameters:
eventType - event type
observerType - observer type
Returns:
true if event is applicable

isClassAssignable

public static boolean isClassAssignable(Class<?> lhs,
                                        Class<?> rhs)
Returns true if rhs is assignable type to the lhs, false otherwise.

Parameters:
lhs - left hand side class
rhs - right hand side class
Returns:
true if rhs is assignable to lhs

isAssignableForParametrized

public static boolean isAssignableForParametrized(ParameterizedType beanType,
                                                  ParameterizedType requiredType)
Returns true if given bean's api type is injectable to injection point required type.

Parameters:
beanType - bean parametrized api type
requiredType - injection point parametrized api type
Returns:
if injection is possible false otherwise

checkBeanAndRequiredTypeisParametrized

public static boolean checkBeanAndRequiredTypeisParametrized(Type beanTypeArg,
                                                             Type requiredTypeArg)
Check parametrized bean type and parametrized required types.

Parameters:
beanTypeArg - parametrized bean type
requiredTypeArg - parametrized required type
Returns:
true if types are assignables

checkRequiredTypeisWildCard

public static boolean checkRequiredTypeisWildCard(Type beanTypeArg,
                                                  Type requiredTypeArg)
Check bean type and required type.

Required type is a wildcard type.

Parameters:
beanTypeArg - bean type
requiredTypeArg - required type
Returns:
true if contdition satisfies

checkRequiredTypeIsClassAndBeanTypeIsVariable

public static boolean checkRequiredTypeIsClassAndBeanTypeIsVariable(Type beanTypeArg,
                                                                    Type requiredTypeArg)
Checking bean type and required type.

Required type is class and bean type is a type variable.

Parameters:
beanTypeArg - bean type
requiredTypeArg - required type
Returns:
true if condition satisfy

checkRequiredTypeIsTypeVariableAndBeanTypeIsClass

public static boolean checkRequiredTypeIsTypeVariableAndBeanTypeIsClass(Type beanTypeArg,
                                                                        Type requiredTypeArg)

checkBeanTypeAndRequiredIsTypeVariable

public static boolean checkBeanTypeAndRequiredIsTypeVariable(Type beanTypeArg,
                                                             Type requiredTypeArg)

classHasFieldWithName

public static boolean classHasFieldWithName(Class<?> clazz,
                                            String fieldName)

classHasMoreThanOneFieldWithName

public static boolean classHasMoreThanOneFieldWithName(Class<?> clazz,
                                                       String fieldName)

getFieldWithName

public static Field getFieldWithName(Class<?> clazz,
                                     String fieldName)

getClassMethodsWithTypes

public static List<Method> getClassMethodsWithTypes(Class<?> clazz,
                                                    String methodName,
                                                    List<Class<?>> parameterTypes)
Parameters:
clazz - webbeans implementation class
methodName - name of the method that is searched
parameterTypes - parameter types of the method(it can be subtype of the actual type arguments of the method)
Returns:
the list of method that satisfies the condition

getClassMethodWithTypes

public static Method getClassMethodWithTypes(Class<?> clazz,
                                             String methodName,
                                             List<Class<?>> parameterTypes)

hasMethodWithName

public static boolean hasMethodWithName(Class<?> clazz,
                                        String methodName)

isPrimitive

public static boolean isPrimitive(Class<?> clazz)

isPrimitiveWrapper

public static boolean isPrimitiveWrapper(Class<?> clazz)

isArray

public static boolean isArray(Class<?> clazz)

isEnum

public static boolean isEnum(Class<?> clazz)

isInValueTypes

public static boolean isInValueTypes(Class<?> clazz)

isValueOkForPrimitiveOrWrapper

public static Object isValueOkForPrimitiveOrWrapper(Class<?> type,
                                                    String value)
Gets the primitive/wrapper value of the parsed String parameter.

Parameters:
type - primitive or wrapper of the primitive type
value - value of the type
Returns:
the parse of the given String value into the corresponding value, if any exception occurs, returns null as the value.

isValueOkForEnum

public static Enum isValueOkForEnum(Class clazz,
                                    String value)

isValueOkForDate

public static Date isValueOkForDate(String value)
                             throws ParseException
Throws:
ParseException

isValueOkForCalendar

public static Calendar isValueOkForCalendar(String value)
                                     throws ParseException
Throws:
ParseException

isValueOkForBigDecimalOrInteger

public static Object isValueOkForBigDecimalOrInteger(Class<?> type,
                                                     String value)

isDefinitionConstainsTypeVariables

public static boolean isDefinitionConstainsTypeVariables(Class<?> clazz)

getTypeVariables

public static TypeVariable<?>[] getTypeVariables(Class<?> clazz)

getActualTypeArguements

public static Type[] getActualTypeArguements(Class<?> clazz)

getActualTypeArguements

public static Type[] getActualTypeArguements(Type type)

getFirstRawType

public static Class<?> getFirstRawType(Type type)

setTypeHierarchy

public static Set<Type> setTypeHierarchy(Set<Type> set,
                                         Type clazz)

getClazz

public static Class<?> getClazz(Type type)
Return raw class type for given type.

Parameters:
type - base type instance
Returns:
class type for given type

setClassTypeHierarchy

public static Set<Type> setClassTypeHierarchy(Set<Type> set,
                                              Class<?> clazz)

setInterfaceTypeHierarchy

public static Set<Type> setInterfaceTypeHierarchy(Set<Type> set,
                                                  Class<?> clazz)

getGenericSuperClassTypeArguments

public static Type[] getGenericSuperClassTypeArguments(Class<?> clazz)

checkParametrizedType

public static boolean checkParametrizedType(ParameterizedType pType)
Return true if it does not contain type variable for wildcard type false otherwise.

Parameters:
pType - parameterized type
Returns:
true if it does not contain type variable for wildcard type

isFirstParametricTypeArgGeneric

public static boolean isFirstParametricTypeArgGeneric(ParameterizedType type)

getGenericSuperInterfacesTypeArguments

public static List<Type[]> getGenericSuperInterfacesTypeArguments(Class<?> clazz)

getFieldWithAnnotation

public static Field getFieldWithAnnotation(Class<?> clazz,
                                           Class<? extends Annotation> annotation)

getFieldsWithType

public static Field[] getFieldsWithType(Class<?> clazz,
                                        Type type)

checkForTypeArguments

public static boolean checkForTypeArguments(Class<?> src,
                                            Type[] typeArguments,
                                            Class<?> target)

setField

public static void setField(Object instance,
                            Field field,
                            Object value)

getRootException

public static Throwable getRootException(Throwable throwable)

getRawTypeForInjectionPoint

public static Class<?> getRawTypeForInjectionPoint(InjectionPoint injectionPoint)
Returns injection point raw type.

Parameters:
injectionPoint - injection point definition
Returns:
injection point raw type

isOverriden

public static boolean isOverriden(Method subClassMethod,
                                  Method superClassMethod)

getDeclaredMethod

public static Method getDeclaredMethod(Class<?> clazz,
                                       String methodName,
                                       Class<?>[] parameters)

getConstructor

public static Constructor<?> getConstructor(Class<?> clazz,
                                            Class<?>[] parameterTypes)


Copyright © 2008-2010 The Apache Software Foundation. All Rights Reserved.