Search in sources :

Example 1 with ParameterAnnotationLifeCycle

use of com.dtflys.forest.lifecycles.ParameterAnnotationLifeCycle in project forest by dromara.

the class ForestMethod method processParameterAnnotation.

/**
 * 处理参数的注解
 * @param parameter 方法参数-字符串模板解析对象,{@link MappingParameter}类实例
 * @param anns 方法参数注解的二维数组
 */
private void processParameterAnnotation(MappingParameter parameter, Annotation[] anns) {
    for (int i = 0; i < anns.length; i++) {
        Annotation ann = anns[i];
        Class annType = ann.annotationType();
        if (annType.getPackage().getName().startsWith("java.")) {
            continue;
        }
        Annotation[] subAnnArray = annType.getAnnotations();
        if (subAnnArray.length > 0) {
            processParameterAnnotation(parameter, subAnnArray);
        }
        ParamLifeCycle paramLifeCycleAnn = (ParamLifeCycle) annType.getAnnotation(ParamLifeCycle.class);
        if (paramLifeCycleAnn != null) {
            Class<? extends ParameterAnnotationLifeCycle> interceptorClass = paramLifeCycleAnn.value();
            if (!Interceptor.class.isAssignableFrom(interceptorClass)) {
                throw new ForestInterceptorDefineException(interceptorClass);
            }
            ParameterAnnotationLifeCycle lifeCycle = addInterceptor(interceptorClass);
            lifeCycle.onParameterInitialized(this, parameter, ann);
        }
    }
}
Also used : ForestInterceptorDefineException(com.dtflys.forest.exceptions.ForestInterceptorDefineException) ParamLifeCycle(com.dtflys.forest.annotation.ParamLifeCycle) ParameterAnnotationLifeCycle(com.dtflys.forest.lifecycles.ParameterAnnotationLifeCycle) Interceptor(com.dtflys.forest.interceptor.Interceptor) Annotation(java.lang.annotation.Annotation)

Aggregations

ParamLifeCycle (com.dtflys.forest.annotation.ParamLifeCycle)1 ForestInterceptorDefineException (com.dtflys.forest.exceptions.ForestInterceptorDefineException)1 Interceptor (com.dtflys.forest.interceptor.Interceptor)1 ParameterAnnotationLifeCycle (com.dtflys.forest.lifecycles.ParameterAnnotationLifeCycle)1 Annotation (java.lang.annotation.Annotation)1