Class MethodAccess

java.lang.Object
org.faktorips.util.MethodAccess

public class MethodAccess extends Object
Wraps access to a method. Allows checks on the method and its invocation.
  • Method Details

    • of

      public static final MethodAccess of(Class<?> clazz, String methodName, Class<?>... parameterTypes)
      Creates a MethodAccess for the given class and method name.

      If the method can not be found, checks and invocations will fail when called.

      Parameters:
      clazz - a class
      methodName - the name of a method of the given class
      Throws:
      NullPointerException - if no class or method name is given
      IllegalArgumentException - if the method name is empty
    • invoke

      public <T> T invoke(String methodDescription, Object object, Object... args)
      Invokes the wrapped method on the given object with the given arguments.
      Type Parameters:
      T - the expected type of the return value
      Parameters:
      methodDescription - a description of what the method does, like "to find a value by name", that will be included in an exception's message if one is thrown
      object - an instance of the wrapped class on which the method should be invoked
      args - the arguments (if any) to be passed to the method
      Returns:
      the method's return value
      Throws:
      MethodAccess.MethodAccessException - if invocation of the method fails
    • invokeStatic

      public <T> T invokeStatic(String methodDescription, Object... args)
      Invokes the wrapped static method on the wrapped class with the given arguments.
      Type Parameters:
      T - the expected type of the return value
      Parameters:
      methodDescription - a description of what the method does, like "to find a value by name", that will be included in an exception's message if one is thrown
      args - the arguments (if any) to be passed to the method
      Returns:
      the method's return value
      Throws:
      MethodAccess.MethodAccessException - if invocation of the method fails
    • exists

      public boolean exists()
      Returns whether the wrapped method actually exists.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • check

      public MethodAccess.Check check(org.faktorips.runtime.MessageList messageList, String msgCodePrefix)
      Creates a new MethodAccess.Check object for this class and method name.

      All checks called on the MethodAccess.Check object report problems to the given MessageList using the given prefix for their message codes.

      The first check to be called should be MethodAccess.Check.exists(), because other checks won't work if there is no method to check.

      Parameters:
      messageList - a list of messages to which this check can report problems
      msgCodePrefix - a prefix to be used for message codes