1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to you under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 /* 18 * a classical listener queue pattern 19 */ 20 21 22 23 /** 24 * @class 25 * @name _ListenerQueue 26 * @extends myfaces._impl._util._Queue 27 * @memberOf myfaces._impl._util 28 * @description Implementation of the listener queue for jsf.js 29 * <p>It is based upon our high performance queue and adds dedicated 30 * methods for listener based closures to the mix </p> 31 * */ 32 myfaces._impl.core._Runtime.extendClass("myfaces._impl._util._ListenerQueue", myfaces._impl._util._Queue, 33 /** 34 * @lends myfaces._impl._util._ListenerQueue.prototype 35 */ 36 { 37 /** 38 * standard constructor 39 */ 40 constructor_: function() { 41 this._callSuper("constructor"); 42 }, 43 44 /** 45 * listener type safety assertion function 46 * 47 * @param {function} listener must be of type function otherwise an error is raised 48 */ 49 _assertListener : function( listener) { 50 if ("function" != typeof (listener)) { 51 var msg = myfaces._impl._util._Lang.getMessage("ERR_PARAM_GENERIC",null,"_ListenerQueue", arguments.caller.toString(),"function" ); 52 throw Error(msg); 53 } 54 }, 55 56 /** 57 * adds a listener to the queue 58 * 59 * @param {function} listener the listener to be added 60 */ 61 enqueue : function(listener) { 62 this._assertListener(listener); 63 this._callSuper("enqueue", listener); 64 }, 65 66 /** 67 * removes a listener form the queue 68 * 69 * @param {function} listener the listener to be removed 70 */ 71 remove : function(listener) { 72 this._assertListener(listener); 73 this._callSuper("remove", listener); 74 }, 75 76 /** 77 * generic broadcast with a number of arguments being passed down 78 * @param {Object} argument, the arguments passed down which are broadcast 79 */ 80 broadcastEvent : function(argument) { 81 var _Lang = myfaces._impl._util._Lang; 82 var _args = _Lang.objToArray(arguments); 83 84 var broadCastFunc = function(element) { 85 element.apply(null, _args); 86 }; 87 try { 88 this.each(broadCastFunc); 89 } finally { 90 broadCastFunc = null; 91 } 92 } 93 });