[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Aspect.aspectOf() behaviour

Title: Message
(Sorry Alex - this was sent to the wrong mailing list) - does the same still apply?
We are using the latest stable aspectJ build (20051015)
-Neil
-----Original Message-----
From: AVERY, Neil, FM
Sent: 17 October 2005 14:24
To: 'user@xxxxxxxxxxxxxxxxxxxxxxxx'
Subject: Aspect.aspectOf() behaviour

All,
If I apply a 'perTarget' Aspect to a object and call Aspects.aspectOf(SimpleAroundAspect.class, testClass) then I get an exception, NoAspectBound...(see below)
 
However, if a prior invocation has occured then Aspects.aspectOf(..) will return the Aspect that was bound....
 
Ideally I would like to get access to an aspect bound to the object instance regardless of whether or not it has been invoked. Is it possible to determine/control the behaviour as its the kind of thing that will affect component lifecycle when interacting with aspects...?
 
Cheers Neil.
 
TEST:
 public void testDifferendAspectInstanceGetsApplied() throws Exception {
  
  TestClass testClass = new TestClass();
>>>//  testClass.doStuff();
  
  Object aspect1 = Aspects.aspectOf(SimpleAroundAspect.class, testClass);
 }
}
THROWS:
org.aspectj.lang.NoAspectBoundException: Exception while initializing org.stuff.SimpleAroundAspect: java.lang.reflect.InvocationTargetException
 at org.aspectj.lang.Aspects.aspectOf(Aspects.java:66)
 at org.stuff.aspectof.SimpleAspectTest.testDifferendAspectInstanceGetsApplied(SimpleAspectTest.java:27)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:585)
 at junit.framework.TestCase.runTest(TestCase.java:154)
 at junit.framework.TestCase.runBare(TestCase.java:127)
 at junit.framework.TestResult$1.protect(TestResult.java:106)
 at junit.framework.TestResult.runProtected(TestResult.java:124)
 at junit.framework.TestResult.run(TestResult.java:109)
 at junit.framework.TestCase.run(TestCase.java:118)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.lang.reflect.InvocationTargetException
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:585)
 at org.aspectj.lang.Aspects.aspectOf(Aspects.java:63)
 ... 14 more
Caused by: org.aspectj.lang.NoAspectBoundException
 at org.stuff.SimpleAroundAspect.aspectOf(SimpleAroundAspect.java:1)
 ... 19 more
 
ASPECT:
package org.stuff;
 
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
 
@Aspect("pertarget(call(* org.stuff.TestClass.*(..)))")
public class SimpleAroundAspect {
 public static int callCount = 0;
 
  @Around("call(* org.stuff.TestClass.*(..))")
  public Object invoke(ProceedingJoinPoint thisJoinPoint) throws Throwable {
  
   System.err.println("called onto SimpleAroundAspect count:" + callCount++);
   return thisJoinPoint.proceed();
  }; 
}
 
 
 
 


***********************************************************************************
The Royal Bank of Scotland plc. Registered in Scotland No 90312. Registered Office: 36 St Andrew Square, Edinburgh EH2 2YB.
Authorised and regulated by the Financial Services Authority

This e-mail message is confidential and for use by the
addressee only. If the message is received by anyone other
than the addressee, please return the message to the sender
by replying to it and then delete the message from your
computer. Internet e-mails are not necessarily secure. The
Royal Bank of Scotland plc does not accept responsibility for
changes made to this message after it was sent.

Whilst all reasonable care has been taken to avoid the
transmission of viruses, it is the responsibility of the recipient to
ensure that the onward transmission, opening or use of this
message and any attachments will not adversely affect its
systems or data. No responsibility is accepted by The Royal
Bank of Scotland plc in this regard and the recipient should carry
out such virus and other checks as it considers appropriate.
Visit our websites at:
http://www.rbs.co.uk/CBFM
http://www.rbsmarkets.com
********************************************************************************