[jboss-user] [JBoss AOP] - Re: The reuse&&JBoss AOP
loupi loupi
do-not-reply at jboss.com
Tue Feb 1 16:24:57 EST 2011
loupi loupi [http://community.jboss.org/people/hsma] created the discussion
"Re: The reuse&&JBoss AOP"
To view the discussion, visit: http://community.jboss.org/message/584755#584755
--------------------------------------------------------------
Hello,
Thank you for your reply, The example that I want to realise is the following(Realization of the observer design pattern with JBossAOP):
Flower (Subject ):
> *package* Bee;
> *public* *class* Flower {
>
> *private* *boolean* isOpen;
>
> *public* *boolean* isOpen(){*returnthis*.isOpen;}
>
> *public* Flower(){
> *this*.isOpen=*false*;
> }
>
> *public* *void* open(){
> *this*.isOpen=*true*;
> }
>
> *public* *void* close(){
> *this*.isOpen=*false*;
> }
> }
>
The Bee class observe the opening and closing of Flower (attribute(isOpen))
**
*PS: for easier reuse of the Bee class, we put the Update method (observer role)in another class and we make an introduction*
Bee (Observer ):
*package* Bee;
*public* *class* Bee {
*private* String name;
*public* Bee(String name){
*this*.name = name;
}
*public* *void* dinner(){
System.+out+.println("Bee "+ name
+ "'s breakfast time!");
}
*public* *void* rest(){
System.+out+.println("Bee" + name
+ "'s bed time!");
}
}
The interface for all observers is the following:
*package* Bee ;
*public* *interface*FlowerObserver {
*public* *void* update();
}
And Mixin class is as follows:
*package* Bee;
*public* *class* BeeObserver *implements* FlowerObserver{
Bee bee;
*public* BeeObserver(Bee bee){*this*.bee=bee;}
*public void* update(){
*if* (isOpen) //the attribute value of Flower
bee.dinner();
*else* bee.rest();
}}
Finally the Main class:
*package* Bee;
*public* *class* Main {
*public* *static* *void*main(String[] args) {
Flower f = *new* Flower();
Beeb1 = *new* Bee("B1");
Beeb2 = *new* Bee("B2");
f.open();
f.close();
f.open();
System.+out+.println("c'estbon");
}
}
theXML file:
<?xmlversion="1.0" encoding="UTF-8"?>
<aop>
<introductionclass="Bee.Bee">
<mixin>
<interfaces>Bee.FlowerObserver</interfaces>
<class>Bee.BeeObserver</class>
<construction>new Bee.BeeObserver(this)</construction>
</mixin>
</introduction>
<aspect class="Bee.BeeObserver"/>
<bind pointcut="set(private boolean Bee.Flower->isOpen)">
<after aspect="Bee.BeeObserver" name="update"/>
</bind>
</aop>
This code contains several errors!! but I would have the following result:
*B1 Bee's breakfast time! B2 Bee's breakfast time! B1 Bee's bed time! B2 Bee's bed time! B1 Bee's breakfast time! B2 Bee's breakfast time!*
*Tahnk's in advance :)
*
--------------------------------------------------------------
Reply to this message by going to Community
[http://community.jboss.org/message/584755#584755]
Start a new discussion in JBoss AOP at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2027]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20110201/4d419c0f/attachment-0001.html
More information about the jboss-user
mailing list