public class BeanUtils extends Object
Constructor and Description |
---|
BeanUtils() |
Modifier and Type | Method and Description |
---|---|
static Field[] |
filter(Field[] fields,
boolean includeStatic,
boolean inclSubClasForComparison,
Class... typesToInclude)
|
static Set<Class> |
getClassesInPackage(Class parentClass,
String packagePath,
Consumer<? super org.springframework.beans.factory.config.BeanDefinition> consumer) |
static Field |
getDeclaredField(Class c,
String name)
Get a field for the Class or return null
|
static Field[] |
getDeclaredFields(Class c)
Get
Class.getDeclaredFields() for the class and its parents
Will contain all static and non-static fields of all visibility. |
static <T> T |
getPreferredBean(Class<T> type,
String preferredName,
org.springframework.context.ApplicationContext context,
Exception incaseCantFindException)
A utility method to select the Bean from the context right for the job
Use then when there are situations of multi module configurations which may supply the context with multiple or no beans of the given type. |
static <T> T |
getPreferredBean(Class<T> type,
String preferredName,
org.springframework.context.ApplicationContext context,
String incaseCantFindException)
A utility method to select the Bean from the context right for the job
Use then when there are situations of multi module configurations which may supply the context with multiple or no beans of the given type. |
static <E extends Throwable> |
getRootCause(E source,
Integer maxDepth)
Get innermost cause upto maxDepth level.
|
static boolean |
isStatic(Field f)
Check if a
Field is static or not |
static boolean |
isValidOrPrimitiveFieldType(Class<?> type)
If primitive, String, Date or Calendar type, will return true
|
static boolean |
unwrapAndSearchExceptions(Throwable source,
Class<? extends Exception>... exceptions)
Unwrap and trap Exceptions of the desired type.
|
public static <T> T getPreferredBean(Class<T> type, String preferredName, org.springframework.context.ApplicationContext context, Exception incaseCantFindException)
T
- Type of being searched fortype
- as ClasspreferredName
- as String (name of bean that will be preferred if there are multiple beans)context
- as ApplicationContext
incaseCantFindException
- as Exceptionpublic static <T> T getPreferredBean(Class<T> type, String preferredName, org.springframework.context.ApplicationContext context, String incaseCantFindException)
T
- Type of being searched fortype
- as ClasspreferredName
- as String (name of bean that will be preferred if there are multiple beans)context
- as ApplicationContext
incaseCantFindException
- as Stringpublic static boolean unwrapAndSearchExceptions(Throwable source, Class<? extends Exception>... exceptions)
Class
match is exact by default. So it ensures to match the Exception type to the specifc type only;
parent child relations are not respected.source
- as Throwable
exceptions
- as Classpublic static <E extends Throwable> E getRootCause(E source, Integer maxDepth)
public static Field[] getDeclaredFields(Class c)
Class.getDeclaredFields()
for the class and its parents
c
- Field
[]public static Field getDeclaredField(Class c, String name)
c
- name
- Field
public static boolean isStatic(Field f)
Field
is static or notf
- as Field
public static boolean isValidOrPrimitiveFieldType(Class<?> type)
type
- public static Field[] filter(Field[] fields, boolean includeStatic, boolean inclSubClasForComparison, Class... typesToInclude)
Field
s and if a specific list of Types is provided then restrict the output to that type/Class of Field
only.
fields
- as Field[] to be filteredincludeStatic
- include static declarationsinclSubClasForComparison
- , if true will compare the field not just for an exact match in the typesToInclude but also any of their derived children in the hierarchy
TODO: Add Unit Test for thisCopyright © 2018. All rights reserved.