1 /** 2 * Constructs a new data adapter. 3 * @class Represents an abstract Class for data adapters. The Adapter class is the base class for all custom adapters in WSO2Vis. 4 * @constructor 5 */ 6 wso2vis.a.Adapter = function() { 7 this.dp = null; 8 this.drList = []; 9 wso2vis.environment.adapters.push(this); 10 id = wso2vis.environment.adapters.length - 1; 11 this.getID = function() { 12 return id; 13 } 14 }; 15 16 /** 17 * Adds a data provider. 18 * @param {wso2vis.p.DataProvider} dp a data provider. 19 */ 20 wso2vis.a.Adapter.prototype.dataProvider = function(dp) { 21 this.dp = dp; 22 this.dp.addDataReceiver(this); 23 return; 24 }; 25 26 /** 27 * Adds a data receiver. 28 * @param {wso2vis.s.Subscriber} dr a data receiver. 29 */ 30 wso2vis.a.Adapter.prototype.addDataReceiver = function(dr) { 31 this.drList.push(dr); 32 }; 33 34 35 /** 36 * Pushes data to all the available data receivers. 37 * @private 38 * @param {json} data a json data object. 39 */ 40 wso2vis.a.Adapter.prototype.pushData = function(data) { 41 var filteredData = this.convertData(data); 42 for (i = 0; i < this.drList.length; i++) { 43 (this.drList[i]).pushData(filteredData); 44 } 45 }; 46 47 /** 48 * Pulls data from the data provider. 49 */ 50 wso2vis.a.Adapter.prototype.pullData = function() { 51 this.dp.pullData(); 52 }; 53 54 /** 55 * Converts data inside the adapter. This method should be override with a custom converter function. 56 * @param {json} data a json data object. 57 * @returns {json} converted json data object. 58 */ 59 wso2vis.a.Adapter.prototype.convertData = function(data) { 60 return data; 61 }; 62 63