Class ReflectionUtils

java.lang.Object
org.apache.nifi.util.ReflectionUtils

public class ReflectionUtils extends Object
  • Field Details

  • Constructor Details

    • ReflectionUtils

      public ReflectionUtils()
  • Method Details

    • invokeMethodsWithAnnotation

      public static void invokeMethodsWithAnnotation(Class<? extends Annotation> annotation, Object instance, Object... args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException
      Invokes all methods on the given instance that have been annotated with the given Annotation. If the signature of the method that is defined in instance uses 1 or more parameters, those parameters must be specified by the args parameter. However, if more arguments are supplied by the args parameter than needed, the extra arguments will be ignored.
      Parameters:
      annotation - annotation
      instance - instance
      args - args
      Throws:
      InvocationTargetException - ex
      IllegalArgumentException - ex
      IllegalAccessException - ex
    • invokeMethodsWithAnnotations

      public static void invokeMethodsWithAnnotations(Class<? extends Annotation> preferredAnnotation, Class<? extends Annotation> alternateAnnotation, Object instance, Object... args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException
      Invokes all methods on the given instance that have been annotated with the given preferredAnnotation and if no such method exists will invoke all methods on the given instance that have been annotated with the given alternateAnnotation, if any exists. If the signature of the method that is defined in instance uses 1 or more parameters, those parameters must be specified by the args parameter. However, if more arguments are supplied by the args parameter than needed, the extra arguments will be ignored.
      Parameters:
      preferredAnnotation - preferred
      alternateAnnotation - alternate
      instance - instance
      args - args
      Throws:
      InvocationTargetException - ex
      IllegalArgumentException - ex
      IllegalAccessException - ex
    • quietlyInvokeMethodsWithAnnotation

      public static boolean quietlyInvokeMethodsWithAnnotation(Class<? extends Annotation> annotation, Object instance, Object... args)
      Invokes all methods on the given instance that have been annotated with the given Annotation. If the signature of the method that is defined in instance uses 1 or more parameters, those parameters must be specified by the args parameter. However, if more arguments are supplied by the args parameter than needed, the extra arguments will be ignored.
      Parameters:
      annotation - annotation
      instance - instance
      args - args
      Returns:
      true if all appropriate methods were invoked and returned without throwing an Exception, false if one of the methods threw an Exception or could not be invoked; if false is returned, an error will have been logged.
    • quietlyInvokeMethodsWithAnnotation

      public static boolean quietlyInvokeMethodsWithAnnotation(Class<? extends Annotation> annotation, Object instance, ComponentLog logger, Object... args)
      Invokes all methods on the given instance that have been annotated with the given Annotation. If the signature of the method that is defined in instance uses 1 or more parameters, those parameters must be specified by the args parameter. However, if more arguments are supplied by the args parameter than needed, the extra arguments will be ignored.
      Parameters:
      annotation - annotation
      instance - instance
      logger - logger
      args - args
      Returns:
      true if all appropriate methods were invoked and returned without throwing an Exception, false if one of the methods threw an Exception or could not be invoked; if false is returned, an error will have been logged.
    • quietlyInvokeMethodsWithAnnotations

      public static boolean quietlyInvokeMethodsWithAnnotations(Class<? extends Annotation> preferredAnnotation, Class<? extends Annotation> alternateAnnotation, Object instance, Object... args)
      Invokes all methods on the given instance that have been annotated with the given preferredAnnotation and if no such method exists will invoke all methods on the given instance that have been annotated with the given alternateAnnotation, if any exists. If the signature of the method that is defined in instance uses 1 or more parameters, those parameters must be specified by the args parameter. However, if more arguments are supplied by the args parameter than needed, the extra arguments will be ignored.
      Parameters:
      preferredAnnotation - preferred
      alternateAnnotation - alternate
      instance - instance
      args - args
      Returns:
      true if all appropriate methods were invoked and returned without throwing an Exception, false if one of the methods threw an Exception or could not be invoked; if false is returned, an error will have been logged.
    • invokeMethodsWithAnnotations

      private static boolean invokeMethodsWithAnnotations(boolean quietly, ComponentLog logger, Object instance, Class<? extends Annotation>[] annotations, Object... args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException
      Throws:
      IllegalAccessException
      IllegalArgumentException
      InvocationTargetException
    • invokeMethodsWithAnnotations

      private static boolean invokeMethodsWithAnnotations(boolean quietly, ComponentLog logger, Object instance, Class<?> clazz, Class<? extends Annotation>[] annotations, Object... args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException
      Throws:
      IllegalAccessException
      IllegalArgumentException
      InvocationTargetException
    • findMethodsWithAnnotations

      public static List<Method> findMethodsWithAnnotations(Class<?> clazz, Class<? extends Annotation>[] annotationClasses)
    • discoverMethodsWithAnnotations

      private static List<Method> discoverMethodsWithAnnotations(Class<?> clazz, Class<? extends Annotation>[] annotations)
    • isAnyAnnotationPresent

      private static boolean isAnyAnnotationPresent(Method method, Class<? extends Annotation>[] annotations)
    • isAnnotationPresent

      private static boolean isAnnotationPresent(Method method, Class<? extends Annotation> annotationClass)
    • buildUpdatedArgumentsList

      private static Object[] buildUpdatedArgumentsList(boolean quietly, Method method, Class<?>[] annotations, ComponentLog processLogger, Object... args)
    • logErrorMessage

      private static void logErrorMessage(String message, ComponentLog processLogger, Throwable e)
    • quietlyInvokeMethodsWithAnnotations

      public static boolean quietlyInvokeMethodsWithAnnotations(Class<? extends Annotation> preferredAnnotation, Class<? extends Annotation> alternateAnnotation, Object instance, ComponentLog logger, Object... args)
      Invokes all methods on the given instance that have been annotated with the given preferredAnnotation and if no such method exists will invoke all methods on the given instance that have been annotated with the given alternateAnnotation, if any exists. If the signature of the method that is defined in instance uses 1 or more parameters, those parameters must be specified by the args parameter. However, if more arguments are supplied by the args parameter than needed, the extra arguments will be ignored.
      Parameters:
      preferredAnnotation - preferred
      alternateAnnotation - alternate
      instance - instance
      logger - the ComponentLog to use for logging any errors. If null, will use own logger, but that will not generate bulletins or easily tie to the Processor's log messages.
      args - args
      Returns:
      true if all appropriate methods were invoked and returned without throwing an Exception, false if one of the methods threw an Exception or could not be invoked; if false is returned, an error will have been logged.