Top Description Inners Fields Constructors Methods
org.springframework.aop.interceptor

public abstract Class ExposeBeanNameAdvisors

extends Object
Class Inheritance
Imports
org.aopalliance.intercept.MethodInterceptor, .MethodInvocation, org.springframework.aop.Advisor, .ProxyMethodInvocation, org.springframework.aop.support.DefaultIntroductionAdvisor, .DefaultPointcutAdvisor, .DelegatingIntroductionInterceptor, org.springframework.beans.factory.NamedBean, org.springframework.lang.Nullable

Convenient methods for creating advisors that may be used when autoproxying beans created with the Spring IoC container, binding the bean name to the current invocation. May support a bean() pointcut designator with AspectJ.

Typically used in Spring auto-proxying, where the bean name is known at proxy creation time.

Authors
Rod Johnson, Juergen Hoeller
Since
2.0
See Also
org.springframework.beans.factory.NamedBean

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
ExposeBeanNameAdvisors.ExposeBeanNameInterceptor

Interceptor that exposes the specified bean name as invocation attribute.

private static class
ExposeBeanNameAdvisors.ExposeBeanNameIntroduction

Introduction that exposes the specified bean name as invocation attribute.

Field Summary

Modifier and TypeField and Description
private static final String
BEAN_NAME_ATTRIBUTE

Binding for the bean name of the bean which is currently being invoked in the ReflectiveMethodInvocation userAttributes Map.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static Advisor
createAdvisorIntroducingNamedBean(String
the bean name to expose
beanName
)

Create a new advisor that will expose the given bean name, introducing the NamedBean interface to make the bean name accessible without forcing the target object to be aware of this Spring IoC concept.

public static Advisor
createAdvisorWithoutIntroduction(String
bean name to expose
beanName
)

Create a new advisor that will expose the given bean name, with no introduction.

public static String

Returns:

the bean name (never null)
getBeanName
()

Find the bean name for the current invocation.

public static String

Returns:

the bean name (never null)
getBeanName
(MethodInvocation
the MethodInvocation that should contain the bean name as an attribute
mi
)

Find the bean name for the given invocation.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BEAN_NAME_ATTRIBUTEback to summary
private static final String BEAN_NAME_ATTRIBUTE

Binding for the bean name of the bean which is currently being invoked in the ReflectiveMethodInvocation userAttributes Map.

Constructor Detail

ExposeBeanNameAdvisorsback to summary
public ExposeBeanNameAdvisors()

Method Detail

createAdvisorIntroducingNamedBeanback to summary
public static Advisor createAdvisorIntroducingNamedBean(String beanName)

Create a new advisor that will expose the given bean name, introducing the NamedBean interface to make the bean name accessible without forcing the target object to be aware of this Spring IoC concept.

Parameters
beanName:String

the bean name to expose

createAdvisorWithoutIntroductionback to summary
public static Advisor createAdvisorWithoutIntroduction(String beanName)

Create a new advisor that will expose the given bean name, with no introduction.

Parameters
beanName:String

bean name to expose

getBeanNameback to summary
public static String getBeanName() throws IllegalStateException

Find the bean name for the current invocation. Assumes that an ExposeBeanNameAdvisor has been included in the interceptor chain, and that the invocation is exposed with ExposeInvocationInterceptor.

Returns:String

the bean name (never null)

Exceptions
IllegalStateException:
if the bean name has not been exposed
getBeanNameback to summary
public static String getBeanName(MethodInvocation mi) throws IllegalStateException

Find the bean name for the given invocation. Assumes that an ExposeBeanNameAdvisor has been included in the interceptor chain.

Parameters
mi:MethodInvocation

the MethodInvocation that should contain the bean name as an attribute

Returns:String

the bean name (never null)

Exceptions
IllegalStateException:
if the bean name has not been exposed
org.springframework.aop.interceptor back to summary

private Class ExposeBeanNameAdvisors.ExposeBeanNameInterceptor

extends Object
implements MethodInterceptor
Class Inheritance
  • java.lang.Object
  • org.springframework.aop.interceptor.ExposeBeanNameAdvisors.ExposeBeanNameInterceptor
All Implemented Interfaces
org.aopalliance.intercept.MethodInterceptor, org.aopalliance.intercept.Interceptor, org.aopalliance.aop.Advice

Interceptor that exposes the specified bean name as invocation attribute.

Field Summary

Modifier and TypeField and Description
private final String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Object
invoke(MethodInvocation
the method invocation joinpoint
mi
)

Implements org.aopalliance.intercept.MethodInterceptor.invoke.

Implement this method to perform extra treatments before and after the invocation.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

beanNameback to summary
private final String beanName

Constructor Detail

ExposeBeanNameInterceptorback to summary
public ExposeBeanNameInterceptor(String beanName)

Method Detail

invokeback to summary
public Object invoke(MethodInvocation mi) throws Throwable

Implements org.aopalliance.intercept.MethodInterceptor.invoke.

Doc from org.aopalliance.intercept.MethodInterceptor.invoke.

Implement this method to perform extra treatments before and after the invocation. Polite implementations would certainly like to invoke Joinpoint#proceed().

Parameters
mi:MethodInvocation

the method invocation joinpoint

Returns:Object

the result of the call to Joinpoint#proceed(); might be intercepted by the interceptor

Annotations
@Override
@Nullable
Exceptions
Throwable:
if the interceptors or the target object throws an exception
org.springframework.aop.interceptor back to summary

private Class ExposeBeanNameAdvisors.ExposeBeanNameIntroduction

extends DelegatingIntroductionInterceptor
implements NamedBean
Class Inheritance
All Implemented Interfaces
org.springframework.beans.factory.NamedBean
Annotations
@SuppressWarnings:serial

Introduction that exposes the specified bean name as invocation attribute.

Field Summary

Modifier and TypeField and Description
private final String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public String
getBeanName()

Implements org.springframework.beans.factory.NamedBean.getBeanName.

Return the name of this bean in a Spring bean factory, if known.
public Object
invoke(MethodInvocation
the method invocation joinpoint
mi
)

Overrides org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke.

Implements org.aopalliance.intercept.MethodInterceptor.invoke.

Subclasses may need to override this if they want to perform custom behaviour in around advice.
Inherited from org.springframework.aop.support.DelegatingIntroductionInterceptor:
doProceed

Field Detail

beanNameback to summary
private final String beanName

Constructor Detail

ExposeBeanNameIntroductionback to summary
public ExposeBeanNameIntroduction(String beanName)

Method Detail

getBeanNameback to summary
public String getBeanName()

Implements org.springframework.beans.factory.NamedBean.getBeanName.

Doc from org.springframework.beans.factory.NamedBean.getBeanName.

Return the name of this bean in a Spring bean factory, if known.

Annotations
@Override
invokeback to summary
public Object invoke(MethodInvocation mi) throws Throwable

Overrides org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke.

Implements org.aopalliance.intercept.MethodInterceptor.invoke.

Doc from org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke.

Subclasses may need to override this if they want to perform custom behaviour in around advice. However, subclasses should invoke this method, which handles introduced interfaces and forwarding to the target.

Parameters
mi:MethodInvocation

Doc from org.aopalliance.intercept.MethodInterceptor.invoke.

the method invocation joinpoint

Returns:Object

Doc from org.aopalliance.intercept.MethodInterceptor.invoke.

the result of the call to Joinpoint#proceed(); might be intercepted by the interceptor

Annotations
@Override
@Nullable
Exceptions
Throwable:

Doc from org.aopalliance.intercept.MethodInterceptor.invoke.

if the interceptors or the target object throws an exception