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 _MF_CLS(_PFX_UTIL+"_ListenerQueue", myfaces._impl._util._Queue,
 33 /**
 34  * @lends myfaces._impl._util._ListenerQueue.prototype
 35  */
 36 {
 37 
 38     /**
 39      * listener type safety assertion function
 40      *
 41      * @param {function} listener must be of type function otherwise an error is raised
 42      */
 43     _assertListener : function( listener) {
 44         if ("function" != typeof (listener)) {
 45             var msg = myfaces._impl._util._Lang.getMessage("ERR_PARAM_GENERIC",null,"_ListenerQueue", arguments.caller.toString(),"function" );
 46             throw Error(msg);
 47         }
 48     },
 49 
 50     /**
 51      * adds a listener to the queue
 52      *
 53      * @param {function} listener the listener to be added
 54      */
 55     enqueue : function(listener) {
 56         this._assertListener(listener);
 57         this._callSuper("enqueue", listener);
 58     },
 59 
 60     /**
 61      * removes a listener form the queue
 62      *
 63      * @param {function} listener the listener to be removed
 64      */
 65     remove : function(listener) {
 66         this._assertListener(listener);
 67         this._callSuper("remove", listener);
 68     },
 69 
 70     /**
 71      * generic broadcast with a number of arguments being passed down
 72      * @param {Object} argument, the arguments passed down which are broadcast
 73      */
 74     broadcastEvent : function(argument) {
 75         var _args = myfaces._impl._util._Lang.objToArray(arguments);
 76 
 77         var broadCastFunc = function(element) {
 78             element.apply(null, _args);
 79         };
 80         try {
 81             this.each(broadCastFunc);
 82         } finally {
 83             broadCastFunc = null;
 84         }
 85     }
 86 });