use of org.springframework.aop.Advisor in project spring-framework by spring-projects.
the class PersistenceExceptionTranslationPostProcessorTests method checkWillTranslateExceptions.
protected void checkWillTranslateExceptions(Object o) {
assertTrue(o instanceof Advised);
Advised a = (Advised) o;
for (Advisor advisor : a.getAdvisors()) {
if (advisor instanceof PersistenceExceptionTranslationAdvisor) {
return;
}
}
fail("No translation");
}
use of org.springframework.aop.Advisor in project spring-framework by spring-projects.
the class AdvisedSupport method copyConfigurationFrom.
/**
* Copy the AOP configuration from the given AdvisedSupport object,
* but allow substitution of a fresh TargetSource and a given interceptor chain.
* @param other the AdvisedSupport object to take proxy configuration from
* @param targetSource the new TargetSource
* @param advisors the Advisors for the chain
*/
protected void copyConfigurationFrom(AdvisedSupport other, TargetSource targetSource, List<Advisor> advisors) {
copyFrom(other);
this.targetSource = targetSource;
this.advisorChainFactory = other.advisorChainFactory;
this.interfaces = new ArrayList<>(other.interfaces);
for (Advisor advisor : advisors) {
if (advisor instanceof IntroductionAdvisor) {
validateIntroductionAdvisor((IntroductionAdvisor) advisor);
}
Assert.notNull(advisor, "Advisor must not be null");
this.advisors.add(advisor);
}
updateAdvisorArray();
adviceChanged();
}
use of org.springframework.aop.Advisor in project spring-framework by spring-projects.
the class ProxyFactoryBean method freshAdvisorChain.
/**
* Return an independent advisor chain.
* We need to do this every time a new prototype instance is returned,
* to return distinct instances of prototype Advisors and Advices.
*/
private List<Advisor> freshAdvisorChain() {
Advisor[] advisors = getAdvisors();
List<Advisor> freshAdvisors = new ArrayList<>(advisors.length);
for (Advisor advisor : advisors) {
if (advisor instanceof PrototypePlaceholderAdvisor) {
PrototypePlaceholderAdvisor pa = (PrototypePlaceholderAdvisor) advisor;
if (logger.isDebugEnabled()) {
logger.debug("Refreshing bean named '" + pa.getBeanName() + "'");
}
// from a getBean() lookup
if (this.beanFactory == null) {
throw new IllegalStateException("No BeanFactory available anymore (probably due to serialization) " + "- cannot resolve prototype advisor '" + pa.getBeanName() + "'");
}
Object bean = this.beanFactory.getBean(pa.getBeanName());
Advisor refreshedAdvisor = namedBeanToAdvisor(bean);
freshAdvisors.add(refreshedAdvisor);
} else {
// Add the shared instance.
freshAdvisors.add(advisor);
}
}
return freshAdvisors;
}
use of org.springframework.aop.Advisor in project spring-framework by spring-projects.
the class PerThisAspect method testIntroductionWithArgumentBinding.
/* prereq AspectJ 1.6.7
@Test
public void testIntroductionBasedOnAnnotationMatch_Spr5307() {
AnnotatedTarget target = new AnnotatedTargetImpl();
List<Advisor> advisors = getFixture().getAdvisors(
new SingletonMetadataAwareAspectInstanceFactory(new MakeAnnotatedTypeModifiable(),"someBean"));
Object proxy = createProxy(target,
advisors,
AnnotatedTarget.class);
System.out.println(advisors.get(1));
assertTrue(proxy instanceof Lockable);
Lockable lockable = (Lockable)proxy;
lockable.locked();
}
*/
// TODO: Why does this test fail? It hasn't been run before, so it maybe never actually passed...
@Test
@Ignore
public void testIntroductionWithArgumentBinding() {
TestBean target = new TestBean();
List<Advisor> advisors = getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new MakeITestBeanModifiable(), "someBean"));
advisors.addAll(getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new MakeLockable(), "someBean")));
Modifiable modifiable = (Modifiable) createProxy(target, advisors, ITestBean.class);
assertThat(modifiable, instanceOf(Modifiable.class));
Lockable lockable = (Lockable) modifiable;
assertFalse(lockable.locked());
ITestBean itb = (ITestBean) modifiable;
assertFalse(modifiable.isModified());
int oldAge = itb.getAge();
itb.setAge(oldAge + 1);
assertTrue(modifiable.isModified());
modifiable.acceptChanges();
assertFalse(modifiable.isModified());
itb.setAge(itb.getAge());
assertFalse("Setting same value does not modify", modifiable.isModified());
itb.setName("And now for something completely different");
assertTrue(modifiable.isModified());
lockable.lock();
assertTrue(lockable.locked());
try {
itb.setName("Else");
fail("Should be locked");
} catch (IllegalStateException ex) {
// Ok
}
lockable.unlock();
itb.setName("Tony");
}
use of org.springframework.aop.Advisor in project spring-framework by spring-projects.
the class PerThisAspect method testMultiplePerTargetAspectsWithOrderAnnotation.
@Test
public void testMultiplePerTargetAspectsWithOrderAnnotation() throws SecurityException, NoSuchMethodException {
TestBean target = new TestBean();
int realAge = 65;
target.setAge(realAge);
List<Advisor> advisors = new LinkedList<>();
PerTargetAspectWithOrderAnnotation10 aspect1 = new PerTargetAspectWithOrderAnnotation10();
aspect1.count = 100;
advisors.addAll(getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(aspect1, "someBean1")));
PerTargetAspectWithOrderAnnotation5 aspect2 = new PerTargetAspectWithOrderAnnotation5();
advisors.addAll(getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(aspect2, "someBean2")));
Collections.sort(advisors, new OrderComparator());
TestBean itb = (TestBean) createProxy(target, advisors, TestBean.class);
assertEquals("Around advice must NOT apply", realAge, itb.getAge());
// Hit the method in the per clause to instantiate the aspect
itb.getSpouse();
assertEquals("Around advice must apply", 0, itb.getAge());
assertEquals("Around advice must apply", 1, itb.getAge());
}
Aggregations