/** * Create a new SimpleMetadataAwareAspectInstanceFactory for the given aspect class. * @param aspectClass the aspect class * @param aspectName the aspect name */ public SimpleMetadataAwareAspectInstanceFactory(Class<?> aspectClass, String aspectName) { super(aspectClass); this.metadata = new AspectMetadata(aspectClass, aspectName); }
/** * Create a new SingletonMetadataAwareAspectInstanceFactory for the given aspect. * @param aspectInstance the singleton aspect instance * @param aspectName the name of the aspect */ public SingletonMetadataAwareAspectInstanceFactory(Object aspectInstance, String aspectName) { super(aspectInstance); this.metadata = new AspectMetadata(aspectInstance.getClass(), aspectName); }
private void testIllegalInstantiationModel(Class<?> c) throws AopConfigException { new AspectMetadata(c, "someBean"); }
@Override public AspectMetadata getAspectMetadata() { return new AspectMetadata(PerTypeWithinAspect.class, "perTypeWithin"); }
/** * Create an {@link AspectMetadata} instance for the supplied aspect type. */ private AspectMetadata createAspectMetadata(Class<?> aspectClass, String aspectName) { AspectMetadata am = new AspectMetadata(aspectClass, aspectName); if (!am.getAjType().isAspect()) { throw new IllegalArgumentException("Class [" + aspectClass.getName() + "] is not a valid aspect type"); } return am; }
/** * Create a BeanFactoryAspectInstanceFactory, providing a type that AspectJ should * introspect to create AJType metadata. Use if the BeanFactory may consider the type * to be a subclass (as when using CGLIB), and the information should relate to a superclass. * @param beanFactory the BeanFactory to obtain instance(s) from * @param name the name of the bean * @param type the type that should be introspected by AspectJ * ({@code null} indicates resolution through {@link BeanFactory#getType} via the bean name) */ public BeanFactoryAspectInstanceFactory(BeanFactory beanFactory, String name, @Nullable Class<?> type) { Assert.notNull(beanFactory, "BeanFactory must not be null"); Assert.notNull(name, "Bean name must not be null"); this.beanFactory = beanFactory; this.name = name; Class<?> resolvedType = type; if (type == null) { resolvedType = beanFactory.getType(name); Assert.notNull(resolvedType, "Unresolvable bean type - explicitly specify the aspect class"); } this.aspectMetadata = new AspectMetadata(resolvedType, name); }
@Test(expected = IllegalArgumentException.class) public void testNotAnAspect() { new AspectMetadata(String.class,"someBean"); }
AspectMetadata amd = new AspectMetadata(beanType, beanName); if (amd.getAjType().getPerClause().getKind() == PerClauseKind.SINGLETON) { MetadataAwareAspectInstanceFactory factory =
@Test public void testSingletonAspect() { AspectMetadata am = new AspectMetadata(ExceptionAspect.class,"someBean"); assertFalse(am.isPerThisOrPerTarget()); assertSame(Pointcut.TRUE, am.getPerClausePointcut()); assertEquals(PerClauseKind.SINGLETON, am.getAjType().getPerClause().getKind()); }
@Test public void testPerTargetAspect() { AspectMetadata am = new AspectMetadata(PerTargetAspect.class,"someBean"); assertTrue(am.isPerThisOrPerTarget()); assertNotSame(Pointcut.TRUE, am.getPerClausePointcut()); assertEquals(PerClauseKind.PERTARGET, am.getAjType().getPerClause().getKind()); }
@Test public void testPerThisAspect() { AspectMetadata am = new AspectMetadata(PerThisAspect.class,"someBean"); assertTrue(am.isPerThisOrPerTarget()); assertNotSame(Pointcut.TRUE, am.getPerClausePointcut()); assertEquals(PerClauseKind.PERTHIS, am.getAjType().getPerClause().getKind()); } }
@Test public void testPerTargetAspect() throws SecurityException, NoSuchMethodException { ClassPathXmlApplicationContext bf = newContext("pertarget.xml"); ITestBean adrian1 = (ITestBean) bf.getBean("adrian"); assertTrue(AopUtils.isAopProxy(adrian1)); // Does not trigger advice or count int explicitlySetAge = 25; adrian1.setAge(explicitlySetAge); assertEquals("Setter does not initiate advice", explicitlySetAge, adrian1.getAge()); // Fire aspect AspectMetadata am = new AspectMetadata(PerTargetAspect.class, "someBean"); assertTrue(am.getPerClausePointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null)); adrian1.getSpouse(); assertEquals("Advice has now been instantiated", 0, adrian1.getAge()); adrian1.setAge(11); assertEquals("Any int setter increments", 2, adrian1.getAge()); adrian1.setName("Adrian"); //assertEquals("Any other setter does not increment", 2, adrian1.getAge()); ITestBean adrian2 = (ITestBean) bf.getBean("adrian"); assertNotSame(adrian1, adrian2); assertTrue(AopUtils.isAopProxy(adrian1)); assertEquals(34, adrian2.getAge()); adrian2.getSpouse(); assertEquals("Aspect now fired", 0, adrian2.getAge()); assertEquals(1, adrian2.getAge()); assertEquals(2, adrian2.getAge()); assertEquals(3, adrian1.getAge()); }
/** * Create a new SimpleMetadataAwareAspectInstanceFactory for the given aspect class. * @param aspectClass the aspect class * @param aspectName the aspect name */ public SimpleMetadataAwareAspectInstanceFactory(Class<?> aspectClass, String aspectName) { super(aspectClass); this.metadata = new AspectMetadata(aspectClass, aspectName); }
/** * Create a new SimpleMetadataAwareAspectInstanceFactory for the given aspect class. * @param aspectClass the aspect class * @param aspectName the aspect name */ public SimpleMetadataAwareAspectInstanceFactory(Class<?> aspectClass, String aspectName) { super(aspectClass); this.metadata = new AspectMetadata(aspectClass, aspectName); }
/** * Create a new SingletonMetadataAwareAspectInstanceFactory for the given aspect. * @param aspectInstance the singleton aspect instance * @param aspectName the name of the aspect */ public SingletonMetadataAwareAspectInstanceFactory(Object aspectInstance, String aspectName) { super(aspectInstance); this.metadata = new AspectMetadata(aspectInstance.getClass(), aspectName); }
/** * Create a new SingletonMetadataAwareAspectInstanceFactory for the given aspect. * @param aspectInstance the singleton aspect instance * @param aspectName the name of the aspect */ public SingletonMetadataAwareAspectInstanceFactory(Object aspectInstance, String aspectName) { super(aspectInstance); this.metadata = new AspectMetadata(aspectInstance.getClass(), aspectName); }
/** * Create a BeanFactoryAspectInstanceFactory, providing a type that AspectJ should * introspect to create AJType metadata. Use if the BeanFactory may consider the type * to be a subclass (as when using CGLIB), and the information should relate to a superclass. * @param beanFactory BeanFactory to obtain instance(s) from * @param name the name of the bean * @param type the type that should be introspected by AspectJ */ public BeanFactoryAspectInstanceFactory(BeanFactory beanFactory, String name, Class<?> type) { Assert.notNull(beanFactory, "BeanFactory must not be null"); Assert.notNull(name, "Bean name must not be null"); this.beanFactory = beanFactory; this.name = name; this.aspectMetadata = new AspectMetadata(type, name); }
/** * Create an {@link AspectMetadata} instance for the supplied aspect type. */ private AspectMetadata createAspectMetadata(Class<?> aspectClass, String aspectName) { AspectMetadata am = new AspectMetadata(aspectClass, aspectName); if (!am.getAjType().isAspect()) { throw new IllegalArgumentException("Class [" + aspectClass.getName() + "] is not a valid aspect type"); } return am; }
/** * Create an {@link AspectMetadata} instance for the supplied aspect type. */ private AspectMetadata createAspectMetadata(Class<?> aspectClass, String aspectName) { AspectMetadata am = new AspectMetadata(aspectClass, aspectName); if (!am.getAjType().isAspect()) { throw new IllegalArgumentException("Class [" + aspectClass.getName() + "] is not a valid aspect type"); } return am; }
/** * Create a BeanFactoryAspectInstanceFactory, providing a type that AspectJ should * introspect to create AJType metadata. Use if the BeanFactory may consider the type * to be a subclass (as when using CGLIB), and the information should relate to a superclass. * @param beanFactory the BeanFactory to obtain instance(s) from * @param name the name of the bean * @param type the type that should be introspected by AspectJ * ({@code null} indicates resolution through {@link BeanFactory#getType} via the bean name) */ public BeanFactoryAspectInstanceFactory(BeanFactory beanFactory, String name, @Nullable Class<?> type) { Assert.notNull(beanFactory, "BeanFactory must not be null"); Assert.notNull(name, "Bean name must not be null"); this.beanFactory = beanFactory; this.name = name; Class<?> resolvedType = type; if (type == null) { resolvedType = beanFactory.getType(name); Assert.notNull(resolvedType, "Unresolvable bean type - explicitly specify the aspect class"); } this.aspectMetadata = new AspectMetadata(resolvedType, name); }