T - type type of object returned by this instance builderpublic class InstanceBuilder<T>
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
T |
build()
Creates the instance by calling the factory method with the given arguments.
|
InstanceBuilder<T> |
fromClass(java.lang.Class<?> factoryClass)
Sets the factory class to use for instance construction.
|
InstanceBuilder<T> |
fromClassName(java.lang.String name)
Sets the class name to be constructed.
|
InstanceBuilder<T> |
fromFactoryMethod(java.lang.String methodName)
Sets the name of the factory method used to construct the instance.
|
static <T> InstanceBuilder<T> |
ofType(java.lang.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(java.lang.Class<? super ArgT> argType,
ArgT value)
Adds an argument to be passed to the factory method.
|
public static <T> InstanceBuilder<T> ofType(java.lang.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(java.lang.String name) throws java.lang.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.
java.lang.ClassNotFoundException - if no class can be found by the given namepublic InstanceBuilder<T> fromClass(java.lang.Class<?> factoryClass)
Modifies and returns the InstanceBuilder for chaining.
public InstanceBuilder<T> fromFactoryMethod(java.lang.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(java.lang.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).
java.lang.RuntimeException - if the method does not exist, on type mismatch, or if the method
cannot be made accessible.