Class MethodExecutionStrategy

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.Object[] arguments  
      private java.lang.reflect.Method method  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private MethodExecutionStrategy​(java.lang.reflect.Method method, java.lang.Object... arguments)  
    • Field Detail

      • method

        private java.lang.reflect.Method method
      • arguments

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

      • MethodExecutionStrategy

        private MethodExecutionStrategy​(java.lang.reflect.Method method,
                                        java.lang.Object... arguments)
    • Method Detail

      • execute

        public java.lang.Object execute​(java.lang.Object instance)
                                 throws javax.script.ScriptException
        Description copied from interface: ExecutionStrategy
        Executes a method on an object instance, or a static method if the specified instance is null.
        Specified by:
        execute in interface ExecutionStrategy
        Parameters:
        instance - the object instance to be executed or null to execute a static method
        Returns:
        the return value of the method, or null
        Throws:
        javax.script.ScriptException - if no method to execute was found
      • byMethod

        public static MethodExecutionStrategy byMethod​(java.lang.reflect.Method method,
                                                       java.lang.Object... arguments)
        Creates a MethodExecutionStrategy that will call the specified Method.
        Parameters:
        method - the Method to execute
        arguments - the arguments to be passed to the method
        Returns:
        the value returned by the method, or null
      • byMainMethod

        public static MethodExecutionStrategy byMainMethod​(java.lang.Class<?> clazz,
                                                           java.lang.String... arguments)
                                                    throws javax.script.ScriptException
        Creates a MethodExecutionStrategy that will call the public static void main(String[] args) with the specified arguments.
        Parameters:
        clazz - the Class
        arguments - the arguments to pass to the main method
        Returns:
        the created MethodExecutionStrategy
        Throws:
        javax.script.ScriptException - if no public static void main(String[] args) method was found
      • byArgumentTypes

        public static MethodExecutionStrategy byArgumentTypes​(java.lang.Class<?> clazz,
                                                              java.lang.String methodName,
                                                              java.lang.Class<?>[] argumentTypes,
                                                              java.lang.Object... arguments)
                                                       throws javax.script.ScriptException
        Creates a MethodExecutionStrategy that will call the public method with the specified argument types and passes the specified argument list.
        Parameters:
        clazz - the Class
        methodName - the method name
        argumentTypes - the argument types defining the constructor to call
        arguments - the arguments to pass to the constructor (may contain null)
        Returns:
        the created MethodExecutionStrategy
        Throws:
        javax.script.ScriptException - if no matching public method was found
      • byMatchingArguments

        public static MethodExecutionStrategy byMatchingArguments​(java.lang.Class<?> clazz,
                                                                  java.lang.String methodName,
                                                                  java.lang.Object... arguments)
                                                           throws javax.script.ScriptException
        Creates a MethodExecutionStrategy that will call a public method that matches the specified arguments. A method 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.
        Parameters:
        clazz - the Class
        methodName - the method name
        arguments - the arguments to be passed to the method
        Returns:
        the created MethodExecutionStrategy
        Throws:
        javax.script.ScriptException - if no matching public method was found