if (org.springframework.aop.framework.Advised.class.isInstance(bean)) { org.springframework.aop.framework.Advised advised = (org.springframework.aop.framework.Advised) bean; targetClass = advised.getTargetClass(); } else { targetClass = bean.getClass();
@SuppressWarnings("rawtypes") public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { if (org.springframework.aop.framework.Advised.class.isInstance(bean)) { org.springframework.aop.framework.Advised advised = (org.springframework.aop.framework.Advised) bean; Class<?> targetClass = advised.getTargetClass(); Compensable compensable = targetClass.getAnnotation(Compensable.class); if (compensable == null) { return bean; } Field[] fields = targetClass.getDeclaredFields(); for (int i = 0; fields != null && i < fields.length; i++) { Field field = fields[i]; Reference reference = field.getAnnotation(Reference.class); if (reference == null) { continue; } ReferenceBean referenceConfig = new ReferenceBean(reference); this.validateReferenceBean(beanName, referenceConfig); } } return bean; }
Class<?> targetClass = advised.getTargetClass(); if (targetClass == null || targetClass.getAnnotation(Compensable.class) == null) { return;
private CompensableInvocation getCompensableInvocation(String identifier, Method method, Object[] args, Compensable annotation, Object target) { CompensableInvocationImpl invocation = new CompensableInvocationImpl(); invocation.setArgs(args); invocation.setIdentifier(identifier); invocation.setSimplified(annotation.simplified()); invocation.setMethod(method); // class-method Class<?> currentClazz = null; if (org.springframework.aop.framework.Advised.class.isInstance(target)) { org.springframework.aop.framework.Advised advised = (org.springframework.aop.framework.Advised) target; currentClazz = advised.getTargetClass(); } else { currentClazz = target.getClass(); } Method[] methodArray = currentClazz.getDeclaredMethods(); boolean confirmFlag = false; boolean cancelFlag = false; for (int i = 0; (confirmFlag == false || cancelFlag == false) && i < methodArray.length; i++) { Method element = methodArray[i]; if (element.getAnnotation(CompensableConfirm.class) != null) { confirmFlag = true; invocation.setConfirmableKey(identifier); } if (element.getAnnotation(CompensableCancel.class) != null) { cancelFlag = true; invocation.setCancellableKey(identifier); } } return invocation; }
private void switchAdvisorOrderIfNecessary(Object bean) { if (org.springframework.aop.framework.Advised.class.isInstance(bean) == false) { return; } org.springframework.aop.framework.Advised advised = (org.springframework.aop.framework.Advised) bean; Class<?> targetClass = advised.getTargetClass(); if (targetClass == null || targetClass.getAnnotation(Compensable.class) == null) { return; } // end-if (targetClass == null || targetClass.getAnnotation(Compensable.class) == null) Advisor[] advisors = advised.getAdvisors(); int compensableIndex = -1; int transactionIndex = -1; for (int i = 0; i < advisors.length; i++) { Advisor advisor = advisors[i]; Advice advice = advisor.getAdvice(); if (org.bytesoft.bytetcc.supports.spring.CompensableMethodInterceptor.class.isInstance(advice)) { compensableIndex = i; } else if (org.springframework.transaction.interceptor.TransactionInterceptor.class.isInstance(advice)) { transactionIndex = i; } } if (transactionIndex != -1 && compensableIndex != -1 && transactionIndex < compensableIndex) { Advisor advisor = advisors[transactionIndex]; advisors[transactionIndex] = advisors[compensableIndex]; advisors[compensableIndex] = advisor; } }
Class<?> beanClass; if (bean instanceof Advised){ // if EnhancerBySpringCGLIB beanClass = ((Advised)bean).getTargetClass(); }else{ beanClass = bean.getClass();