<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">
<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>
                                <td>
                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>
                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px; -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
Re: The reuse&&JBoss AOP
</h3>
<span style="margin-bottom: 10px;">
created by <a href="http://community.jboss.org/people/hsma">loupi loupi</a> in <i>JBoss AOP</i> - <a href="http://community.jboss.org/message/584755#584755">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">
<div class="jive-rendered-content"><p><span style="font-size: 11pt; background-color: white; font-family: 'Calibri','sans-serif';">Hello, </span><span style="background-color: white; font-family: 'Calibri','sans-serif'; font-size: 11pt;"><br/>Thank you for your reply,  <span class="longtext">The example that I want to realise is the following(Realization of the observer design pattern with JBossAOP): </span></span></p><p><span style="font-size: 11pt; background-color: white; font-family: 'Calibri','sans-serif';">Flower (Subject ): </span></p><blockquote class="jive-quote"><p><strong style="font-size: 10pt; font-family: 'Courier New';">package</strong><span style="font-family: 'Courier New'; font-size: 10pt;"> Bee;</span></p><p><strong style="font-size: 10pt; font-family: 'Courier New';">public</strong><span style="font-family: 'Courier New'; font-size: 10pt;"> <strong>class</strong> Flower {</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="font-family: 'Courier New'; font-size: 10pt;">      <strong>private</strong> <strong>boolean</strong> isOpen; </span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="font-family: 'Courier New'; font-size: 10pt;">      <strong>public</strong> <strong>boolean</strong> isOpen(){<strong>returnthis</strong>.isOpen;}</span></p><p>      </p><p><span style="font-family: 'Courier New'; font-size: 10pt;">      <strong>public</strong> Flower(){</span></p><p><span style="font-family: 'Courier New'; font-size: 10pt;">            <strong>this</strong>.isOpen=<strong>false</strong>;</span></p><p><span style="font-family: 'Courier New'; font-size: 10pt;">                  }</span></p><p>      </p><p><span style="font-family: 'Courier New'; font-size: 10pt;">      <strong>public</strong> <strong>void</strong> open(){</span></p><p><span style="font-family: 'Courier New'; font-size: 10pt;">            <strong>this</strong>.isOpen=<strong>true</strong>;</span>          </p><p><span style="font-family: 'Courier New'; font-size: 10pt;">      }</span></p><p>      </p><p><span style="font-family: 'Courier New'; font-size: 10pt;">      <strong>public</strong> <strong>void</strong> close(){</span></p><p><span style="font-family: 'Courier New'; font-size: 10pt;">            <strong>this</strong>.isOpen=<strong>false</strong>;</span></p><p><span style="font-family: 'Courier New'; font-size: 10pt;">      }</span></p><p><span style="font-family: 'Courier New'; font-size: 10pt;">}</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p></blockquote><p><span class="longtext">The Bee class observe  the opening and closing of Flower (attribute(isOpen)) </span><br/><span class="hps"><span lang="EN" style="font-family: 'Calibri','sans-serif'; font-size: 11pt;"> </span></span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"><strong><span class="hps"><span lang="EN" style="font-family: 'Calibri','sans-serif'; font-size: 11pt;"> </span></span></strong> </p><p><strong><span class="hps"><span lang="EN" style="font-family: 'Calibri','sans-serif'; font-size: 11pt;">PS: for</span></span><span class="shorttext"><span lang="EN" style="font-family: 'Calibri','sans-serif'; font-size: 11pt;"> </span><span class="hps"><span lang="EN" style="font-family: 'Calibri','sans-serif'; font-size: 11pt;">easier reuse</span></span> of </span><span style="font-size: 11pt; font-family: 'Calibri','sans-serif';">the Bee class, we put the Update method (observer role)in another class and we make an introduction </span></strong></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="font-size: 11pt; background-color: white; font-family: 'Calibri','sans-serif';">Bee (Observer ): </span></p><pre class="jive_text_macro jive_macro_quote"><p><strong style="font-size: 10pt; font-family: 'Courier New';">package</strong><span style="font-family: 'Courier New'; font-size: 10pt;"> Bee;</span> </p><p><strong style="font-size: 10pt; font-family: 'Courier New';">public</strong><span style="font-family: 'Courier New'; font-size: 10pt;"> <strong>class</strong> Bee {</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><strong style="font-size: 10pt; font-family: 'Courier New';">private</strong><span style="font-family: 'Courier New'; font-size: 10pt;"> String name;</span></p><p>      </p><p><strong style="font-size: 10pt; font-family: 'Courier New';">public</strong><span style="font-family: 'Courier New'; font-size: 10pt;"> Bee(String name){</span></p><p><span style="font-family: 'Courier New'; font-size: 10pt;">      <strong>this</strong>.name = name;</span></p><p><span style="font-family: 'Courier New'; font-size: 10pt;">}</span></p><p>      </p><p><strong style="font-size: 10pt; font-family: 'Courier New';">public</strong><span style="font-family: 'Courier New'; font-size: 10pt;"> <strong>void</strong> dinner(){</span></p><p><span style="font-family: 'Courier New'; font-size: 10pt;">      System.<em>out</em>.println("Bee "+ name </span></p><p><span style="font-family: 'Courier New'; font-size: 10pt;">                   + "'s breakfast time!");</span></p><p><span style="font-family: 'Courier New'; font-size: 10pt;">      }</span></p><p>      </p><p><span style="font-family: 'Courier New'; font-size: 10pt;">      <strong>public</strong> <strong>void</strong> rest(){</span></p><p><span style="font-family: 'Courier New'; font-size: 10pt;">            System.<em>out</em>.println("Bee" + name </span></p><p><span style="font-family: 'Courier New'; font-size: 10pt;">                    + "'s bed time!");</span>            </p><p><span style="font-family: 'Courier New'; font-size: 10pt;">      }     </span>         </p><p><span style="font-family: 'Courier New'; font-size: 10pt;">}</span></p></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="font-size: 11pt; background-color: white; font-family: 'Calibri','sans-serif';">The interface for all observers is the following:</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"><span style="font-size: 11pt; background-color: white; font-family: 'Calibri','sans-serif';"> </span> </p><pre class="jive_text_macro jive_macro_quote"><p><strong style="font-size: 10pt; font-family: 'Courier New';">package</strong><span style="font-family: 'Courier New'; font-size: 10pt;"> Bee ;</span></p><p><strong style="font-size: 10pt; font-family: 'Courier New';">public</strong><span style="font-family: 'Courier New'; font-size: 10pt;"> <strong>interface</strong>FlowerObserver {</span>    </p><p><span style="font-family: 'Courier New'; font-size: 10pt;">      <strong>public</strong> <strong>void</strong> update();</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="font-family: 'Courier New'; font-size: 10pt;">}</span></p></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="font-size: 11pt; font-family: 'Calibri','sans-serif';">And Mixin class is as follows: </span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"><span style="font-size: 11pt; background-color: white; font-family: 'Calibri','sans-serif';"> </span> </p><pre class="jive_text_macro jive_macro_quote"><p><strong style="font-size: 10pt; font-family: 'Courier New';">package</strong><span style="font-family: 'Courier New'; font-size: 10pt;"> Bee;</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><strong style="font-size: 10pt; font-family: 'Courier New';">public</strong><span style="font-family: 'Courier New'; font-size: 10pt;"> <strong>class</strong> BeeObserver <strong>implements </strong>FlowerObserver{</span></p><p>         </p><p><span style="font-family: 'Courier New'; font-size: 10pt;">        Bee bee;</span></p><p>         </p><p><span style="font-family: 'Courier New'; font-size: 10pt;">         <strong>public </strong>BeeObserver(Bee bee){<strong>this</strong>.bee=bee;}</span></p><p><span style="font-family: 'Courier New'; font-size: 10pt;">         <strong>public void</strong> update(){</span></p><p><span style="font-family: 'Courier New'; font-size: 10pt;">              <strong>if</strong> (<span style="text-decoration: underline;">isOpen</span>) //</span>the attribute value of Flower</p><p><span style="font-family: 'Courier New'; font-size: 10pt;">               bee.dinner(); </span></p><p>                     </p><p><span style="font-family: 'Courier New'; font-size: 10pt;">              <strong>else</strong>  bee.rest();</span></p><p>                     </p><p><span style="font-family: 'Courier New'; font-size: 10pt;">}}</span></p></pre><p><span style="font-size: 11pt; font-family: 'Calibri','sans-serif';">Finally the Main class: <br/></span></p><pre class="jive_text_macro jive_macro_quote"><p><strong style="font-size: 10pt; font-family: 'Courier New';">package</strong><span style="font-family: 'Courier New'; font-size: 10pt;"> Bee;</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><strong style="font-size: 10pt; font-family: 'Courier New';">public</strong><span style="font-family: 'Courier New'; font-size: 10pt;"> <strong>class</strong> Main {</span></p><p><strong style="font-size: 10pt; font-family: 'Courier New';">public</strong><span style="font-family: 'Courier New'; font-size: 10pt;"> <strong>static</strong> <strong>void</strong>main(String[] args) {</span></p><p>        </p><p><span style="font-family: 'Courier New'; font-size: 10pt;">      Flower f = <strong>new</strong> Flower();     </span></p><p><span style="font-family: 'Courier New'; font-size: 10pt;">      Beeb1 = <strong>new</strong> Bee("B1");</span></p><p><span style="font-family: 'Courier New'; font-size: 10pt;">      Beeb2 = <strong>new</strong> Bee("B2");</span></p><p>      </p><p><span style="font-family: 'Courier New'; font-size: 10pt;">        f.open();</span></p><p><span style="font-family: 'Courier New'; font-size: 10pt;">        f.close();</span></p><p><span style="font-family: 'Courier New'; font-size: 10pt;">        f.open();</span></p><p><span style="font-family: 'Courier New'; font-size: 10pt;">        System.<em>out</em>.println("c'estbon");</span></p><p><span style="font-family: 'Courier New'; font-size: 10pt;">    }</span></p><p><span style="font-family: 'Courier New'; font-size: 10pt;">}</span></p></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="font-size: 11pt; font-family: 'Calibri','sans-serif';">theXML file: </span></p><p><span style="font-size: 11pt; font-family: 'Calibri','sans-serif';"><br/></span></p><pre class="jive_text_macro jive_macro_quote"><p><span style="font-family: 'Courier New'; font-size: 10pt;"><?xmlversion="1.0" encoding="UTF-8"?></span></p><p><span style="font-family: 'Courier New'; font-size: 10pt;"><aop></span></p><p>   </p><p><span style="font-family: 'Courier New'; font-size: 10pt;">   <introductionclass="Bee.Bee"></span></p><p><span style="font-family: 'Courier New'; font-size: 10pt;">        <mixin></span></p><p><span style="font-family: 'Courier New'; font-size: 10pt;">           <interfaces>Bee.FlowerObserver</interfaces> </span></p><p><span style="font-family: 'Courier New'; font-size: 10pt;">           <class>Bee.BeeObserver</class></span></p><p><span style="font-family: 'Courier New'; font-size: 10pt;">            <construction>new Bee.BeeObserver(this)</construction></span></p><p><span style="font-family: 'Courier New'; font-size: 10pt;">        </mixin></span></p><p><span style="font-family: 'Courier New'; font-size: 10pt;">    </introduction>  </span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="font-family: 'Courier New'; font-size: 10pt;">   <aspect class="Bee.BeeObserver"/></span></p><p><span style="font-family: 'Courier New'; font-size: 10pt;">   <bind pointcut="set(private boolean Bee.Flower->isOpen)"></span></p><p><span style="font-family: 'Courier New'; font-size: 10pt;">   <after aspect="Bee.BeeObserver" name="update"/></span></p><p><span style="font-family: 'Courier New'; font-size: 10pt;">   </bind></span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="font-family: 'Courier New'; font-size: 10pt;"></aop></span></p></pre><p><span style="font-size: 11pt; font-family: 'Calibri','sans-serif';">This code contains several errors!! but I would have the following result: </span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><strong><span style="font-size: 11pt; font-family: 'Calibri','sans-serif';">B1 Bee's breakfast time! </span><span style="font-family: 'Calibri','sans-serif'; font-size: 11pt;"><br/>B2 Bee's breakfast time! <br/>B1 Bee's bed time! <br/>B2 Bee's bed time! <br/>B1 Bee's breakfast time! <br/>B2 Bee's breakfast time! </span></strong></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><strong style="font-size: 11pt; font-family: 'Calibri','sans-serif';">Tahnk's in advance <span> :) </span><br/></strong></p></div>
<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
<p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/584755#584755">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in JBoss AOP at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2027">Community</a></p>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>