|
Humboldt Alignment Editor 2.5.0 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objecteu.esdihumboldt.util.reflection.ReflectionHelper
public class ReflectionHelper
Provides several utility methods which use Java Reflections to access hidden types, fields and methods.
Constructor Summary | |
---|---|
ReflectionHelper()
|
Method Summary | ||
---|---|---|
static Field |
findDeepField(Class<?> c,
String property,
Class<?> propertyType)
Returns a field for a given property, no matter if the field is visible or hidden or if it is declared in the given class or in a superclass. |
|
static Method |
findDeepGetter(Class<?> c,
String property,
Class<?> propertyType)
Returns a getter method for a given property, no matter if the method is visible or hidden or if it is declared in the given class or in a superclass or implemented interface. |
|
static Method |
findDeepSetter(Class<?> c,
String property,
Class<?> propertyType)
Returns a setter method for a given property, no matter if the method is visible or hidden or if it is declared in the given class or in a superclass or implemented interface. |
|
static Field |
findField(Class<?> c,
String property,
Class<?> propertyType)
Returns a public field for a given property |
|
static Method |
findGetter(Class<?> c,
String property,
Class<?> propertyType)
Returns a public getter method for a given property |
|
static Class<?> |
findMostSpecificMatch(Class<?> clazz,
Collection<Class<?>> group,
boolean checkAssignability)
Find the most specialised class from group compatible with clazz. |
|
static Method |
findSetter(Class<?> c,
String property,
Class<?> propertyType)
Returns a public setter method for a given property |
|
static List<Class<?>> |
getClassesFromPackage(String pkg,
ClassLoader classLoader)
Gets a list of all classes in the given package and all subpackages recursively. |
|
static List<Class<?>> |
getClassesFromPackage(String pkg,
ClassLoader classLoader,
boolean recursive)
Gets a list of all classes in the given package |
|
static URL |
getCurrentJarURL()
|
|
static
|
getDeepProperty(Object bean,
String propertyName)
Invokes a getter for a property, no matter if the getter is visible or hidden or if it is declared in the given class or in a superclass or implemented interface. |
|
static
|
getDeepPropertyOrField(Object bean,
String propertyName,
Class<T> valueClass)
Invokes a getter for a property, or gets the matching field, no matter what. |
|
static File[] |
getFilesFromPackage(String pkg)
Returns an array of all files contained by a given package |
|
static
|
getProperty(Object bean,
String propertyName)
Invokes a public getter for a property |
|
static List<String> |
getSubPackagesFromPackage(String pkg)
Gets a list of all subpackages in the given package |
|
static List<String> |
getSubPackagesFromPackage(String pkg,
boolean recursive)
Gets a list of all subpackages in the given package |
|
static void |
setDeepProperty(Object bean,
String propertyName,
Object value)
Invokes a setter for a property, no matter if the setter is visible or hidden or if it is declared in the given class or in a superclass or implemented interface. |
|
static void |
setPackageResolver(PackageResolver res)
Sets the package resolver used to retrieve URLs to packages |
|
static void |
setProperty(Object bean,
String propertyName,
Object value)
Invokes a public setter for a property |
|
static
|
shallowEnforceDeepProperties(T src,
T dst)
Performs a shallow copy of all fields defined by the class of src and all superclasses. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ReflectionHelper()
Method Detail |
---|
public static void setPackageResolver(PackageResolver res)
res
- the package resolvergetFilesFromPackage(String)
public static Method findSetter(Class<?> c, String property, Class<?> propertyType)
c
- the class which would contain the setter methodproperty
- the propertypropertyType
- the property's type
public static Method findDeepSetter(Class<?> c, String property, Class<?> propertyType)
c
- the class which would contain the setter methodproperty
- the propertypropertyType
- the property's type
public static Method findGetter(Class<?> c, String property, Class<?> propertyType)
c
- the class which would contain the getter methodproperty
- the propertypropertyType
- the property's type
public static Method findDeepGetter(Class<?> c, String property, Class<?> propertyType)
c
- the class which would contain the getter methodproperty
- the propertypropertyType
- the property's type (can be null if the type does not
matter)
public static Field findField(Class<?> c, String property, Class<?> propertyType)
c
- the class which would contain the fieldproperty
- the propertypropertyType
- the property's type
public static Field findDeepField(Class<?> c, String property, Class<?> propertyType)
c
- the class which would contain the fieldproperty
- the propertypropertyType
- the property's type
public static void setProperty(Object bean, String propertyName, Object value) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, NoSuchMethodException
bean
- the object to invoke the public setter onpropertyName
- the name of the property that shall be updatedvalue
- the value passed to the setter
IllegalArgumentException
- if the argument's type is invalid
IllegalAccessException
- if the setter is not accessible
InvocationTargetException
- if the setter throws an exception
NoSuchMethodException
- if there is no setter for this propertypublic static void setDeepProperty(Object bean, String propertyName, Object value) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, NoSuchMethodException
bean
- the object to invoke the public setter onpropertyName
- the name of the property that shall be updatedvalue
- the value passed to the setter
IllegalArgumentException
- if the argument's type is invalid
IllegalAccessException
- if the setter is not accessible
InvocationTargetException
- if the setter throws an exception
NoSuchMethodException
- if there is no setter for this propertypublic static <T> T getProperty(Object bean, String propertyName) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, NoSuchMethodException
T
- the result typebean
- the object to invoke the public getter onpropertyName
- the name of the property to retrieve
IllegalArgumentException
- if the argument's type is invalid
IllegalAccessException
- if the getter is not accessible
InvocationTargetException
- if the getter throws an exception
NoSuchMethodException
- if there is no getter for this propertypublic static <T> T getDeepProperty(Object bean, String propertyName) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, NoSuchMethodException
T
- the result typebean
- the object to invoke the getter onpropertyName
- the name of the property to retrieve
IllegalArgumentException
- if the argument's type is invalid
IllegalAccessException
- if the setter is not accessible
InvocationTargetException
- if the setter throws an exception
NoSuchMethodException
- if there is no setter for this propertypublic static <T> T getDeepPropertyOrField(Object bean, String propertyName, Class<T> valueClass) throws IllegalArgumentException, InvocationTargetException
bean
- the object to invoke the getter onpropertyName
- the name of the property to retrievevalueClass
- the class of the property or field
IllegalArgumentException
- if the argument's type is invalid
InvocationTargetException
- if the getter throws an exception
IllegalStateException
- is the field could be found or accessedpublic static URL getCurrentJarURL() throws MalformedURLException
MalformedURLException
- if the URL to the jar file could not be
createdpublic static File[] getFilesFromPackage(String pkg) throws IOException
pkg
- the package (e.g. "de.igd.fhg.CityServer3D")
IOException
- if the package could not be foundpublic static List<Class<?>> getClassesFromPackage(String pkg, ClassLoader classLoader) throws IOException
pkg
- the packageclassLoader
- the class loader to use
IOException
- if a subpackage or a class could not be loadedpublic static List<Class<?>> getClassesFromPackage(String pkg, ClassLoader classLoader, boolean recursive) throws IOException
pkg
- the packageclassLoader
- the class loader to userecursive
- true if all subpackages shall be traversed too
IOException
- if a subpackage or a class could not be loadedpublic static List<String> getSubPackagesFromPackage(String pkg) throws IOException
pkg
- the package
IOException
- if a subpackage or a class could not be loadedpublic static List<String> getSubPackagesFromPackage(String pkg, boolean recursive) throws IOException
pkg
- the packagerecursive
- true if all subpackages shall be traversed too
IOException
- if a subpackage or a class could not be loadedpublic static Class<?> findMostSpecificMatch(Class<?> clazz, Collection<Class<?>> group, boolean checkAssignability)
Find the most specialised class from group compatible with clazz. A direct superclass match is searched and returned if found.
If not and checkAssignability is true, the most derived assignable class is being searched.
See The Java Language Specification, sections 5.1.1 and 5.1.4 , for details.
clazz
- a classgroup
- a collection of classes to match againstcheckAssignability
- whether to use assignability when no direct
match is found
public static <T> void shallowEnforceDeepProperties(T src, T dst) throws IllegalArgumentException, IllegalAccessException
T
- the type of the source and destination objectsrc
- the source objectdst
- the destination object
IllegalArgumentException
- if a field is unaccessible
IllegalAccessException
- if a field is not accessible
|
Humboldt Alignment Editor 2.5.0 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |