org.basex.util
Class Reflect

java.lang.Object
  extended by org.basex.util.Reflect

public final class Reflect
extends java.lang.Object

This class assembles some reflection methods. Most exceptions are caught and replaced by a null value.

Author:
BaseX Team 2005-12, BSD License, Christian Gruen

Method Summary
static boolean available(java.lang.String pattern, java.lang.Object... ext)
          Checks if the class specified by the pattern is available.
static java.lang.reflect.Field field(java.lang.Class<?> clazz, java.lang.String name)
          Caches and returns a reference to the specified field, or null.
static java.lang.reflect.Constructor<?> find(java.lang.Class<?> clazz, java.lang.Class<?>... types)
          Caches and returns a constructor by parameter types.
static java.lang.Class<?> find(java.lang.String name)
          Caches and returns a reference to the specified class, or null.
static java.lang.Class<?> find(java.lang.String[] names)
          Returns a class reference to one of the specified classes, or null.
static java.lang.Class<?> find(java.lang.String pattern, java.lang.Object... ext)
          Caches and returns a reference to the class specified by the pattern, or null.
static java.lang.Class<?> forName(java.lang.String name)
          Caches and returns a reference to the specified class, or throws an exception.
static java.lang.Object get(java.lang.Class<?> clazz)
          Returns a class instance, or throws a runtime exception.
static java.lang.Object get(java.lang.reflect.Constructor<?> clazz, java.lang.Object... args)
          Returns a class instance, or null.
static java.lang.Object invoke(java.lang.reflect.Method method, java.lang.Object object, java.lang.Object... args)
          Invokes the specified method.
static java.lang.reflect.Method method(java.lang.Class<?> clazz, java.lang.String name, java.lang.Class<?>... types)
          Finds a public, protected or private method by name and parameter types.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

available

public static boolean available(java.lang.String pattern,
                                java.lang.Object... ext)
Checks if the class specified by the pattern is available.

Parameters:
pattern - class pattern
ext - optional extension
Returns:
result of check

find

public static java.lang.Class<?> find(java.lang.String name)
Caches and returns a reference to the specified class, or null.

Parameters:
name - fully qualified class name
Returns:
reference, or null if the class is not found

forName

public static java.lang.Class<?> forName(java.lang.String name)
                                  throws java.lang.Throwable
Caches and returns a reference to the specified class, or throws an exception.

Parameters:
name - fully qualified class name
Returns:
class reference
Throws:
java.lang.Throwable - any exception or error

field

public static java.lang.reflect.Field field(java.lang.Class<?> clazz,
                                            java.lang.String name)
Caches and returns a reference to the specified field, or null.

Parameters:
clazz - class to search for the constructor
name - field name
Returns:
reference, or null if the field is not found

find

public static java.lang.Class<?> find(java.lang.String pattern,
                                      java.lang.Object... ext)
Caches and returns a reference to the class specified by the pattern, or null.

Parameters:
pattern - class pattern
ext - optional extension
Returns:
reference, or null if the class is not found

find

public static java.lang.Class<?> find(java.lang.String[] names)
Returns a class reference to one of the specified classes, or null.

Parameters:
names - fully qualified class names
Returns:
reference, or null if the class is not found

find

public static java.lang.reflect.Constructor<?> find(java.lang.Class<?> clazz,
                                                    java.lang.Class<?>... types)
Caches and returns a constructor by parameter types.

Parameters:
clazz - class to search for the constructor
types - constructor parameters
Returns:
null if the constructor is not found

method

public static java.lang.reflect.Method method(java.lang.Class<?> clazz,
                                              java.lang.String name,
                                              java.lang.Class<?>... types)
Finds a public, protected or private method by name and parameter types.

Parameters:
clazz - class to search for the method
name - method name
types - method parameters
Returns:
reference, or null if the method is not found

get

public static java.lang.Object get(java.lang.Class<?> clazz)
Returns a class instance, or throws a runtime exception.

Parameters:
clazz - class
Returns:
instance

get

public static java.lang.Object get(java.lang.reflect.Constructor<?> clazz,
                                   java.lang.Object... args)
Returns a class instance, or null.

Parameters:
clazz - class
args - arguments
Returns:
instance

invoke

public static java.lang.Object invoke(java.lang.reflect.Method method,
                                      java.lang.Object object,
                                      java.lang.Object... args)
Invokes the specified method.

Parameters:
method - method to run
object - object (null for static methods)
args - arguments
Returns:
result of method call