public class DefaultConstructorStrategy extends java.lang.Object implements ConstructorStrategy
ConstructorStrategy implementation.
This implementation has three static constructor methods to define the constructor that should be called:
byDefaultConstructor() to call the public default no-argument constructor.byArgumentTypes(Class[], Object...) to call the public constructor with the
specified argument types and pass it the specified arguments.byMatchingArguments(Object...) to call a public constructor that matches the
specified arguments.| Modifier and Type | Method and Description |
|---|---|
static DefaultConstructorStrategy |
byArgumentTypes(java.lang.Class<?>[] argumentTypes,
java.lang.Object... arguments)
Creates a
DefaultConstructorStrategy that will call the public constructor with the
specified argument types and passes the specified argument list. |
static DefaultConstructorStrategy |
byDefaultConstructor()
Creates a
DefaultConstructorStrategy that will call the public default no-argument constructor. |
static DefaultConstructorStrategy |
byMatchingArguments(java.lang.Object... arguments)
Creates a
DefaultConstructorStrategy that will call a public constructor that matches the
specified arguments. |
java.lang.Object |
construct(java.lang.Class<?> clazz)
Constructs an instance of a
Class. |
public java.lang.Object construct(java.lang.Class<?> clazz)
throws javax.script.ScriptException
ConstructorStrategyClass.construct in interface ConstructorStrategyclazz - the Classnulljavax.script.ScriptException - if the instance could not be constructedpublic static DefaultConstructorStrategy byDefaultConstructor()
DefaultConstructorStrategy that will call the public default no-argument constructor.DefaultConstructorStrategypublic static DefaultConstructorStrategy byArgumentTypes(java.lang.Class<?>[] argumentTypes, java.lang.Object... arguments)
DefaultConstructorStrategy that will call the public constructor with the
specified argument types and passes the specified argument list.argumentTypes - the argument types defining the constructor to callarguments - the arguments to pass to the constructor (may contain null)DefaultConstructorStrategypublic static DefaultConstructorStrategy byMatchingArguments(java.lang.Object... arguments)
DefaultConstructorStrategy that will call a public constructor that matches the
specified arguments.
A constructor must match all specified arguments, except null values which
match any non-primitive type.
The conversion from object types into corresponding primitive types
(for example Integer into int) is handled automatically.
If multiple public constructors match the specified arguments the
construct(Class) method will throw a ScriptException.arguments - the arguments to pass to the constructor (may contain null)DefaultConstructorStrategy