T - type type of object returned by this instance builderpublic class InstanceBuilder<T> extends Object
| Modifier and Type | Method and Description |
|---|---|
T |
build()
Creates the instance by calling the factory method with the given
arguments.
|
InstanceBuilder<T> |
fromClass(Class<?> factoryClass)
Sets the factory class to use for instance construction.
|
InstanceBuilder<T> |
fromClassName(String name)
Sets the class name to be constructed.
|
InstanceBuilder<T> |
fromFactoryMethod(String methodName)
Sets the name of the factory method used to construct the instance.
|
static <T> InstanceBuilder<T> |
ofType(Class<T> type)
Create an InstanceBuilder for the given type.
|
static <T> InstanceBuilder<T> |
ofType(TypeDescriptor<T> token)
Create an InstanceBuilder for the given type.
|
<ArgT> InstanceBuilder<T> |
withArg(Class<? super ArgT> argType,
ArgT value)
Adds an argument to be passed to the factory method.
|
public static <T> InstanceBuilder<T> ofType(Class<T> type)
The specified type is the type returned by build(), which is
typically the common base type or interface of the instance being
constructed.
public static <T> InstanceBuilder<T> ofType(TypeDescriptor<T> token)
The specified type is the type returned by build(), which is
typically the common base type or interface for the instance to be
constructed.
The TypeDescriptor argument allows specification of generic types. For example,
a List<String> return type can be specified as
ofType(new TypeDescriptor<List<String>>(){}).
public InstanceBuilder<T> fromClassName(String name) throws ClassNotFoundException
If the name is a simple name (ie Class.getSimpleName()), then
the package of the return type is added as a prefix.
The default class is the return type, specified in ofType(java.lang.Class<T>).
Modifies and returns the InstanceBuilder for chaining.
ClassNotFoundException - if no class can be found by the given namepublic InstanceBuilder<T> fromClass(Class<?> factoryClass)
Modifies and returns the InstanceBuilder for chaining.
public InstanceBuilder<T> fromFactoryMethod(String methodName)
The default, if no factory method was specified, is to look for a class constructor.
Modifies and returns the InstanceBuilder for chaining.
public <ArgT> InstanceBuilder<T> withArg(Class<? super ArgT> argType, ArgT value)
The argument type is used to lookup the factory method. This type may be a supertype of the argument value's class.
Modifies and returns the InstanceBuilder for chaining.
ArgT - the argument typepublic T build()
fromClassName(String).
fromFactoryMethod(String).
RuntimeException - if the method does not exist, on type mismatch,
or if the method cannot be made accessible.