1 //!-- UTF8 2 /* 3 Oregano Multiuser Server - Version 1.1.0 - April 14th, 2004 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 MessageHandler 28 29 @description : 30 Enregistre les gestionnaires de message. 31 32 33 @author Jens Halm copyright http://www.spicefactory.org/ 34 @author erixtekila copyleft http://www.v-i-a.net 35 ------------------------------------------- 36 version history : 37 1.2.0 : 05/01/05 38 - Portage en actionscript 2 pour le 39 compile time type checking 40 - Transformation en classe 41 ------------------------------------------- 42 */ 43 44 import org.omus.msg.*; 45 46 /** 47 * Active la gestion de réception de message par accusé de réception 48 * via des gestionnaires d'événements (callback) appellés suite 49 * au résultat de l'envoi d'un message au serveur. 50 * 51 * @author Jens Halm copyright http://www.spicefactory.org/ 52 @author erixtekila copyleft http://www.v-i-a.net 53 * @version 1.2.0 54 */ 55 class org.omus.msg.MessageHandler 56 { 57 //-------------------- 58 // PROPRIETES 59 //-------------------- 60 /** 61 * Un tableau associatif des gestionnaires. 62 */ 63 private var handlers:Object; 64 65 /** 66 * Une référence à l'objet supportant l'accusé de réception (callback) 67 */ 68 private var target:Object; 69 70 //-------------------- 71 // CONSTRUCTEUR 72 //-------------------- 73 /** 74 * 75 */ 76 public function MessageHandler () 77 { 78 // trace(this+ " installé."); 79 // initMessageHandler(); 80 } 81 82 //-------------------- 83 // METHODES PUBLIQUES 84 //-------------------- 85 /** 86 * Utilisé dans un contexte littéral. 87 * 88 * @return Une chaine définissant l'objet. 89 */ 90 public function toString():String 91 { 92 return "[Objet MessageHandler]"; 93 } 94 95 /** 96 * Initialise le système de messages. 97 * 98 * @param refObject L'objet supportant le callback généré par MessageRouter 99 */ 100 public function initMessageHandler (refObject:Object):Void 101 { 102 handlers = new Object(); 103 target = refObject; 104 } 105 106 /** 107 * Active la gestion d'un type d'accusé de réception en fonction du contenu de son enveloppe. 108 * 109 * @param env Une référence à l'enveloppe. 110 */ 111 public function handleMessage (env:Envelope):Void 112 { 113 // Renvoi le sujet d'un message via son enveloppe conservé dans handlers 114 var mName = handlers[env.getMessage().getSubject()]; 115 if (mName == undefined) 116 { 117 // Logs internes 118 _global.oregano.iLog.error("clj-046","envelope = " + env.toString()); 119 return; 120 } 121 // Active la méthode associée au message 122 target[mName](env); 123 } 124 125 /** 126 * Rajoute un accusé de réception. 127 * 128 * @param subject Le type de message. 129 * @param methodName Le nom de l'événement gérant un type de message. 130 */ 131 public function addHandler (subject:String, methodName:String):Void 132 { 133 handlers[subject] = methodName; 134 } 135 } 136