Class DefaultConstructorStrategy

    • Field Detail

      • argumentTypes

        private java.lang.Class<?>[] argumentTypes
      • arguments

        private final java.lang.Object[] arguments
    • Constructor Detail

      • DefaultConstructorStrategy

        private DefaultConstructorStrategy​(java.lang.Class<?>[] argumentTypes,
                                           java.lang.Object[] arguments)
    • Method Detail

      • construct

        public java.lang.Object construct​(java.lang.Class<?> clazz)
                                   throws javax.script.ScriptException
        Description copied from interface: ConstructorStrategy
        Constructs an instance of a Class.
        Specified by:
        construct in interface ConstructorStrategy
        Parameters:
        clazz - the Class
        Returns:
        the constructed instance or null
        Throws:
        javax.script.ScriptException - if the instance could not be constructed
      • byArgumentTypes

        public 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.
        Parameters:
        argumentTypes - the argument types defining the constructor to call
        arguments - the arguments to pass to the constructor (may contain null)
        Returns:
        the created DefaultConstructorStrategy
      • byMatchingArguments

        public static DefaultConstructorStrategy byMatchingArguments​(java.lang.Object... arguments)
        Creates a 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.
        Parameters:
        arguments - the arguments to pass to the constructor (may contain null)
        Returns:
        the created DefaultConstructorStrategy
      • findConstructor

        private java.lang.reflect.Constructor<?> findConstructor​(java.lang.Class<?> clazz,
                                                                 java.lang.Class<?>[] argumentTypes,
                                                                 java.lang.Object[] arguments)
                                                          throws java.lang.NoSuchMethodException,
                                                                 javax.script.ScriptException
        Throws:
        java.lang.NoSuchMethodException
        javax.script.ScriptException