@Typed public final class Reflection extends Object
Modifier and Type | Method and Description |
---|---|
static Method |
findMethod(Object base,
String methodName,
Object[] params)
Finds a method based on the method name, amount of parameters and limited typing, if necessary prefixed with "get".
|
static <T> T |
instance(Class<T> clazz)
Creates a new instance of the class represented by the given Class object
|
static <T> T |
instance(String className)
Creates an instance of a class with the given fully qualified class name.
|
static void |
setProperties(Object object,
Map<String,Object> propertiesToSet)
Sets a collection of properties of a given object to the values associated with those properties.
|
static Class<?> |
toClass(String className)
Returns the Class instance associated with the class of the given string, using the context class
loader and if that fails the defining class loader of the current class.
|
public static void setProperties(Object object, Map<String,Object> propertiesToSet)
In the map that represents these properties, each key represents the name of the property, with the value associated with that key being the value that is set for the property.
E.g. map entry key = foo, value = "bar", which "bar" an instance of String, will conceptually result in the
following call: object.setFoo("string");
NOTE: This particular method assumes that there's a write method for each property in the map with the right type. No specific checking is done whether this is indeed the case.
object
- the object on which properties will be setpropertiesToSet
- the map containing properties and their values to be set on the objectpublic static Method findMethod(Object base, String methodName, Object[] params)
Note that this supports overloading, but a limited one. Given an actual parameter of type Long, this will select a method accepting Number when the choice is between Number and a non-compatible type like String. However, it will NOT select the best match if the choice is between Number and Long.
base
- the object in which the method is to be foundmethodName
- name of the method to be foundparams
- the method parameterspublic static Class<?> toClass(String className)
className
- fully qualified class name of the class for which a Class instance needs to be createdpublic static <T> T instance(String className)
T
- The generic object type.className
- fully qualified class name of the class for which an instance needs to be createdIllegalStateException
- if the class cannot be foundpublic static <T> T instance(Class<T> clazz)
T
- The generic object type.clazz
- the Class object for which an instance needs to be createdIllegalStateException
- if the class cannot be found, or cannot be instantiated or when a security manager prevents this operationCopyright © 2012–2014 OmniFaces. All rights reserved.