[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] How to rewrite a class with AspectJ
|
Hi Mohammad,
if I understand correctly, when a method annotated with @Observable is executed, you want to see if there are fields in that class with an instance of an observer, and call a method on the observer.
You can use AspectJ to execute an advice before/after/around the execution of @Obervable methods, and use thisJoinPoint or the this() construct to find the instance of the method.
Once you are there, you must use plain java reflection, and not AspectJ, to find fields in that class that contains an observer and invoke observer methods.
To add @EJB annotation to all fields of type X where X is annotated with @Observer, you can use declare @class and write a type pattern that uses @Observer annotation. If @Observer annotation is placed on methods, you can use hasmethod() to find classes that has such methods, but beware cause hasmethod is somewhat experimental.
Hope this helps,
Simone
2010/4/19 is_maximum
<mnrz57@xxxxxxxxx>
Thanks Simone, yes this is exactly what I want... but another question is
that this is used using 'declare' and as far as I know declare is placed in
aspect definition. How can I place it in a for-loop.
Let me tell you the scenario may be I am in wrong way...
I am trying to implement an observer pattern in EJB 3.0. I saw many
implementation using aspectJ but mine is a little different. The difference
is that I want to inject observer into observable...
Because session beans are managed object and in my case both observer and
observable supposed to be session beans I want application server injects
observer session beans in observable SB and then call observer methods
These observer and observable methods will be annotated by the developer
with say @Observer and @Observable
What I wanted was to look for @Observer methods and find their interface and
put them like this:
@EJB
private ObserverInterface1 observer1
than each time the determined method is called I can call
observer1.notifyObserver() method
Can you please help me on this?
View this message in context: http://old.nabble.com/How-to-rewrite-a-class-with-AspectJ-tp28280867p28287273.html