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