Top Description Fields Constructors Methods
org.springframework.aop.aspectj.annotation

public Class AspectJProxyFactory

extends ProxyCreatorSupport
Class Inheritance
Annotations
@SuppressWarnings:serial
Imports
java.util.List, .Map, java.util.concurrent.ConcurrentHashMap, org.aspectj.lang.reflect.PerClauseKind, org.springframework.aop.Advisor, org.springframework.aop.aspectj.AspectJProxyUtils, .SimpleAspectInstanceFactory, org.springframework.aop.framework.ProxyCreatorSupport, org.springframework.aop.support.AopUtils, org.springframework.core.annotation.AnnotationAwareOrderComparator, org.springframework.util.Assert, .ClassUtils

AspectJ-based proxy factory, allowing for programmatic building of proxies which include AspectJ aspects (code style as well annotation style).
Authors
Rob Harrop, Juergen Hoeller, Ramnivas Laddad
Since
2.0
See Also
addAspect(Object), addAspect(Class), getProxy(), getProxy(ClassLoader), org.springframework.aop.framework.ProxyFactory

Field Summary

Modifier and TypeField and Description
private static final Map<Class<?>, Object>
aspectCache

Cache for singleton aspect instances.

private final AspectJAdvisorFactory

Constructor Summary

AccessConstructor and Description
public
AspectJProxyFactory()

Create a new AspectJProxyFactory.

public
AspectJProxyFactory(Object
the target object to be proxied
target
)

Create a new AspectJProxyFactory.

public
AspectJProxyFactory(Class<?>... interfaces)

Create a new AspectJProxyFactory.

Method Summary

Modifier and TypeMethod and Description
private void
public void
addAspect(Object
the AspectJ aspect instance
aspectInstance
)

Add the supplied aspect instance to the chain.

public void
addAspect(Class<?>
the AspectJ aspect class
aspectClass
)

Add an aspect of the supplied type to the end of the advice chain.

private MetadataAwareAspectInstanceFactory
createAspectInstanceFactory(AspectMetadata am, Class<?> aspectClass, String aspectName)

Create a MetadataAwareAspectInstanceFactory for the supplied aspect type.

private AspectMetadata
createAspectMetadata(Class<?> aspectClass, String aspectName)

Create an AspectMetadata instance for the supplied aspect type.

public <T> T

Returns:

the new proxy
getProxy
()

Create a new proxy according to the settings in this factory.

public <T> T

Returns:

the new proxy
getProxy
(ClassLoader
the class loader to create the proxy with
classLoader
)

Create a new proxy according to the settings in this factory.

private Object
getSingletonAspectInstance(Class<?> aspectClass)

Get the singleton aspect instance for the supplied aspect type.

Inherited from org.springframework.aop.framework.ProxyCreatorSupport:
addListeneradviceChangedcreateAopProxygetAopProxyFactoryisActiveremoveListenersetAopProxyFactory

Field Detail

aspectCacheback to summary
private static final Map<Class<?>, Object> aspectCache

Cache for singleton aspect instances.

aspectFactoryback to summary
private final AspectJAdvisorFactory aspectFactory

Constructor Detail

AspectJProxyFactoryback to summary
public AspectJProxyFactory()

Create a new AspectJProxyFactory.

AspectJProxyFactoryback to summary
public AspectJProxyFactory(Object target)

Create a new AspectJProxyFactory.

Will proxy all interfaces that the given target implements.

Parameters
target:Object

the target object to be proxied

AspectJProxyFactoryback to summary
public AspectJProxyFactory(Class<?>... interfaces)

Create a new AspectJProxyFactory. No target, only interfaces. Must add interceptors.

Method Detail

addAdvisorsFromAspectInstanceFactoryback to summary
private void addAdvisorsFromAspectInstanceFactory(MetadataAwareAspectInstanceFactory instanceFactory)

Add all Advisors from the supplied MetadataAwareAspectInstanceFactory to the current chain. Exposes any special purpose Advisors if needed.

See Also
AspectJProxyUtils#makeAdvisorChainAspectJCapableIfNecessary(List)
addAspectback to summary
public void addAspect(Object aspectInstance)

Add 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.

Parameters
aspectInstance:Object

the AspectJ aspect instance

addAspectback to summary
public void addAspect(Class<?> aspectClass)

Add an aspect of the supplied type to the end of the advice chain.

Parameters
aspectClass:Class<?>

the AspectJ aspect class

createAspectInstanceFactoryback to summary
private MetadataAwareAspectInstanceFactory createAspectInstanceFactory(AspectMetadata am, Class<?> aspectClass, String aspectName)

Create a MetadataAwareAspectInstanceFactory for the supplied aspect type. If the aspect type has no per clause, then a SingletonMetadataAwareAspectInstanceFactory is returned, otherwise a PrototypeAspectInstanceFactory is returned.

createAspectMetadataback to summary
private AspectMetadata createAspectMetadata(Class<?> aspectClass, String aspectName)

Create an AspectMetadata instance for the supplied aspect type.

getProxyback to summary
public <T> T getProxy()

Create a new proxy according to the settings in this factory.

Can be called repeatedly. Effect will vary if we've added or removed interfaces. Can add and remove interceptors.

Uses a default class loader: Usually, the thread context class loader (if necessary for proxy creation).

Returns:T

the new proxy

Annotations
@SuppressWarnings:unchecked
getProxyback to summary
public <T> T getProxy(ClassLoader classLoader)

Create a new proxy according to the settings in this factory.

Can be called repeatedly. Effect will vary if we've added or removed interfaces. Can add and remove interceptors.

Uses the given class loader (if necessary for proxy creation).

Parameters
classLoader:ClassLoader

the class loader to create the proxy with

Returns:T

the new proxy

Annotations
@SuppressWarnings:unchecked
getSingletonAspectInstanceback to summary
private Object getSingletonAspectInstance(Class<?> aspectClass)

Get the singleton aspect instance for the supplied aspect type. An instance is created if one cannot be found in the instance cache.