Search in sources :

Example 1 with MethodLifeCycle

use of com.dtflys.forest.annotation.MethodLifeCycle in project forest by dromara.

the class InterfaceProxyHandler method processBaseAnnotation.

@SuppressWarnings("deprecation")
private void processBaseAnnotation(Class parentAnnType, Annotation[] annotations) {
    for (int i = 0; i < annotations.length; i++) {
        Annotation annotation = annotations[i];
        Class<? extends Annotation> annType = annotation.annotationType();
        if (annType.getName().startsWith("java.")) {
            continue;
        }
        Annotation[] subAnnotations = annType.getAnnotations();
        if (parentAnnType != null && !annType.equals(parentAnnType)) {
            processBaseAnnotation(annType, subAnnotations);
        }
        if (annotation instanceof BaseURL) {
            BaseURL baseURLAnn = (BaseURL) annotation;
            String value = baseURLAnn.value();
            if (value == null || value.trim().length() == 0) {
                continue;
            }
            String baseURL = value.trim();
            baseMetaRequest.setUrl(baseURL);
        } else {
            BaseLifeCycle baseLifeCycle = annotation.annotationType().getAnnotation(BaseLifeCycle.class);
            MethodLifeCycle methodLifeCycle = annotation.annotationType().getAnnotation(MethodLifeCycle.class);
            if (baseLifeCycle != null || methodLifeCycle != null) {
                if (baseLifeCycle != null) {
                    Class<? extends BaseAnnotationLifeCycle> interceptorClass = baseLifeCycle.value();
                    if (interceptorClass != null) {
                        BaseAnnotationLifeCycle baseInterceptor = interceptorFactory.getInterceptor(interceptorClass);
                        baseInterceptor.onProxyHandlerInitialized(this, annotation);
                    }
                }
                baseAnnotations.add(annotation);
            }
        }
    }
}
Also used : MethodLifeCycle(com.dtflys.forest.annotation.MethodLifeCycle) BaseURL(com.dtflys.forest.annotation.BaseURL) BaseAnnotationLifeCycle(com.dtflys.forest.lifecycles.BaseAnnotationLifeCycle) Annotation(java.lang.annotation.Annotation) BaseLifeCycle(com.dtflys.forest.annotation.BaseLifeCycle)

Example 2 with MethodLifeCycle

use of com.dtflys.forest.annotation.MethodLifeCycle 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;
}
Also used : MethodLifeCycle(com.dtflys.forest.annotation.MethodLifeCycle) ForestInterceptorDefineException(com.dtflys.forest.exceptions.ForestInterceptorDefineException) Interceptor(com.dtflys.forest.interceptor.Interceptor) BaseLifeCycle(com.dtflys.forest.annotation.BaseLifeCycle)

Aggregations

BaseLifeCycle (com.dtflys.forest.annotation.BaseLifeCycle)2 MethodLifeCycle (com.dtflys.forest.annotation.MethodLifeCycle)2 BaseURL (com.dtflys.forest.annotation.BaseURL)1 ForestInterceptorDefineException (com.dtflys.forest.exceptions.ForestInterceptorDefineException)1 Interceptor (com.dtflys.forest.interceptor.Interceptor)1 BaseAnnotationLifeCycle (com.dtflys.forest.lifecycles.BaseAnnotationLifeCycle)1 Annotation (java.lang.annotation.Annotation)1