has pointcut and interfaces
adrian.brock Sep 29, 2005 4:05 PMI've added a test that shows a problem with the way the pointcut matcher
handles interfaces and "has" pointcut. Or more accurately the way reflection
describes it.
The pointcut expression is
execution(* *->*(..)) AND has(* org.jboss.test.aop.basic.InterfaceUsedInHas->*(..))
or intercept all methods if the POJO has a method from "InterfaceUsedInUs".
TEST Interface used in has org.jboss.test.aop.basic.InterfaceUsedInHasImpl methods=[public void org.jboss.test.aop.basic.InterfaceUsedInHasImpl.someMethod(), public org.jboss.aop.InstanceAdvisor org.jboss.test.aop.basic.InterfaceUsedInHasImpl._getInstanceAdvisor(), public org.jboss.aop.Advisor org.jboss.test.aop.basic.InterfaceUsedInHasImpl._getAdvisor(), pub lic void org.jboss.test.aop.basic.InterfaceUsedInHasImpl._setInstanceAdvisor(org.jboss.aop.InstanceAdvisor), public void org.jboss.test.aop.basic.InterfaceUsedInHasImp l.org$jboss$test$aop$basic$InterfaceUsedInHasImpl$someMethod$aop()] org.jboss.test.aop.basic.SubclassInterfaceUsedInHasImpl methods=[public void org.jboss.test.aop.basic.SubclassInterfaceUsedInHasImpl.someOtherMethod(), public org.jbos s.aop.Advisor org.jboss.test.aop.basic.SubclassInterfaceUsedInHasImpl._getAdvisor(), public void org.jboss.test.aop.basic.SubclassInterfaceUsedInHasImpl.org$jboss$test $aop$basic$SubclassInterfaceUsedInHasImpl$someOtherMethod$aop()] Testcase: testInterfaceUsedInHas took 0.014 sec Caused an ERROR should have intercepted InterfaceUsedInHasImpl.someMethod() java.lang.RuntimeException: should have intercepted InterfaceUsedInHas.someMethod() at org.jboss.test.aop.basic.AOPTester.testInterfaceUsedInHas(AOPTester.java:555)
The problem is that the implementation class only has such a method from the
class it extends and then it is said to come from the implementation class.
public class SubclassInterfaceUsedInHasImpl extends InterfaceUsedInHasImpl { public void someOtherMethod() { } }
I bring this issue up because I'm looking at how to "introduce" an interface
without seeding the target class (and it is also in the context that all methods should
be intercepted so it is not really an introduction).
i.e. JCA 1.5 message inflow
execution(* *->*(..)) AND has(* javax.resource.spi.endpoint.MessageEndpoint->*(..))
where the MessageEndpoint methods and "onMessage(...)" are all intercepted.