Results 1 to 3 of 3

Thread: why the "this" matches the target object's type?

  1. #1
    Join Date
    Nov 2007
    Location
    DalianCity, Liaoning Province, China
    Posts
    11

    Talking 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. #2
    Join Date
    Nov 2005
    Location
    Reutlingen, Germany
    Posts
    2,098

    Default

    Quote 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
    This post can contain insufficient information.

  3. #3
    Join Date
    Nov 2007
    Location
    DalianCity, Liaoning Province, China
    Posts
    11

    Default

    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 at 08:54 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •