Announcement Announcement Module
Collapse
No announcement yet.
Suppress interface from a class Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Suppress interface from a class

    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.ProxyFact oryBean">

    <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

  • #2
    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.

    Comment


    • #3
      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

      Comment


      • #4
        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.

        Comment


        • #5
          Thanks for your help...
          Thierry

          Comment

          Working...
          X