diff --git a/dist/contactJS.js b/dist/contactJS.js index 224875a799eece4b5767f92248b868fa5bbee1b9..2ef45a4c4a5cd1fc981621fa0e37494b84db674c 100644 --- a/dist/contactJS.js +++ b/dist/contactJS.js @@ -2614,7 +2614,7 @@ define('callbackList',['easejs', 'abstractList', 'callback'], * @returns {CallbackList} */ 'public withItems': function(_callbackList){ - var list = new Array(); + var list = []; if(_callbackList instanceof Array){ list = _callbackList; } else if (Class.isA(CallbackList, _callbackList)) { @@ -2654,11 +2654,10 @@ define('callbackList',['easejs', 'abstractList', 'callback'], * @public * @alias putAll * @memberof CallbackList# - * @param {(CallbackList|Array)} - * _callbackList CallbackList + * @param {(CallbackList|Array)} _callbackList CallbackList */ 'public putAll' : function(_callbackList){ - var list = new Array(); + var list = []; if(_callbackList instanceof Array){ list = _callbackList; } else if (Class.isA(CallbackList, _callbackList)) { @@ -2715,7 +2714,7 @@ define('callbackList',['easejs', 'abstractList', 'callback'], return true; } return false; - }, + } }); @@ -3677,6 +3676,144 @@ define('subscriberList',['easejs', 'abstractList', 'subscriber'], return SubscriberList; }); +/** + * This module represents a WidgetHandle which contains name and id of the + * Widget that should be subscribed to. + * + * @module WidgetHandle + * @fileOverview + */ +define('widgetHandle',[ 'easejs' ], function(easejs) { + var Class = easejs.Class; + + /** + * @class WidgetHandle + * @classdesc This Class contains name and id of a Widget that should be + * subscribed to. + * @requires easejs + */ + var WidgetHandle = Class('WidgetHandle', { + + /** + * @alias name + * @private + * @type {string} + * @memberof WidgetHandle# + * @desc Name of the Widget that should be subscribed to. + */ + 'private name' : '', + /** + * @alias id + * @private + * @type {string} + * @memberof WidgetHandle# + * @desc Id of the Widget that should be subscribed to. + */ + 'private id' : '', + + /** + * Builder for variable name + * + * @public + * @alias withName + * @memberof WidgetHandle# + * @param {string} _name + * @returns {WidgetHandle} + */ + 'public withName' : function(_name) { + this.setName(_name); + return this; + }, + + /** + * Builder for variable id + * + * @public + * @alias withId + * @memberof WidgetHandle# + * @param {string} _id + * @returns {WidgetHandle} + */ + 'public withId' : function(_id) { + this.setId(_id); + return this; + }, + + /** + * Returns the name of the Widget that should be subscribed to. + * + * @public + * @alias getName + * @memberof WidgetHandle# + * @returns {string} name + */ + 'public getName' : function() { + return this.name; + }, + + /** + * Sets the name of the Widget that should be subscribed to. + * + * @public + * @alias setName + * @memberof WidgetHandle# + * @param {string} _name name of the Widget that should be subscribed to + */ + 'public setName' : function(_name) { + if (typeof _name === 'string') { + this.name = _name; + } + }, + + /** + * Returns the id of the Widget that should be subscribed to. + * + * @public + * @alias getId + * @memberof WidgetHandle# + * @returns {string} + */ + 'public getId' : function() { + return this.id; + }, + + /** + * Sets the id of the Widget that should be subscribed to. + * + * @public + * @alias setId + * @memberof WidgetHandle# + * @param {string} _id id of the Widget that should be subscribed to + */ + 'public setId' : function(_id) { + if (typeof _id === 'string') { + this.id = _id; + } + }, + + /** + * Compare the specified WidgetHandle with this instance + * + * @public + * @alias equals + * @memberof WidgetHandle# + * @param {WidgetHandle} _widgetHandle WidgetHandle that should be compared + * @returns {boolean} + */ + 'public equals' : function(_widgetHandle) { + if (Class.isA(WidgetHandle, _widgetHandle)) { + if (_widgetHandle.getName() == this.getName() + && _widgetHandle.getId() == this.getId()) { + return true; + } + } + return false; + }, + + }); + + return WidgetHandle; +}); /** * This module represents the WidgetDescription. * It describes the most important information for the communication with a specific widget. @@ -3684,8 +3821,8 @@ define('subscriberList',['easejs', 'abstractList', 'subscriber'], * @module WidgetDescription * @fileOverview */ -define('widgetDescription',['easejs', 'attributeTypeList'], - function(easejs, AttributeTypeList){ +define('widgetDescription',['easejs', 'attributeTypeList', 'widgetHandle'], + function(easejs, AttributeTypeList, WidgetHandle){ var Class = easejs.Class; var WidgetDescription = Class('WidgetDescription',{ @@ -3712,7 +3849,15 @@ define('widgetDescription',['easejs', 'attributeTypeList'], * @memberof WidgetDescription# * @desc List of attributeTypes that are provided. */ - 'protected outAttributeTypes' : [], + 'protected outAttributeTypes' : [], + /** + * @alias callbackNames + * @protected + * @type {array} + * @memberof WidgetDescription# + * @desc Array of available callback names. + */ + 'protected callbackNames' : [], /** * Constructor: Initializes the inAttributeTypes. @@ -3831,7 +3976,7 @@ define('widgetDescription',['easejs', 'attributeTypeList'], 'public setName' : function(_name){ if(typeof _name === 'string'){ this.name = _name; - }; + } }, /** @@ -3852,11 +3997,11 @@ define('widgetDescription',['easejs', 'attributeTypeList'], * Adds an outAttributeType to the list * * @public - * @alias setOutAttributeType + * @alias addOutAttributeType * @memberof WidgetDescription# * @param {AttributeType} _outAttributeType AttributeType that are provided */ - 'public setOutAttributeType' : function(_outAttributeType){ + 'public addOutAttributeType' : function(_outAttributeType){ this.outAttributeTypes.put(_outAttributeType); }, @@ -3864,17 +4009,29 @@ define('widgetDescription',['easejs', 'attributeTypeList'], * Adds outAttributeTypes that are provided by the Widget * * @public - * @alias setOutAttributeTypes + * @alias addOutAttributeTypes * @memberof WidgetDescription# * @param {(AttributeTypeList|Array)} _outAttributeTypes List of AttributeType that are provided */ - 'public setOutAttributeTypes' : function(_outAttributeTypes){ + 'public addOutAttributeTypes' : function(_outAttributeTypes){ this.outAttributeTypes.putAll(_outAttributeTypes); - } + }, + + 'public setCallbackNames' : function(_callbackNames) { + this.callbackNames = _callbackNames; + }, + + 'public addCallbackName' : function(_callbackName) { + this.callbackNames.push(_callbackName); + }, + + 'public getHandle' : function() { + return new WidgetHandle().withName(this.name).withId(this.id); + } - }); + }); - return WidgetDescription; + return WidgetDescription; }); /** @@ -4000,8 +4157,10 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeTy * @requires Discoverer * @constructs Widget */ - 'virtual public __construct' : function() { + 'virtual public __construct' : function(_discoverer) { this.id = Math.uuid(); + this.discoverer = _discoverer; + this.register(); this.attributeTypes = new AttributeTypeList(); this.constantAttributeTypes = new AttributeTypeList(); this.attributes = new AttributeValueList(); @@ -4053,11 +4212,11 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeTy * Returns the available AttributeTypes. * * @public - * @alias getWidgetAttributeTypes + * @alias getAttributeTypes * @memberof Widget# * @returns {AttributeTypeList} */ - 'public getWidgetAttributeTypes' : function() { + 'public getAttributeTypes' : function() { return this.attributeTypes; }, @@ -4078,11 +4237,11 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeTy * Returns the last acquired Attributes. * * @public - * @alias queryAttributes + * @alias getAttributes * @memberof Widget# * @returns {AttributeValueList} */ - 'public queryAttributes' : function() { + 'public getAttributes' : function() { return this.attributes; }, @@ -4102,27 +4261,40 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeTy * Returns the ConstantAttributes. * * @public - * @alias queryConstantAttributes + * @alias getConstantAttributes * @memberof Widget# * @returns {AttributeValueList} */ - 'public queryConstantAttributes' : function() { + 'public getConstantAttributes' : function() { return this.constantAttributes; }, /** - * Returns the specified Callbacks that can be - * subscribed. + * Returns a list of callbacks that can be + * subscribed to. * * @public - * @alias queryCallbacks + * @alias getCallbacks * @memberof Widget# * @returns {CallbackList} */ - 'public queryCallbacks' : function() { + 'public getCallbackList' : function() { return this.callbacks; }, + /** + * Returns the specified callbacks that can be + * subscribed to. + * + * @public + * @alias getCallbacks + * @memberof Widget# + * @returns {Array} + */ + 'public getCallbacks' : function() { + return this.callbacks.getItems(); + }, + 'public queryServices' : function() { return this.services; }, @@ -4459,11 +4631,16 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeTy this.initAttributes(); this.initConstantAttributes(); this.initCallbacks(); + + this.didFinishInitialization(); }, + 'public virtual didFinishInitialization' : function() { + + }, + /** * Notifies other components and sends the attributes. - * Must be overridden by the subclasses * * @virtual * @public @@ -4540,8 +4717,8 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeTy */ 'public queryWidget' : function() { var response = new AttributeValueList(); - response.putAll(this.queryAttributes()); - response.putAll(this.queryConstantAttributes()); + response.putAll(this.getAttributes()); + response.putAll(this.getConstantAttributes()); return response; }, @@ -4561,8 +4738,8 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeTy } else { this.queryGenerator(); var response = new AttributeValueList(); - response.putAll(this.queryAttributes()); - response.putAll(this.queryConstantAttributes()); + response.putAll(this.getAttributes()); + response.putAll(this.getConstantAttributes()); return response; } }, @@ -4581,9 +4758,7 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeTy for ( var i in subscriberList) { var subscriber = subscriberList[i]; if (subscriber.getSubscriptionCallbacks().containsKey( _callback.getName())) { - console.log(subscriber.getSubscriberId()); if(this.dataValid(subscriber.getConditions())){ - console.log('condition' + true); var subscriberInstance = this.discoverer.getComponent(subscriber.getSubscriberId()); var callSubset = _callback.getAttributeTypes(); var subscriberSubset = subscriber.getAttributesSubset(); @@ -4620,7 +4795,7 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeTy var conditionAttributeType = condition.getAttributeType(); var conditionAttributeTypeList = new AttributeTypeList() .withItems(new Array(conditionAttributeType)); - var newValue = this.queryAttributes().getSubset(conditionAttributeTypeList); + var newValue = this.getAttributes().getSubset(conditionAttributeTypeList); var oldValue = this.getOldAttributes.getSubset(conditionAttributeTypeList); return condition.compare(newValue, oldValue); } @@ -4632,14 +4807,19 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeTy * Returns the description of this component. * @virtual * @public - * @alias getWidgetDescription + * @alias getDescription * @memberof Widget# * @returns {WidgetDescription} */ - 'virtual public getWidgetDescription' : function() { + 'virtual public getDescription' : function() { var description = new WidgetDescription().withId(this.id).withName(this.name); - description.setOutAttributeTypes(this.attributeTypes); - description.setOutAttributeTypes(this.constantAttributeTypes); + description.addOutAttributeTypes(this.attributeTypes); + description.addOutAttributeTypes(this.constantAttributeTypes); + // TODO: getCallbackNames for CallbackList + var widgetCallbacks = this.callbacks.getItems(); + for(var i in widgetCallbacks) { + description.addCallbackName(widgetCallbacks[i].getName()); + } return description; }, @@ -4685,7 +4865,7 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeTy if (this.discoverer) { this.discoverer.registerNewComponent(this); } - } + }, // /** // * Unregisters the component to the associated discoverer @@ -4702,165 +4882,31 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeTy // } // }, + 'public getHandle' : function() { + return this.getDescription().getHandle(); + } + }); return Widget; }); /** - * This module represents a WidgetHandle which contains name and id of the - * Widget that should be subscribed to. + * This module represents a WidgetHandleList. It is a subclass of + * AbstractList. * - * @module WidgetHandle + * @module WidgetHandleList * @fileOverview */ -define('widgetHandle',[ 'easejs' ], function(easejs) { - var Class = easejs.Class; - - /** - * @class WidgetHandle - * @classdesc This Class contains name and id of a Widget that should be - * subscribed to. - * @requires easejs - */ - var WidgetHandle = Class('WidgetHandle', { - - /** - * @alias name - * @private - * @type {string} - * @memberof WidgetHandle# - * @desc Name of the Widget that should be subscribed to. - */ - 'private name' : '', - /** - * @alias id - * @private - * @type {string} - * @memberof WidgetHandle# - * @desc Id of the Widget that should be subscribed to. - */ - 'private id' : '', - - /** - * Builder for variable name - * - * @public - * @alias withName - * @memberof WidgetHandle# - * @param {string} _name - * @returns {WidgetHandle} - */ - 'public withName' : function(_name) { - this.setName(_name); - return this; - }, - - /** - * Builder for variable id - * - * @public - * @alias withId - * @memberof WidgetHandle# - * @param {string} _id - * @returns {WidgetHandle} - */ - 'public withId' : function(_id) { - this.setId(_id); - return this; - }, - - /** - * Returns the name of the Widget that should be subscribed to. - * - * @public - * @alias getName - * @memberof WidgetHandle# - * @returns {string} name - */ - 'public getName' : function() { - return this.name; - }, - +define('widgetHandleList',[ 'easejs', 'abstractList', 'widgetHandle', 'widget'], + function(easejs, AbstractList, WidgetHandle, Widget) { + var Class = easejs.Class; /** - * Sets the name of the Widget that should be subscribed to. - * - * @public - * @alias setName - * @memberof WidgetHandle# - * @param {string} _name name of the Widget that should be subscribed to - */ - 'public setName' : function(_name) { - if (typeof _name === 'string') { - this.name = _name; - } - }, - - /** - * Returns the id of the Widget that should be subscribed to. - * - * @public - * @alias getId - * @memberof WidgetHandle# - * @returns {string} - */ - 'public getId' : function() { - return this.id; - }, - - /** - * Sets the id of the Widget that should be subscribed to. - * - * @public - * @alias setId - * @memberof WidgetHandle# - * @param {string} _id id of the Widget that should be subscribed to - */ - 'public setId' : function(_id) { - if (typeof _id === 'string') { - this.id = _id; - } - }, - - /** - * Compare the specified WidgetHandle with this instance - * - * @public - * @alias equals - * @memberof WidgetHandle# - * @param {WidgetHandle} _widgetHandle WidgetHandle that should be compared - * @returns {boolean} - */ - 'public equals' : function(_widgetHandle) { - if (Class.isA(WidgetHandle, _widgetHandle)) { - if (_widgetHandle.getName() == this.getName() - && _widgetHandle.getId() == this.getId()) { - return true; - } - } - return false; - }, - - }); - - return WidgetHandle; -}); -/** - * This module represents a WidgetHandleList. It is a subclass of - * AbstractList. - * - * @module WidgetHandleList - * @fileOverview - */ -define('widgetHandleList',[ 'easejs', 'abstractList', 'widgetHandle' ], - function(easejs, AbstractList, WidgetHandle) { - var Class = easejs.Class; - /** - * @class WidgetHandleList - * @classdesc This class represents a list for WidgetHandle. - * @extends AbstractList - * @requires easejs - * @requires AbstractList - * @requires WidgetHandle + * @class WidgetHandleList + * @classdesc This class represents a list for WidgetHandle. + * @extends AbstractList + * @requires easejs + * @requires AbstractList + * @requires WidgetHandle */ var WidgetHandleList = Class('WidgetHandleList').extend(AbstractList,{ /** @@ -4908,20 +4954,20 @@ define('widgetHandleList',[ 'easejs', 'abstractList', 'widgetHandle' ], }, /** - * Adds the specified item to theitem list. + * Adds a widget handle to the list. * * @public * @alias put * @memberof WidgetHandleList# - * @param {WidgetHandle} - * _widgetHandle WidgetHandle + * @param {WidgetHandle|Widget} _widgetHandleOrWidget WidgetHandle */ - 'public put' : function(_widgetHandle) { - if (Class.isA(WidgetHandle, _widgetHandle)) { - if (!(this.containsKey(_widgetHandle.getName()))) { + 'public put' : function(_widgetHandleOrWidget) { + if (Class.isA(Widget, _widgetHandleOrWidget)) _widgetHandleOrWidget = _widgetHandleOrWidget.getHandle(); + if (Class.isA(WidgetHandle, _widgetHandleOrWidget)) { + if (!(this.containsKey(_widgetHandleOrWidget.getName()))) { this.counter++; } - this.items[_widgetHandle.getName()] = _widgetHandle; + this.items[_widgetHandleOrWidget.getName()] = _widgetHandleOrWidget; } }, @@ -4993,7 +5039,7 @@ define('widgetHandleList',[ 'easejs', 'abstractList', 'widgetHandle' ], return true; } return false; - }, + } }); return WidgetHandleList; }); @@ -5074,12 +5120,12 @@ define('aggregator',['easejs', 'MathUuid','widget', 'widgetHandle', 'widgetHandl * @requires WidgetHandleList * @constructs Aggregator */ - 'override public __construct': function() + 'override virtual public __construct': function(_discoverer) { this.id = Math.uuid(); this.widgets = new WidgetHandleList(); this.initWidgetHandles(); - this.__super(); + this.__super(_discoverer); this.aggregatorSetup(); }, @@ -5351,7 +5397,7 @@ define('aggregator',['easejs', 'MathUuid','widget', 'widgetHandle', 'widgetHandl }, /** - * Adds a new subscription to this Aggregator. + * Adds the specified callbacks of a widget to the aggregator. * * @public * @alias addWidgetSubscription @@ -5359,7 +5405,7 @@ define('aggregator',['easejs', 'MathUuid','widget', 'widgetHandle', 'widgetHandl * @param {WidgetHandle} _widgetHandle Widget that should be subscribed. * @param {CallbackList} _callbacks required Callbacks */ - 'public addWidgetSubscription' : function(_widgetHandle, _callbackList){ + 'public addWidgetSubscription' : function(_widgetHandle, _callbackList){ if(Class.isA(WidgetHandle, _widgetHandle) && Class.isA(CallbackList, _callbackList)){ var widget = this.discoverer.getComponent(_widgetHandle.getId()); if(widget && widget.getName() === _widgetHandle.getName()){ @@ -5540,30 +5586,18 @@ define('aggregator',['easejs', 'MathUuid','widget', 'widgetHandle', 'widgetHandl 'public getStorageOverview' : function(){ return this.db.getAttributesOverview(); }, - + /** * Only actualizes the attributeType cache in th database. * For an alternativ action can be used a callback. - * + * * @public * @alias queryTables * @memberof Aggregator# * @param {?function} _function for alternative actions, because an asynchronous function is used */ 'public queryTables' : function(_function){ - this.db.getAttributeNames(_function); - }, - - /** - * Returns the description of this component. - * @virtual - * @public - * @alias getAggregatorDescription - * @memberof Aggregator# - * @returns {WidgetDescription} - */ - 'virtual public getAggregatorDescription' : function(){ - return this.getWidgetDescription(); + this.db.getAttributeNames(_function); } }); @@ -5663,8 +5697,7 @@ define('interpreterDescription',['easejs','attributeTypeList','widgetDescription function(easejs,AttributeTypeList,WidgetDescription){ var Class = easejs.Class; var InterpreterDescription = Class('InterpreterDescription'). - extend(WidgetDescription, - { + extend(WidgetDescription, { /** * @alias inAttributeTypes * @private @@ -5753,553 +5786,141 @@ define('interpreterDescription',['easejs','attributeTypeList','widgetDescription */ 'public setInAttributeTypes' : function(_inAttributeTypes){ this.inAttributeTypes.putAll(_inAttributeTypes); - }, - - }); + } - return InterpreterDescription; - + }); + + return InterpreterDescription; }); /** - * This module representing a Context Discoverer. + * This module represents a InterpreterResult. * - * @module Discoverer + * @module InterpreterResult * @fileOverview */ -define('discoverer',[ 'easejs', 'attributeTypeList' ], function(easejs, - AttributeTypeList) { - var Class = easejs.Class; - - var Discoverer = Class('Discoverer', { +define('interpreterResult',['easejs', 'attributeValueList'], + function(easejs, AttributeValueList){ + var Class = easejs.Class; + + var InterpreterResult = Class('InterpreterResult',{ + + /** + * @alias timestamp + * @private + * @type {date} + * @memberof InterpreterResult# + * @desc Time of the interpretation. + */ + 'private timestamp' : '', + /** + * @alias outAttributes + * @private + * @type {AttributeValueList} + * @memberof InterpreterResult# + * @desc Interpreted data. + */ + 'private outAttributes' : [], + + /** + * @alias inAttributes + * @private + * @type {AttributeValueList} + * @memberof InterpreterResult# + * @desc Data, which were used for the interpretation. + */ + 'private inAttributes' : [], + + /** + * Constructor: Initializes the in- and outAttributes. + * + * @class InterpreterResult + * @classdesc Contains the interpreted data, inclusive the input for the interpretation. + * @requires easejs + * @requires AttributeValueList + */ + 'public __construct' : function() { + this.inAttributes = new AttributeValueList(); + this.outAttributes = new AttributeValueList(); + }, + + /** + * Builder for timestamp. + * + * @public + * @alias withTimestamp + * @memberof InterpreterResult# + * @param {String} _timestamp timestamp + * @returns {InterpreterResult} + */ + 'public withTimestamp' : function(_timestamp){ + this.setTimestamp(_timestamp); + return this; + }, - /** - * @alias widgets - * @private - * @type {Array} - * @memberof Discoverer# - * @desc List of available Widgets. - */ - 'private widgets' : [], - - /** - * @alias aggregators - * @private - * @type {Array} - * @memberof Discoverer# - * @desc List of available Aggregators. - */ - 'private aggregators' : [], - - /** - * @alias interpreter - * @private - * @type {Array} - * @memberof Discoverer# - * @desc List of available Interpreter. - */ - 'private interpreter' : [], - - /** - * Constructor: All known components given in the associated functions will be registered as startup. - * - * @class Discoverer - * @classdesc The Discoverer handles requests for components and attributes. - * @requires easejs - * @requires AttributeTypeList - * @constructs Discoverer - */ - 'public __construct' : function() { - this.register(); - }, - - /** - * Returns the type of this class, in this case - * "Discoverer". - * - * @public - * @alias getType - * @memberof Discoverer# - * @returns {string} - */ - 'public getType' : function() { - return 'Discoverer'; - }, - - /* - * single call for registering the different categories of components - */ - /** - * Single call for registration of the different categories of components. - * Calls: registerWidgets(), registerAggregators(), registerInterpreter() - * - * @private - * @alias register - * @memberof Discoverer# - */ - 'private register' : function() { - this.registerWidgets(); - this.registerAggregators(); - this.registerInterpreter(); - }, - - /** - * Registers all specified widgets. - * - * @private - * @alias registerWidgets - * @memberof Discoverer# - */ - 'private registerWidgets' : function() { - }, - - /** - * Registers all specified aggregators. - * - * @private - * @alias registerAggregators - * @memberof Discoverer# - */ - 'private registerAggregators' : function() { - }, - - /** - * Registers all specified interpreters. - * - * @private - * @alias registerInterpreter - * @memberof Discoverer# - */ - 'private registerInterpreter' : function() { - }, - - /** - * Registers the specified component. - * - * @public - * @alias registerNewComponent - * @memberof Discoverer# - * @param {Widget|Aggregator|Interpreter} _component the component that should be registered - */ - 'public registerNewComponent' : function(_component) { - var category = this.identificationHelper(_component); - if (category) { - this.registryHelper(category, _component); - } - }, - - /** - * Deletes a component from the Discoverer. - * - * @public - * @alias unregisterComponent - * @memberof Discoverer# - * @param {string} _id id of the component that should be registered - */ - 'public unregisterComponent' : function(_id) { - var component = this.getComponent(_id); - var category = this.identificationHelper(component); - if (category) { - category.splice(_id, 1); - } - }, - - /** - * Returns the widget for the specified id. - * - * @public - * @alias getWidget - * @memberof Discoverer# - * @param {string} _id id of the component that should be returned - * @returns {?Widget} - */ - 'public getWidget' : function(_id) { - var widget = this.widgets[_id]; - if(!widget){ - this.widgets.splice(_id, 1); - return null; - } - return widget; - }, - - /** - * Returns the aggregator for the specified id. - * - * @public - * @alias getAggregator - * @memberof Discoverer# - * @param {string} _id id of the component that should be returned - * @returns {Aggregator} - */ - 'public getAggregator' : function(_id) { - var aggregator = this.aggregators[_id]; - if(!aggregator ){ - this.aggregators.splice(_id, 1); - return null; - } - return aggregator; - }, - - /** - * Returns the interpreter for the specified id. - * - * @public - * @alias getInterpreter - * @memberof Discoverer# - * @param {string} _id id of the component that should be returned - * @returns {Interpreter} - */ - 'public getInterpreter' : function(_id) { - var interpret = this.interpreter[_id]; - if(!interpret){ - this.interpreter.splice(_id, 1); - return null; - } - return interpret; - }, - - /** - * Returns the instance (widget, aggregator or interpreter) for the specified id. - * - * @public - * @alias getComponent - * @memberof Discoverer# - * @param {string} _id id of the component that should be returned - * @returns {?(Widget|Aggregator|Interpreter)} - */ - 'public getComponent' : function(_id) { - var component = this.getWidget(_id); - if (component) { - return component; - } - var component = this.getAggregator(_id); - if (component) { - return component; - } - var component = this.getInterpreter(_id); - if (component) { - return component; - } - return null; - }, - - /** - * Returns the description of all registered widgets. - * - * @public - * @alias getWidgetDescriptions - * @memberof Discoverer# - * @returns {Array} - */ - 'public getWidgetDescriptions' : function() { - var widgetDescription = new Array(); - var widgets = this.widgets; - for ( var i in widgets) { - var singleWidget = widgets[i]; - widgetDescription.push(singleWidget.getWidgetDescription()); - } - return widgetDescription; - }, - - /** - * Returns the description of all registered aggregators. - * - * @public - * @alias getAggregatorDescriptions - * @memberof Discoverer# - * @returns {Array} - */ - 'public getAggregatorDescriptions' : function() { - var aggregatorDescription = new Array(); - var aggregators = this.aggregators; - for ( var i in aggregators) { - var singleAggregator = aggregators[i]; - aggregatorDescription.push(singleAggregator.getAggregatorDescription()); - } - return aggregatorDescription; - }, - - /** - * Returns the description of all registered interpreter. - * - * @public - * @alias getInterpreterDescriptions - * @memberof Discoverer# - * @returns {Array} - */ - 'public getInterpreterDescriptions' : function() { - var interpreterDescription = new Array(); - var interpreters = this.interpreter; - for ( var i in interpreters) { - var singleInterpreter = interpreters[i]; - interpreterDescription.push(singleInterpreter.getInterpreterDescription()); - } - return interpreterDescription; - }, - - /** - * Returns the description of all registered components (widget, aggregator and interpreter). - * - * @public - * @alias getDescriptions - * @memberof Discoverer# - * @returns {Array} - */ - 'public getDescriptions' : function() { - var response = new Array(); - response = response.concat(this.getWidgetDescriptions()); - response = response.concat(this.getAggregatorDescriptions()); - response = response.concat(this.getInterpreterDescriptions()); - return response; - }, - - /** - * Returns all components that have the specified attribute as - * outAttribute. It can be chosen between the verification of - * all attributes or at least one attribute. - * - * @public - * @alias getComponentsByAttributes - * @memberof Discoverer# - * @param {(AttributeTypeList|Array)} _attributeTypeList list of searched attributes - * @param {boolean} _all choise of the verification mode - * @returns {Array} - */ - 'public getComponentsByAttributes' : function(_attributeTypeList, _all) { - var componentList = new Array(); - var list = new Array(); - if (_attributeTypeList instanceof Array) { - list = _attributeTypeList; - } else if (Class.isA(AttributeTypeList, _attributeTypeList)) { - list = _attributeTypeList.getItems(); - } - if (list) { - var descriptions = this.getDescriptions(); - for (var i in descriptions) { - var description = descriptions[i]; - if(_all && this.containsAllAttributes(description, list)){ - componentList.push(this.getComponent(description.getId())); - } else if(!_all && this.containsAtLeastOneAttribute(description, list)){ - componentList.push(this.getComponent(description.getId())); - } - } - } - return componentList; - }, - - /*********************************************************************** - * Helper * - **********************************************************************/ - /** - * Helper: Verifies whether a component description contains all searched attributes. - * - * @private - * @alias containsAllAttributes - * @memberof Discoverer# - * @param {(WidgetDescription|InterpreterDescription)} _description description of a component - * @param {Array} _list searched attributes - * @returns {boolean} - */ - 'private containsAllAttributes' : function(_description,_list) { - for ( var j in _list) { - var attribute = _list[j]; - if (!_description.getOutAttributeTypes().contains(attribute)) { - return false; - } - } - return true; - }, - - /** - * Helper: Verifies whether a component description contains at least on searched attributes. - * - * @private - * @alias containsAtLeastOneAttribute - * @memberof Discoverer# - * @param {(WidgetDescription|InterpreterDescription)} _description description of a component - * @param {Array} _list searched attributes - * @returns {boolean} - */ - 'private containsAtLeastOneAttribute' : function(_description,_list) { - for ( var j in _list) { - var attribute = _list[j]; - if (_description.getOutAttributeTypes().contains(attribute)) { - return true; - } - } - return false; - }, - - /** - * Helper: Saves the given component in the category list. - * - * @private - * @alias registryHelper - * @memberof Discoverer# - * @param {string} _category category of component to register - * @param {(Widget|Aggregator|Interpreter)} _component component that should be registered - */ - 'private registryHelper' : function(_category, _component) { - _category[_component.getId()] = _component; - }, - - /* - * identifies the category of an instance widgets, aggregators, - * interpreter are currently supported - */ - /** - * Helper: Identifies the category of an instance. Widgets, aggregators, - * interpreter are currently supported. - * - * @private - * @alias identificationHelper - * @memberof Discoverer# - * @param {(Widget|Aggregator|Interpreter)} _component that should be identified - */ - 'private identificationHelper' : function(_component) { - if (_component.getType() == 'Widget') { - return this.widgets; - } else if (_component.getType() == 'Aggregator') { - return this.aggregators; - } else if (_component.getType() == 'Interpreter') { - return this.interpreter; - } else { - return null; - } - } - - }); - - return Discoverer; -}); -/** - * This module represents a InterpreterResult. - * - * @module InterpreterResult - * @fileOverview - */ -define('interpreterResult',['easejs', 'attributeValueList'], - function(easejs, AttributeValueList){ - var Class = easejs.Class; - - var InterpreterResult = Class('InterpreterResult',{ - - /** - * @alias timestamp - * @private - * @type {date} - * @memberof InterpreterResult# - * @desc Time of the interpretation. - */ - 'private timestamp' : '', - /** - * @alias outAttributes - * @private - * @type {AttributeValueList} - * @memberof InterpreterResult# - * @desc Interpreted data. - */ - 'private outAttributes' : [], - - /** - * @alias inAttributes - * @private - * @type {AttributeValueList} - * @memberof InterpreterResult# - * @desc Data, which were used for the interpretation. - */ - 'private inAttributes' : [], - - /** - * Constructor: Initializes the in- and outAttributes. - * - * @class InterpreterResult - * @classdesc Contains the interpreted data, inclusive the input for the interpretation. - * @requires easejs - * @requires AttributeValueList - */ - 'public __construct' : function() { - this.inAttributes = new AttributeValueList(); - this.outAttributes = new AttributeValueList(); - }, - - /** - * Builder for timestamp. - * - * @public - * @alias withTimestamp - * @memberof InterpreterResult# - * @param {String} _timestamp timestamp - * @returns {InterpreterResult} - */ - 'public withTimestamp' : function(_timestamp){ - this.setTimestamp(_timestamp); - return this; - }, - - /** - * Builder for outAttributes. - * - * @public - * @alias withOutAttributes - * @memberof InterpreterResult# - * @param {(AttributeValueList|Array)} _outAttributes values - * @returns {InterpreterResult} - */ - 'public withOutAttributes' : function(_outAttributes){ - this.setOutAttributes(_outAttributes); - return this; - }, - - /** - * Builder for inAttributes. - * - * @public - * @alias withInAttributes - * @memberof InterpreterResult# - * @param {(AttributeValueList|Array)} _inAttributes values - * @returns {InterpreterResult} - */ - 'public withInAttributes' : function(_inAttributes){ - this.setInAttributes(_inAttributes); - return this; - }, - - - /** - * Returns the interpretation time. - * - * @public - * @alias getTimestamp - * @memberof InterpreterResult# - * @returns {date} - */ - 'public getTimestamp' : function(){ - return this.timestamp; - }, - - /** - * Returns the interpreted attributes. - * - * @public - * @alias getOutAttributes - * @memberof InterpreterResult# - * @returns {AttributeValueList} - */ - 'public getOutAttributes' : function(){ - return this.outAttributes; - }, - - /** - * Returns the inAttributes. - * - * @public - * @alias getInAttributes - * @memberof InterpreterResult# - * @returns {AttributeValueList} - */ - 'public getInAttributes' : function(){ - return this.inAttributes; - }, + /** + * Builder for outAttributes. + * + * @public + * @alias withOutAttributes + * @memberof InterpreterResult# + * @param {(AttributeValueList|Array)} _outAttributes values + * @returns {InterpreterResult} + */ + 'public withOutAttributes' : function(_outAttributes){ + this.setOutAttributes(_outAttributes); + return this; + }, + + /** + * Builder for inAttributes. + * + * @public + * @alias withInAttributes + * @memberof InterpreterResult# + * @param {(AttributeValueList|Array)} _inAttributes values + * @returns {InterpreterResult} + */ + 'public withInAttributes' : function(_inAttributes){ + this.setInAttributes(_inAttributes); + return this; + }, + + + /** + * Returns the interpretation time. + * + * @public + * @alias getTimestamp + * @memberof InterpreterResult# + * @returns {date} + */ + 'public getTimestamp' : function(){ + return this.timestamp; + }, + + /** + * Returns the interpreted attributes. + * + * @public + * @alias getOutAttributes + * @memberof InterpreterResult# + * @returns {AttributeValueList} + */ + 'public getOutAttributes' : function(){ + return this.outAttributes; + }, + + /** + * Returns the inAttributes. + * + * @public + * @alias getInAttributes + * @memberof InterpreterResult# + * @returns {AttributeValueList} + */ + 'public getInAttributes' : function(){ + return this.inAttributes; + }, /** * Sets the interpretation time. @@ -6450,351 +6071,768 @@ define('interpreter',[ 'easejs', 'MathUuid', 'attributeType', 'attributeTypeList * @requires InterpreterDescription * @constructs Interpreter */ - 'public __construct' : function() { + 'public __construct' : function(_discoverer) { this.id = Math.uuid(); + this.discoverer = _discoverer; + this.register(); this.inAttributeTypes = new AttributeTypeList(); this.outAttributeTypes = new AttributeTypeList(); this.inAttributeValues = new AttributeValueList(); this.outAttributeValues = new AttributeValueList(); this.initInterpreter(); }, - + + /** + * Returns the name of the interpreter. + * + * @public + * @alias getName + * @memberof Interpreter# + * @returns {string} + */ + 'public getName' : function() { + return this.name; + }, + + /** + * Returns the id of the interpreter. + * + * @public + * @alias getId + * @memberof Interpreter# + * @returns {string} + */ + 'public getId' : function() { + return this.id; + }, + + /** + * Returns the type of this class, in this case + * "Interpreter". + * + * @public + * @alias getType + * @memberof Interpreter# + * @returns {string} + */ + 'public getType' : function() { + return 'Interpreter'; + }, + + /** + * Initializes interpreter and sets the expected inAttributes + * and provided outAttributes. + * @private + * @alias initInterpreter + * @memberof Interpreter# + */ + 'private initInterpreter' : function() { + this.initInAttributes(); + this.initOutAttributes(); + }, + + /** + * Initializes the inAttributes. + * + * @function + * @abstract + * @protected + * @alias initInAttributes + * @memberof Interpreter# + */ + 'abstract protected initInAttributes' : [], + /** + * Initializes the outAttributes. + * + * @function + * @abstract + * @protected + * @alias initOutAttributes + * @memberof Interpreter# + */ + 'abstract protected initOutAttributes' : [], + + /** + * Returns the expected inAttributeTypes. + * + * @public + * @alias getInAttributeTypes + * @memberof Interpreter# + * @returns {AttributeTypeList} + */ + 'public getInAttributeTypes' : function() { + return this.inAttributeTypes; + }, + + /** + * Sets an inAttribute. + * + * @protected + * @alias setInAttribute + * @memberof Interpreter# + * @param {string} _name name of the attribute + * @param {string} _type type of the attribute + * @param {string} _value value of the attribute + * @param {ParameterList|Array} _parameter Parameter of the attribute. + */ + 'protected setInAttribute' : function(_name, _type, _value, _parameters) { + var attributeValue = new AttributeValue().withName(_name) + .withValue(_value).withType(_type).withParameters(_parameters); + if (this.isInAttribute(attributeValue)) { + this.inAttributeValues.put(attributeValue); + } + }, + + /** + * Sets an inAttributes. + * + * @protected + * @alias setInAttributeValues + * @memberof Interpreter# + * @param {(AttributeValueList|Array)} _attributeValueList Attributes to set. + */ + 'protected setInAttributeValues' : function(_attributeValueList) { + this.inAttributeValues = new AttributeValueList().withItems(_attributeValueList); + }, + /** + * Verifies whether the specified attribute is contained in inAttributeList. + * + * @protected + * @alias isInAttribute + * @memberof Interpreter# + * @param {AttributeValue} _attribute Attribute that should be verified. + * @return {boolean} + */ + 'protected isInAttribute' : function(_attribute) { + var type = _attribute.getAttributeType(); + if (this.inAttributeTypes.contains(type)) { + return true; + } else { + return false; + } + }, + + /** + * Returns the provided outAttributeTypes. + * + * @public + * @alias getOutAttributeTypes + * @memberof Interpreter# + * @returns {AttributeTypeList} + */ + 'public getOutAttributeTypes' : function() { + return this.outAttributeTypes; + }, + + /** + * Adds an outAttribute. + * + * @protected + * @alias setOutAttribute + * @memberof Interpreter# + * @param {string} _name name of the attribute + * @param {string} _type type of the attribute + * @param {string} _value value of the attribute + * @param {ParameterList|Array} _parameter Parameter of the attribute. + */ + 'protected setOutAttribute' : function(_name, _type, _value,_parameters) { + var attributeValue = new AttributeValue().withName(_name) + .withValue(_value).withType(_type).withParameters(_parameters); + if (this.isOutAttribute(attributeValue)) { + this.outAttributeValues.put(attributeValue); + } + }, + + /** + * Verifies whether the specified attribute is contained in outAttributeList. + * + * @protected + * @alias isOutAttribute + * @memberof Interpreter# + * @param {AttributeValue} _attribute Attribute that should be verified. + * @return {boolean} + */ + 'protected isOutAttribute' : function(_attribute) { + var type = _attribute.getAttributeType(); + if (this.outAttributeTypes.contains(type)) { + return true; + } else { + return false; + } + }, + /** - * Returns the name of the interpreter. + * Validates the data and calls interpretData. * * @public - * @alias getName + * @alias callInterpreter * @memberof Interpreter# - * @returns {string} + * @param {AttributeValueList} _dataToInterpret Data that should be interpreted. + * @param {?function} _function For additional actions, if an asynchronous function is used. */ - 'public getName' : function() { - return this.name; + 'public callInterpreter' : function(_dataToInterpret, _function) { + if (_dataToInterpret && this.canHandle(_dataToInterpret)) { + if(_function && typeof(_function) == 'function'){ + this.interpretData(_dataToInterpret, _function); + } else { + this.interpretData(_dataToInterpret); + } + this.setInAttributeValues(_dataToInterpret); + this.lastInterpretation = new Date(); + } else { + var list = this.outAttributeTypes.getItems(); + for ( var i in list) { + this.setOutAttribute(list[i].getName(), list[i].getType(), 'unavailable'); + } + + } }, /** - * Returns the id of the interpreter. + * Interprets the data. * + * @function + * @abstract * @public - * @alias getId + * @alias interpretData * @memberof Interpreter# - * @returns {string} + * @param {AttributeValueList} _data Data that should be interpreted. + * @param {?function} _function For additional actions, if an asynchronous function is used. */ - 'public getId' : function() { - return this.id; - }, - + 'abstract protected interpretData' : [ '_data', '_function' ], + /** - * Returns the type of this class, in this case - * "Interpreter". + * Checks whether the specified data match the expected. * - * @public - * @alias getType + * @protected + * @alias canHandle * @memberof Interpreter# - * @returns {string} + * @param {AttributeValueList} _inAtts Data that should be verified. */ - 'public getType' : function() { - return 'Interpreter'; + 'protected canHandle' : function(_inAtts) { + var list = new Array(); + if (_inAtts instanceof Array) { + list = _inAtts; + } else if (Class.isA(AttributeValueList, _inAtts)) { + list = _inAtts.getItems(); + } + if (list.length == 0 || _inAtts.size() != this.getInAttributeTypes().size()) { + return false; + } + for ( var i in list) { + var inAtt = list[i]; + if (!this.isInAttribute(inAtt)) { + return false; + } + } + return true; }, /** - * Initializes interpreter and sets the expected inAttributes - * and provided outAttributes. - * @private - * @alias initInterpreter + * Returns the interpreted data. + * + * @protected + * @alias getInterpretedData * @memberof Interpreter# + * @returns {AttributeValueList} */ - 'private initInterpreter' : function() { - this.initInAttributes(); - this.initOutAttributes(); + 'public getInterpretedData' : function() { + var result = new InterpreterResult().withTimestamp(this.lastInterpretation). + withInAttributes(this.inAttributeValues). + withOutAttributes(this.outAttributeValues); + return result; }, /** - * Initializes the inAttributes. + * Returns the time of the last interpretation. * - * @function - * @abstract * @protected - * @alias initInAttributes + * @alias getLastInterpretionTime * @memberof Interpreter# + * @returns {Date} */ - 'abstract protected initInAttributes' : [], + 'public getLastInterpretionTime' : function() { + return this.lastInterpretation; + }, + /** - * Initializes the outAttributes. - * - * @function - * @abstract - * @protected - * @alias initOutAttributes + * Returns the description of this component. + * @virtual + * @public + * @alias getInterpreterDescription * @memberof Interpreter# + * @returns {InterpreterDescription} */ - 'abstract protected initOutAttributes' : [], + 'virtual public getDescription' : function() { + var description = new InterpreterDescription().withId( + this.id).withName(this.name); + description.addOutAttributeTypes(this.outAttributeTypes); + description.setInAttributeTypes(this.inAttributeTypes); + return description; + }, /** - * Returns the expected inAttributeTypes. - * + * Sets and registers to the associated Discoverer. * @public - * @alias getInAttributeTypes + * @alias setDiscoverer * @memberof Interpreter# - * @returns {AttributeTypeList} + * @param {Discoverer} _discoverer Discoverer */ - 'public getInAttributeTypes' : function() { - return this.inAttributeTypes; + 'public setDiscoverer' : function(_discoverer) { + if (!this.discoverer) { + this.discoverer = _discoverer; + this.register(); + } }, /** - * Sets an inAttribute. + * Registers the component to the associated Discoverer. * - * @protected - * @alias setInAttribute + * @public + * @alias register * @memberof Interpreter# - * @param {string} _name name of the attribute - * @param {string} _type type of the attribute - * @param {string} _value value of the attribute - * @param {ParameterList|Array} _parameter Parameter of the attribute. */ - 'protected setInAttribute' : function(_name, _type, _value, _parameters) { - var attributeValue = new AttributeValue().withName(_name) - .withValue(_value).withType(_type).withParameters(_parameters); - if (this.isInAttribute(attributeValue)) { - this.inAttributeValues.put(attributeValue); + 'protected register' : function() { + if (this.discoverer) { + this.discoverer.registerNewComponent(this); } + }, + +// /** +// * Unregisters the component to the associated discoverer +// * and deletes the reference. +// * +// * @public +// * @alias register +// * @memberof Widget# +// */ +// 'protected unregister' : function() { +// if (this.discoverer) { +// this.discoverer.unregisterComponent(this.getId()); +// this.discoverer = null; +// } +// }, + + }); + + return Interpreter; + }); +/** + * This module representing a Context Discoverer. + * + * @module Discoverer + * @fileOverview + */ +define('discoverer',[ 'easejs', 'attributeTypeList', 'widget', 'interpreter', 'aggregator' ], function(easejs, + AttributeTypeList, Widget, Interpreter, Aggregator) { + var Class = easejs.Class; + + var Discoverer = Class('Discoverer', { + + /** + * @alias widgets + * @private + * @type {Array} + * @memberof Discoverer# + * @desc List of available Widgets. + */ + 'private widgets' : [], + + /** + * @alias aggregators + * @private + * @type {Array} + * @memberof Discoverer# + * @desc List of available Aggregators. + */ + 'private aggregators' : [], + + /** + * @alias interpreter + * @private + * @type {Array} + * @memberof Discoverer# + * @desc List of available Interpreter. + */ + 'private interpreter' : [], + + /** + * Constructor: All known components given in the associated functions will be registered as startup. + * + * @class Discoverer + * @classdesc The Discoverer handles requests for components and attributes. + * @requires easejs + * @requires AttributeTypeList + * @constructs Discoverer + */ + 'public __construct' : function() { + this.register(); + }, + + /** + * Returns the type of this class, in this case + * "Discoverer". + * + * @public + * @alias getType + * @memberof Discoverer# + * @returns {string} + */ + 'public getType' : function() { + return 'Discoverer'; + }, + + /* + * single call for registering the different categories of components + */ + /** + * Single call for registration of the different categories of components. + * Calls: registerWidgets(), registerAggregators(), registerInterpreter() + * + * @private + * @alias register + * @memberof Discoverer# + */ + 'private register' : function() { + this.registerWidgets(); + this.registerAggregators(); + this.registerInterpreter(); + }, - /** - * Sets an inAttributes. - * - * @protected - * @alias setInAttributeValues - * @memberof Interpreter# - * @param {(AttributeValueList|Array)} _attributeValueList Attributes to set. - */ - 'protected setInAttributeValues' : function(_attributeValueList) { - this.inAttributeValues = new AttributeValueList().withItems(_attributeValueList); - }, - /** - * Verifies whether the specified attribute is contained in inAttributeList. - * - * @protected - * @alias isInAttribute - * @memberof Interpreter# - * @param {AttributeValue} _attribute Attribute that should be verified. - * @return {boolean} - */ - 'protected isInAttribute' : function(_attribute) { - var type = _attribute.getAttributeType(); - if (this.inAttributeTypes.contains(type)) { - return true; - } else { - return false; - } - }, + /** + * Registers all specified widgets. + * + * @private + * @alias registerWidgets + * @memberof Discoverer# + */ + 'private registerWidgets' : function() { + }, - /** - * Returns the provided outAttributeTypes. - * - * @public - * @alias getOutAttributeTypes - * @memberof Interpreter# - * @returns {AttributeTypeList} - */ - 'public getOutAttributeTypes' : function() { - return this.outAttributeTypes; - }, + /** + * Registers all specified aggregators. + * + * @private + * @alias registerAggregators + * @memberof Discoverer# + */ + 'private registerAggregators' : function() { + }, - /** - * Adds an outAttribute. - * - * @protected - * @alias setOutAttribute - * @memberof Interpreter# - * @param {string} _name name of the attribute - * @param {string} _type type of the attribute - * @param {string} _value value of the attribute - * @param {ParameterList|Array} _parameter Parameter of the attribute. - */ - 'protected setOutAttribute' : function(_name, _type, _value,_parameters) { - var attributeValue = new AttributeValue().withName(_name) - .withValue(_value).withType(_type).withParameters(_parameters); - if (this.isOutAttribute(attributeValue)) { - this.outAttributeValues.put(attributeValue); - } - }, + /** + * Registers all specified interpreters. + * + * @private + * @alias registerInterpreter + * @memberof Discoverer# + */ + 'private registerInterpreter' : function() { + }, - /** - * Verifies whether the specified attribute is contained in outAttributeList. - * - * @protected - * @alias isOutAttribute - * @memberof Interpreter# - * @param {AttributeValue} _attribute Attribute that should be verified. - * @return {boolean} - */ - 'protected isOutAttribute' : function(_attribute) { - var type = _attribute.getAttributeType(); - if (this.outAttributeTypes.contains(type)) { - return true; - } else { - return false; - } - }, + /** + * Registers the specified component. + * + * @public + * @alias registerNewComponent + * @memberof Discoverer# + * @param {Widget|Aggregator|Interpreter} _component the component that should be registered + */ + 'public registerNewComponent' : function(_component) { + var category = this.identificationHelper(_component); + if (category) { + this.registryHelper(category, _component); + } + }, - /** - * Validates the data and calls interpretData. - * - * @public - * @alias callInterpreter - * @memberof Interpreter# - * @param {AttributeValueList} _dataToInterpret Data that should be interpreted. - * @param {?function} _function For additional actions, if an asynchronous function is used. - */ - 'public callInterpreter' : function(_dataToInterpret, _function) { - if (_dataToInterpret && this.canHandle(_dataToInterpret)) { - if(_function && typeof(_function) == 'function'){ - this.interpretData(_dataToInterpret, _function); - } else { - this.interpretData(_dataToInterpret); - } - this.setInAttributeValues(_dataToInterpret); - this.lastInterpretation = new Date(); - } else { - var list = this.outAttributeTypes.getItems(); - for ( var i in list) { - this.setOutAttribute(list[i].getName(), list[i].getType(), 'unavailable'); - } + /** + * Deletes a component from the Discoverer. + * + * @public + * @alias unregisterComponent + * @memberof Discoverer# + * @param {string} _id id of the component that should be registered + */ + 'public unregisterComponent' : function(_id) { + var component = this.getComponent(_id); + var category = this.identificationHelper(component); + if (category) { + category.splice(_id, 1); + } + }, - } - }, + /** + * Returns the widget for the specified id. + * + * @public + * @alias getWidget + * @memberof Discoverer# + * @param {string} _id id of the component that should be returned + * @returns {?Widget} + */ + 'public getWidget' : function(_id) { + var widget = this.widgets[_id]; + if(!widget){ + this.widgets.splice(_id, 1); + return null; + } + return widget; + }, - /** - * Interprets the data. - * - * @function - * @abstract - * @public - * @alias interpretData - * @memberof Interpreter# - * @param {AttributeValueList} _data Data that should be interpreted. - * @param {?function} _function For additional actions, if an asynchronous function is used. - */ - 'abstract protected interpretData' : [ '_data', '_function' ], + /** + * Returns the aggregator for the specified id. + * + * @public + * @alias getAggregator + * @memberof Discoverer# + * @param {string} _id id of the component that should be returned + * @returns {Aggregator} + */ + 'public getAggregator' : function(_id) { + var aggregator = this.aggregators[_id]; + if(!aggregator ){ + this.aggregators.splice(_id, 1); + return null; + } + return aggregator; + }, - /** - * Checks whether the specified data match the expected. - * - * @protected - * @alias canHandle - * @memberof Interpreter# - * @param {AttributeValueList} _inAtts Data that should be verified. - */ - 'protected canHandle' : function(_inAtts) { - var list = new Array(); - if (_inAtts instanceof Array) { - list = _inAtts; - } else if (Class.isA(AttributeValueList, _inAtts)) { - list = _inAtts.getItems(); - } - if (list.length == 0 || _inAtts.size() != this.getInAttributeTypes().size()) { - return false; - } - for ( var i in list) { - var inAtt = list[i]; - if (!this.isInAttribute(inAtt)) { - return false; - } - } - return true; - }, + /** + * Returns the interpreter for the specified id. + * + * @public + * @alias getInterpreter + * @memberof Discoverer# + * @param {string} _id id of the component that should be returned + * @returns {Interpreter} + */ + 'public getInterpreter' : function(_id) { + var interpret = this.interpreter[_id]; + if(!interpret){ + this.interpreter.splice(_id, 1); + return null; + } + return interpret; + }, + + /** + * Returns the instance (widget, aggregator or interpreter) for the specified id. + * + * @public + * @alias getComponent + * @memberof Discoverer# + * @param {string} _id id of the component that should be returned + * @returns {?(Widget|Aggregator|Interpreter)} + */ + 'public getComponent' : function(_id) { + var component = this.getWidget(_id); + if (component) { + return component; + } + var component = this.getAggregator(_id); + if (component) { + return component; + } + var component = this.getInterpreter(_id); + if (component) { + return component; + } + return null; + }, - /** - * Returns the interpreted data. - * - * @protected - * @alias getInterpretedData - * @memberof Interpreter# - * @returns {AttributeValueList} - */ - 'public getInterpretedData' : function() { - var result = new InterpreterResult().withTimestamp(this.lastInterpretation). - withInAttributes(this.inAttributeValues). - withOutAttributes(this.outAttributeValues); - return result; - }, + /** + * Returns the description of all registered widgets. + * + * @public + * @alias getWidgetDescriptions + * @memberof Discoverer# + * @returns {Array} + */ + 'private getWidgetDescriptions' : function() { + var widgetDescription = []; + var widgets = this.widgets; + for (var i in widgets) { + var singleWidget = widgets[i]; + widgetDescription.push(singleWidget.getDescription()); + } + return widgetDescription; + }, - /** - * Returns the time of the last interpretation. - * - * @protected - * @alias getLastInterpretionTime - * @memberof Interpreter# - * @returns {Date} - */ - 'public getLastInterpretionTime' : function() { - return this.lastInterpretation; - }, + /** + * Returns the description of all registered aggregators. + * + * @public + * @alias getAggregatorDescriptions + * @memberof Discoverer# + * @returns {Array} + */ + 'private getAggregatorDescriptions' : function() { + var aggregatorDescription = []; + var aggregators = this.aggregators; + for (var i in aggregators) { + var singleAggregator = aggregators[i]; + aggregatorDescription.push(singleAggregator.getDescription()); + } + return aggregatorDescription; + }, - /** - * Returns the description of this component. - * @virtual - * @public - * @alias getInterpreterDescription - * @memberof Interpreter# - * @returns {InterpreterDescription} - */ - 'virtual public getInterpreterDescription' : function() { - var description = new InterpreterDescription().withId( - this.id).withName(this.name); - description.setOutAttributeTypes(this.outAttributeTypes); - description.setInAttributeTypes(this.inAttributeTypes); - return description; - }, + /** + * Returns the description of all registered interpreter. + * + * @public + * @alias getInterpreterDescriptions + * @memberof Discoverer# + * @returns {Array} + */ + 'private getInterpreterDescriptions' : function() { + var interpreterDescription = []; + var interpreters = this.interpreter; + for ( var i in interpreters) { + var singleInterpreter = interpreters[i]; + interpreterDescription.push(singleInterpreter.getDescription()); + } + return interpreterDescription; + }, - /** - * Sets and registers to the associated Discoverer. - * @public - * @alias setDiscoverer - * @memberof Interpreter# - * @param {Discoverer} _discoverer Discoverer - */ - 'public setDiscoverer' : function(_discoverer) { - if (!this.discoverer) { - this.discoverer = _discoverer; - this.register(); - } - }, + /** + * Returns the description of all registered components (widget, aggregator and interpreter). + * + * @public + * @alias getDescriptions + * @memberof Discoverer# + * @param {Array} _componentTypes Component types to get descriptions for. Defaults to Widget, Interpreter and Aggregator. + * @returns {Array} + */ + 'public getDescriptions' : function(_componentTypes) { + if (typeof _componentTypes == "undefined") _componentTypes = [Widget, Interpreter, Aggregator]; + var response = []; + if (jQuery.inArray(Widget, _componentTypes) != -1) response = response.concat(this.getWidgetDescriptions()); + if (jQuery.inArray(Aggregator, _componentTypes) != -1) response = response.concat(this.getAggregatorDescriptions()); + if (jQuery.inArray(Interpreter, _componentTypes) != -1) response = response.concat(this.getInterpreterDescriptions()); + return response; + }, - /** - * Registers the component to the associated Discoverer. - * - * @public - * @alias register - * @memberof Interpreter# - */ - 'protected register' : function() { - if (this.discoverer) { - this.discoverer.registerNewComponent(this); + /** + * Returns all components that have the specified attribute as + * outAttribute. It can be chosen between the verification of + * all attributes or at least one attribute. + * + * @public + * @alias getComponentsByAttributes + * @memberof Discoverer# + * @param {(AttributeTypeList|Array)} _attributeTypeList list of searched attributes + * @param {boolean} _all choise of the verification mode + * @param {Array} _componentTypes Components types to search for + * @returns {Array} + */ + 'public getComponentsByAttributes' : function(_attributeTypeList, _all, _componentTypes) { + var componentList = []; + var list = []; + if (typeof _componentTypes == "undefined") _componentTypes = [Widget, Interpreter, Aggregator]; + if (_attributeTypeList instanceof Array) { + list = _attributeTypeList; + } else if (Class.isA(AttributeTypeList, _attributeTypeList)) { + list = _attributeTypeList.getItems(); + } + if (list) { + var descriptions = this.getDescriptions(_componentTypes); + for (var i in descriptions) { + var description = descriptions[i]; + if(_all && this.containsAllAttributes(description, list)){ + componentList.push(this.getComponent(description.getId())); + } else if(!_all && this.containsAtLeastOneAttribute(description, list)){ + componentList.push(this.getComponent(description.getId())); } + } + } + return componentList; + }, - }, - -// /** -// * Unregisters the component to the associated discoverer -// * and deletes the reference. -// * -// * @public -// * @alias register -// * @memberof Widget# -// */ -// 'protected unregister' : function() { -// if (this.discoverer) { -// this.discoverer.unregisterComponent(this.getId()); -// this.discoverer = null; -// } -// }, + /*********************************************************************** + * Helper * + **********************************************************************/ + /** + * Helper: Verifies whether a component description contains all searched attributes. + * + * @private + * @alias containsAllAttributes + * @memberof Discoverer# + * @param {(WidgetDescription|InterpreterDescription)} _description description of a component + * @param {Array} _list searched attributes + * @returns {boolean} + */ + 'private containsAllAttributes' : function(_description,_list) { + for ( var j in _list) { + var attribute = _list[j]; + if (!_description.getOutAttributeTypes().contains(attribute)) { + return false; + } + } + return true; + }, - }); + /** + * Helper: Verifies whether a component description contains at least on searched attributes. + * + * @private + * @alias containsAtLeastOneAttribute + * @memberof Discoverer# + * @param {(WidgetDescription|InterpreterDescription)} _description description of a component + * @param {Array} _list searched attributes + * @returns {boolean} + */ + 'private containsAtLeastOneAttribute' : function(_description,_list) { + for ( var j in _list) { + var attribute = _list[j]; + if (_description.getOutAttributeTypes().contains(attribute)) { + return true; + } + } + return false; + }, + + /** + * Helper: Saves the given component in the category list. + * + * @private + * @alias registryHelper + * @memberof Discoverer# + * @param {string} _category category of component to register + * @param {(Widget|Aggregator|Interpreter)} _component component that should be registered + */ + 'private registryHelper' : function(_category, _component) { + _category[_component.getId()] = _component; + }, - return Interpreter; - }); + /* + * identifies the category of an instance widgets, aggregators, + * interpreter are currently supported + */ + /** + * Helper: Identifies the category of an instance. Widgets, aggregators, + * interpreter are currently supported. + * + * @private + * @alias identificationHelper + * @memberof Discoverer# + * @param {(Widget|Aggregator|Interpreter)} _component that should be identified + */ + 'private identificationHelper' : function(_component) { + if (_component.getType() == 'Widget') { + return this.widgets; + } else if (_component.getType() == 'Aggregator') { + return this.aggregators; + } else if (_component.getType() == 'Interpreter') { + return this.interpreter; + } else { + return null; + } + } + + }); + + return Discoverer; +}); define('contactJS',['retrievalResult', 'storage', 'aggregator', diff --git a/examples/GeoLocationWidget.js b/examples/GeoLocationWidget.js index 03cda5e102ea0f2337edb86482e942b371e79218..d937c7c66314159e8e72959ba68ac0c2bab1bdf9 100644 --- a/examples/GeoLocationWidget.js +++ b/examples/GeoLocationWidget.js @@ -56,7 +56,7 @@ define([ 'easejs', 'contactJS' ], /** * Initializes constantAttributes. For this class: no * constantAttributes available - * + * * @protected * @alias initConstantAttributes * @memberof GeoLocationWidget# @@ -67,22 +67,21 @@ define([ 'easejs', 'contactJS' ], /** * Initializes Callbacks. For this class: * UPDATE (latitude and longitude) - * + * * @protected * @alias initCallbacks * @memberof GeoLocationWidget# */ 'protected initCallbacks' : function() { var list = new contactJS.AttributeTypeList(); - list.put(this.getWidgetAttributeTypes().getItem("latitude")); - list.put(this.getWidgetAttributeTypes().getItem("longitude")); + list.put(this.getAttributeTypes().getItem("latitude")); + list.put(this.getAttributeTypes().getItem("longitude")); var call = new contactJS.Callback().withName('UPDATE').withAttributeTypes(list); this.addCallback(call); }, - 'override public notify' : function() { - var callbacks = this.queryCallbacks().getItems(); + var callbacks = this.getCallbackList().getItems(); for(var i in callbacks){ this.sendToSubscriber(callbacks[i]); } @@ -92,7 +91,7 @@ define([ 'easejs', 'contactJS' ], * Implements queryGenerator(). Query latitude and * longitude by calling * navigator.geolocation.getCurrentPosition(). - * + * * @override * @protected * @alias queryGenerator @@ -109,13 +108,13 @@ define([ 'easejs', 'contactJS' ], } else { alert("Keine Ortung moeglich"); } - + }, /** * Success function for navigator.geolocation.getCurrentPosition() used in * queryGenerator(). Stores the values in the associated attributes. - * + * * @callback * @private * @alias onSuccess @@ -143,12 +142,13 @@ define([ 'easejs', 'contactJS' ], /** * Error function for navigator.geolocation.getCurrentPosition() used in * queryGenerator(). - * + * * @callback * @private * @alias onError * @memberof GeoLocationWidget# * @param error + * @param {this} self */ 'private onError' : function(error, self, _function) { var latitude = new contactJS.AttributeValue().withName('latitude') diff --git a/js/modules/aggregator/aggregator.js b/js/modules/aggregator/aggregator.js index d39eebfdff088ec61c80b024eb7462566eab0141..0ebc163843a6c57e1a6e5345eedadf5cba0f4a7b 100644 --- a/js/modules/aggregator/aggregator.js +++ b/js/modules/aggregator/aggregator.js @@ -75,12 +75,12 @@ define(['easejs', 'MathUuid','widget', 'widgetHandle', 'widgetHandleList', * @requires WidgetHandleList * @constructs Aggregator */ - 'override public __construct': function() + 'override virtual public __construct': function(_discoverer) { this.id = Math.uuid(); this.widgets = new WidgetHandleList(); this.initWidgetHandles(); - this.__super(); + this.__super(_discoverer); this.aggregatorSetup(); }, @@ -352,7 +352,7 @@ define(['easejs', 'MathUuid','widget', 'widgetHandle', 'widgetHandleList', }, /** - * Adds a new subscription to this Aggregator. + * Adds the specified callbacks of a widget to the aggregator. * * @public * @alias addWidgetSubscription @@ -360,7 +360,7 @@ define(['easejs', 'MathUuid','widget', 'widgetHandle', 'widgetHandleList', * @param {WidgetHandle} _widgetHandle Widget that should be subscribed. * @param {CallbackList} _callbacks required Callbacks */ - 'public addWidgetSubscription' : function(_widgetHandle, _callbackList){ + 'public addWidgetSubscription' : function(_widgetHandle, _callbackList){ if(Class.isA(WidgetHandle, _widgetHandle) && Class.isA(CallbackList, _callbackList)){ var widget = this.discoverer.getComponent(_widgetHandle.getId()); if(widget && widget.getName() === _widgetHandle.getName()){ @@ -413,7 +413,7 @@ define(['easejs', 'MathUuid','widget', 'widgetHandle', 'widgetHandleList', var list = []; if(_data instanceof Array){ list = _data; - } else if (Class.isA( AttributeValueList, _data)) { + } else if (Class.isA(AttributeValueList, _data)) { list = _data.getItems(); } for(var i in list){ @@ -541,31 +541,24 @@ define(['easejs', 'MathUuid','widget', 'widgetHandle', 'widgetHandleList', 'public getStorageOverview' : function(){ return this.db.getAttributesOverview(); }, - + /** * Only actualizes the attributeType cache in th database. * For an alternativ action can be used a callback. - * + * * @public * @alias queryTables * @memberof Aggregator# * @param {?function} _function for alternative actions, because an asynchronous function is used */ 'public queryTables' : function(_function){ - this.db.getAttributeNames(_function); - }, - - /** - * Returns the description of this component. - * @virtual - * @public - * @alias getAggregatorDescription - * @memberof Aggregator# - * @returns {WidgetDescription} - */ - 'virtual public getAggregatorDescription' : function(){ - return this.getWidgetDescription(); - } + this.db.getAttributeNames(_function); + }, + + 'virtual public queryReferencedWidget' :function(_widgetHandle, _callback){ + var widget = this.discoverer.getWidget(_widgetHandle.getId()); + widget.updateWidgetInformation(_callback); + } }); diff --git a/js/modules/descriptions/interpreterDescription.js b/js/modules/descriptions/interpreterDescription.js index 0409583dcbde1392fa6844385fb986f4048f850f..afb433f45a2a03d23b4f52047ff0fa990c565d9a 100644 --- a/js/modules/descriptions/interpreterDescription.js +++ b/js/modules/descriptions/interpreterDescription.js @@ -9,8 +9,7 @@ define(['easejs','attributeTypeList','widgetDescription'], function(easejs,AttributeTypeList,WidgetDescription){ var Class = easejs.Class; var InterpreterDescription = Class('InterpreterDescription'). - extend(WidgetDescription, - { + extend(WidgetDescription, { /** * @alias inAttributeTypes * @private @@ -99,10 +98,9 @@ define(['easejs','attributeTypeList','widgetDescription'], */ 'public setInAttributeTypes' : function(_inAttributeTypes){ this.inAttributeTypes.putAll(_inAttributeTypes); - }, - - }); + } + + }); - return InterpreterDescription; - + return InterpreterDescription; }); \ No newline at end of file diff --git a/js/modules/descriptions/widgetDescription.js b/js/modules/descriptions/widgetDescription.js index ff92f79921ed25aa85e7c52c4668687a2eef70af..f9161152b85a86c465602adea197b78aaefa878f 100644 --- a/js/modules/descriptions/widgetDescription.js +++ b/js/modules/descriptions/widgetDescription.js @@ -5,8 +5,8 @@ * @module WidgetDescription * @fileOverview */ -define(['easejs', 'attributeTypeList'], - function(easejs, AttributeTypeList){ +define(['easejs', 'attributeTypeList', 'widgetHandle'], + function(easejs, AttributeTypeList, WidgetHandle){ var Class = easejs.Class; var WidgetDescription = Class('WidgetDescription',{ @@ -33,7 +33,15 @@ define(['easejs', 'attributeTypeList'], * @memberof WidgetDescription# * @desc List of attributeTypes that are provided. */ - 'protected outAttributeTypes' : [], + 'protected outAttributeTypes' : [], + /** + * @alias callbackNames + * @protected + * @type {array} + * @memberof WidgetDescription# + * @desc Array of available callback names. + */ + 'protected callbackNames' : [], /** * Constructor: Initializes the inAttributeTypes. @@ -152,7 +160,7 @@ define(['easejs', 'attributeTypeList'], 'public setName' : function(_name){ if(typeof _name === 'string'){ this.name = _name; - }; + } }, /** @@ -173,11 +181,11 @@ define(['easejs', 'attributeTypeList'], * Adds an outAttributeType to the list * * @public - * @alias setOutAttributeType + * @alias addOutAttributeType * @memberof WidgetDescription# * @param {AttributeType} _outAttributeType AttributeType that are provided */ - 'public setOutAttributeType' : function(_outAttributeType){ + 'public addOutAttributeType' : function(_outAttributeType){ this.outAttributeTypes.put(_outAttributeType); }, @@ -185,16 +193,28 @@ define(['easejs', 'attributeTypeList'], * Adds outAttributeTypes that are provided by the Widget * * @public - * @alias setOutAttributeTypes + * @alias addOutAttributeTypes * @memberof WidgetDescription# * @param {(AttributeTypeList|Array)} _outAttributeTypes List of AttributeType that are provided */ - 'public setOutAttributeTypes' : function(_outAttributeTypes){ + 'public addOutAttributeTypes' : function(_outAttributeTypes){ this.outAttributeTypes.putAll(_outAttributeTypes); - } + }, + + 'public setCallbackNames' : function(_callbackNames) { + this.callbackNames = _callbackNames; + }, + + 'public addCallbackName' : function(_callbackName) { + this.callbackNames.push(_callbackName); + }, + + 'public getHandle' : function() { + return new WidgetHandle().withName(this.name).withId(this.id); + } - }); + }); - return WidgetDescription; + return WidgetDescription; }); \ No newline at end of file diff --git a/js/modules/discoverer/discoverer.js b/js/modules/discoverer/discoverer.js index a2265dfac899c611d940ffb4338c9e930e143e24..dda9524b3a8daf8e0f656a597f64373c5ffce09c 100644 --- a/js/modules/discoverer/discoverer.js +++ b/js/modules/discoverer/discoverer.js @@ -4,8 +4,8 @@ * @module Discoverer * @fileOverview */ -define([ 'easejs', 'attributeTypeList' ], function(easejs, - AttributeTypeList) { +define([ 'easejs', 'attributeTypeList', 'widget', 'interpreter', 'aggregator' ], function(easejs, + AttributeTypeList, Widget, Interpreter, Aggregator) { var Class = easejs.Class; var Discoverer = Class('Discoverer', { @@ -228,12 +228,12 @@ define([ 'easejs', 'attributeTypeList' ], function(easejs, * @memberof Discoverer# * @returns {Array} */ - 'public getWidgetDescriptions' : function() { - var widgetDescription = new Array(); + 'private getWidgetDescriptions' : function() { + var widgetDescription = []; var widgets = this.widgets; - for ( var i in widgets) { + for (var i in widgets) { var singleWidget = widgets[i]; - widgetDescription.push(singleWidget.getWidgetDescription()); + widgetDescription.push(singleWidget.getDescription()); } return widgetDescription; }, @@ -246,12 +246,12 @@ define([ 'easejs', 'attributeTypeList' ], function(easejs, * @memberof Discoverer# * @returns {Array} */ - 'public getAggregatorDescriptions' : function() { - var aggregatorDescription = new Array(); + 'private getAggregatorDescriptions' : function() { + var aggregatorDescription = []; var aggregators = this.aggregators; - for ( var i in aggregators) { + for (var i in aggregators) { var singleAggregator = aggregators[i]; - aggregatorDescription.push(singleAggregator.getAggregatorDescription()); + aggregatorDescription.push(singleAggregator.getDescription()); } return aggregatorDescription; }, @@ -264,12 +264,12 @@ define([ 'easejs', 'attributeTypeList' ], function(easejs, * @memberof Discoverer# * @returns {Array} */ - 'public getInterpreterDescriptions' : function() { - var interpreterDescription = new Array(); + 'private getInterpreterDescriptions' : function() { + var interpreterDescription = []; var interpreters = this.interpreter; for ( var i in interpreters) { var singleInterpreter = interpreters[i]; - interpreterDescription.push(singleInterpreter.getInterpreterDescription()); + interpreterDescription.push(singleInterpreter.getDescription()); } return interpreterDescription; }, @@ -280,13 +280,15 @@ define([ 'easejs', 'attributeTypeList' ], function(easejs, * @public * @alias getDescriptions * @memberof Discoverer# + * @param {Array} _componentTypes Component types to get descriptions for. Defaults to Widget, Interpreter and Aggregator. * @returns {Array} */ - 'public getDescriptions' : function() { - var response = new Array(); - response = response.concat(this.getWidgetDescriptions()); - response = response.concat(this.getAggregatorDescriptions()); - response = response.concat(this.getInterpreterDescriptions()); + 'public getDescriptions' : function(_componentTypes) { + if (typeof _componentTypes == "undefined") _componentTypes = [Widget, Interpreter, Aggregator]; + var response = []; + if (jQuery.inArray(Widget, _componentTypes) != -1) response = response.concat(this.getWidgetDescriptions()); + if (jQuery.inArray(Aggregator, _componentTypes) != -1) response = response.concat(this.getAggregatorDescriptions()); + if (jQuery.inArray(Interpreter, _componentTypes) != -1) response = response.concat(this.getInterpreterDescriptions()); return response; }, @@ -300,18 +302,20 @@ define([ 'easejs', 'attributeTypeList' ], function(easejs, * @memberof Discoverer# * @param {(AttributeTypeList|Array)} _attributeTypeList list of searched attributes * @param {boolean} _all choise of the verification mode + * @param {Array} _componentTypes Components types to search for * @returns {Array} */ - 'public getComponentsByAttributes' : function(_attributeTypeList, _all) { - var componentList = new Array(); - var list = new Array(); + 'public getComponentsByAttributes' : function(_attributeTypeList, _all, _componentTypes) { + var componentList = []; + var list = []; + if (typeof _componentTypes == "undefined") _componentTypes = [Widget, Interpreter, Aggregator]; if (_attributeTypeList instanceof Array) { list = _attributeTypeList; } else if (Class.isA(AttributeTypeList, _attributeTypeList)) { list = _attributeTypeList.getItems(); } if (list) { - var descriptions = this.getDescriptions(); + var descriptions = this.getDescriptions(_componentTypes); for (var i in descriptions) { var description = descriptions[i]; if(_all && this.containsAllAttributes(description, list)){ diff --git a/js/modules/interpreter/interpreter.js b/js/modules/interpreter/interpreter.js index 0b2705fa8271320c268992385597feff5f00ca6c..8e7f950124ec97d00b8c267e30fb4c546f504072 100644 --- a/js/modules/interpreter/interpreter.js +++ b/js/modules/interpreter/interpreter.js @@ -92,8 +92,10 @@ define([ 'easejs', 'MathUuid', 'attributeType', 'attributeTypeList', * @requires InterpreterDescription * @constructs Interpreter */ - 'public __construct' : function() { + 'public __construct' : function(_discoverer) { this.id = Math.uuid(); + this.discoverer = _discoverer; + this.register(); this.inAttributeTypes = new AttributeTypeList(); this.outAttributeTypes = new AttributeTypeList(); this.inAttributeValues = new AttributeValueList(); @@ -382,10 +384,10 @@ define([ 'easejs', 'MathUuid', 'attributeType', 'attributeTypeList', * @memberof Interpreter# * @returns {InterpreterDescription} */ - 'virtual public getInterpreterDescription' : function() { + 'virtual public getDescription' : function() { var description = new InterpreterDescription().withId( this.id).withName(this.name); - description.setOutAttributeTypes(this.outAttributeTypes); + description.addOutAttributeTypes(this.outAttributeTypes); description.setInAttributeTypes(this.inAttributeTypes); return description; }, diff --git a/js/modules/subscriber/callbackList.js b/js/modules/subscriber/callbackList.js index ef1e2bfe05913dded7121883f238cfd376a578ca..8dfbe6598039cb54c278745b0b09c0132e72908e 100644 --- a/js/modules/subscriber/callbackList.js +++ b/js/modules/subscriber/callbackList.js @@ -46,7 +46,7 @@ define(['easejs', 'abstractList', 'callback'], * @returns {CallbackList} */ 'public withItems': function(_callbackList){ - var list = new Array(); + var list = []; if(_callbackList instanceof Array){ list = _callbackList; } else if (Class.isA(CallbackList, _callbackList)) { @@ -86,11 +86,10 @@ define(['easejs', 'abstractList', 'callback'], * @public * @alias putAll * @memberof CallbackList# - * @param {(CallbackList|Array)} - * _callbackList CallbackList + * @param {(CallbackList|Array)} _callbackList CallbackList */ 'public putAll' : function(_callbackList){ - var list = new Array(); + var list = []; if(_callbackList instanceof Array){ list = _callbackList; } else if (Class.isA(CallbackList, _callbackList)) { @@ -147,7 +146,7 @@ define(['easejs', 'abstractList', 'callback'], return true; } return false; - }, + } }); diff --git a/js/modules/widget/widget.js b/js/modules/widget/widget.js index a02196c017f9fbbf47c8aa6badb082491c9cd813..91c85a033125616b9efd214c203e5310c6418314 100644 --- a/js/modules/widget/widget.js +++ b/js/modules/widget/widget.js @@ -121,8 +121,10 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeType', * @requires Discoverer * @constructs Widget */ - 'virtual public __construct' : function() { + 'virtual public __construct' : function(_discoverer) { this.id = Math.uuid(); + this.discoverer = _discoverer; + this.register(); this.attributeTypes = new AttributeTypeList(); this.constantAttributeTypes = new AttributeTypeList(); this.attributes = new AttributeValueList(); @@ -174,11 +176,11 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeType', * Returns the available AttributeTypes. * * @public - * @alias getWidgetAttributeTypes + * @alias getAttributeTypes * @memberof Widget# * @returns {AttributeTypeList} */ - 'public getWidgetAttributeTypes' : function() { + 'public getAttributeTypes' : function() { return this.attributeTypes; }, @@ -199,11 +201,11 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeType', * Returns the last acquired Attributes. * * @public - * @alias queryAttributes + * @alias getAttributes * @memberof Widget# * @returns {AttributeValueList} */ - 'public queryAttributes' : function() { + 'public getAttributes' : function() { return this.attributes; }, @@ -223,27 +225,40 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeType', * Returns the ConstantAttributes. * * @public - * @alias queryConstantAttributes + * @alias getConstantAttributes * @memberof Widget# * @returns {AttributeValueList} */ - 'public queryConstantAttributes' : function() { + 'public getConstantAttributes' : function() { return this.constantAttributes; }, /** - * Returns the specified Callbacks that can be - * subscribed. + * Returns a list of callbacks that can be + * subscribed to. * * @public - * @alias queryCallbacks + * @alias getCallbacks * @memberof Widget# * @returns {CallbackList} */ - 'public queryCallbacks' : function() { + 'public getCallbackList' : function() { return this.callbacks; }, + /** + * Returns the specified callbacks that can be + * subscribed to. + * + * @public + * @alias getCallbacks + * @memberof Widget# + * @returns {Array} + */ + 'public getCallbacks' : function() { + return this.callbacks.getItems(); + }, + 'public queryServices' : function() { return this.services; }, @@ -580,11 +595,16 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeType', this.initAttributes(); this.initConstantAttributes(); this.initCallbacks(); + + this.didFinishInitialization(); }, + 'public virtual didFinishInitialization' : function() { + + }, + /** * Notifies other components and sends the attributes. - * Must be overridden by the subclasses * * @virtual * @public @@ -661,8 +681,8 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeType', */ 'public queryWidget' : function() { var response = new AttributeValueList(); - response.putAll(this.queryAttributes()); - response.putAll(this.queryConstantAttributes()); + response.putAll(this.getAttributes()); + response.putAll(this.getConstantAttributes()); return response; }, @@ -682,8 +702,8 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeType', } else { this.queryGenerator(); var response = new AttributeValueList(); - response.putAll(this.queryAttributes()); - response.putAll(this.queryConstantAttributes()); + response.putAll(this.getAttributes()); + response.putAll(this.getConstantAttributes()); return response; } }, @@ -702,9 +722,7 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeType', for ( var i in subscriberList) { var subscriber = subscriberList[i]; if (subscriber.getSubscriptionCallbacks().containsKey( _callback.getName())) { - console.log(subscriber.getSubscriberId()); if(this.dataValid(subscriber.getConditions())){ - console.log('condition' + true); var subscriberInstance = this.discoverer.getComponent(subscriber.getSubscriberId()); var callSubset = _callback.getAttributeTypes(); var subscriberSubset = subscriber.getAttributesSubset(); @@ -741,7 +759,7 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeType', var conditionAttributeType = condition.getAttributeType(); var conditionAttributeTypeList = new AttributeTypeList() .withItems(new Array(conditionAttributeType)); - var newValue = this.queryAttributes().getSubset(conditionAttributeTypeList); + var newValue = this.getAttributes().getSubset(conditionAttributeTypeList); var oldValue = this.getOldAttributes.getSubset(conditionAttributeTypeList); return condition.compare(newValue, oldValue); } @@ -753,14 +771,19 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeType', * Returns the description of this component. * @virtual * @public - * @alias getWidgetDescription + * @alias getDescription * @memberof Widget# * @returns {WidgetDescription} */ - 'virtual public getWidgetDescription' : function() { + 'virtual public getDescription' : function() { var description = new WidgetDescription().withId(this.id).withName(this.name); - description.setOutAttributeTypes(this.attributeTypes); - description.setOutAttributeTypes(this.constantAttributeTypes); + description.addOutAttributeTypes(this.attributeTypes); + description.addOutAttributeTypes(this.constantAttributeTypes); + // TODO: getCallbackNames for CallbackList + var widgetCallbacks = this.callbacks.getItems(); + for(var i in widgetCallbacks) { + description.addCallbackName(widgetCallbacks[i].getName()); + } return description; }, @@ -806,7 +829,7 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeType', if (this.discoverer) { this.discoverer.registerNewComponent(this); } - } + }, // /** // * Unregisters the component to the associated discoverer @@ -823,6 +846,10 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeType', // } // }, + 'public getHandle' : function() { + return this.getDescription().getHandle(); + } + }); return Widget; diff --git a/js/modules/widget/widgetHandleList.js b/js/modules/widget/widgetHandleList.js index 2861eb69fcd8561e91923bed92c39c497387a761..f575e2aca5aabc5922341d27f7f92190f6ed03c7 100644 --- a/js/modules/widget/widgetHandleList.js +++ b/js/modules/widget/widgetHandleList.js @@ -5,8 +5,8 @@ * @module WidgetHandleList * @fileOverview */ -define([ 'easejs', 'abstractList', 'widgetHandle' ], - function(easejs, AbstractList, WidgetHandle) { +define([ 'easejs', 'abstractList', 'widgetHandle', 'widget'], + function(easejs, AbstractList, WidgetHandle, Widget) { var Class = easejs.Class; /** * @class WidgetHandleList @@ -45,7 +45,7 @@ define([ 'easejs', 'abstractList', 'widgetHandle' ], * @returns {WidgetHandleList} */ 'public withItems' : function(_widgetHandleList) { - var list = new Array(); + var list = []; if (_widgetHandleList instanceof Array) { list = _widgetHandleList; } else if (Class.isA(WidgetHandleList, _widgetHandleList)) { @@ -62,20 +62,20 @@ define([ 'easejs', 'abstractList', 'widgetHandle' ], }, /** - * Adds the specified item to theitem list. + * Adds a widget handle to the list. * * @public * @alias put * @memberof WidgetHandleList# - * @param {WidgetHandle} - * _widgetHandle WidgetHandle + * @param {WidgetHandle|Widget} _widgetHandleOrWidget WidgetHandle */ - 'public put' : function(_widgetHandle) { - if (Class.isA(WidgetHandle, _widgetHandle)) { - if (!(this.containsKey(_widgetHandle.getName()))) { + 'public put' : function(_widgetHandleOrWidget) { + if (Class.isA(Widget, _widgetHandleOrWidget)) _widgetHandleOrWidget = _widgetHandleOrWidget.getHandle(); + if (Class.isA(WidgetHandle, _widgetHandleOrWidget)) { + if (!(this.containsKey(_widgetHandleOrWidget.getName()))) { this.counter++; } - this.items[_widgetHandle.getName()] = _widgetHandle; + this.items[_widgetHandleOrWidget.getName()] = _widgetHandleOrWidget; } }, @@ -147,7 +147,7 @@ define([ 'easejs', 'abstractList', 'widgetHandle' ], return true; } return false; - }, + } }); return WidgetHandleList; }); \ No newline at end of file diff --git a/qunitTest/aggregatorTest.js b/qunitTest/aggregatorTest.js index 68ab1346df61fe6515d5c962e4710a36225bf59c..3dc335d034e6e931c98ab32b1c4c3a0bb3dc9a6e 100644 --- a/qunitTest/aggregatorTest.js +++ b/qunitTest/aggregatorTest.js @@ -3,8 +3,10 @@ require(['configTest'], function() { function(TestAggregator, GeoLocationWidget, contactJS){ QUnit.test( "TestAggregator ", function( assert ) { - - var testAggregator = new TestAggregator(); + + //initializes the infrastructure + var discoverer = new contactJS.Discoverer(); + var testAggregator = new TestAggregator(discoverer); var id = testAggregator.getId(); assert.ok( id && id !== "null" && id !== "undefined","Passed!: id is not null" ); @@ -16,16 +18,11 @@ require(['configTest'], function() { var widgetHandles = testAggregator.getWidgets(); assert.equal( widgetHandles.size(), 0,"Passed!: no subscribed Widgets" ); - - //initializes the infrastructure - var discoverer = new contactJS.Discoverer(); - testAggregator.setDiscoverer(discoverer); - var geoLocationWidget = new GeoLocationWidget(); - geoLocationWidget.setDiscoverer(discoverer); + var geoLocationWidget = new GeoLocationWidget(discoverer); //subscription - var widget = discoverer.getWidgetDescriptions(); + var widget = discoverer.getDescriptions([contactJS.Widget]); var handle = new contactJS.WidgetHandle().withName('GeoLocationWidget').withId(widget[0].getId()); @@ -51,7 +48,7 @@ require(['configTest'], function() { var subscriber = geoLocationWidget.getSubscriber(); assert.equal(subscriber.size(), 1,"subscribe Passed!: one subscribed Widget in geolocationWidget too"); - var values = testAggregator.queryAttributes(); + var values = testAggregator.getAttributes(); assert.equal( values.size(), 3,"Passed!: two available attributes" ); var latitude = values.getItem('latitude'); assert.equal(latitude.getName(), 'latitude',"subscribed Attributes Passed!: latitude exists" ); diff --git a/qunitTest/discovererTest.js b/qunitTest/discovererTest.js index eae95f21e5acd961e5ffe3163d2a23a848f6873f..742becdbc132932f59339bb4203f73a001ea5fc2 100644 --- a/qunitTest/discovererTest.js +++ b/qunitTest/discovererTest.js @@ -8,18 +8,17 @@ require(['configTest'], function() { assert.equal( discoverer.getType(), 'Discoverer',"Passed!: type -> Discoverer" ); //register Widget - var geo = new GeoLocationWidget(); - geo.setDiscoverer(discoverer); + var geo = new GeoLocationWidget(discoverer); //initWidgets ->geoLocationWidget expected //tested with getWidgetDescriptions - var wDescs = discoverer.getWidgetDescriptions(); - assert.equal( wDescs.length, 1,"getWidgetDescriptions passed!: One Widget is registerd" ); - assert.equal( wDescs[0].getName(), 'GeoLocationWidget',"getWidgetDescriptions passed!: Name of the registerd Widget is the expected one" ); + var wDescs = discoverer.getDescriptions([contactJS.Widget]); + assert.equal( wDescs.length, 1,"getWidgetDescriptions passed!: One Widget is registered" ); + assert.equal( wDescs[0].getName(), 'GeoLocationWidget',"getWidgetDescriptions passed!: Name of the registered Widget is the expected one" ); //same procedure with getDescriptions var wDescs2 = discoverer.getDescriptions(); - assert.equal( wDescs2.length, 1,"getDescriptions passed!: One Widget is registerd" ); - assert.equal( wDescs2[0].getName(), 'GeoLocationWidget',"getDescriptions passed!: Name of the registerd Widget is the expected one" ); + assert.equal( wDescs2.length, 1,"getDescriptions passed!: One Widget is registered" ); + assert.equal( wDescs2[0].getName(), 'GeoLocationWidget',"getDescriptions passed!: Name of the registered Widget is the expected one" ); //getWidgets var widget = discoverer.getWidget(wDescs[0].getId()); assert.ok( widget,"getWidget passed!: an instance was returned" ); @@ -32,15 +31,14 @@ require(['configTest'], function() { assert.equal( widget2.getName(), 'GeoLocationWidget',"getComponent passed!: name of the instance is te expected one" ); //register Interpreter - var testInterpreter =new AddressInterpreter(); - testInterpreter.setDiscoverer(discoverer); + var testInterpreter = new AddressInterpreter(discoverer); //tested with getWidgetDescriptions - var iDescs = discoverer.getInterpreterDescriptions(); - assert.equal( iDescs.length, 1,"getInterpreterDescriptions passed!: One Interpreter is registerd" ); - assert.equal( iDescs[0].getName(), 'AddressInterpreter',"getInterpreterDescriptions passed!: Name of the registerd Interpreter is the expected one" ); + var iDescs = discoverer.getDescriptions([contactJS.Interpreter]); + assert.equal( iDescs.length, 1,"getInterpreterDescriptions passed!: One Interpreter is registered" ); + assert.equal( iDescs[0].getName(), 'AddressInterpreter',"getInterpreterDescriptions passed!: Name of the registered Interpreter is the expected one" ); //same procedure with getDescriptions var iDescs2 = discoverer.getDescriptions(); - assert.equal( iDescs2.length, 2,"getDescriptions passed!: three instances are registerd" ); + assert.equal( iDescs2.length, 2,"getDescriptions passed!: three instances are registered" ); //getWidgets var interpreter = discoverer.getInterpreter(iDescs[0].getId()); assert.ok( interpreter,"getInterpreter passed!: an instance was returned" ); @@ -56,7 +54,7 @@ require(['configTest'], function() { var testAggregator =new TestAggregator(); testAggregator.setDiscoverer(discoverer); //tested with getWidgetDescriptions - var aDescs = discoverer.getAggregatorDescriptions(); + var aDescs = discoverer.getDescriptions([contactJS.Aggregator]); assert.equal( aDescs.length, 1,"getAggregatorDescriptions passed!: One Aggregator is registered" ); assert.equal( aDescs[0].getName(), 'TestAggregator',"getAggregatorDescriptions passed!: Name of the registered Interpreter is the expected one" ); //same procedure with getDescriptions @@ -80,7 +78,7 @@ require(['configTest'], function() { .withType('double').withParameter(testParameter); var longitudeType = new contactJS.AttributeType().withName('longitude') .withType('double'); - var array = new Array(); + var array = []; array.push(longitudeType); //one searched attribute @@ -92,15 +90,23 @@ require(['configTest'], function() { assert.equal( list2.length, 2," getComponentsByAttributes passed!: returned 2 components which provided at least one attribute (one attribute was specified)" ); assert.equal( list2[0].getName(), 'GeoLocationWidget'," getComponentsByAttributes passed!: returned expected instance (one attribute was specified)" ); assert.equal( list2[1].getName(), 'TestAggregator'," getComponentsByAttributes passed!: returned second expected instance (one attribute was specified)" ); - + + //one searched attribute with restricted component type + var list3 = discoverer.getComponentsByAttributes(array, false, [contactJS.Widget]); + assert.equal( list3.length, 1," getComponentsByAttributes passed!: returned 1 component which provided at least one attribute (one attribute was specified) and is a widget" ); + assert.equal( list3[0].getName(), 'GeoLocationWidget'," getComponentsByAttributes passed!: returned expected instance (one attribute was specified)" ); + var list4 = discoverer.getComponentsByAttributes(array, true, [contactJS.Widget]); + assert.equal( list4.length, 1," getComponentsByAttributes passed!: returned 1 component which provided at least one attribute (one attribute was specified) and is a widget" ); + assert.equal( list4[0].getName(), 'GeoLocationWidget'," getComponentsByAttributes passed!: returned expected instance (one attribute was specified)" ); + //two searched attributes array.push(latitudeType); - var list3 = discoverer.getComponentsByAttributes(array, false); - assert.equal( list3.length, 2," getComponentsByAttributes passed!: returned 2 components which provided at least one attribute (two attributes were specified)" ); - assert.equal( list3[0].getName(), 'GeoLocationWidget'," getComponentsByAttributes passed!: returned expected instance (two attributes were specified)" ); - assert.equal( list3[1].getName(), 'TestAggregator'," getComponentsByAttributes passed!: returned second expected instance (two attributes were specified)" ); - var list4 = discoverer.getComponentsByAttributes(array, true); - assert.equal( list4.length, 0," getComponentsByAttributes passed!: returned 0 components which provided all attribute (two attributes were specified)" ); + var list5 = discoverer.getComponentsByAttributes(array, false); + assert.equal( list5.length, 2," getComponentsByAttributes passed!: returned 2 components which provided at least one attribute (two attributes were specified)" ); + assert.equal( list5[0].getName(), 'GeoLocationWidget'," getComponentsByAttributes passed!: returned expected instance (two attributes were specified)" ); + assert.equal( list5[1].getName(), 'TestAggregator'," getComponentsByAttributes passed!: returned second expected instance (two attributes were specified)" ); + var list6 = discoverer.getComponentsByAttributes(array, true); + assert.equal( list6.length, 0," getComponentsByAttributes passed!: returned 0 components which provided all attribute (two attributes were specified)" ); }); diff --git a/qunitTest/interpret_AggregatorInterpreterTest.js b/qunitTest/interpret_AggregatorInterpreterTest.js index cd4e3e409a44a7200c89200883ed4d316a932fff..94f2b42d263d98e1da241b79f9aa5380d7f98790 100644 --- a/qunitTest/interpret_AggregatorInterpreterTest.js +++ b/qunitTest/interpret_AggregatorInterpreterTest.js @@ -11,7 +11,7 @@ require(['configTest'], function() { testAggregator.setDiscoverer(discoverer); testInterpreter.setDiscoverer(discoverer); - var interpreter = discoverer.getInterpreterDescriptions(); + var interpreter = discoverer.getDescriptions([contactJS.Interpreter]); //put data into aggregator var latitudeValue = new contactJS.AttributeValue().withName('latitude') @@ -41,7 +41,7 @@ require(['configTest'], function() { assert.equal( data2.size(), 3,"Passed!: three available attributes" ); var item = data2.getItem('formattedAddress'); assert.ok(item,"Callback passed!: interpreted data exists" ); - var add = "Charlottenstraße 70, 14467 Potsdam, Deutschland"; + var add = "Charlottenstraße 70, 14467 Potsdam, Deutschland"; assert.equal(item.getValue(), add ,"Passed!: interpreted data equals expected value" ); }; diff --git a/qunitTest/interpreterTest.js b/qunitTest/interpreterTest.js index 5a69fd23484e9b857cfbad5692d535838458827f..3924411208449c69a0d719c2164459c0091d8b9b 100644 --- a/qunitTest/interpreterTest.js +++ b/qunitTest/interpreterTest.js @@ -32,7 +32,7 @@ require(['configTest'], function() { //interpreterDescription - var desc = testInterpreter.getInterpreterDescription(); + var desc = testInterpreter.getDescription(); assert.ok( desc,"Passed!: InterpreterDescription exists" ); assert.equal ( desc.getId(), id, "Passed!: InterpreterDescription contains expected id" ); assert.equal ( desc.getName(), 'AddressInterpreter', "Passed!: InterpreterDescription contains expected id" ); @@ -63,7 +63,7 @@ require(['configTest'], function() { var att = list[i]; assert.ok(att,"Callback passed!: interpreted data exists" ); assert.ok(att.getAttributeType().equals(formattedAddress),"Callback passed!: interpreted data equals expected type" ); - var add = "Charlottenstraße 70, 14467 Potsdam, Deutschland"; + var add = "Charlottenstraße 70, 14467 Potsdam, Deutschland"; assert.equal(att.getValue(), add ,"Passed!: interpreted data equals expected value" ); }; }; diff --git a/qunitTest/notify_AggregatorWidgetTest.js b/qunitTest/notify_AggregatorWidgetTest.js index 68c3c661f733ecd34561a36c324cd6c3b47f9eb2..6fc54ec8681cdef613f68c12e3513814bd95392f 100644 --- a/qunitTest/notify_AggregatorWidgetTest.js +++ b/qunitTest/notify_AggregatorWidgetTest.js @@ -13,7 +13,7 @@ require(['configTest'], function() { geoLocationWidget.setDiscoverer(discoverer); //subscription - var widget = discoverer.getWidgetDescriptions(); + var widget = discoverer.getDescriptions([contactJS.Widget]); var handle = new contactJS.WidgetHandle().withName('GeoLocationWidget').withId(widget[0].getId()); @@ -36,7 +36,7 @@ require(['configTest'], function() { var geoLocationWidget = discoverer.getComponent(widget[0].getId()); var checkValues = function(){ geoLocationWidget.notify(); - var newValues = testAggregator.queryAttributes(); + var newValues = testAggregator.getAttributes(); assert.equal( newValues.size(), 3,"notify Passed!: two available attributes" ); var latitude = newValues.getItem('latitude'); diff --git a/qunitTest/widgetHandleListTest.js b/qunitTest/widgetHandleListTest.js index b8345a275d7bb4b74fb3c0aafa8132ea1013ad8e..b88c02397624d938a7055ced18184e9eb8a57583 100644 --- a/qunitTest/widgetHandleListTest.js +++ b/qunitTest/widgetHandleListTest.js @@ -1,10 +1,12 @@ require(['configTest'], function() { - require(['contactJS'],function(contactJS){ + require(['../examples/GeoLocationWidget', 'contactJS'],function(GeoLocationWidget, contactJS){ QUnit.test( "WidgetHandleList", function( assert ) { var widgetHandle = new contactJS.WidgetHandle().withName('testWidget').withId('testId'); var widgetHandle2 = new contactJS.WidgetHandle().withName('testWidget2').withId('testId2'); var widgetHandle3 = new contactJS.WidgetHandle().withName('testWidget3').withId('testId3'); + + var geoWidget = new GeoLocationWidget(new contactJS.Discoverer()); var array = new Array(); array.push(widgetHandle2); @@ -14,12 +16,14 @@ require(['configTest'], function() { var list2 = new contactJS.WidgetHandleList(); list2.put(widgetHandle); - - assert.ok( list2.size() == 1, "Passed!: Put type to list (put)" ); + assert.ok( list2.size() == 1, "Passed!: Put widget handle to list (put)" ); list2.putAll(array); - assert.ok( list2.size() == 3, "Passed!: Put another two type to list (putAll)" ); - + assert.ok( list2.size() == 3, "Passed!: Put another two widget handles to list (putAll)" ); + + list2.put(geoWidget); + assert.ok( list2.size() == 4, "Passed!: Put widget to list (put)" ); + //contains assert.ok( list2.contains(widgetHandle), "Passed!: contains -> true" ); assert.ok( !list.contains(widgetHandle), "Passed!: contains -> false" ); diff --git a/qunitTest/widgetTest.js b/qunitTest/widgetTest.js index 15ed2a3bfa5f3ba5bdafa4d20d5816007ab30893..1ff3a20bfe4c4080d2eaefb861d5342a27946694 100644 --- a/qunitTest/widgetTest.js +++ b/qunitTest/widgetTest.js @@ -3,9 +3,8 @@ require(['configTest'], function() { function(GeoLocationWidget, contactJS){ QUnit.asyncTest( "GeoLocationWidget ", function( assert ) { - - - var testWidget = new GeoLocationWidget(); + var discoverer = new contactJS.Discoverer(); + var testWidget = new GeoLocationWidget(discoverer); var id = testWidget.getId(); assert.ok( id && id !== "null" && id !== "undefined", "Passed!: id is not null" ); @@ -13,13 +12,13 @@ require(['configTest'], function() { assert.equal( testWidget.getName(), 'GeoLocationWidget', "Passed!: name -> GeoLocationWidget" ); //attributeTypes - var types = testWidget.getWidgetAttributeTypes(); + var types = testWidget.getAttributeTypes(); assert.equal(types.size(), 2,"getWidgetAttributeTypes Passed!: two types were returned" ); var constantTypes = testWidget.getWidgetConstantAttributeTypes(); assert.equal(constantTypes.size(), 0,"getWidgetConstantAttributeTypes Passed!: zero constantTypes was returned" ); //callbacks - var callbacks = testWidget.queryCallbacks(); + var callbacks = testWidget.getCallbackList(); assert.equal(callbacks.size(), 1,"queryCallbacks Passed!: one callback was returned" ); //subscriber @@ -27,7 +26,7 @@ require(['configTest'], function() { assert.equal(subscriber.size(), 0,"getSubscriber Passed!: zero subscriber was returned" ); //attributes - var attributes= testWidget.queryAttributes(); + var attributes= testWidget.getAttributes(); assert.equal(attributes.size(), 2,"queryAttributes Passed!: two attributes were returned" ); var latitude = attributes.getItem('latitude'); assert.equal(latitude.getName(), 'latitude',"queryAttributes Passed!: latitude exists" ); @@ -47,8 +46,7 @@ require(['configTest'], function() { var longitude2 = attributes.getItem('longitude'); assert.equal(longitude2.getName(), 'longitude',"updateAndQueryWidget without callbackPassed!: longitude exists" ); assert.equal(longitude2.getValue(), 'undefined',"value of longitude is not updated yet: " + longitude2.getValue() ); - - + //updateAndQuery with callback var testUpdateAndQuery = function(){ var attributes2 = testWidget.queryWidget();