1 //!-- UTF8 2 /* 3 Oregano Multiuser Server - Version 1.2.0 - January 4th, 2005 4 5 Web: www.oregano-server.org 6 Mail: info@oregano-server.org 7 8 Copyright 2003 - 2004 Jens Halm / Cologne, Germany 9 10 This library is free software; you can redistribute it and/or 11 modify it under the terms of the GNU Lesser General Public 12 License as published by the Free Software Foundation; either 13 version 2.1 of the License, or (at your option) any later version. 14 15 This library is distributed in the hope that it will be useful, 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 Lesser General Public License for more details. 19 20 You should have received a copy of the GNU Lesser General Public 21 License along with this library; if not, write to the Free Software 22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 */ 24 25 /* 26 ------------------------------------------- 27 Classe EventDispatcher 28 29 @description : 30 Enveloppe de la classe EventSource. 31 (Conserve l'implémentation originale) 32 33 EXTENDS EventSource 34 35 @author Jens Halm copyright http://www.spicefactory.org/ 36 @author erixtekila copyleft http://www.v-i-a.net 37 ------------------------------------------- 38 version history : 39 1.2.0 : 30/12/04 40 - Portage en actionscript 2 pour le 41 compile time type checking 42 - Transformation en classe 43 - Utilise les méthodes d'EventSource au maximum. 44 - return null sur checkArguments 45 ------------------------------------------- 46 */ 47 48 import org.omus.util.EventSource; 49 import org.omus.util._Class; 50 51 /** 52 * Enveloppe de la classe EventSource. 53 * (Conserve l'implémentation originale) 54 * 55 * @author Jens Halm copyright http://www.spicefactory.org/ 56 * @author erixtekila copyleft http://www.v-i-a.net 57 * @version 1.2.0 58 */ 59 class org.omus.util.EventDispatcher extends EventSource 60 { 61 //-------------------- 62 // CONSTRUCTEUR 63 //-------------------- 64 public function EventDispatcher() 65 { 66 // Initialisation du super constructeur pour diponibilité de _listener 67 super(); 68 69 // trace(this+" initialisé"); 70 } 71 72 //-------------------- 73 // METHODES PUBLIQUES 74 //-------------------- 75 /** 76 * Utilisé dans un contexte littéral. 77 * 78 * @return Une chaine définissant l'objet. 79 */ 80 public function toString():String 81 { 82 return "[Objet EventDispatcher]"; 83 } 84 85 /** 86 * Ajoute un nouvel observateur. 87 * 88 * @param listener Référence de l'observateur. 89 * @return Un booléen indiquant la réussite de l'opération ou null. 90 */ 91 public function addListener (listener:Object):Boolean 92 { 93 // TODO : Accès Singleton 94 var clazz = _Class.getInstance(); 95 if (! clazz.checkArguments("org.omus.util.EventDispatcher.addListener",[[listener, Object, true]])) return null; 96 return super.addListener(listener); 97 } 98 99 /** 100 * Notifie les observateurs d'un événement. 101 * Autant de paramètres que souhaité peuvent être passés en argument. 102 * 103 * @param logLevel Une chaine caractérisant le niveau de log de l'information. 104 * @param eventName Nom de l'événement. 105 * @param arg [option]Autant d'arguments que nécessaire passés à l'observateur. 106 */ 107 public function fireEvent (logLevel:String, eventName:String):Void 108 { 109 // Suppression du premier argument 110 var params = arguments.concat(); 111 params.shift(); 112 broadcastMessage.apply (this, params); 113 114 // Système de log 115 // Logs internes 116 if (eventName != "onLog" && _global.oregano.iLog[logLevel+"Enabled"]()) 117 { 118 var str = "event = " + eventName + "\narguments = "; 119 // Transforme en tableau la liste d'arguments 120 var args = new Array(); 121 for (var i = 2; i < 7; i++) 122 { 123 var a = arguments[i]; 124 if (typeof(a) != "undefined") args.push(a); 125 } 126 str += org.omus.util.Log.formatArray(args, 1) + "\nnumber of listeners = " + super.countListeners(); 127 // Logs internes 128 _global.oregano.iLog.logLocal("INFO", "clj-060", str); 129 } 130 } 131 } 132