org.springframework.aop.support.DelegatingIntroductionInterceptor Java Examples

The following examples show how to use org.springframework.aop.support.DelegatingIntroductionInterceptor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractAopProxyTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #2
Source File: ScriptFactoryPostProcessor.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example #3
Source File: AbstractAopProxyTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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());
}
 
Example #4
Source File: ScriptFactoryPostProcessor.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example #5
Source File: PermissionCheckCollection.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #6
Source File: PermissionCheckedCollection.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #7
Source File: PermissionCheckedValue.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #8
Source File: AbstractAopProxyTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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());
}
 
Example #9
Source File: GenericMessageEndpointFactory.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #10
Source File: AbstractAopProxyTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * 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) {
	}
}
 
Example #11
Source File: ScopedProxyFactoryBean.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #12
Source File: ScopedProxyFactoryBean.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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());
}
 
Example #13
Source File: GenericMessageEndpointFactory.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #14
Source File: GenericMessageEndpointFactory.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * 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(getMessageListener());
	DelegatingIntroductionInterceptor introduction = new DelegatingIntroductionInterceptor(endpoint);
	introduction.suppressInterface(MethodInterceptor.class);
	proxyFactory.addAdvice(introduction);
	return (MessageEndpoint) proxyFactory.getProxy();
}
 
Example #15
Source File: ScriptFactoryPostProcessor.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * 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, @Nullable Class<?>[] interfaces, boolean proxyTargetClass) {
	ProxyFactory proxyFactory = new ProxyFactory();
	proxyFactory.setTargetSource(ts);
	ClassLoader classLoader = this.beanClassLoader;

	if (interfaces != null) {
		proxyFactory.setInterfaces(interfaces);
	}
	else {
		Class<?> targetClass = ts.getTargetClass();
		if (targetClass != null) {
			proxyFactory.setInterfaces(ClassUtils.getAllInterfacesForClass(targetClass, this.beanClassLoader));
		}
	}

	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);
}
 
Example #16
Source File: ScopedProxyFactoryBean.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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);

	Assert.notNull(this.targetBeanName, "Property 'targetBeanName' is required");
	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());
}
 
Example #17
Source File: GenericMessageEndpointFactory.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * 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(getMessageListener());
	DelegatingIntroductionInterceptor introduction = new DelegatingIntroductionInterceptor(endpoint);
	introduction.suppressInterface(MethodInterceptor.class);
	proxyFactory.addAdvice(introduction);
	return (MessageEndpoint) proxyFactory.getProxy();
}
 
Example #18
Source File: AbstractAopProxyTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Note that an introduction can't throw an unexpected checked exception,
 * as it's constrained 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) {
	}
}
 
Example #19
Source File: ScopedProxyFactoryBean.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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);

	Assert.notNull(this.targetBeanName, "Property 'targetBeanName' is required");
	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());
}
 
Example #20
Source File: AbstractAopProxyTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Note that an introduction can't throw an unexpected checked exception,
 * as it's constrained 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) {
	}
}
 
Example #21
Source File: ScriptFactoryPostProcessor.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * 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, @Nullable Class<?>[] interfaces, boolean proxyTargetClass) {
	ProxyFactory proxyFactory = new ProxyFactory();
	proxyFactory.setTargetSource(ts);
	ClassLoader classLoader = this.beanClassLoader;

	if (interfaces != null) {
		proxyFactory.setInterfaces(interfaces);
	}
	else {
		Class<?> targetClass = ts.getTargetClass();
		if (targetClass != null) {
			proxyFactory.setInterfaces(ClassUtils.getAllInterfacesForClass(targetClass, this.beanClassLoader));
		}
	}

	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);
}
 
Example #22
Source File: ThreadLocalTargetSource.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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);
}
 
Example #23
Source File: AbstractPoolingTargetSource.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * 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);
}
 
Example #24
Source File: ThreadLocalTargetSource.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * 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);
}
 
Example #25
Source File: TimestampIntroductionAdvisor.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * @param dii
 */
public TimestampIntroductionAdvisor() {
	super(new DelegatingIntroductionInterceptor(new TimestampIntroductionInterceptor()));
}
 
Example #26
Source File: TimestampIntroductionAdvisor.java    From spring-analysis-note with MIT License 4 votes vote down vote up
public TimestampIntroductionAdvisor() {
	super(new DelegatingIntroductionInterceptor(new TimestampIntroductionInterceptor()));
}
 
Example #27
Source File: AbstractPoolingTargetSource.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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);
}
 
Example #28
Source File: TimestampIntroductionAdvisor.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * @param dii
 */
public TimestampIntroductionAdvisor() {
	super(new DelegatingIntroductionInterceptor(new TimestampIntroductionInterceptor()));
}
 
Example #29
Source File: DeclareParentsAdvisor.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Create a new advisor for this DeclareParents field.
 * @param interfaceType static field defining the introduction
 * @param typePattern type pattern the introduction is restricted to
 * @param delegateRef the delegate implementation object
 */
public DeclareParentsAdvisor(Class<?> interfaceType, String typePattern, Object delegateRef) {
	this(interfaceType, typePattern, delegateRef.getClass(),
		 new DelegatingIntroductionInterceptor(delegateRef));
}
 
Example #30
Source File: DeclareParentsAdvisor.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Create a new advisor for this DeclareParents field.
 * @param interfaceType static field defining the introduction
 * @param typePattern type pattern the introduction is restricted to
 * @param delegateRef the delegate implementation object
 */
public DeclareParentsAdvisor(Class<?> interfaceType, String typePattern, Object delegateRef) {
	this(interfaceType, typePattern, delegateRef.getClass(),
		 new DelegatingIntroductionInterceptor(delegateRef));
}