final ReturnValueKeyProvider returnAnnotation = targetMethod.getAnnotation(ReturnValueKeyProvider.class);
if (returnAnnotation != null) {
final Method beanMethod = ReturnValueKeyProvider.class.getDeclaredMethod("keyProviderBeanName", null);
final String beanName = (String) beanMethod.invoke(returnAnnotation, null);
if (beanName == null || beanName.length() < 1) {
throw new InvalidParameterException(String.format(
"No valid keyIndexBeanName defined in annotation [%s] on method [%s]",
ReturnValueKeyProvider.class.getName(),
targetMethod.getName()
));
}
data.setKeyIndex(-1);
data.setKeyProviderBeanName(beanName);
return;
}
final Annotation[][] paramAnnotationArrays = targetMethod.getParameterAnnotations();
int foundIndex = Integer.MIN_VALUE;
Annotation foundAnnotation = null;
if (paramAnnotationArrays != null && paramAnnotationArrays.length > 0) {
for (int ix = 0; ix < paramAnnotationArrays.length; ix++) {
final Annotation[] paramAnnotations = paramAnnotationArrays[ix];
if (paramAnnotations != null && paramAnnotations.length > 0) {
for (int jx = 0; jx < paramAnnotations.length; jx++) {
final Annotation paramAnnotation = paramAnnotations[jx];
if (ParameterValueKeyProvider.class.equals(paramAnnotation.annotationType())) {
if (foundIndex >= 0) {
throw new InvalidParameterException(String.format(
"Multiple annotations of type [%s] found on method [%s]",
ParameterValueKeyProvider.class.getName(),
targetMethod.getName()
));
}
foundAnnotation = paramAnnotation;
foundIndex = ix;
}
}
}
}
}
if (foundIndex < 0 || foundAnnotation == null) {
throw new InvalidParameterException(String.format(
"No KeyProvider annotation found method [%s]",
targetMethod.getName()
));
}
final Method beanMethod = ParameterValueKeyProvider.class.getDeclaredMethod("keyProviderBeanName", null);
final String beanName = (String) beanMethod.invoke(foundAnnotation, null);
if (beanName == null || beanName.length() < 1) {
throw new InvalidParameterException(String.format(
"No valid keyIndexBeanName defined in annotation [%s] on method [%s]",
ParameterValueKeyProvider.class.getName(),
targetMethod.getName()
));
}