Announcement Announcement Module
No announcement yet.
why the "this" matches the target object's type? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • why the "this" matches the target object's type?

    ProxyFactory weaver = new ProxyFactory();
    weaver.setTarget(new InterceptableTwo());
    AspectJExpressionPointcut p = new AspectJExpressionPointcut(); p.setExpression("this(org.darrenstudio.books.unvei lspring.aop.pointcut.aspectj.InterceptableTwo)");
    DefaultPointcutAdvisor aspect = new DefaultPointcutAdvisor(p,new AjAfterAdvice() );

    Interceptable proxy = (Interceptable)weaver.getProxy();

    as to the proxy pattern , although the proxy object and the target implement the same interface(Interceptable interface here), but it does not mean the expression "proxy instanceof target" is true, right?

    but the code above still matches, who can tell me why?

  • #2
    Originally posted by fujohnwang View Post
    but the code above still matches, who can tell me why?
    What exactly do you test for? I only see proxy.isInterceptable(). proxy instanceof target would also not work. And proxy instanceof InterceptableTwo really should return false since you switched off class-proxying.



    • #3
      In fact , I am testing the difference between "this" and "target" designators,
      if "proxy instanceof InterceptableTwo" returns false, then why the pointcut defined with "this" designator matches and the advice get executed?
      ```````````````` |
      InterceptableOne -----InterceptableTwo

      if I use the pointcut expression such "this(Interceptable)", and the pointcut matches and advice executes, I can accept this result, but the pointcut I assigned is "this(InterceptableTwo)" , and I turned to use Dynamic proxy, the target Object is InterceptableTwo, why the pointcut still matches and send the advice to run?

      Or I misunderstand the true meanings of the "this" and "target"?
      Last edited by fujohnwang; Nov 11th, 2007, 08:54 PM.