Results 1 to 6 of 6

Thread: is this ok?

  1. #1
    Join Date
    Nov 2005
    Location
    Iasi, Romania
    Posts
    104

    Default is this ok?

    Shouldn't this pass?

    Code:
    public class PointcutTest extends TestCase {
    	
    	public void testPointcut() throws Exception {
    		AspectJExpressionPointcut p = new AspectJExpressionPointcut();
    		p.setExpression("execution(* *.service.*(..))");
    		assertFalse(p.matches(java.lang.Long.class));
    	}
    
    }

  2. #2
    Join Date
    Nov 2005
    Location
    Iasi, Romania
    Posts
    104

    Default

    I'm forced to use this construction. Is this the intended behavior or it is a bug?

    Code:
    	
    	public void testPointcutWithWithin() throws Exception {
    		AspectJExpressionPointcut p = new AspectJExpressionPointcut();
    		p.setExpression("within(com.xyz..AccountService) && execution(* com.xyz..AccountService.*(..))");
    		assertFalse(p.matches(java.lang.Long.class));
    	}

  3. #3
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    First of all your first pointcut is wrong.

    Code:
    execution(* *.service.*(..))
    The wildcard in AspectJ expression language is '..' not a '*' the '*' is for 1 level the otherone is for 0 or more levels. Next to that you specify an execution pointcut but aren't trying to execute anything. Also your pointcut is off on that because you either aren't defining a method to call or aren't defining a class to intercept.

    Code:
    execution(* *..service.*.*(..))
    Is the actuall expression to use.

    Next to that you should check if a method call would match the pointcut.

    Code:
    public void testPointcut() throws Exception {
    	AspectJExpressionPointcut p = new AspectJExpressionPointcut();
    	p.setExpression("execution(* *..service.*.*(..))");
    	Method m = ClassUtils.getMethodIfAvailable(Long.class, "valueOf", new Class[] {String.class});
    	assertFalse(p.matches(m, java.lang.Long.class, new Object[] {"12"}));
    }
    However one question I have is WHY are you doing this?!
    Last edited by Marten Deinum; Mar 7th, 2008 at 06:16 AM. Reason: Copy/Paste error.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  4. #4
    Join Date
    Nov 2005
    Location
    Iasi, Romania
    Posts
    104

    Default

    Thank you for the response. Please excuse me for the first post. It was a copy/paste error. The second one contains the correct AspectJ expression.
    The reason for doing this is a sequence of code in AopUtils.canApply(..) method
    Code:
    if (!pc.getClassFilter().matches(targetClass)) {
    			return false;
    }
    I was in debug and expected that this returned false but it didn't. I thought that this is the normal execution path because the expression includes a pattern for matching the actual class. When using within(...) expression the code works. Can you please explain what is the purpose of this? Thank you.

  5. #5
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    You are comparing apples and oranges here. The matches here is the matches of the ClassFilter NOT the matches of the Pointcut!

    Hmm not entirely true I check the implementation you use and getClassFilter() returns this so p.matches and p.getClassFilter().matches do the same....
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  6. #6
    Join Date
    Nov 2005
    Location
    Iasi, Romania
    Posts
    104

    Default

    I don't think I understand when this sequence returns false. The AspectJPointcut.getClassFilter() returns this as the class filter. My test result is the same when using p.getClassFilter(). Maybe I didn't understand correctly what is the purpose of the ClassFilter? Thank you.

Posting Permissions

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