277294.ijbsn.asia Button.java 2004-03-24T16:00:00Z 2004-03-24T16:00:00Z <br/><TEXTAREA name="code" class="java" rows="16" cols="100">package examples.command.aspectj; /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- * * This file is part of the design patterns project at UBC * * The contents of this file are subject to the Mozilla Public License * Version 1.1 (the &quot;License&quot;); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/. * * Software distributed under the License is distributed on an &quot;AS IS&quot; basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is ca.ubc.cs.spl.pattern. * * Contributor(s): */ import javax.swing.JButton; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; /** * Implements a simple extension of JButton that supplies its own * ActionListener and calls its own &lt;code&gt;clicked()&lt;/code&gt; method * whenever the button is pressed. * * @author Jan Hannemann * @author Gregor Kiczales * @version 1.0, 05/13/02 * */ public class Button extends JButton { /** * Creates a new button with the provided label * * @param name the label of the button */ public Button(String name) { super(name); this.setActionCommand(name); this.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { clicked(); } }); } /** * Stub method that is called whenever the button is pressed. */ public void clicked() {} }</TEXTAREA><br><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> 2004-03-24T16:00:00Z ButtonCommand.java 2004-03-24T16:00:00Z 2004-03-24T16:00:00Z <br/><TEXTAREA name="code" class="java" rows="16" cols="100">package examples.command.aspectj; /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- * * This file is part of the design patterns project at UBC * * The contents of this file are subject to the Mozilla Public License * Version 1.1 (the &quot;License&quot;); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/. * * Software distributed under the License is distributed on an &quot;AS IS&quot; basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is ca.ubc.cs.spl.pattern. * * Contributor(s): */ import ca.ubc.cs.spl.pattern.library.Command; import ca.ubc.cs.spl.pattern.library.CommandReceiver; /** * Implements a sample command. This one prints a short message to * &lt;code&gt;System.out&lt;/code&gt; whenever it executes. The message is * &lt;quote&gt;&quot;ButtonCommand executed&quot;&lt;/quote&gt;. * * @author Jan Hannemann * @author Gregor Kiczales * @version 1.1, 10/29/02 */ public class ButtonCommand implements Command { private Printer printer = new Printer(); /** * Implements a sample command. This one prints a short message to * &lt;code&gt;System.out&lt;/code&gt; whenever it executes. The message is * &lt;quote&gt;&quot;ButtonCommand executed&quot;&lt;/quote&gt;. */ public void executeCommand(CommandReceiver receiver ) { printer.println(&quot;ButtonCommand executed&quot;); } } </TEXTAREA><br><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> 2004-03-24T16:00:00Z ButtonCommand2.java 2004-03-24T16:00:00Z 2004-03-24T16:00:00Z <br/><TEXTAREA name="code" class="java" rows="16" cols="100">package examples.command.aspectj; /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- * * This file is part of the design patterns project at UBC * * The contents of this file are subject to the Mozilla Public License * Version 1.1 (the &quot;License&quot;); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/. * * Software distributed under the License is distributed on an &quot;AS IS&quot; basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is ca.ubc.cs.spl.pattern. * * Contributor(s): */ /** * Implements a sample clas that becomes a command in the pattern context. * Instead of implementing the &lt;i&gt;Command&lt;/i&gt; interface directly, the pattern * aspect assigns that role to this class and fills in the &lt;code&gt; * executeCommand()&lt;/code&gt; method.&lt;p&gt; * * This illustrates that any exisiting class can be turned into a &lt;i&gt;Command * &lt;/i&gt; without having to change the class itself. * * @author Jan Hannemann * @author Gregor Kiczales * @version 1.0, 07/13/02 */ public class ButtonCommand2 {} </TEXTAREA><br><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> 2004-03-24T16:00:00Z ButtonCommanding.java 2004-03-24T16:00:00Z 2004-03-24T16:00:00Z <br/><TEXTAREA name="code" class="java" rows="16" cols="100">package examples.command.aspectj; import ca.ubc.cs.spl.pattern.library.CommandProtocol; import ca.ubc.cs.spl.pattern.library.Command; import ca.ubc.cs.spl.pattern.library.CommandInvoker; import ca.ubc.cs.spl.pattern.library.CommandReceiver; import java.io.PrintStream; public aspect ButtonCommanding extends CommandProtocol { declare parents: Button implements CommandInvoker; declare parents: Printer implements CommandReceiver; declare parents: ButtonCommand implements Command; // Unneccessay declare parents: ButtonCommand2 implements Command; // &quot;Making&quot; a class // a Command /** * Implements a sample command. This one prints a short message to * &lt;code&gt;System.out&lt;/code&gt; whenever it executes. The message is * &lt;quote&gt;&quot;ButtonCommand number 2 executed&quot;&lt;/quote&gt;. */ public void ButtonCommand2.executeCommand(CommandReceiver receiver) { ((Printer) receiver).println(&quot;ButtonCommand number 2 executed&quot;); } /** * The join points after which to execute the command. * This replaces the normally scattered myCommand.execute() calls. * In this example, a call to &lt;code&gt;Button.clicked()&lt;/code&gt; triggers * the execution of the command. * * @param invoker the object invoking the command */ protected pointcut commandTrigger(CommandInvoker invoker): call(void Button.clicked()) &amp;&amp; target(invoker); } </TEXTAREA><br><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> 2004-03-24T16:00:00Z Main.java 2004-03-24T16:00:00Z 2004-03-24T16:00:00Z <br/><TEXTAREA name="code" class="java" rows="16" cols="100">package examples.command.aspectj; /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- * * This file is part of the design patterns project at UBC * * The contents of this file are subject to the Mozilla Public License * Version 1.1 (the &quot;License&quot;); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/. * * Software distributed under the License is distributed on an &quot;AS IS&quot; basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is ca.ubc.cs.spl.pattern. * * Contributor(s): */ import javax.swing.JFrame; import javax.swing.JPanel; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import ca.ubc.cs.spl.pattern.library.Command; /** * Implements the driver for the command design pattern example.&lt;p&gt; * * Intent: &lt;i&gt;Encapsulate a request as an object, thereby letting you * parameterize clients with different requests, queueu or log requests, * and support undoable operations.&lt;/i&gt;&lt;p&gt; * * Participatng objects are &lt;code&gt;Button&lt;/code&gt;s as &lt;i&gt;Invoker&lt;/i&gt;s, * and a &lt;code&gt;ButtonCommand&lt;/code&gt; and &lt;code&gt;ButtonCommand2&lt;/code&gt; as * two concrete &lt;i&gt;Command&lt;/i&gt;s. * * This example creates a simple GUI with three buttons. Each button has a * command associated with it that is executed when the button is pressed. * Button1 and button3 have the same command, button2 has a different one. * * &lt;p&gt;&lt;i&gt;This is the Java version.&lt;/i&gt;&lt;p&gt; * * This version of the pattern lets the developer specify what should trigger * a call to &lt;code&gt;executeCommand()&lt;/code&gt;, without changing the &lt;i&gt;Invoker * &lt;/i&gt; code. * * Neither &lt;i&gt;Commands&lt;/i&gt; nor &lt;i&gt;Invoker&lt;/i&gt; have to know of their * involvement in the pattern and can actually act as both. * &lt;code&gt;ButtonCommanding2&lt;/code&gt; is an example of a &lt;i&gt;Command&lt;/i&gt; that * is unaware of its role. In such cases, the concrete pattern instance * aspect assigns the role and defines the &lt;i&gt;Command&lt;/i&gt;'s behavior. * * @author Jan Hannemann * @author Gregor Kiczales * @version 1.0, 05/13/02 * * @see Button * @see ButtonCommand * @see Buttoncommand2 */ public class Main extends JFrame { /** * This example creates a simple GUI with three buttons. Each button has a * command associated with it that is executed when the button is pressed. * Button1 and button3 have the same command, button2 has a different one. */ public static void main(String[] args) { Button button1 = new Button(&quot;Button1&quot;); Button button2 = new Button(&quot;Button2&quot;); Button button3 = new Button(&quot;Button3&quot;); Command com1 = new ButtonCommand(); Command com2 = new ButtonCommand2(); JPanel pane = new JPanel(); pane.add(button1); ButtonCommanding.aspectOf().setCommand(button1, com1); pane.add(button2); ButtonCommanding.aspectOf().setCommand(button2, com2); ButtonCommanding.aspectOf().setReceiver(com2, new Printer()); pane.add(button3); ButtonCommanding.aspectOf().setCommand(button3, com1); JFrame frame = new JFrame(&quot;Testing: Command Pattern&quot;); frame.getContentPane().add(pane); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) {System.exit(0);} }); frame.pack(); frame.setVisible(true); } } </TEXTAREA><br><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> 2004-03-24T16:00:00Z Printer.java 2004-03-24T16:00:00Z 2004-03-24T16:00:00Z <br/><TEXTAREA name="code" class="java" rows="16" cols="100">package examples.command.aspectj; /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- * * This file is part of the design patterns project at UBC * * The contents of this file are subject to the Mozilla Public License * Version 1.1 (the &quot;License&quot;); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/. * * Software distributed under the License is distributed on an &quot;AS IS&quot; basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is ca.ubc.cs.spl.patterns. * * Contributor(s): */ /** * Helper class that is used as a receiver for the Command pattern. * * @author Jan Hannemann * @author Gregor Kiczales * @version 1.1, 10/29/02 * */ public class Printer { public void println(String s) { System.out.println(s); } } </TEXTAREA><br><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> 2004-03-24T16:00:00Z files.lst 2004-03-24T16:00:00Z 2004-03-24T16:00:00Z <br/><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> 2004-03-24T16:00:00Z