PDA

View Full Version : Suppress interface from a class



templth
Aug 30th, 2004, 11:12 AM
Hello,

I see that it's possible to remove an interface from a class with a subclass of DelegatingIntroductionInterceptor and the method suppressInterface.
Is there an exemple in documentation?

I try the following:

-- SuppressInterfaceMixin.java

import org.springframework.aop.support.DelegatingIntroduc tionInterceptor;
import org.aopalliance.intercept.MethodInvocation;

public class SuppressInterfaceMixin extends DelegatingIntroductionInterceptor {
public SuppressInterfaceMixin() {
suppressInterface(Test.class);

}
}

-- applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC
"-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">

<beans>

<bean id="businesslogicbean" class="org.springframework.aop.framework.ProxyFactoryBean">

<property name="proxyInterfaces">
<value>IBusinessLogic,Test</value>
</property>

<property name="target">
<ref local="beanTarget"/>
</property>

<property name="interceptorNames">
<list>
<value>suppressionAdvisor</value>
</list>
</property>

</bean>

<!-- Bean Classes -->
<bean id="beanTarget" class="BusinessLogic"/>

<bean id="suppressionAdvisor" class="SuppressInterfaceMixin"/>

</beans>

PS: I want to suppress Test interface from BusinessLogic class...

Thanks for your help.
Thierry

Rod Johnson
Aug 30th, 2004, 11:44 AM
It's possible to suppress an interface that would otherwise have been introuced by a DelegatingIntroductionInterceptor, but not suppress an interface implemented by the target. You can either:

1. use an introduction interceptor to introduce something that disables all methods on that interface, e.g. by throwing UnsupportedOperationException

2. simply hide the fact that the target implements that interface. If you're using JDK proxies, rather than CGLIB proxies (proxying interfaces only) just omit that interface from the proxied interfaces list and it will be impossible to cast the advised object to the interface you want to suppress. So simply remove "Test" from proxyInterfaces and you're done.

templth
Aug 31st, 2004, 02:04 AM
Hi Rod,

Thanks for your answer and all the works you made on the framework!! Thanks too for your books that are really interesting...

I have tested the 2. and will look at the 1.
But in which case can we use the suppressInterface method of class DelegatingIntroductionInterceptor? and what is its utility?

Thierry

Rod Johnson
Aug 31st, 2004, 10:10 AM
But in which case can we use the suppressInterface method of class DelegatingIntroductionInterceptor? and what is its utility?
You would use it if the delegate implemented more interfaces than you wanted to expose, and you were using the DefaultIntroductionAdvisor constructor that takes an DelegatingIntroductionInterceptor and automatically picks up the implemented interfaces.

templth
Sep 2nd, 2004, 07:30 AM
Thanks for your help...
Thierry