package org.theonefx.wcframework.cache; import java.lang.reflect.Method; import org.theonefx.wcframework.aop.AopCore; import org.theonefx.wcframework.aop.ExactlyPointcut; import org.theonefx.wcframework.aop.Pointcut; import org.theonefx.wcframework.cache.annotation.MethodCache; import org.theonefx.wcframework.core.BeanDefinitionRegistry; import org.theonefx.wcframework.core.ClassParseContext; import org.theonefx.wcframework.core.ClassParser; import org.theonefx.wcframework.core.ClassWrapper; public class CacheClassParser implements ClassParser { private final MethodCacheManager cacheManager; private final AopCore aopCore; private final CacheMethodInterceptorGenerator generator; public CacheClassParser(AopCore aopCore, MethodCacheManager cacheManager) { this.cacheManager = cacheManager; this.aopCore = aopCore; generator = new CacheMethodInterceptorGenerator(cacheManager); } @Override public void parse(ClassWrapper<?> wrapper, BeanDefinitionRegistry registry, ClassParseContext context) { Method[] methods = wrapper.getAllDeclaredMethodsWithoutTop(); for (Method method : methods) { MethodCache methodCache = method.getAnnotation(MethodCache.class); if (methodCache != null) { Pointcut pointcut = new ExactlyPointcut(wrapper.getWrapperedClass(), method); aopCore.registInterceptor(pointcut, generator); } } } }