Package org.apache.nifi.util
Class ReflectionUtils
java.lang.Object
org.apache.nifi.util.ReflectionUtils
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final org.slf4j.Logger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static Object[]buildUpdatedArgumentsList(boolean quietly, Method method, Class<?>[] annotations, ComponentLog processLogger, Object... args) discoverMethodsWithAnnotations(Class<?> clazz, Class<? extends Annotation>[] annotations) findMethodsWithAnnotations(Class<?> clazz, Class<? extends Annotation>[] annotationClasses) static voidinvokeMethodsWithAnnotation(Class<? extends Annotation> annotation, Object instance, Object... args) Invokes all methods on the given instance that have been annotated with the given Annotation.private static booleaninvokeMethodsWithAnnotations(boolean quietly, ComponentLog logger, Object instance, Class<?> clazz, Class<? extends Annotation>[] annotations, Object... args) private static booleaninvokeMethodsWithAnnotations(boolean quietly, ComponentLog logger, Object instance, Class<? extends Annotation>[] annotations, Object... args) static voidinvokeMethodsWithAnnotations(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.private static booleanisAnnotationPresent(Method method, Class<? extends Annotation> annotationClass) private static booleanisAnyAnnotationPresent(Method method, Class<? extends Annotation>[] annotations) private static voidlogErrorMessage(String message, ComponentLog processLogger, Throwable e) static booleanquietlyInvokeMethodsWithAnnotation(Class<? extends Annotation> annotation, Object instance, Object... args) Invokes all methods on the given instance that have been annotated with the given Annotation.static booleanquietlyInvokeMethodsWithAnnotation(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.static booleanquietlyInvokeMethodsWithAnnotations(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.static booleanquietlyInvokeMethodsWithAnnotations(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.
-
Field Details
-
LOG
private static final org.slf4j.Logger LOG -
annotationCache
-
-
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 ininstanceuses 1 or more parameters, those parameters must be specified by theargsparameter. However, if more arguments are supplied by theargsparameter than needed, the extra arguments will be ignored.- Parameters:
annotation- annotationinstance- instanceargs- args- Throws:
InvocationTargetException- exIllegalArgumentException- exIllegalAccessException- 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 ininstanceuses 1 or more parameters, those parameters must be specified by theargsparameter. However, if more arguments are supplied by theargsparameter than needed, the extra arguments will be ignored.- Parameters:
preferredAnnotation- preferredalternateAnnotation- alternateinstance- instanceargs- args- Throws:
InvocationTargetException- exIllegalArgumentException- exIllegalAccessException- 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 ininstanceuses 1 or more parameters, those parameters must be specified by theargsparameter. However, if more arguments are supplied by theargsparameter than needed, the extra arguments will be ignored.- Parameters:
annotation- annotationinstance- instanceargs- args- Returns:
trueif all appropriate methods were invoked and returned without throwing an Exception,falseif one of the methods threw an Exception or could not be invoked; iffalseis 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 ininstanceuses 1 or more parameters, those parameters must be specified by theargsparameter. However, if more arguments are supplied by theargsparameter than needed, the extra arguments will be ignored.- Parameters:
annotation- annotationinstance- instancelogger- loggerargs- args- Returns:
trueif all appropriate methods were invoked and returned without throwing an Exception,falseif one of the methods threw an Exception or could not be invoked; iffalseis 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 ininstanceuses 1 or more parameters, those parameters must be specified by theargsparameter. However, if more arguments are supplied by theargsparameter than needed, the extra arguments will be ignored.- Parameters:
preferredAnnotation- preferredalternateAnnotation- alternateinstance- instanceargs- args- Returns:
trueif all appropriate methods were invoked and returned without throwing an Exception,falseif one of the methods threw an Exception or could not be invoked; iffalseis 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 -
invokeMethodsWithAnnotations
private static boolean invokeMethodsWithAnnotations(boolean quietly, ComponentLog logger, Object instance, Class<?> clazz, Class<? extends Annotation>[] annotations, Object... args) 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
-
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 ininstanceuses 1 or more parameters, those parameters must be specified by theargsparameter. However, if more arguments are supplied by theargsparameter than needed, the extra arguments will be ignored.- Parameters:
preferredAnnotation- preferredalternateAnnotation- alternateinstance- instancelogger- 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:
trueif all appropriate methods were invoked and returned without throwing an Exception,falseif one of the methods threw an Exception or could not be invoked; iffalseis returned, an error will have been logged.
-