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

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

    ProxyFactory weaver = new ProxyFactory();
    weaver.setProxyTargetClass(false);
    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() );
    weaver.addAdvisor(aspect);

    Interceptable proxy = (Interceptable)weaver.getProxy();
    System.out.println(proxy.isInterceptable());


    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.

    Joerg

    Comment


    • #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?
      ````````````Interceptable
      ```````````````` |
      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.

      Comment

      Working...
      X