Flavia Rainone [http://community.jboss.org/people/flavia.rainone%40jboss.com] 
created the discussion

"Re: The reuse&&JBoss AOP"

To view the discussion, visit: http://community.jboss.org/message/585280#585280

--------------------------------------------------------------
In order to do that, first of all you need to change the signature of update 
method to something like this:


package Bee ;
public interface FlowerObserver {    
      public void update(boolean isOpen);
}



Now, your implementation must also receive the isOpen value as a parameter and 
that way you can check on whether the flower is open before deciding to either 
call Bee.dinner() or Bee.rest().

Another thing that you have to workaround is how to call this. JBoss AOP needs 
to control the creation of aspects. AFAIK, this is not a limiting factor 
exclusive to JBoss AOP, all AOP languages/tools need to have some control of 
how to create the aspect. So, you can't have as an aspect an  object you 
created yourself (i.e, it can't be the bees you are creating in main).

To workaround that:

- keep the interface as above
- add an Observable interface and a Mixin for that:
public interface Observable {
    public void addObserver(FlowerObserver observer);
    public void notifyAll();
}
 
public ObservableMixin {
    private Collection<FlowerObserver> observers = ...;
    private final Flower flower;
    public ObservableMixin(Flower flower) { this.flower = flower}
    public void addObserver(FlowerObserver observer) { observers.ad(observer);}
    public void notifyAll() { for(FlowerObserver: observers) { 
observer.update(flower.isOpen());}}
}
 


- and finally an after aspect that triggers the notification (use just the same 
xml you used, but replace BeeObserver update() by the ObserverAspect 
updateObservers advice below):

public class ObserverAspect() {
      public void updateObservers(@Target Observable observable) { 
observable.notifyAll(); }
}


- don't forget to add the ObservableMixin above to Flower class!

Now, in main, you can make:

((Observable) flower).addObserver((FlowerObserver) bee1);
((Observable) flower).addObserver((FlowerObserver) bee2);


And that's it!
--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/585280#585280]

Start a new discussion in JBoss AOP at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2027]

_______________________________________________
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to