use of com.dtflys.forest.interceptor.Interceptor in project forest by dromara.
the class ForestMethod method getAnnotationLifeCycleClass.
private Class<? extends Interceptor> getAnnotationLifeCycleClass(Annotation annotation) {
Class<? extends Annotation> annType = annotation.annotationType();
Class<? extends MethodAnnotationLifeCycle> interceptorClass = null;
MethodLifeCycle methodLifeCycleAnn = annType.getAnnotation(MethodLifeCycle.class);
if (methodLifeCycleAnn == null) {
BaseLifeCycle baseLifeCycle = annType.getAnnotation(BaseLifeCycle.class);
if (baseLifeCycle != null) {
Class<? extends BaseAnnotationLifeCycle> baseAnnLifeCycleClass = baseLifeCycle.value();
if (baseAnnLifeCycleClass != null) {
if (MethodAnnotationLifeCycle.class.isAssignableFrom(baseAnnLifeCycleClass)) {
interceptorClass = (Class<? extends MethodAnnotationLifeCycle>) baseAnnLifeCycleClass;
} else {
return baseAnnLifeCycleClass;
}
}
}
}
if (methodLifeCycleAnn != null || interceptorClass != null) {
if (interceptorClass == null) {
interceptorClass = methodLifeCycleAnn.value();
if (!Interceptor.class.isAssignableFrom(interceptorClass)) {
throw new ForestInterceptorDefineException(interceptorClass);
}
}
}
return interceptorClass;
}
use of com.dtflys.forest.interceptor.Interceptor 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