Update of /cvsroot/springframework/spring/tiger/src/org/springframework/aop/aspectj/annotation
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4412/tiger/src/org/springframework/aop/aspectj/annotation
Modified Files:
AspectJProxyFactory.java
Log Message:
Added addAspect(Object) to AspectJProxyFactory
Index: AspectJProxyFactory.java
===================================================================
RCS file: /cvsroot/springframework/spring/tiger/src/org/springframework/aop/aspectj/annotation/AspectJProxyFactory.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** AspectJProxyFactory.java 19 Apr 2006 14:56:23 -0000 1.1
--- AspectJProxyFactory.java 20 Apr 2006 13:06:27 -0000 1.2
***************
*** 45,48 ****
--- 45,53 ----
/**
+ * The {@link AspectJAdvisorFactory} used by this instance.
+ */
+ private final AspectJAdvisorFactory aspectFactory = new ReflectiveAspectJAdvisorFactory();
+
+ /**
* Caches singleton aspect instances.
*/
***************
*** 98,107 ****
/**
* Adds an aspect of the supplied type to the end of the advice chain.
*/
public void addAspect(Class aspectType) {
-
String beanName = aspectType.getName();
! AspectJAdvisorFactory aspectFactory = new ReflectiveAspectJAdvisorFactory();
AspectMetadata am = new AspectMetadata(aspectType, beanName);
--- 103,149 ----
/**
+ * Adds the supplied aspect instance to the chain. The type of the aspect instance
+ * supplied must be a singleton aspect. True singleton lifecycle is not honoured when
+ * using this method - the caller is responsible for managing the lifecycle of any
+ * aspects added in this way.
+ */
+ public void addAspect(Object aspect) {
+ Class aspectType = aspect.getClass();
+ String beanName = aspectType.getName();
+ AspectMetadata am = createAspectMetadata(aspectType, beanName);
+ if (am.getAjType().getPerClause().getKind() != PerClauseKind.SINGLETON) {
+ throw new IllegalArgumentException("Aspect type '" + aspectType.getName() + "' is not a singleton aspect.");
+ }
+ MetadataAwareAspectInstanceFactory instanceFactory = new SingletonMetadataAwareAspectInstanceFactory(aspect, beanName);
+ addAdvisorsFromAspectInstanceFactory(instanceFactory);
+ }
+
+ /**
* Adds an aspect of the supplied type to the end of the advice chain.
*/
public void addAspect(Class aspectType) {
String beanName = aspectType.getName();
! AspectMetadata am = createAspectMetadata(aspectType, beanName);
! MetadataAwareAspectInstanceFactory instanceFactory = createAspectInstanceFactory(am, aspectType, beanName);
! addAdvisorsFromAspectInstanceFactory(instanceFactory);
! }
!
! /**
! * Adds all {@link Advisor Advisors} from the supplied {@link MetadataAwareAspectInstanceFactory} to
! * the curren chain. Exposes any special purpose {@link Advisor Advisors} if needed.
! * @see #makeAdvisorChainAspectJCapableIfNecessary()
! */
! private void addAdvisorsFromAspectInstanceFactory(MetadataAwareAspectInstanceFactory instanceFactory) {
! List advisors = this.aspectFactory.getAdvisors(instanceFactory);
! this.addAllAdvisors((Advisor[]) advisors.toArray(new Advisor[advisors.size()]));
!
! makeAdvisorChainAspectJCapableIfNecessary();
! }
!
! /**
! * Creates an {@link AspectMetadata} instance for the supplied aspect type.
! * @throws IllegalArgumentException if the supplied {@link Class} is not a valid aspect type.
! */
! private AspectMetadata createAspectMetadata(Class aspectType, String beanName) {
AspectMetadata am = new AspectMetadata(aspectType, beanName);
***************
*** 110,119 ****
}
! MetadataAwareAspectInstanceFactory instanceFactory = createAspectInstanceFactory(am, aspectType, beanName);
!
! List advisors = aspectFactory.getAdvisors(instanceFactory);
! this.addAllAdvisors((Advisor[]) advisors.toArray(new Advisor[advisors.size()]));
!
! makeAdvisorChainAspectJCapableIfNecessary();
}
--- 152,156 ----
}
! return am;
}
|