Package com.epam.xml.utils
Class ReflectUtil
java.lang.Object
com.epam.xml.utils.ReflectUtil
Provides ability to work with generic type.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidclearAttributes(Object source, Class<? extends Annotation> attributeMarker) static StringconcateStrings(Object instance, String value) Concatenates the strings.static ObjectcreateGenericInstance(Class clazz) Creates the generic instance if clazz.static Class<?>getClassInPath(String path, String className) static voidinvokeAddListValue(Object instance, Object value, Method method) Invokes add to list methodstatic voidinvokeAddToList(Object instance, Method method, String value, Class<?> type) Invokes the methodstatic voidinvokeSetValue(Object instance, Object value, Method method) Invokes the method.static voidinvokeSetValue(Object instance, String value, Class<?> type, Method method) Invokes the methodstatic booleanReturns true, if array.static booleanReturns true if method for array type.static booleanisPrimitiveField(Class<?> type) Checks if @type is primitivestatic ObjectparseValue(String value, Class classType) Creates a instance of classType with specified value.static StringprepareSting(String propertyName, boolean isUpper, boolean setter) Constructs the method name.
-
Method Details
-
getClassInPath
public static Class<?> getClassInPath(String path, String className) throws IOException, ClassNotFoundException - Throws:
IOExceptionClassNotFoundException
-
prepareSting
Constructs the method name.- Parameters:
propertyName- the name of propertyisUpper- if flag set to true, the first letter in property name replaced to uppper.setter- the setter flag, if sets to true the method name concats withsetprefix, v.vget.
-
parseValue
Creates a instance of classType with specified value.- Parameters:
value- the valueclassType- the class- Throws:
RuntimeException- if classType is undefined
-
createGenericInstance
public static Object createGenericInstance(Class clazz) throws InstantiationException, IllegalAccessException Creates the generic instance if clazz.- Parameters:
clazz- the class- Throws:
InstantiationExceptionIllegalAccessException
-
isPrimitiveField
Checks if @type is primitive- Parameters:
type- the type
-
invokeAddToList
public static void invokeAddToList(Object instance, Method method, String value, Class<?> type) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, InstantiationException Invokes the method- Parameters:
instance- the instancemethod- the methodvalue- the valuetype- the type- Throws:
IllegalAccessExceptionInvocationTargetExceptionNoSuchMethodExceptionInstantiationException
-
invokeAddListValue
Invokes add to list method- Parameters:
instance- the instancevalue- the valuemethod- the method
-
invokeSetValue
Invokes the method.- Parameters:
instance- the instancevalue- the valuemethod- the method
-
invokeSetValue
public static void invokeSetValue(Object instance, String value, Class<?> type, Method method) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException Invokes the method- Parameters:
instance- the instancevalue- the valuetype- the typemethod- the method- Throws:
NoSuchMethodExceptionIllegalAccessExceptionInvocationTargetExceptionInstantiationException
-
isArray
Returns true, if array.- Parameters:
clazz- - Class<?>- Returns:
- true if class is List or ArrayList
-
isArray
Returns true if method for array type.- Parameters:
method- the method- Returns:
- true if class is List or ArrayList
-
concateStrings
Concatenates the strings.- Parameters:
instance- the instancevalue- the value- Returns:
- String
-
clearAttributes
-