Class DefaultConstructorStrategy
- java.lang.Object
-
- ch.obermuhlner.scriptengine.java.constructor.DefaultConstructorStrategy
-
- All Implemented Interfaces:
ConstructorStrategy
public class DefaultConstructorStrategy extends java.lang.Object implements ConstructorStrategy
The defaultConstructorStrategyimplementation. 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.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static DefaultConstructorStrategybyArgumentTypes(java.lang.Class<?>[] argumentTypes, java.lang.Object... arguments)Creates aDefaultConstructorStrategythat will call the public constructor with the specified argument types and passes the specified argument list.static DefaultConstructorStrategybyDefaultConstructor()Creates aDefaultConstructorStrategythat will call the public default no-argument constructor.static DefaultConstructorStrategybyMatchingArguments(java.lang.Object... arguments)Creates aDefaultConstructorStrategythat will call a public constructor that matches the specified arguments.java.lang.Objectconstruct(java.lang.Class<?> clazz)Constructs an instance of aClass.
-
-
-
Method Detail
-
construct
public java.lang.Object construct(java.lang.Class<?> clazz) throws javax.script.ScriptExceptionDescription copied from interface:ConstructorStrategyConstructs an instance of aClass.- Specified by:
constructin interfaceConstructorStrategy- Parameters:
clazz- theClass- Returns:
- the constructed instance or
null - Throws:
javax.script.ScriptException- if the instance could not be constructed
-
byDefaultConstructor
public static DefaultConstructorStrategy byDefaultConstructor()
Creates aDefaultConstructorStrategythat will call the public default no-argument constructor.- Returns:
- the created
DefaultConstructorStrategy
-
byArgumentTypes
public static DefaultConstructorStrategy byArgumentTypes(java.lang.Class<?>[] argumentTypes, java.lang.Object... arguments)
Creates aDefaultConstructorStrategythat will call the public constructor with the specified argument types and passes the specified argument list.- Parameters:
argumentTypes- the argument types defining the constructor to callarguments- the arguments to pass to the constructor (may containnull)- Returns:
- the created
DefaultConstructorStrategy
-
byMatchingArguments
public static DefaultConstructorStrategy byMatchingArguments(java.lang.Object... arguments)
Creates aDefaultConstructorStrategythat will call a public constructor that matches the specified arguments. A constructor must match all specified arguments, exceptnullvalues which match any non-primitive type. The conversion from object types into corresponding primitive types (for exampleIntegerintoint) is handled automatically. If multiple public constructors match the specified arguments theconstruct(Class)method will throw aScriptException.- Parameters:
arguments- the arguments to pass to the constructor (may containnull)- Returns:
- the created
DefaultConstructorStrategy
-
-