Package org.basex.util
Class Reflect
- java.lang.Object
-
- org.basex.util.Reflect
-
public final class Reflect extends Object
This class assembles some reflection methods. Most exceptions are caught and replaced by anull
value.- Author:
- BaseX Team 2005-24, BSD License, Christian Gruen
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
available(String pattern, Object... ext)
Checks if the class specified by the pattern is available.static Field
field(Class<?> clazz, String name)
Caches and returns a reference to the specified field ornull
.static <O> Constructor<O>
find(Class<O> clazz, Class<?>... types)
Caches and returns a constructor by parameter types.static Class<?>
find(String name)
Caches and returns a reference to the specified class.static Class<?>
find(String pattern, Object... ext)
Caches and returns a reference to the class specified by the pattern, ornull
.static Class<?>
forName(String name)
Caches and returns a reference to the specified class, or throws an exception.static <O> O
get(Class<O> clazz)
Returns a class instance.static <O> O
get(Constructor<O> constructor, Object... args)
Returns a class instance ornull
.static Object
get(Field field, Object object)
Returns the value of a field.static Object
invoke(Method method, Object object, Object... args)
Invokes the specified method.static Method
method(Class<?> clazz, String name, Class<?>... types)
Finds a public, protected or private method by name and parameter types.
-
-
-
Method Detail
-
available
public static boolean available(String pattern, Object... ext)
Checks if the class specified by the pattern is available.- Parameters:
pattern
- class patternext
- optional extension- Returns:
- result of check
-
find
public static Class<?> find(String name)
Caches and returns a reference to the specified class.- Parameters:
name
- fully qualified class name- Returns:
- reference, or
null
if the class is not found
-
forName
public static Class<?> forName(String name) throws ClassNotFoundException
Caches and returns a reference to the specified class, or throws an exception.- Parameters:
name
- fully qualified class name- Returns:
- class reference
- Throws:
ClassNotFoundException
- any exception or error
-
field
public static Field field(Class<?> clazz, String name)
Caches and returns a reference to the specified field ornull
.- Parameters:
clazz
- class to search for the constructorname
- field name- Returns:
- reference or
null
if the field is not found
-
find
public static Class<?> find(String pattern, Object... ext)
Caches and returns a reference to the class specified by the pattern, ornull
.- Parameters:
pattern
- class patternext
- optional extension- Returns:
- reference or
null
if the class is not found
-
find
public static <O> Constructor<O> find(Class<O> clazz, Class<?>... types)
Caches and returns a constructor by parameter types.- Type Parameters:
O
- class type- Parameters:
clazz
- class to search for the constructortypes
- constructor parameters- Returns:
- constructor, or
null
if the constructor is not found
-
method
public static Method method(Class<?> clazz, String name, Class<?>... types)
Finds a public, protected or private method by name and parameter types.- Parameters:
clazz
- class to search for the methodname
- method nametypes
- method parameters- Returns:
- method, or
null
if the method is not found
-
get
public static <O> O get(Class<O> clazz)
Returns a class instance.- Type Parameters:
O
- type- Parameters:
clazz
- class- Returns:
- instance or
null
-
get
public static <O> O get(Constructor<O> constructor, Object... args)
Returns a class instance ornull
.- Type Parameters:
O
- class type- Parameters:
constructor
- constructorargs
- arguments- Returns:
- instance or
null
-
invoke
public static Object invoke(Method method, Object object, Object... args)
Invokes the specified method.- Parameters:
method
- method to runobject
- object (null
for static methods)args
- arguments- Returns:
- result of method call or
null
-
-