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 void
clearAttributes
(Object source, Class<? extends Annotation> attributeMarker) static String
concateStrings
(Object instance, String value) Concatenates the strings.static Object
createGenericInstance
(Class clazz) Creates the generic instance if clazz.static Class<?>
getClassInPath
(String path, String className) static void
invokeAddListValue
(Object instance, Object value, Method method) Invokes add to list methodstatic void
invokeAddToList
(Object instance, Method method, String value, Class<?> type) Invokes the methodstatic void
invokeSetValue
(Object instance, Object value, Method method) Invokes the method.static void
invokeSetValue
(Object instance, String value, Class<?> type, Method method) Invokes the methodstatic boolean
Returns true, if array.static boolean
Returns true if method for array type.static boolean
isPrimitiveField
(Class<?> type) Checks if @type is primitivestatic Object
parseValue
(String value, Class classType) Creates a instance of classType with specified value.static String
prepareSting
(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:
IOException
ClassNotFoundException
-
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 withset
prefix, 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:
InstantiationException
IllegalAccessException
-
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:
IllegalAccessException
InvocationTargetException
NoSuchMethodException
InstantiationException
-
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:
NoSuchMethodException
IllegalAccessException
InvocationTargetException
InstantiationException
-
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
-