private void inspect() { managerModCount = manager.getModCount(); // first global, then type level, then method level // but later one can override pre (for same annotation) List<Annotation> typeLevel = new ArrayList<Annotation>(); Class<?> serviceType = serviceClass; while (serviceType != null) { for (Annotation ann : serviceType.getAnnotations()) { if (ann.annotationType().isAnnotationPresent(AcServiceIntercepted.class)) { putOrAppendAnnotation(typeLevel, ann); } } Class<?> theType = serviceType; serviceType = null; for (Class<?> superInf : theType.getInterfaces()) { if (AcService.class.isAssignableFrom(superInf)) { serviceType = superInf; break; } } } for (Method method : serviceClass.getMethods()) { List<Annotation> annList = new ArrayList<Annotation>(typeLevel); for (Annotation ann : method.getAnnotations()) { if (ann.annotationType().isAnnotationPresent(AcServiceIntercepted.class)) { putOrAppendAnnotation(annList, ann); } } methodAnnotationList.put(method, annList); setupRuntimeInterceptorList(method); } }
private void setupRuntimeInterceptorList(Method method) { List<InterceptorAnnotationPair> runtimeInterceptorList = new ArrayList<InterceptorAnnotationPair>(); for (AcServiceInterceptor interceptor : manager.getInterceptors(serviceId)) { runtimeInterceptorList.add(new InterceptorAnnotationPair(interceptor, null)); } List<Annotation> annList = methodAnnotationList.get(method); for (Annotation ann : annList) { runtimeInterceptorList.add( new InterceptorAnnotationPair( manager.createSingletonInterceptor( ann.annotationType().getAnnotation(AcServiceIntercepted.class).value()), ann)); } methodInterceptorList.put( method, runtimeInterceptorList.toArray( new InterceptorAnnotationPair[runtimeInterceptorList.size()])); }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (manager.getModCount() != managerModCount) { synchronized (this) { if (manager.getModCount() != managerModCount) { int modCount = manager.getModCount(); setupRuntimeInterceptorList(method); managerModCount = modCount; } } } InterceptorAnnotationPair[] interceptorAnnPair = methodInterceptorList.get(method); AcServiceInvokeContext context = new AcServiceInvokeContext(interceptorAnnPair); context.setArguments(args); context.setMethod(method); context.setService(service); context.setCoreRuntime(manager.getCoreRuntime()); try { return context.proceed(); } catch (InvocationTargetException e) { throw e.getCause(); } }