use of com.dtflys.forest.lifecycles.MethodAnnotationLifeCycle in project forest by dromara.
the class ForestMethod method addMetaRequestAnnotation.
/**
* 添加元请求注释
* @param annotation 注解
* @param interceptorClass 拦截器类
*/
private void addMetaRequestAnnotation(Annotation annotation, Class interceptorClass) {
Class<? extends Annotation> annType = annotation.annotationType();
RequestAttributes requestAttributesAnn = annType.getAnnotation(RequestAttributes.class);
if (requestAttributesAnn != null) {
Map<String, Object> attrTemplates = ReflectUtils.getAttributesFromAnnotation(annotation);
for (String key : attrTemplates.keySet()) {
Object value = attrTemplates.get(key);
if (value instanceof CharSequence) {
MappingTemplate template = makeTemplate(annType, key, value.toString());
attrTemplates.put(key, template);
} else if (String[].class.isAssignableFrom(value.getClass())) {
String[] stringArray = (String[]) value;
int len = stringArray.length;
MappingTemplate[] templates = new MappingTemplate[stringArray.length];
for (int i = 0; i < len; i++) {
String item = stringArray[i];
MappingTemplate template = makeTemplate(annType, key, item);
templates[i] = template;
}
attrTemplates.put(key, templates);
}
}
InterceptorAttributes attributes = new InterceptorAttributes(interceptorClass, attrTemplates);
if (interceptorAttributesList == null) {
interceptorAttributesList = new LinkedList<>();
}
interceptorAttributesList.add(attributes);
}
Interceptor interceptor = addInterceptor(interceptorClass);
if (interceptor instanceof MethodAnnotationLifeCycle) {
MethodAnnotationLifeCycle lifeCycle = (MethodAnnotationLifeCycle) interceptor;
lifeCycle.onMethodInitialized(this, annotation);
}
}
Aggregations