org.apache.webbeans.util
Class ClassUtil

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

public final class ClassUtil
extends java.lang.Object

Utility classes with respect to the class operations.

Since:
1.0
Author:
Gurkan Erdogdu

Field Summary
static java.util.Map<java.lang.Class<?>,java.lang.Class<?>> PRIMITIVE_TO_WRAPPERS_MAP
           
 
Method Summary
static java.lang.Object callInstanceMethod(java.lang.reflect.Method method, java.lang.Object instance, java.lang.Object[] args)
          Call method on the instance with given arguments.
static boolean checkBeanAndRequiredTypeisParametrized(java.lang.reflect.Type beanTypeArg, java.lang.reflect.Type requiredTypeArg)
          Check parametrized bean type and parametrized required types.
static boolean checkBeanTypeAndRequiredIsTypeVariable(java.lang.reflect.Type beanTypeArg, java.lang.reflect.Type requiredTypeArg)
           
static boolean checkEventTypeAssignability(java.lang.reflect.Type eventType, java.lang.reflect.Type observerType)
          Checks that event is applicable for the given observer type.
static boolean checkParametrizedType(java.lang.reflect.ParameterizedType pType)
          Return true if it does not contain type variable for wildcard type false otherwise.
static boolean checkRequiredTypeIsClassAndBeanTypeIsVariable(java.lang.reflect.Type beanTypeArg, java.lang.reflect.Type requiredTypeArg)
          Checking bean type and required type.
static boolean checkRequiredTypeIsTypeVariableAndBeanTypeIsClass(java.lang.reflect.Type beanTypeArg, java.lang.reflect.Type requiredTypeArg)
           
static boolean checkRequiredTypeisWildCard(java.lang.reflect.Type beanTypeArg, java.lang.reflect.Type requiredTypeArg)
          Check bean type and required type.
static java.lang.reflect.Type[] getActualTypeArguements(java.lang.reflect.Type type)
           
static java.lang.Class<?> getClass(java.lang.reflect.Type type)
          Gets the class of the given type arguments.
static java.lang.Class<?> getClassFromName(java.lang.String name)
           
static java.util.List<java.lang.reflect.Method> getClassMethodsWithTypes(java.lang.Class<?> clazz, java.lang.String methodName, java.util.List<java.lang.Class<?>> parameterTypes)
           
static java.lang.reflect.Method getClassMethodWithTypes(java.lang.Class<?> clazz, java.lang.String methodName, java.util.List<java.lang.Class<?>> parameterTypes)
           
static java.lang.Class<?> getClazz(java.lang.reflect.Type type)
          Return raw class type for given type.
static java.lang.reflect.Method[] getDeclaredMethods(java.lang.Class<?> clazz)
          Gets the declared methods of the given class.
static java.lang.reflect.Field[] getFieldsWithType(WebBeansContext webBeansContext, java.lang.Class<?> clazz, java.lang.reflect.Type type)
           
static java.lang.Class<?>[] getMethodParameterTypes(java.lang.reflect.Method method)
           
 java.lang.Package getPackage(java.lang.String packageName)
          Gets java package if exist.
static java.lang.Class<?> getPrimitiveWrapper(java.lang.Class<?> clazz)
           
static java.lang.Class<?> getRawTypeForInjectionPoint(javax.enterprise.inject.spi.InjectionPoint injectionPoint)
          Returns injection point raw type.
static java.lang.Class<?> getReturnType(java.lang.reflect.Method method)
          Gets the return type of the method.
static java.util.List<java.lang.Class<?>> getSuperClasses(java.lang.Class<?> clazz, java.util.List<java.lang.Class<?>> list)
           
static boolean hasFinalMethod(java.lang.Class<?> clazz)
          Check for class that has a final method or not.
static boolean isAbstract(java.lang.Integer modifier)
          Check abstract modifier.
static boolean isArray(java.lang.Class<?> clazz)
           
static boolean isAssignable(java.lang.reflect.Type beanType, java.lang.reflect.Type requiredType)
          See specification 5.2.3.
static boolean isAssignableForParametrized(java.lang.reflect.ParameterizedType beanType, java.lang.reflect.ParameterizedType requiredType)
          Returns true if given bean's api type is injectable to injection point required type.
static boolean isClassAssignable(java.lang.Class<?> lhs, java.lang.Class<?> rhs)
          Returns true if rhs is assignable type to the lhs, false otherwise.
static boolean isConcrete(java.lang.Class<?> clazz)
          Returna true if the class is not abstract and interface.
static boolean isDefinitionConstainsTypeVariables(java.lang.Class<?> clazz)
           
static boolean isFinal(java.lang.Integer modifier)
          Check final modifier.
static boolean isInnerClazz(java.lang.Class<?> clazz)
          Check the class is inner or not
static boolean isInterface(java.lang.Integer modifier)
          Check interface modifier.
static boolean isMethodHasCheckedException(java.lang.reflect.Method method)
          Check method throws checked exception or not.
static boolean isMethodHasException(java.lang.reflect.Method method)
          Check method throws Exception or not.
static boolean isMethodHasParameter(java.lang.reflect.Method method)
          Check that method has any formal arguments.
static boolean isMoreThanOneMethodWithName(java.lang.String methodName, java.lang.Class<?> clazz)
           
static boolean isObjectMethod(java.lang.String methodName)
           
static boolean isOverriden(java.lang.reflect.Method subClassMethod, java.lang.reflect.Method superClassMethod)
           
static boolean isParametrizedType(java.lang.reflect.Type type)
          Returns true if type is an instance of ParameterizedType else otherwise.
static boolean isTypeVariable(java.lang.reflect.Type type)
          Returns true if type is an instance of TypeVariable else otherwise.
static boolean isUnboundedTypeVariable(java.lang.reflect.Type type)
           
static boolean isWildCardType(java.lang.reflect.Type type)
          Returns true if type is an instance of WildcardType else otherwise.
static java.lang.Object newInstance(WebBeansContext webBeansContext, java.lang.Class<?> clazz)
           
static java.util.Set<java.lang.reflect.Type> setInterfaceTypeHierarchy(java.util.Set<java.lang.reflect.Type> set, java.lang.Class<?> clazz)
           
static java.util.Set<java.lang.reflect.Type> setTypeHierarchy(java.util.Set<java.lang.reflect.Type> set, java.lang.reflect.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 java.util.Map<java.lang.Class<?>,java.lang.Class<?>> PRIMITIVE_TO_WRAPPERS_MAP
Method Detail

newInstance

public static java.lang.Object newInstance(WebBeansContext webBeansContext,
                                           java.lang.Class<?> clazz)

getClassFromName

public static java.lang.Class<?> getClassFromName(java.lang.String name)

isFinal

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

Parameters:
modifier - modifier
Returns:
true or false

isAbstract

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

Parameters:
modifier - modifier
Returns:
true or false

isInterface

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

Parameters:
modifier - modifier
Returns:
true or false

hasFinalMethod

public static boolean hasFinalMethod(java.lang.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(java.lang.Class<?> clazz)
Check the class is inner or not

Parameters:
clazz - to check
Returns:
true or false

getPrimitiveWrapper

public static java.lang.Class<?> getPrimitiveWrapper(java.lang.Class<?> clazz)

getClass

public static java.lang.Class<?> getClass(java.lang.reflect.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 java.lang.reflect.Method[] getDeclaredMethods(java.lang.Class<?> clazz)
Gets the declared methods of the given class.

Parameters:
clazz - class instance
Returns:
the declared methods

isMethodHasParameter

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

Parameters:
method - method instance
Returns:
true or false

getReturnType

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

Parameters:
method - method instance
Returns:
return type

isMethodHasCheckedException

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

Parameters:
method - method instance
Returns:
trur or false

isMethodHasException

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

Parameters:
method - method instance
Returns:
trur or false

callInstanceMethod

public static java.lang.Object callInstanceMethod(java.lang.reflect.Method method,
                                                  java.lang.Object instance,
                                                  java.lang.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 java.util.List<java.lang.Class<?>> getSuperClasses(java.lang.Class<?> clazz,
                                                                 java.util.List<java.lang.Class<?>> list)

getMethodParameterTypes

public static java.lang.Class<?>[] getMethodParameterTypes(java.lang.reflect.Method method)

isObjectMethod

public static boolean isObjectMethod(java.lang.String methodName)

isMoreThanOneMethodWithName

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

getPackage

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

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

isParametrizedType

public static boolean isParametrizedType(java.lang.reflect.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(java.lang.reflect.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(java.lang.reflect.Type type)

isTypeVariable

public static boolean isTypeVariable(java.lang.reflect.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(java.lang.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(java.lang.reflect.Type beanType,
                                   java.lang.reflect.Type requiredType)
See specification 5.2.3.

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

checkEventTypeAssignability

public static boolean checkEventTypeAssignability(java.lang.reflect.Type eventType,
                                                  java.lang.reflect.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(java.lang.Class<?> lhs,
                                        java.lang.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(java.lang.reflect.ParameterizedType beanType,
                                                  java.lang.reflect.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(java.lang.reflect.Type beanTypeArg,
                                                             java.lang.reflect.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(java.lang.reflect.Type beanTypeArg,
                                                  java.lang.reflect.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(java.lang.reflect.Type beanTypeArg,
                                                                    java.lang.reflect.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(java.lang.reflect.Type beanTypeArg,
                                                                        java.lang.reflect.Type requiredTypeArg)

checkBeanTypeAndRequiredIsTypeVariable

public static boolean checkBeanTypeAndRequiredIsTypeVariable(java.lang.reflect.Type beanTypeArg,
                                                             java.lang.reflect.Type requiredTypeArg)

getClassMethodsWithTypes

public static java.util.List<java.lang.reflect.Method> getClassMethodsWithTypes(java.lang.Class<?> clazz,
                                                                                java.lang.String methodName,
                                                                                java.util.List<java.lang.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 java.lang.reflect.Method getClassMethodWithTypes(java.lang.Class<?> clazz,
                                                               java.lang.String methodName,
                                                               java.util.List<java.lang.Class<?>> parameterTypes)

isArray

public static boolean isArray(java.lang.Class<?> clazz)

isDefinitionConstainsTypeVariables

public static boolean isDefinitionConstainsTypeVariables(java.lang.Class<?> clazz)

getActualTypeArguements

public static java.lang.reflect.Type[] getActualTypeArguements(java.lang.reflect.Type type)

setTypeHierarchy

public static java.util.Set<java.lang.reflect.Type> setTypeHierarchy(java.util.Set<java.lang.reflect.Type> set,
                                                                     java.lang.reflect.Type clazz)

getClazz

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

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

setInterfaceTypeHierarchy

public static java.util.Set<java.lang.reflect.Type> setInterfaceTypeHierarchy(java.util.Set<java.lang.reflect.Type> set,
                                                                              java.lang.Class<?> clazz)

checkParametrizedType

public static boolean checkParametrizedType(java.lang.reflect.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 java.lang.reflect.Field[] getFieldsWithType(WebBeansContext webBeansContext,
                                                          java.lang.Class<?> clazz,
                                                          java.lang.reflect.Type type)

getRawTypeForInjectionPoint

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

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

isOverriden

public static boolean isOverriden(java.lang.reflect.Method subClassMethod,
                                  java.lang.reflect.Method superClassMethod)


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