本文整理汇总了Java中org.springframework.aop.support.DelegatingIntroductionInterceptor类的典型用法代码示例。如果您正苦于以下问题:Java DelegatingIntroductionInterceptor类的具体用法?Java DelegatingIntroductionInterceptor怎么用?Java DelegatingIntroductionInterceptor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DelegatingIntroductionInterceptor类属于org.springframework.aop.support包,在下文中一共展示了DelegatingIntroductionInterceptor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import org.springframework.aop.support.DelegatingIntroductionInterceptor; //导入依赖的package包/类
/**
* Helper method to create a {@link PermissionCheckedValue} from an existing <code>Object</code>.
*
* @param object the <code>Object</code> to proxy
* @return a <code>Object</code> of the same type but including the
* {@link PermissionCheckedValue} interface
*/
@SuppressWarnings("unchecked")
public static final <T extends Object> T create(T object)
{
// Create the mixin
DelegatingIntroductionInterceptor mixin = new PermissionCheckedValueMixin();
// Create the advisor
IntroductionAdvisor advisor = new DefaultIntroductionAdvisor(mixin, PermissionCheckedValue.class);
// Proxy
ProxyFactory pf = new ProxyFactory(object);
pf.addAdvisor(advisor);
Object proxiedObject = pf.getProxy();
// Done
return (T) proxiedObject;
}
示例2: create
import org.springframework.aop.support.DelegatingIntroductionInterceptor; //导入依赖的package包/类
/**
* Helper method to create a {@link PermissionCheckedCollection} from an existing <code>Collection</code>
*
* @param <TT> the type of the <code>Collection</code>
* @param collection the <code>Collection</code> to proxy
* @param isCutOff <tt>true</tt> if permission checking was cut off before completion
* @param sizeUnchecked number of entries from the original collection that were not checked
* @param sizeOriginal number of entries in the original, pre-checked collection
* @return a <code>Collection</code> of the same type but including the
* {@link PermissionCheckedCollection} interface
*/
@SuppressWarnings("unchecked")
public static final <TT> Collection<TT> create(
Collection<TT> collection,
boolean isCutOff, int sizeUnchecked, int sizeOriginal)
{
// Create the mixin
DelegatingIntroductionInterceptor mixin = new PermissionCheckedCollectionMixin<Integer>(
isCutOff,
sizeUnchecked,
sizeOriginal
);
// Create the advisor
IntroductionAdvisor advisor = new DefaultIntroductionAdvisor(mixin, PermissionCheckedCollection.class);
// Proxy
ProxyFactory pf = new ProxyFactory(collection);
pf.addAdvisor(advisor);
Object proxiedObject = pf.getProxy();
// Done
return (Collection<TT>) proxiedObject;
}
示例3: create
import org.springframework.aop.support.DelegatingIntroductionInterceptor; //导入依赖的package包/类
/**
* Helper method to create a {@link PermissionCheckCollection} from an existing <code>Collection</code>
*
* @param <TT> the type of the <code>Collection</code>
* @param collection the <code>Collection</code> to proxy
* @param targetResultCount the desired number of results or default to the collection size
* @param cutOffAfterTimeMs the number of milliseconds to wait before cut-off or zero to use the system default
* time-based cut-off.
* @param cutOffAfterCount the number of permission checks to process before cut-off or zero to use the system default
* count-based cut-off.
* @return a <code>Collection</code> of the same type but including the
* {@link PermissionCheckCollection} interface
*/
@SuppressWarnings("unchecked")
public static final <TT> Collection<TT> create(
Collection<TT> collection,
int targetResultCount, long cutOffAfterTimeMs, int cutOffAfterCount)
{
if (targetResultCount <= 0)
{
targetResultCount = collection.size();
}
// Create the mixin
DelegatingIntroductionInterceptor mixin = new PermissionCheckCollectionMixin<Integer>(
targetResultCount,
cutOffAfterTimeMs,
cutOffAfterCount);
// Create the advisor
IntroductionAdvisor advisor = new DefaultIntroductionAdvisor(mixin, PermissionCheckCollection.class);
// Proxy
ProxyFactory pf = new ProxyFactory(collection);
pf.addAdvisor(advisor);
Object proxiedObject = pf.getProxy();
// Done
return (Collection<TT>) proxiedObject;
}
示例4: createRefreshableProxy
import org.springframework.aop.support.DelegatingIntroductionInterceptor; //导入依赖的package包/类
/**
* Create a refreshable proxy for the given AOP TargetSource.
* @param ts the refreshable TargetSource
* @param interfaces the proxy interfaces (may be {@code null} to
* indicate proxying of all interfaces implemented by the target class)
* @return the generated proxy
* @see RefreshableScriptTargetSource
*/
protected Object createRefreshableProxy(TargetSource ts, Class<?>[] interfaces, boolean proxyTargetClass) {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTargetSource(ts);
ClassLoader classLoader = this.beanClassLoader;
if (interfaces == null) {
interfaces = ClassUtils.getAllInterfacesForClass(ts.getTargetClass(), this.beanClassLoader);
}
proxyFactory.setInterfaces(interfaces);
if (proxyTargetClass) {
classLoader = null; // force use of Class.getClassLoader()
proxyFactory.setProxyTargetClass(proxyTargetClass);
}
DelegatingIntroductionInterceptor introduction = new DelegatingIntroductionInterceptor(ts);
introduction.suppressInterface(TargetSource.class);
proxyFactory.addAdvice(introduction);
return proxyFactory.getProxy(classLoader);
}
示例5: createRefreshableProxy
import org.springframework.aop.support.DelegatingIntroductionInterceptor; //导入依赖的package包/类
/**
* Create a refreshable proxy for the given AOP TargetSource.
*
* @param ts
* the refreshable TargetSource
* @param interfaces
* the proxy interfaces (may be {@code null} to indicate proxying
* of all interfaces implemented by the target class)
* @return the generated proxy
* @see RefreshableScriptTargetSource
*/
protected Object createRefreshableProxy(TargetSource ts, Class<?>[] interfaces, boolean proxyTargetClass) {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTargetSource(ts);
ClassLoader classLoader = this.beanClassLoader;
if (interfaces == null) {
interfaces = ClassUtils.getAllInterfacesForClass(ts.getTargetClass(), this.beanClassLoader);
}
proxyFactory.setInterfaces(interfaces);
if (proxyTargetClass) {
classLoader = null; // force use of Class.getClassLoader()
proxyFactory.setProxyTargetClass(true);
}
DelegatingIntroductionInterceptor introduction = new DelegatingIntroductionInterceptor(ts);
introduction.suppressInterface(TargetSource.class);
proxyFactory.addAdvice(introduction);
return proxyFactory.getProxy(classLoader);
}
示例6: createRefreshableProxy
import org.springframework.aop.support.DelegatingIntroductionInterceptor; //导入依赖的package包/类
/**
* Create a refreshable proxy for the given AOP TargetSource.
* @param ts the refreshable TargetSource
* @param interfaces the proxy interfaces (may be {@code null} to
* indicate proxying of all interfaces implemented by the target class)
* @return the generated proxy
* @see RefreshableScriptTargetSource
*/
protected Object createRefreshableProxy(TargetSource ts, Class<?>[] interfaces, boolean proxyTargetClass) {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTargetSource(ts);
ClassLoader classLoader = this.beanClassLoader;
if (interfaces == null) {
interfaces = ClassUtils.getAllInterfacesForClass(ts.getTargetClass(), this.beanClassLoader);
}
proxyFactory.setInterfaces(interfaces);
if (proxyTargetClass) {
classLoader = null; // force use of Class.getClassLoader()
proxyFactory.setProxyTargetClass(true);
}
DelegatingIntroductionInterceptor introduction = new DelegatingIntroductionInterceptor(ts);
introduction.suppressInterface(TargetSource.class);
proxyFactory.addAdvice(introduction);
return proxyFactory.getProxy(classLoader);
}
示例7: testAdviceImplementsIntroductionInfo
import org.springframework.aop.support.DelegatingIntroductionInterceptor; //导入依赖的package包/类
@Test
public void testAdviceImplementsIntroductionInfo() throws Throwable {
TestBean tb = new TestBean();
String name = "tony";
tb.setName(name);
ProxyFactory pc = new ProxyFactory(tb);
NopInterceptor di = new NopInterceptor();
pc.addAdvice(di);
final long ts = 37;
pc.addAdvice(new DelegatingIntroductionInterceptor(new TimeStamped() {
@Override
public long getTimeStamp() {
return ts;
}
}));
ITestBean proxied = (ITestBean) createProxy(pc);
assertEquals(name, proxied.getName());
TimeStamped intro = (TimeStamped) proxied;
assertEquals(ts, intro.getTimeStamp());
}
示例8: aopAdvice
import org.springframework.aop.support.DelegatingIntroductionInterceptor; //导入依赖的package包/类
public static void aopAdvice() {
// 参见:com.bdsoft.bdceo.spring.aop包下的模拟实现类
// before-advice: ResourceSetupBeforeAdvice
// exception-advice: ExceptionBarrierThrowsAdvice
// after-advice: TaskexecutionAfterReturningAdvice
// around-advice: PerformanceMethodInterceptor
// 特殊: Introduction类advice演示
ITester delegate = new Tester();
DelegatingIntroductionInterceptor dii = new DelegatingIntroductionInterceptor(
delegate);
DelegatePerTargetObjectIntroductionInterceptor dptoii = new DelegatePerTargetObjectIntroductionInterceptor(
Tester.class, ITester.class);
}
示例9: createEndpoint
import org.springframework.aop.support.DelegatingIntroductionInterceptor; //导入依赖的package包/类
/**
* Wrap each concrete endpoint instance with an AOP proxy,
* exposing the message listener's interfaces as well as the
* endpoint SPI through an AOP introduction.
*/
@Override
public MessageEndpoint createEndpoint(XAResource xaResource) throws UnavailableException {
GenericMessageEndpoint endpoint = (GenericMessageEndpoint) super.createEndpoint(xaResource);
ProxyFactory proxyFactory = new ProxyFactory(this.messageListener);
DelegatingIntroductionInterceptor introduction = new DelegatingIntroductionInterceptor(endpoint);
introduction.suppressInterface(MethodInterceptor.class);
proxyFactory.addAdvice(introduction);
return (MessageEndpoint) proxyFactory.getProxy();
}
示例10: setBeanFactory
import org.springframework.aop.support.DelegatingIntroductionInterceptor; //导入依赖的package包/类
@Override
public void setBeanFactory(BeanFactory beanFactory) {
if (!(beanFactory instanceof ConfigurableBeanFactory)) {
throw new IllegalStateException("Not running in a ConfigurableBeanFactory: " + beanFactory);
}
ConfigurableBeanFactory cbf = (ConfigurableBeanFactory) beanFactory;
this.scopedTargetSource.setBeanFactory(beanFactory);
ProxyFactory pf = new ProxyFactory();
pf.copyFrom(this);
pf.setTargetSource(this.scopedTargetSource);
Class<?> beanType = beanFactory.getType(this.targetBeanName);
if (beanType == null) {
throw new IllegalStateException("Cannot create scoped proxy for bean '" + this.targetBeanName +
"': Target type could not be determined at the time of proxy creation.");
}
if (!isProxyTargetClass() || beanType.isInterface() || Modifier.isPrivate(beanType.getModifiers())) {
pf.setInterfaces(ClassUtils.getAllInterfacesForClass(beanType, cbf.getBeanClassLoader()));
}
// Add an introduction that implements only the methods on ScopedObject.
ScopedObject scopedObject = new DefaultScopedObject(cbf, this.scopedTargetSource.getTargetBeanName());
pf.addAdvice(new DelegatingIntroductionInterceptor(scopedObject));
// Add the AopInfrastructureBean marker to indicate that the scoped proxy
// itself is not subject to auto-proxying! Only its target bean is.
pf.addInterface(AopInfrastructureBean.class);
this.proxy = pf.getProxy(cbf.getBeanClassLoader());
}
示例11: testIntroductionThrowsUncheckedException
import org.springframework.aop.support.DelegatingIntroductionInterceptor; //导入依赖的package包/类
/**
* Note that an introduction can't throw an unexpected checked exception,
* as it's constained by the interface.
*/
@Test
public void testIntroductionThrowsUncheckedException() throws Throwable {
TestBean target = new TestBean();
target.setAge(21);
ProxyFactory pc = new ProxyFactory(target);
@SuppressWarnings("serial")
class MyDi extends DelegatingIntroductionInterceptor implements TimeStamped {
/**
* @see test.util.TimeStamped#getTimeStamp()
*/
@Override
public long getTimeStamp() {
throw new UnsupportedOperationException();
}
}
pc.addAdvisor(new DefaultIntroductionAdvisor(new MyDi()));
TimeStamped ts = (TimeStamped) createProxy(pc);
try {
ts.getTimeStamp();
fail("Should throw UnsupportedOperationException");
}
catch (UnsupportedOperationException ex) {
}
}
示例12: setBeanFactory
import org.springframework.aop.support.DelegatingIntroductionInterceptor; //导入依赖的package包/类
public void setBeanFactory(BeanFactory beanFactory) {
if (!(beanFactory instanceof ConfigurableBeanFactory)) {
throw new IllegalStateException("Not running in a ConfigurableBeanFactory: " + beanFactory);
}
ConfigurableBeanFactory cbf = (ConfigurableBeanFactory) beanFactory;
this.scopedTargetSource.setBeanFactory(beanFactory);
ProxyFactory pf = new ProxyFactory();
pf.copyFrom(this);
pf.setTargetSource(this.scopedTargetSource);
Class<?> beanType = beanFactory.getType(this.targetBeanName);
if (beanType == null) {
throw new IllegalStateException("Cannot create scoped proxy for bean '" + this.targetBeanName +
"': Target type could not be determined at the time of proxy creation.");
}
if (!isProxyTargetClass() || beanType.isInterface() || Modifier.isPrivate(beanType.getModifiers())) {
pf.setInterfaces(ClassUtils.getAllInterfacesForClass(beanType, cbf.getBeanClassLoader()));
}
// Add an introduction that implements only the methods on ScopedObject.
ScopedObject scopedObject = new DefaultScopedObject(cbf, this.scopedTargetSource.getTargetBeanName());
pf.addAdvice(new DelegatingIntroductionInterceptor(scopedObject));
// Add the AopInfrastructureBean marker to indicate that the scoped proxy
// itself is not subject to auto-proxying! Only its target bean is.
pf.addInterface(AopInfrastructureBean.class);
this.proxy = pf.getProxy(cbf.getBeanClassLoader());
}
示例13: createProxyFactory
import org.springframework.aop.support.DelegatingIntroductionInterceptor; //导入依赖的package包/类
private void createProxyFactory(RefreshableScriptTargetSource ts,
Class<?>[] interfaces, ClassLoader loader) {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTargetSource(ts);
proxyFactory.setInterfaces(interfaces);
DelegatingIntroductionInterceptor introduction = new DelegatingIntroductionInterceptor(ts);
introduction.suppressInterface(TargetSource.class);
proxyFactory.addAdvice(introduction);
proxyFactory.getProxy(loader);
}
示例14: getPoolingConfigMixin
import org.springframework.aop.support.DelegatingIntroductionInterceptor; //导入依赖的package包/类
/**
* Return an IntroductionAdvisor that providing a mixin
* exposing statistics about the pool maintained by this object.
*/
public DefaultIntroductionAdvisor getPoolingConfigMixin() {
DelegatingIntroductionInterceptor dii = new DelegatingIntroductionInterceptor(this);
return new DefaultIntroductionAdvisor(dii, PoolingConfig.class);
}
示例15: getStatsMixin
import org.springframework.aop.support.DelegatingIntroductionInterceptor; //导入依赖的package包/类
/**
* Return an introduction advisor mixin that allows the AOP proxy to be
* cast to ThreadLocalInvokerStats.
*/
public IntroductionAdvisor getStatsMixin() {
DelegatingIntroductionInterceptor dii = new DelegatingIntroductionInterceptor(this);
return new DefaultIntroductionAdvisor(dii, ThreadLocalTargetSourceStats.class);
}