public class ObjectFactory
extends java.lang.Object
ConstructorParameters
annotation.Modifier and Type | Class and Description |
---|---|
class |
ObjectFactory.ObjectArguments |
Modifier and Type | Method and Description |
---|---|
ObjectFactory.ObjectArguments |
createObjectArguments(Configuration configuration)
Creates an
ObjectFactory.ObjectArguments instance from the given configuration, which can then be used to generate an
object of some type. |
java.util.Optional<java.lang.Object> |
generate(ObjectFactory.ObjectArguments arguments)
Generates a new object for the given arguments.
|
<T> java.util.Optional<T> |
generate(ObjectFactory.ObjectArguments arguments,
java.lang.Class<T> type)
Generates a new object of the given type for the given arguments.
|
java.util.Optional<java.lang.Class<?>> |
getClassForName(java.lang.String name)
Get the class for the given name.
|
static ObjectFactory |
getFactory()
Gets the factory which can be used to generate objects.
|
void |
registerGeneratableType(java.lang.Class<?> type)
Register the given generatable type with this factory.
|
static void |
setFactory(ObjectFactory factory)
Sets the factory which can be used to generate objects.
|
public static ObjectFactory getFactory()
public static void setFactory(ObjectFactory factory)
public final ObjectFactory.ObjectArguments createObjectArguments(Configuration configuration)
ObjectFactory.ObjectArguments
instance from the given configuration, which can then be used to generate an
object of some type. This method will always return an ObjectArguments instance, however it is not certain that
an object can be generated from it.configuration
- The configuration to create an ObjectFactory.ObjectArguments
instance from. This configuration
must have two keys: Properties.TYPE
specifies the
fully-qualified name of the type to generate, and Properties.ARGS
specifies the arguments for the constructor. Note that this value may have one of three
different types: A comma-separated String of the arguments in order, a ConfigurationArray
containing the arguments in order, or a Configuration
with named arguments. In the last
case, the constructor must have a ConstructorParameters
annotation with named parameters.
Note that for each argument, only Strings, doubles, integers or booleans are supported.public final <T> java.util.Optional<T> generate(ObjectFactory.ObjectArguments arguments, java.lang.Class<T> type)
T
- The generic type of the new object.arguments
- The arguments given to generate the new object.type
- The desired type of the new object.public java.util.Optional<java.lang.Object> generate(ObjectFactory.ObjectArguments arguments)
arguments
- The arguments given to generate the new object.public java.util.Optional<java.lang.Class<?>> getClassForName(java.lang.String name)
name
- The fully qualified class name.public void registerGeneratableType(java.lang.Class<?> type)
Class.forName(String)
don't need to be specifically registered.type
- The type of objects newly generatable by this factory.