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 Map<Class<?>,Class<?>> PRIMITIVE_TO_WRAPPERS_MAP
           
 
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)
          Deprecated. use checkBeanAndRequiredTypeIsParametrized(Type, Type)
static boolean checkBeanAndRequiredTypeIsParametrized(Type beanTypeArg, Type requiredTypeArg)
          Check parametrized bean type and parametrized required types.
static boolean checkBeanTypeAndRequiredIsTypeVariable(Type beanTypeArg, Type requiredTypeArg)
           
static boolean checkEventTypeAssignability(Type eventType, Type observerType)
          Checks that event is applicable for the given observer type.
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)
          Deprecated. use checkRequiredTypeIsWildCard(Type, Type)
static boolean checkRequiredTypeIsWildCard(Type beanTypeArg, Type requiredTypeArg)
          Check bean type and required type.
static Type[] getActualTypeArguements(Type type)
          Deprecated. use getActualTypeArguments(Type)
static Type[] getActualTypeArguments(Type type)
          Returns declared type arguments if type is a ParameterizedType instance, else an empty array.
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 Method[] getDeclaredMethods(Class<?> clazz)
          Gets the declared methods of the given class.
static Field[] getFieldsWithType(WebBeansContext webBeansContext, Class<?> clazz, Type type)
           
static Class<?>[] getMethodParameterTypes(Method method)
           
 Package getPackage(String packageName)
          Gets java package if exist.
static Class<?> getPrimitiveWrapper(Class<?> clazz)
           
static Class<?> getRawTypeForInjectionPoint(javax.enterprise.inject.spi.InjectionPoint injectionPoint)
          Returns injection point raw type.
static Class<?> getReturnType(Method method)
          Gets the return type of the method.
static List<Class<?>> getSuperClasses(Class<?> clazz, List<Class<?>> list)
           
static boolean hasFinalMethod(Class<?> clazz)
          Check for class that has a final method or not.
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 boolean isDefinitionConstainsTypeVariables(Class<?> clazz)
          Deprecated. use isDefinitionContainsTypeVariables(Class)
static boolean isDefinitionContainsTypeVariables(Class<?> clazz)
          Learn whether the specified class is defined with type parameters.
static boolean isFinal(Integer modifier)
          Check final modifier.
static boolean isInnerClazz(Class<?> clazz)
          Check the class is inner or not
static boolean isInterface(Integer modifier)
          Check interface modifier.
static boolean isMethodHasCheckedException(Method method)
          Check method throws checked 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 isOverridden(Method subClassMethod, Method superClassMethod)
          Learn whether superClassMethod is overridden by subClassMethod.
static boolean isOverriden(Method subClassMethod, Method superClassMethod)
          Deprecated. use isOverridden(Method, Method)
static boolean isParametrizedType(Type type)
          Returns true if type is an instance of ParameterizedType else otherwise.
static boolean isTypeVariable(Type type)
          Returns true if type is an instance of TypeVariable else otherwise.
static boolean isUnboundedTypeVariable(Type type)
           
static boolean isWildCardType(Type type)
          Returns true if type is an instance of WildcardType else otherwise.
static Object newInstance(WebBeansContext webBeansContext, Class<?> clazz)
           
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_TO_WRAPPERS_MAP

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

newInstance

public static Object newInstance(WebBeansContext webBeansContext,
                                 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:
clazz - to check
Returns:
true or false

getPrimitiveWrapper

public static Class<?> getPrimitiveWrapper(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

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)

isObjectMethod

public static boolean isObjectMethod(String methodName)

isMoreThanOneMethodWithName

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

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

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

@Deprecated
public static boolean checkBeanAndRequiredTypeisParametrized(Type beanTypeArg,
                                                                        Type requiredTypeArg)
Deprecated. use checkBeanAndRequiredTypeIsParametrized(Type, Type)

Check parametrized bean type and parametrized required types.

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

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
Since:
1.1.1

checkRequiredTypeisWildCard

@Deprecated
public static boolean checkRequiredTypeisWildCard(Type beanTypeArg,
                                                             Type requiredTypeArg)
Deprecated. use checkRequiredTypeIsWildCard(Type, Type)

Check bean type and required type.

Required type is a wildcard type.

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

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 condition satisfies
Since:
1.1.1

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)

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)

isArray

public static boolean isArray(Class<?> clazz)

isDefinitionConstainsTypeVariables

@Deprecated
public static boolean isDefinitionConstainsTypeVariables(Class<?> clazz)
Deprecated. use isDefinitionContainsTypeVariables(Class)

Learn whether the specified class is defined with type parameters.

Parameters:
clazz - to check
Returns:
true if there are type parameters

isDefinitionContainsTypeVariables

public static boolean isDefinitionContainsTypeVariables(Class<?> clazz)
Learn whether the specified class is defined with type parameters.

Parameters:
clazz - to check
Returns:
true if there are type parameters
Since:
1.1.1

getActualTypeArguements

@Deprecated
public static Type[] getActualTypeArguements(Type type)
Deprecated. use getActualTypeArguments(Type)

Returns declared type arguments if type is a ParameterizedType instance, else an empty array. Get the actual type arguments of a type.

Parameters:
type -
Returns:
array of type arguments available

getActualTypeArguments

public static Type[] getActualTypeArguments(Type type)
Returns declared type arguments if type is a ParameterizedType instance, else an empty array. Get the actual type arguments of a type.

Parameters:
type -
Returns:
array of type arguments available
Since:
1.1.1

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

setInterfaceTypeHierarchy

public static Set<Type> setInterfaceTypeHierarchy(Set<Type> set,
                                                  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

getFieldsWithType

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

getRawTypeForInjectionPoint

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

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

isOverriden

@Deprecated
public static boolean isOverriden(Method subClassMethod,
                                             Method superClassMethod)
Deprecated. use isOverridden(Method, Method)

Learn whether superClassMethod is overridden by subClassMethod.

Parameters:
subClassMethod - potentially overriding
superClassMethod - potentially overridden
Returns:
true if overridden

isOverridden

public static boolean isOverridden(Method subClassMethod,
                                   Method superClassMethod)
Learn whether superClassMethod is overridden by subClassMethod.

Parameters:
subClassMethod - potentially overriding
superClassMethod - potentially overridden
Returns:
true if overridden
Since:
1.1.1


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