@Override public void addAdvisor(Advisor advisor) { int pos = this.advisors.size(); addAdvisor(pos, advisor); }
public void addAdvisor(int pos, Advisor advisor) throws AopConfigException { if (advisor instanceof IntroductionAdvisor) { addAdvisor(pos, (IntroductionAdvisor) advisor); } else { addAdvisorInternal(pos, advisor); } }
@Override public boolean replaceAdvisor(Advisor a, Advisor b) throws AopConfigException { Assert.notNull(a, "Advisor a must not be null"); Assert.notNull(b, "Advisor b must not be null"); int index = indexOf(a); if (index == -1) { return false; } removeAdvisor(index); addAdvisor(index, b); return true; }
@Override public void addAdvisor(int pos, Advisor advisor) throws AopConfigException { if (advisor instanceof IntroductionAdvisor) { validateIntroductionAdvisor((IntroductionAdvisor) advisor); } addAdvisorInternal(pos, advisor); }
/** * Cannot add introductions this way unless the advice implements IntroductionInfo. */ @Override public void addAdvice(int pos, Advice advice) throws AopConfigException { Assert.notNull(advice, "Advice must not be null"); if (advice instanceof IntroductionInfo) { // We don't need an IntroductionAdvisor for this kind of introduction: // It's fully self-describing. addAdvisor(pos, new DefaultIntroductionAdvisor(advice, (IntroductionInfo) advice)); } else if (advice instanceof DynamicIntroductionAdvice) { // We need an IntroductionAdvisor for this kind of introduction. throw new AopConfigException("DynamicIntroductionAdvice may only be added as part of IntroductionAdvisor"); } else { addAdvisor(pos, new DefaultPointcutAdvisor(advice)); } }
Advisor[] advisor = buildAdvisors(beanName, getAdvicesAndAdvisorsForBean(null, null, null)); for (Advisor avr : advisor) { advised.addAdvisor(0, avr);
@Override public void addAdvisor(Advisor advisor) { int pos = this.advisors.size(); addAdvisor(pos, advisor); }
public void addAdvisor(Advisor advisor) { int pos = this.advisors.size(); addAdvisor(pos, advisor); }
@Override public boolean replaceAdvisor(Advisor a, Advisor b) throws AopConfigException { Assert.notNull(a, "Advisor a must not be null"); Assert.notNull(b, "Advisor b must not be null"); int index = indexOf(a); if (index == -1) { return false; } removeAdvisor(index); addAdvisor(index, b); return true; }
@Override public boolean replaceAdvisor(Advisor a, Advisor b) throws AopConfigException { Assert.notNull(a, "Advisor a must not be null"); Assert.notNull(b, "Advisor b must not be null"); int index = indexOf(a); if (index == -1) { return false; } removeAdvisor(index); addAdvisor(index, b); return true; }
/** * Take interfaces and ProxyConfig configuration from the * other AdvisedSupport, but allow substitution of a fresh * TargetSource and interceptor chain * @param other other AdvisedSupport object to take * interfaces and ProxyConfig superclass configuration from * @param ts new TargetSource * @param pAdvisors new Advisor chain */ protected void copyConfigurationFrom(AdvisedSupport other, TargetSource ts, List pAdvisors) { copyFrom(other); this.targetSource = ts; setInterfaces((Class[]) other.interfaces.toArray(new Class[other.interfaces.size()])); this.advisors = new LinkedList(); for (int i = 0; i < pAdvisors.size(); i++) { Advisor advice = (Advisor) pAdvisors.get(i); addAdvisor(advice); } }
/** * Cannot add introductions this way unless the advice implements IntroductionInfo. */ @Override public void addAdvice(int pos, Advice advice) throws AopConfigException { Assert.notNull(advice, "Advice must not be null"); if (advice instanceof IntroductionInfo) { // We don't need an IntroductionAdvisor for this kind of introduction: // It's fully self-describing. addAdvisor(pos, new DefaultIntroductionAdvisor(advice, (IntroductionInfo) advice)); } else if (advice instanceof DynamicIntroductionAdvice) { // We need an IntroductionAdvisor for this kind of introduction. throw new AopConfigException("DynamicIntroductionAdvice may only be added as part of IntroductionAdvisor"); } else { addAdvisor(pos, new DefaultPointcutAdvisor(advice)); } }
/** * Cannot add introductions this way unless the advice implements IntroductionInfo. */ @Override public void addAdvice(int pos, Advice advice) throws AopConfigException { Assert.notNull(advice, "Advice must not be null"); if (advice instanceof IntroductionInfo) { // We don't need an IntroductionAdvisor for this kind of introduction: // It's fully self-describing. addAdvisor(pos, new DefaultIntroductionAdvisor(advice, (IntroductionInfo) advice)); } else if (advice instanceof DynamicIntroductionAdvice) { // We need an IntroductionAdvisor for this kind of introduction. throw new AopConfigException("DynamicIntroductionAdvice may only be added as part of IntroductionAdvisor"); } else { addAdvisor(pos, new DefaultPointcutAdvisor(advice)); } }
/** * Cannot add introductions this way unless the advice implements IntroductionInfo. */ public void addAdvice(int pos, Advice advice) throws AopConfigException { if (advice instanceof Interceptor && !(advice instanceof MethodInterceptor)) { throw new AopConfigException(getClass().getName() + " only handles AOP Alliance MethodInterceptors"); } if (advice instanceof IntroductionInfo) { // We don't need an IntroductionAdvisor for this kind of introduction: // it's fully self-describing addAdvisor(pos, new DefaultIntroductionAdvisor(advice, (IntroductionInfo) advice)); } else if (advice instanceof DynamicIntroductionAdvice) { // We need an IntroductionAdvisor for this kind of introduction throw new AopConfigException("DynamicIntroductionAdvice may only be added as part of IntroductionAdvisor"); } else { addAdvisor(pos, new DefaultPointcutAdvisor(advice)); } }
/** * Replace the given advisor. * <p><b>NB:</b> If the advisor is an IntroductionAdvisor * and the replacement is not or implements different interfaces, * the proxy will need to be re-obtained or the old interfaces * won't be supported and the new interface won't be implemented. * @param a advisor to replace * @param b advisor to replace it with * @return whether it was replaced. If the advisor wasn't found in the * list of advisors, this method returns false and does nothing. */ public final boolean replaceAdvisor(Advisor a, Advisor b) throws AopConfigException { int index = indexOf(a); if (index == -1 || b == null) { return false; } removeAdvisor(index); addAdvisor(index, b); return true; }
Class<?>[] classes = {B.class}; AdvisedSupport config = new AdvisedSupport(classes); try { config.setTargetSource(((Advised) b).getTargetSource()); } catch (Exception e) { e.printStackTrace(); } for (Advisor advisor : ((Advised) b).getAdvisors()) { Advice advice = advisor.getAdvice(); if ((advice instanceof AbstractAspectJAdvice) && "advice.A2".equals( ((AbstractAspectJAdvice) advice).getAspectName())) { // Do not add A2 advisor } else { config.addAdvisor(advisor); } } DefaultAopProxyFactory factory = new DefaultAopProxyFactory(); B newB = (B)factory.createAopProxy(config).getProxy();