Package org.frankframework.util
Class ClassUtils
java.lang.Object
org.frankframework.util.ClassUtils
A collection of class management utility methods.
- Author:
- Johan Verrips
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
returns the className of the object, likenameOf(Object)
, but without [name] suffix for aHasName
.static <T> T
convertToType
(Class<T> type, String value) Converts the String value to the supplied type.getClassInfo
(Class<?> clazz, ClassLoader classLoader) getClassInfoList
(Class<?> clazz) static Constructor
<?> getConstructorOnType
(Class<?> clas, Class<?>[] parameterTypes) Retrieves the constructor of a class, based on the parametersstatic Object
getDeclaredFieldValue
(Object o, Class<?> c, String name) static Object
getDeclaredFieldValue
(Object o, String name) static URL
getResourceURL
(String resource) Attempts to locate the resource, first on the local class-path, if no match, it attempts to find the resource as file-path.static Object
invokeGetter
(Object o, String name, boolean forceAccess) static void
invokeSetter
(Object bean, Method method, String valueToSet) Throws IllegalArgumentException if the argument type is incompatible Throws IllegalStateException if the argument cannot be set on the target beanstatic void
invokeSetter
(Object o, String name, Object value) static void
invokeSetter
(Object o, String name, Object value, Class<?> clazz) static boolean
isClassPresent
(String className) static Class
<?> Load a class given its name.static String
returns the className of the object, without the package name.static <T> T
newInstance
(Class<T> clazz) static <T> T
newInstance
(String className, Class<T> expectedType) Create a new instance given a class name.
-
Method Details
-
getResourceURL
Attempts to locate the resource, first on the local class-path, if no match, it attempts to find the resource as file-path.- Throws:
FileNotFoundException
- in case the resource name is invalid
-
getConstructorOnType
public static Constructor<?> getConstructorOnType(Class<?> clas, Class<?>[] parameterTypes) throws NoSuchMethodException Retrieves the constructor of a class, based on the parameters- Throws:
NoSuchMethodException
-
newInstance
public static <T> T newInstance(String className, Class<T> expectedType) throws ReflectiveOperationException, SecurityException Create a new instance given a class name. The constructor of the class does NOT have parameters.- Parameters:
className
- The class name to loadexpectedType
- The class type to expect- Returns:
- A new instance
- Throws:
ReflectiveOperationException
- If an instantiation error occursSecurityException
- If a security violation occurs
-
newInstance
public static <T> T newInstance(Class<T> clazz) throws ReflectiveOperationException, SecurityException -
loadClass
Load a class given its name. We want to use a known ClassLoader.- Parameters:
className
- A class name- Returns:
- The class pointed to by
className
- Throws:
ClassNotFoundException
- If a loading error occurs
-
nameOf
returns the className of the object, without the package name. -
classNameOf
returns the className of the object, likenameOf(Object)
, but without [name] suffix for aHasName
. -
isClassPresent
-
invokeSetter
Throws IllegalArgumentException if the argument type is incompatible Throws IllegalStateException if the argument cannot be set on the target bean -
convertToType
@Nullable public static <T> T convertToType(Class<T> type, String value) throws IllegalArgumentException Converts the String value to the supplied type.- Parameters:
type
- to convert the input value to- Returns:
- The converted value, of type <T>.
- Throws:
IllegalArgumentException
- (or NumberFormatException) when the value cannot be converted to the given type T.
-
invokeSetter
public static void invokeSetter(Object o, String name, Object value) throws SecurityException, ReflectiveOperationException, IllegalArgumentException -
invokeSetter
public static void invokeSetter(Object o, String name, Object value, Class<?> clazz) throws SecurityException, ReflectiveOperationException, IllegalArgumentException -
invokeGetter
public static Object invokeGetter(Object o, String name, boolean forceAccess) throws SecurityException, ReflectiveOperationException, IllegalArgumentException -
getDeclaredFieldValue
public static Object getDeclaredFieldValue(Object o, Class<?> c, String name) throws IllegalArgumentException, SecurityException, NoSuchFieldException -
getDeclaredFieldValue
public static Object getDeclaredFieldValue(Object o, String name) throws IllegalArgumentException, SecurityException, NoSuchFieldException -
getClassInfoList
-
getClassInfo
-