diff --git a/build/contactJS.js b/build/contactJS.js index 78ae4cc9ae13eb201a1861f3b97a8373a9f55c14..4099c202e030e10add890d9145ff19fbe42a6ba8 100644 --- a/build/contactJS.js +++ b/build/contactJS.js @@ -10,8 +10,7 @@ 'conditionMethod', 'equals', 'unequals', - 'interpreterDescription', - 'widgetDescription', + 'discoverer', 'translation', 'interpreter', @@ -34,8 +33,6 @@ ConditionMethod, Equals, UnEquals, - InterpreterDescription, - WidgetDescription, Discoverer, Translation, Interpreter, @@ -65,8 +62,6 @@ contactJS.ConditionMethod = ConditionMethod; contactJS.Equals = Equals; contactJS.UnEquals = UnEquals; - contactJS.InterpreterDescription = InterpreterDescription; - contactJS.WidgetDescription = WidgetDescription; contactJS.Discoverer = Discoverer; contactJS.Translation = Translation; contactJS.Interpreter = Interpreter; diff --git a/dist/contactJS.js b/dist/contactJS.js index 9639fe6b52245b91831f144e6de7905a94a41f14..06193453c5549e0f59e455cb0f390e5c945bc231 100644 --- a/dist/contactJS.js +++ b/dist/contactJS.js @@ -3536,235 +3536,6 @@ define('subscriberList',['easejs', 'abstractList', 'subscriber'], return SubscriberList; }); -/** - * This module represents the WidgetDescription. - * It describes the most important information for the communication with a specific widget. - * - * @module WidgetDescription - * @fileOverview - */ -define('widgetDescription',['easejs', 'attributeList'], - function(easejs, AttributeList){ - var Class = easejs.Class; - var WidgetDescription = Class('WidgetDescription',{ - - /** - * @alias id - * @protected - * @type {string} - * @memberof WidgetDescription# - * @desc Id of the Widget that are described by this object. - */ - 'protected id' : '', - /** - * @alias name - * @protected - * @type {string} - * @memberof WidgetDescription# - * @desc Name of the Widget that are described by this object. - */ - 'protected name' : '', - /** - * @alias outAttributeTypes - * @protected - * @type {AttributeTypeList} - * @memberof WidgetDescription# - * @desc List of attributeTypes that are provided. - */ - 'protected outAttributeTypes' : [], - /** - * @alias callbackNames - * @protected - * @type {array} - * @memberof WidgetDescription# - * @desc Array of available callback names. - */ - 'protected callbackNames' : [], - - /** - * Constructor: Initializes the inAttributeTypes. - * - * @virtual - * @class WidgetDescription - * @classdesc The description of a Widget and the communication with it. - * @requires easejs - * @requires AttributeTypeList - * @constructs WidgetDescription - */ - 'virtual public __construct' : function(){ - this.outAttributeTypes = new AttributeList(); - }, - - /** - * Builder for name - * - * @public - * @alias withName - * @memberof WidgetDescription# - * @param {string} _name Name of the Widget that are described by this object. - * @returns {WidgetDescription} - */ - 'public withName' : function(_name){ - this.setName(_name); - return this; - }, - - /** - * Builder for id - * - * @public - * @alias withId - * @memberof WidgetDescription# - * @param {string} _id Id of the Widget that are described by this object. - * @returns {WidgetDescription} - */ - 'public withId' : function(_id){ - this.setId(_id); - return this; - }, - - /** - * Builder for outAttributeType list - * - * @public - * @alias withOutAttributeTypes - * @memberof WidgetDescription# - * @param {(AttributeTypeList|Array)} _outAttributeTypes List of AttributeType that are provided - * @returns {WidgetDescription} - */ - 'public withOutAttributeTypes' : function(_outAttributeTypes){ - this.setOutAttributeTypes(_outAttributeTypes); - return this; - }, - - /** - * Builder for outAttributeType - * - * @public - * @alias withInAttributeType - * @memberof WidgetDescription# - * @param {AttributeType} _outAttributeType AttributeType that are provided - * @returns {WidgetDescription} - */ - 'public withOutAttributeType' : function(_outAttributeType){ - this.setOutAttributeType(_outAttributeType); - return this; - }, - - /** - * Returns the name of the described widget. - * - * @public - * @alias getName - * @memberof WidgetDescription# - * @returns {String} - */ - 'public getName' : function(){ - return this.name; - }, - - /** - * Returns the id of the described widget. - * - * @public - * @alias getId - * @memberof WidgetDescription# - * @returns {String} - */ - 'public getId' : function(){ - return this.id; - }, - - /** - * Returns outAttributeTypes of the widget. - * - * @public - * @alias getOutAttributeTypes - * @memberof WidgetDescription# - * @returns {AttributeTypeList} - */ - 'public getOutAttributeTypes' : function(){ - return this.outAttributeTypes; - }, - - /** - * Sets the name of the described widget. - * - * @public - * @alias setName - * @memberof WidgetDescription# - * @params {String} _name Name of the described widget - */ - 'public setName' : function(_name){ - if(typeof _name === 'string'){ - this.name = _name; - } - }, - - /** - * Sets the id of the described widget. - * - * @public - * @alias setId - * @memberof WidgetDescription# - * @params {String} _id Id of the described widget - */ - 'public setId' : function(_id){ - if(typeof _id === 'string') { - this.id = _id; - } - }, - - /** - * Adds an outAttributeType to the list - * - * @public - * @alias addOutAttributeType - * @memberof WidgetDescription# - * @param {AttributeType} _outAttributeType AttributeType that are provided - */ - 'public addOutAttributeType' : function(_outAttributeType){ - this.outAttributeTypes.put(_outAttributeType); - }, - - /** - * Adds outAttributeTypes that are provided by the Widget - * - * @public - * @alias addOutAttributeTypes - * @memberof WidgetDescription# - * @param {(AttributeList|Array)} _outAttributeTypes List of AttributeType that are provided - */ - 'public addOutAttributeTypes' : function(_outAttributeTypes){ - this.outAttributeTypes.putAll(_outAttributeTypes); - }, - - 'public setCallbackNames' : function(_callbackNames) { - this.callbackNames = _callbackNames; - }, - - 'public addCallbackName' : function(_callbackName) { - this.callbackNames.push(_callbackName); - }, - - /** - * Returns true if the widget can satisfy the requested attribute type. - * - * @public - * @alias doesSatisfyAttributeType - * @memberof WidgetDescription# - * @param {AttributeType} _attribute - * @returns {boolean} - */ - - 'public doesSatisfyAttributeType': function(_attribute) { - return this.getOutAttributeTypes().containsTypeOf(_attribute); - } - }); - - return WidgetDescription; - -}); /** * This module representing a Context Widget. * @@ -3772,11 +3543,9 @@ define('widgetDescription',['easejs', 'attributeList'], * @fileOverview */ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', - 'attributeList', 'conditionList', - 'subscriber', 'subscriberList', 'widgetDescription'], + 'attributeList', 'conditionList', 'subscriber', 'subscriberList'], function(easejs, MathUuid, Callback, CallbackList, Attribute, - AttributeList, ConditionList, - Subscriber, SubscriberList, WidgetDescription) { + AttributeList, ConditionList, Subscriber, SubscriberList) { var AbstractClass = easejs.AbstractClass; var Class = easejs.Class; @@ -3805,7 +3574,7 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * @memberof Widget# * @desc All available Attributes and their values. */ - 'protected attributes' : [], + 'protected outAttributes' : [], /** * @alias oldAttributes * @protected @@ -3814,7 +3583,7 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * @desc This temporary variable is used for storing the old attribute values. * So these can be used to check conditions. */ - 'protected oldAttributes' : [], + 'protected oldOutAttributes' : [], /** * @alias constantAttributes * @protected @@ -3822,7 +3591,7 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * @memberof Widget# * @desc All available constant Attributes and their values. */ - 'protected constantAttributes' : [], + 'protected constantOutAttributes' : [], /** * @alias callbacks * @protected @@ -3874,8 +3643,8 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', this.id = Math.uuid(); this.discoverer = _discoverer; this.register(); - this.attributes = new AttributeList(); - this.constantAttributes = new AttributeList(); + this.outAttributes = new AttributeList(); + this.constantOutAttributes = new AttributeList(); this.subscribers = new SubscriberList(); this.callbacks = new CallbackList(); this.init(_attributeTypes); @@ -3927,11 +3696,11 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * @memberof Widget# * @returns {AttributeList} */ - 'public getAttributes' : function(_attributeList) { + 'public getOutAttributes' : function(_attributeList) { if (Class.isA(AttributeList, _attributeList)) { - return this.attributes.getSubset(_attributeList); + return this.outAttributes.getSubset(_attributeList); } else { - return this.attributes; + return this.outAttributes; } }, @@ -3944,11 +3713,11 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * @memberof Widget# * @returns {AttributeList} */ - 'public getConstantAttributes' : function(_attributeList) { + 'public getConstantOutAttributes' : function(_attributeList) { if (Class.isA(AttributeList, _attributeList)) { - return this.constantAttributes.getSubset(_attributeList); + return this.constantOutAttributes.getSubset(_attributeList); } else { - return this.constantAttributes; + return this.constantOutAttributes; } }, @@ -3959,7 +3728,7 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * @returns {*} */ 'public getValueForAttributeWithTypeOf': function(_attributeType) { - return this.getAttributes().getAttributeWithTypeOf(_attributeType).getValue(); + return this.getOutAttributes().getAttributeWithTypeOf(_attributeType).getValue(); }, /** @@ -3971,7 +3740,7 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * @returns {AttributeList} */ 'public getOldAttributes' : function() { - return this.oldAttributes; + return this.oldOutAttributes; }, /** @@ -4053,12 +3822,10 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * @protected * @alias setAttributes * @memberof Widget# - * @param {(AttributeValueList|Array)} - * _attributes List or Array of - * AttributeValues + * @param {(AttributeList|Array)} _attributes List or Array of AttributeValues */ - 'protected setAttributes' : function(_attributes) { - var list = new Array(); + 'protected setOutAttributes' : function(_attributes) { + var list = []; if (_attributes instanceof Array) { list = _attributes.reduce(function(o, v, i) { o[i] = v; @@ -4067,12 +3834,12 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', } else if (Class.isA(AttributeValueList,_attributes)) { list = _attributes.getItems(); } - this.oldAttributes = this.attributes; + this.oldOutAttributes = this.outAttributes; for ( var i in list) { var attribute = list[i]; if (Class.isA(AttributeValue, attribute)) { attribute.setTimestamp(this.getCurrentTime()); - this.attributes.put(attribute); + this.outAttributes.put(attribute); var type = new AttributeType().withName(attribute.getName()) .withType(attribute.getType()) @@ -4089,17 +3856,17 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * updated. * * @public - * @alias addAttribute + * @alias addOutAttribute * @memberof Widget# * @param {Attribute} _attribute AttributeValue */ - 'public addAttribute' : function(_attribute, _multipleInstances) { + 'public addOutAttribute' : function(_attribute, _multipleInstances) { _multipleInstances = typeof _multipleInstances == "undefined" ? false : _multipleInstances; if (Class.isA(Attribute, _attribute)) { - if (!this.attributes.containsTypeOf(_attribute)) { - this.oldAttributes = this.attributes; + if (!this.outAttributes.containsTypeOf(_attribute)) { + this.oldOutAttributes = this.outAttributes; _attribute.setTimestamp(this.getCurrentTime()); - this.attributes.put(_attribute, _multipleInstances); + this.outAttributes.put(_attribute, _multipleInstances); } } }, @@ -4109,14 +3876,12 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * associated AttributeTypes. * * @protected - * @alias setConstantAttributes + * @alias setConstantOutAttributes * @memberof Widget# - * @param {(AttributeValueList|Array)} - * _constantAttributes List or Array of - * AttributeValues + * @param {(AttributeList|Array)} _constantAttributes List or Array of AttributeValues */ - 'protected setConstantAttributes' : function(_constantAttributes) { - var list = new Array(); + 'protected setConstantOutAttributes' : function(_constantAttributes) { + var list = []; if (_constantAttributes instanceof Array) { list = _constantAttributes; } else if (Class.isA(AttributeValueList,_constantAttributes)) { @@ -4142,12 +3907,11 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * updated. * * @protected - * @alias addConstantAttribute + * @alias addConstantOutAttribute * @memberof Widget# - * @param {AttributeValue} - * _constantAttribute AttributeValue + * @param {AttributeValue} _constantAttribute AttributeValue */ - 'protected addConstantAttribute' : function(_constantAttribute) { + 'protected addConstantOutAttribute' : function(_constantAttribute) { if (Class.isA(AttributeValue, _constantAttribute)) { if (!this.constantAttributes .contains(_constantAttribute)) { @@ -4270,14 +4034,13 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * provided Attribute. * * @protected - * @alias isAttribute + * @alias isOutAttribute * @memberof Widget# - * @param {AttributeValue} - * _attribute + * @param {Attribute} _attribute * @returns {boolean} */ - 'protected isAttribute' : function(_attribute) { - return !!this.attributes.containsTypeOf(_attribute); + 'protected isOutAttribute' : function(_attribute) { + return !!this.outAttributes.containsTypeOf(_attribute); }, /** @@ -4289,7 +4052,7 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * @alias initAttributes * @memberof Widget# */ - 'abstract protected initAttributes' : [], + 'abstract protected initOutAttributes' : [], /** * Initializes the provided ConstantAttributes. @@ -4300,7 +4063,7 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * @alias initConstantAttributes * @memberof Widget# */ - 'abstract protected initConstantAttributes' : [], + 'abstract protected initConstantOutAttributes' : [], /** * Initializes the provided Callbacks. @@ -4322,8 +4085,8 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * @memberof Widget# */ 'protected init' : function(_attributeTypes) { - this.initAttributes(); - this.initConstantAttributes(); + this.initOutAttributes(); + this.initConstantOutAttributes(); this.initCallbacks(); this.didFinishInitialization(_attributeTypes); @@ -4395,7 +4158,7 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * @public * @alias putData * @memberof Widget# - * @param {(AttributeValueList|Array)} _data Data that should be entered. + * @param {(AttributeList|Array)} _data Data that should be entered. * */ 'virtual public putData' : function(_data) { @@ -4407,8 +4170,8 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', } for ( var i in list) { var x = list[i]; - if (Class.isA(Attribute, x) && this.isAttribute(x)) { - this.addAttribute(x); + if (Class.isA(Attribute, x) && this.isOutAttribute(x)) { + this.addOutAttribute(x); } } @@ -4425,8 +4188,8 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', */ 'public queryWidget' : function() { var response = new AttributeList(); - response.putAll(this.getAttributes()); - response.putAll(this.getConstantAttributes()); + response.putAll(this.getOutAttributes()); + response.putAll(this.getConstantOutAttributes()); return response; }, @@ -4445,10 +4208,7 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', this.queryGenerator(_function); } else { this.queryGenerator(); - var response = new AttributeList(); - response.putAll(this.getAttributes()); - response.putAll(this.getConstantAttributes()); - return response; + return this.queryWidget(); } }, @@ -4458,19 +4218,19 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * @protected * @alias sendToSubscriber * @memberof Widget# - * @param {string} _callbackName Name of the searched Callback. + * @param {string} _callback Name of the searched Callback. */ 'protected sendToSubscriber' : function(_callback) { if (_callback && Class.isA(Callback, _callback)) { var subscriberList = this.subscribers.getItems(); - for ( var i in subscriberList) { + for (var i in subscriberList) { var subscriber = subscriberList[i]; if (subscriber.getSubscriptionCallbacks().contains(_callback)) { if(this.dataValid(subscriber.getConditions())){ var subscriberInstance = this.discoverer.getComponent(subscriber.getSubscriberId()); var callSubset = _callback.getAttributeTypes(); var subscriberSubset = subscriber.getAttributesSubset(); - var data = this.attributes.getSubset(callSubset); + var data = this.outAttributes.getSubset(callSubset); if (subscriberSubset && subscriberSubset.size() > 0) { data = data.getSubset(subscriberSubset); } @@ -4498,7 +4258,7 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', } if (!_conditions.isEmpty()) { var items = _condition.getItems(); - for ( var i in items) { + for (var i in items) { var condition = items[i]; var conditionAttributeType = condition.getAttributeType(); var conditionAttributeTypeList = new AttributeTypeList() @@ -4511,25 +4271,6 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', return false; }, - /** - * Returns the description of this component. - * @virtual - * @public - * @alias getDescription - * @memberof Widget# - * @returns {WidgetDescription} - */ - 'virtual public getDescription' : function() { - var description = new WidgetDescription().withId(this.id).withName(this.name); - description.addOutAttributeTypes(this.attributes); - description.addOutAttributeTypes(this.constantAttributes); - var widgetCallbacks = this.callbacks.getItems(); - for(var i in widgetCallbacks) { - description.addCallbackName(widgetCallbacks[i].getName()); - } - return description; - }, - /** * Runs the context acquisition constantly in an interval. * Can be called by init. @@ -4572,132 +4313,24 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', 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 Widget; -}); -/** - * This module represents the InterpreterDescription. - * It describes the most important information for the communication with a specific interpreter. - * - * @module InterpreterDescription - * @fileOverview - */ -define('interpreterDescription',['easejs','attributeList', 'widgetDescription'], - function(easejs,AttributeList, WidgetDescription){ - var Class = easejs.Class; - var InterpreterDescription = Class('InterpreterDescription'). - extend(WidgetDescription, { - /** - * @alias inAttributeTypes - * @private - * @type {AttributeTypeList} - * @memberof InterpreterDescription# - * @desc List of all Attributes that are expected for interpretation. - */ - 'private inAttributeTypes' : [], - - /** - * Constructor: Calls the constructor of the WidgetDescription - * and initializes the inAttributeTypes. - * - * @class InterpreterDescription - * @classdesc The description of an interpreter and the communication with it. - * @extends WidgetDescription - * @requires easejs - * @requires AttributeList - * @requires WidgetDescription - * @constructs InterpreterDescription - */ - 'override public __construct' : function(){ - this.__super(); - this.inAttributeTypes = new AttributeList(); - }, - - /** - * Builder for inAttributeType list - * - * @public - * @alias withInAttributeTypes - * @memberof InterpreterDescription# - * @param {(AttributeList|Array)} _inAttributeTypes List of AttributeType that are expected - * @returns {InterpreterDescription} - */ - 'public withInAttributeTypes' : function(_inAttributeTypes){ - this.setInAttributeTypes(_inAttributeTypes); - return this; - }, - - /** - * Builder for inAttributeType - * - * @public - * @alias withInAttributeType - * @memberof InterpreterDescription# - * @param {AttributeType} _inAttributeType AttributeType that are expected - * @returns {InterpreterDescription} - */ - 'public withInAttributeType' : function(_inAttributeType){ - this.setInAttributeType(_inAttributeType); - return this; - }, - - /** - * Returns inAttributeTypes of the interpreter - * - * @public - * @alias getInAttributeTypes - * @memberof InterpreterDescription# - * @returns {AttributeTypeList} - */ - 'public getInAttributeTypes' : function(){ - return this.inAttributeTypes; }, /** - * Adds an inAttributeType to the list - * - * @public - * @alias setInAttributeType - * @memberof InterpreterDescription# - * @param {AttributeType} _inAttributeType AttributeType that are expected - */ - 'public setInAttributeType' : function(_inAttributeType){ - this.inAttributeTypes.put(_inAttributeType); - }, - - /** - * Adds inAttributeTypes that are expected - * + * Returns true if the widget can satisfy the requested attribute type. + * * @public - * @alias setInAttributeTypes - * @memberof InterpreterDescription# - * @param {(AttributeTypeList|Array)} _inAttributeTypes List of AttributeType that are expected + * @alias doesSatisfyAttributeType + * @memberof WidgetDescription# + * @param {AttributeType} _attribute + * @returns {boolean} */ - 'public setInAttributeTypes' : function(_inAttributeTypes){ - this.inAttributeTypes.putAll(_inAttributeTypes); - } - }); + 'virtual public doesSatisfyAttributeType': function(_attribute) { + return this.outAttributes.containsTypeOf(_attribute); + } + }); - return InterpreterDescription; + return Widget; }); /** * This module represents a InterpreterResult. @@ -4890,10 +4523,8 @@ define('interpreterResult',['easejs', 'attributeList'], * @module Interpreter * @fileOverview */ -define('interpreter',[ 'easejs', 'MathUuid', 'attribute', 'attributeList', - 'interpreterDescription', 'interpreterResult' ], - function(easejs, MathUuid, Attribute, AttributeList, - InterpreterDescription, InterpreterResult) { +define('interpreter',[ 'easejs', 'MathUuid', 'attribute', 'attributeList', 'interpreterResult' ], + function(easejs, MathUuid, Attribute, AttributeList, InterpreterResult) { var Class = easejs.Class; var AbstractClass = easejs.AbstractClass; var Interpreter = AbstractClass('Interpreter', @@ -5296,6 +4927,10 @@ define('interpreter',[ 'easejs', 'MathUuid', 'attribute', 'attributeList', 'public getOutAttributesWithInputParameters': function() { return this.outAttributes.getAttributesWithInputParameters(); + }, + + 'public doesSatisfyAttributeType': function(_attribute) { + return this.outAttributes.containsTypeOf(_attribute); } }); @@ -5332,10 +4967,10 @@ define('interpretation',['easejs', 'interpreter', 'attributeList'], */ define('aggregator',['easejs', 'MathUuid','widget', 'attribute', 'attributeList', 'subscriber', - 'subscriberList', 'callbackList', 'storage', 'widgetDescription', 'interpreter', 'interpretation'], + 'subscriberList', 'callbackList', 'storage', 'interpreter', 'interpretation'], function(easejs, MathUuid, Widget, Attribute, AttributeList, Subscriber, SubscriberList, - CallbackList, Storage, WidgetDescription, Interpreter, Interpretation){ + CallbackList, Storage, Interpreter, Interpretation){ var Class = easejs.Class; var Aggregator = Class('Aggregator'). @@ -5485,14 +5120,14 @@ define('aggregator',['easejs', 'MathUuid','widget', * @alias initAttributes * @memberof Aggregator# */ - 'protected initAttributes' : function(){ + 'protected initOutAttributes' : function(){ if(this.widgets.length > 0){ var widgetIdList = this.widgets; for(var i in widgetIdList){ var widgetId = widgetIdList[i]; var widgetInstance = this.discoverer.getComponent(widgetId); if (widgetInstance) { - this.setAttributes(widgetInstance.queryAttributes()); + this.setOutAttributes(widgetInstance.queryAttributes()); } } } @@ -5505,7 +5140,7 @@ define('aggregator',['easejs', 'MathUuid','widget', * @alias initConstantAttributes * @memberof Aggregator# */ - 'protected initConstantAttributes' : function(){ + 'protected initConstantOutAttributes' : function(){ if(this.widgets.length > 0){ var widgetIdList = this.widgets; for(var i in widgetIdList){ @@ -5577,7 +5212,7 @@ define('aggregator',['easejs', 'MathUuid','widget', 'virtual protected setAggregatorAttributeValues' : function(_attributes) { for (var index in _attributes) { var theAttribute = _attributes[index]; - this.addAttribute(theAttribute); + this.addOutAttribute(theAttribute); } }, @@ -5618,7 +5253,7 @@ define('aggregator',['easejs', 'MathUuid','widget', * @returns {AttributeList} */ 'public getCurrentData' : function(){ - return this.attributes; + return this.outAttributes; }, /** @@ -5670,11 +5305,11 @@ define('aggregator',['easejs', 'MathUuid','widget', * @public * @alias addWidgetSubscription * @memberof Aggregator# - * @param {String|Widget|WidgetDescription} _widgetIdOrWidget Widget that should be subscribed. + * @param {String|Widget} _widgetIdOrWidget Widget that should be subscribed. * @param {CallbackList} _callbackList required Callbacks */ 'public addWidgetSubscription' : function(_widgetIdOrWidget, _callbackList){ - if (Class.isA(Widget, _widgetIdOrWidget) || Class.isA(WidgetDescription, _widgetIdOrWidget)) { + if (Class.isA(Widget, _widgetIdOrWidget)) { if (Class.isA(Widget, _widgetIdOrWidget) && (!_callbackList || !Class.isA(CallbackList, _callbackList))) { _callbackList = _widgetIdOrWidget.getCallbackList(); } @@ -5691,7 +5326,7 @@ define('aggregator',['easejs', 'MathUuid','widget', var typeList = singleCallback.getAttributeTypes().getItems(); for(var y in typeList){ var singleType = typeList[y]; - this.addAttribute(singleType); + this.addOutAttribute(singleType); } } this.addWidget(_widgetIdOrWidget); @@ -5737,8 +5372,8 @@ define('aggregator',['easejs', 'MathUuid','widget', } for(var i in list){ var x = list[i]; - if(Class.isA(Attribute, x ) && this.isAttribute(x)){ - this.addAttribute(x); + if(Class.isA(Attribute, x ) && this.isOutAttribute(x)){ + this.addOutAttribute(x); if(this.db){ this.store(x); } @@ -5893,18 +5528,19 @@ define('aggregator',['easejs', 'MathUuid','widget', /** * - * @private + * @override + * @public * @alias doesSatisfyAttributeType * @param _attribute * @returns {boolean} */ - 'private doesSatisfyAttributeType': function(_attribute) { + 'override public doesSatisfyAttributeType': function(_attribute) { var componentUUIDs = this.getComponentUUIDs(); var doesSatisfy = false; for (var index in componentUUIDs) { var theComponent = this.discoverer.getComponent(componentUUIDs[index]); - if (theComponent.getDescription().doesSatisfyAttributeType(_attribute)) { + if (theComponent.doesSatisfyAttributeType(_attribute)) { doesSatisfy = true; } } @@ -5936,7 +5572,7 @@ define('aggregator',['easejs', 'MathUuid','widget', // if the component was added before, ignore it if (!this.hasComponent(theComponent.getId())) { - var outAttributes = theComponent.getDescription().getOutAttributeTypes().getItems(); + var outAttributes = theComponent.getOutAttributes().getItems(); // if component is a widget and it wasn't added before, subscribe to its callbacks if (Class.isA(Widget, theComponent)) { @@ -5947,7 +5583,7 @@ define('aggregator',['easejs', 'MathUuid','widget', for (var widgetOutAttributeIndex in outAttributes) { var widgetOutAttribute = outAttributes[widgetOutAttributeIndex]; // add the attribute type to the aggregators list of handled attribute types - if (!this.getAttributes().containsTypeOf(widgetOutAttribute)) this.addAttribute(widgetOutAttribute); + if (!this.getOutAttributes().containsTypeOf(widgetOutAttribute)) this.addOutAttribute(widgetOutAttribute); console.log("I can now satisfy attribute "+widgetOutAttribute+" with the help of "+theComponent.getName()+"! That was easy :)"); _unsatisfiedAttributes.removeAttributeWithTypeOf(widgetOutAttribute); } @@ -5988,7 +5624,7 @@ define('aggregator',['easejs', 'MathUuid','widget', for (var unsatisfiedAttributeIndex in _unsatisfiedAttributes.getItems()) { var theUnsatisfiedAttribute = _unsatisfiedAttributes.getItems()[unsatisfiedAttributeIndex]; if (theUnsatisfiedAttribute.equalsTypeOf(interpreterOutAttribute)) { - this.addAttribute(theUnsatisfiedAttribute); + this.addOutAttribute(theUnsatisfiedAttribute); console.log("I can now satisfy attribute "+theUnsatisfiedAttribute+" with the help of "+theComponent.getName()+"! Great!"); this.interpretations.push(new Interpretation(theComponent.getId(), theComponent.getInAttributes(), new AttributeList().withItems([theUnsatisfiedAttribute]))); } @@ -5997,8 +5633,8 @@ define('aggregator',['easejs', 'MathUuid','widget', } } else { console.log("Found interpreter but can't satisfy required attributes."); - for (var j in theComponent.getDescription().getInAttributeTypes().getItems()) { - console.log("Missing "+theComponent.getDescription().getInAttributeTypes().getItems()[j]+"."); + for (var j in theComponent.getInAttributes().getItems()) { + console.log("Missing "+theComponent.getInAttributes().getItems()[j]+"."); } } } @@ -6017,7 +5653,7 @@ define('aggregator',['easejs', 'MathUuid','widget', * @memberof Aggregator# */ 'virtual public didFinishSetup': function() { - unsatisfiedAttributes = this.getAttributes().clone(); + unsatisfiedAttributes = this.getOutAttributes().clone(); // get all widgets that satisfy attribute types this.getComponentsForUnsatisfiedAttributeTypes(unsatisfiedAttributes, false, [Widget]); @@ -6025,7 +5661,7 @@ define('aggregator',['easejs', 'MathUuid','widget', this.getComponentsForUnsatisfiedAttributeTypes(unsatisfiedAttributes, false, [Interpreter]); console.log("Unsatisfied attributes: "+unsatisfiedAttributes.size()); - console.log("Satisfied attributes: "+this.getAttributes().size()); + console.log("Satisfied attributes: "+this.getOutAttributes().size()); console.log("Interpretations "+this.interpretations.length); }, @@ -6049,14 +5685,14 @@ define('aggregator',['easejs', 'MathUuid','widget', completedQueriesCounter++; if (completedQueriesCounter == self.widgets.length) { if (_callback && typeof(_callback) == 'function') { - _callback(self.getAttributes()); + _callback(self.getOutAttributes()); } } }); } } else { if (_callback && typeof(_callback) == 'function') { - _callback(self.getAttributes()); + _callback(self.getOutAttributes()); } } }, @@ -6077,14 +5713,14 @@ define('aggregator',['easejs', 'MathUuid','widget', for (var index in this.interpretations) { var theInterpretation = this.interpretations[index]; var theInterpreterId = theInterpretation.interpreterId; - var interpretationInAttributeValues = this.getAttributes(theInterpretation.inAttributeTypes); - var interpretationOutAttributeValues = this.getAttributes(theInterpretation.outAttributeTypes); + var interpretationInAttributeValues = this.getOutAttributes(theInterpretation.inAttributeTypes); + var interpretationOutAttributeValues = this.getOutAttributes(theInterpretation.outAttributeTypes); self.interpretData(theInterpreterId, interpretationInAttributeValues, interpretationOutAttributeValues, function(_interpretedData) { for (var j in _interpretedData.getItems()) { var theInterpretedData = _interpretedData.getItems()[j]; - self.addAttribute(theInterpretedData); + self.addOutAttribute(theInterpretedData); if (self.db){ self.store(theInterpretedData); } @@ -6093,14 +5729,14 @@ define('aggregator',['easejs', 'MathUuid','widget', completedQueriesCounter++; if (completedQueriesCounter == self.interpretations.length) { if (_callback && typeof(_callback) == 'function') { - _callback(self.getAttributes()); + _callback(self.getOutAttributes()); } } }); } } else { if (_callback && typeof(_callback) == 'function') { - _callback(self.getAttributes()); + _callback(self.getOutAttributes()); } } }, @@ -6229,7 +5865,7 @@ define('discoverer',[ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggre * @memberof Discoverer# * @desc List of available Widgets. */ - 'private widgets' : {}, + 'private widgets' : [], /** * @alias aggregators @@ -6238,16 +5874,16 @@ define('discoverer',[ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggre * @memberof Discoverer# * @desc List of available Aggregators. */ - 'private aggregators' : {}, + 'private aggregators' : [], /** - * @alias interpreter + * @alias interpreters * @private * @type {Object} * @memberof Discoverer# * @desc List of available Interpreter. */ - 'private interpreter' : {}, + 'private interpreters' : [], /** * Constructor: All known components given in the associated functions will be registered as startup. @@ -6259,7 +5895,7 @@ define('discoverer',[ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggre * @constructs Discoverer */ 'public __construct' : function() { - this.register(); + }, /** @@ -6275,53 +5911,6 @@ define('discoverer',[ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggre 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. * @@ -6331,10 +5920,9 @@ define('discoverer',[ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggre * @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); - } + if (_component.getType() == "Widget" && this.getWidget(_component.getId()) == null) this.widgets.push(_component); + if (_component.getType() == "Interpreter" && this.getInterpreter(_component.getId()) == null) this.interpreters.push(_component); + if (_component.getType() == "Aggregator" && this.getAggregator(_component.getId()) == null) this.aggregators.push(_component); }, /** @@ -6346,10 +5934,17 @@ define('discoverer',[ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggre * @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); + for (var wi in this.widgets) { + var theWidget = this.widgets[wi]; + if (_id == theWidget.getId()) this.widgets.splice(wi, 1); + } + for (var ii in this.interpreters) { + var theInterpreter = this.interpreters[ii]; + if (_id == theInterpreter.getId()) this.interpreters.splice(ii, 1); + } + for (var ai in this.aggregators) { + var theAggregator= this.aggregators[ai]; + if (_id == theAggregator.getId()) this.aggregators.splice(ai, 1); } }, @@ -6363,12 +5958,11 @@ define('discoverer',[ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggre * @returns {?Widget} */ 'public getWidget' : function(_id) { - var widget = this.widgets[_id]; - if(!widget){ - delete(this.widgets[_id]); - return null; + for (var index in this.widgets) { + var theWidget = this.widgets[index]; + if (theWidget.getId() == _id) return theWidget; } - return widget; + return null; }, /** @@ -6381,12 +5975,11 @@ define('discoverer',[ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggre * @returns {Aggregator} */ 'public getAggregator' : function(_id) { - var aggregator = this.aggregators[_id]; - if(!aggregator ){ - delete(this.aggregators[_id]); - return null; + for (var index in this.aggregators) { + var theAggregator = this.aggregators[index]; + if (theAggregator.getId() == _id) return theAggregator; } - return aggregator; + return null; }, /** @@ -6399,14 +5992,32 @@ define('discoverer',[ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggre * @returns {Interpreter} */ 'public getInterpreter' : function(_id) { - var interpret = this.interpreter[_id]; - if(!interpret){ - delete(this.interpreter[_id]); - return null; + for (var index in this.interpreters) { + var theInterpreter = this.interpreters[index]; + if (theInterpreter.getId() == _id) return theInterpreter; } - return interpret; + return null; + }, + + /** + * Returns all registered components (widget, aggregator and interpreter). + * + * @public + * @alias getComponents + * @memberof Discoverer# + * @param {Array} _componentTypes Component types to get descriptions for. Defaults to Widget, Interpreter and Aggregator. + * @returns {Array} + */ + 'public getComponents' : function(_componentTypes) { + if (typeof _componentTypes == "undefined") _componentTypes = [Widget, Interpreter, Aggregator]; + var response = []; + if (jQuery.inArray(Widget, _componentTypes) != -1) response = response.concat(this.widgets); + if (jQuery.inArray(Aggregator, _componentTypes) != -1) response = response.concat(this.aggregators); + if (jQuery.inArray(Interpreter, _componentTypes) != -1) response = response.concat(this.interpreters); + return response; }, + /** * Returns the instance (widget, aggregator or interpreter) for the specified id. * @@ -6432,78 +6043,6 @@ define('discoverer',[ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggre return null; }, - /** - * 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 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 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; - }, - - /** - * 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; - }, - /** * Returns all components that have the specified attribute as * outAttribute. It can be chosen between the verification of @@ -6527,13 +6066,13 @@ define('discoverer',[ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggre list = _attributeList.getItems(); } if (typeof list != "undefined") { - 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())); + var components = this.getComponents(_componentTypes); + for (var i in components) { + var theComponent = components[i]; + if(_all && this.containsAllAttributes(theComponent, list)) { + componentList.push(theComponent); + } else if(!_all && this.containsAtLeastOneAttribute(theComponent, list)) { + componentList.push(theComponent); } } } @@ -6549,14 +6088,14 @@ define('discoverer',[ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggre * @private * @alias containsAllAttributes * @memberof Discoverer# - * @param {(WidgetDescription|InterpreterDescription)} _description description of a component + * @param {(WidgetDescription|InterpreterDescription)} _component description of a component * @param {Array} _list searched attributes * @returns {boolean} */ - 'private containsAllAttributes' : function(_description,_list) { + 'private containsAllAttributes' : function(_component, _list) { for ( var j in _list) { var attribute = _list[j]; - if (!_description.doesSatisfyAttributeType(attribute)) { + if (!_component.doesSatisfyAttributeType(attribute)) { return false; } } @@ -6569,58 +6108,19 @@ define('discoverer',[ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggre * @private * @alias containsAtLeastOneAttribute * @memberof Discoverer# - * @param {(WidgetDescription|InterpreterDescription)} _description description of a component + * @param {(WidgetDescription|InterpreterDescription)} _component description of a component * @param {Array} _list searched attributes * @returns {boolean} */ - 'private containsAtLeastOneAttribute' : function(_description, _list) { + 'private containsAtLeastOneAttribute' : function(_component, _list) { for (var j in _list) { var attribute = _list[j]; - if (_description.doesSatisfyAttributeType(attribute)) { + if (_component.doesSatisfyAttributeType(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; @@ -6637,8 +6137,7 @@ define('discoverer',[ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggre 'conditionMethod', 'equals', 'unequals', - 'interpreterDescription', - 'widgetDescription', + 'discoverer', 'interpreter', 'interpreterResult', @@ -6660,8 +6159,6 @@ define('discoverer',[ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggre ConditionMethod, Equals, UnEquals, - InterpreterDescription, - WidgetDescription, Discoverer, Interpreter, InterpreterResult, @@ -6690,14 +6187,12 @@ define('discoverer',[ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggre contactJS.ConditionMethod = ConditionMethod; contactJS.Equals = Equals; contactJS.UnEquals = UnEquals; - contactJS.InterpreterDescription = InterpreterDescription; - contactJS.WidgetDescription = WidgetDescription; contactJS.Discoverer = Discoverer; contactJS.Interpreter = Interpreter; contactJS.InterpreterResult = InterpreterResult; contactJS.Callback = Callback; contactJS.CallbackList = CallbackList; - contactJS.Subscriber =Subscriber; + contactJS.Subscriber = Subscriber; contactJS.SubscriberList = SubscriberList; contactJS.Widget = Widget; contactJS.AbstractList = AbstractList; diff --git a/examples/GeoLocationWidget.js b/examples/GeoLocationWidget.js index c8fd8515b90f41e55f693c2374419bb30dd3c37f..f48054c8cb165f69d9965bb9744927ad41f9db67 100644 --- a/examples/GeoLocationWidget.js +++ b/examples/GeoLocationWidget.js @@ -7,7 +7,7 @@ define(['easejs', 'contactJS'], function (easejs, contactJS) { var GeoLocationWidget = Class('GeoLocationWidget').extend(contactJS.Widget, { 'public name': 'GeoLocationWidget', - 'protected initAttributes': function () { + 'protected initOutAttributes': function () { var latitude = new contactJS.Attribute() .withName('latitude') .withType('double'); @@ -16,16 +16,16 @@ define(['easejs', 'contactJS'], function (easejs, contactJS) { .withName('longitude') .withType('double'); - this.addAttribute(latitude); - this.addAttribute(longitude); + this.addOutAttribute(latitude); + this.addOutAttribute(longitude); }, - 'protected initConstantAttributes': function () { + 'protected initConstantOutAttributes': function () { }, 'protected initCallbacks': function () { - this.addCallback(new contactJS.Callback().withName('UPDATE').withAttributeTypes(this.getAttributes())); + this.addCallback(new contactJS.Callback().withName('UPDATE').withAttributeTypes(this.getOutAttributes())); }, 'override protected queryGenerator': function (_function) { @@ -34,8 +34,8 @@ define(['easejs', 'contactJS'], function (easejs, contactJS) { if(navigator.geolocation){ navigator.geolocation.getCurrentPosition(function(_position) { - response.put(self.getAttributes().getItems()[0].setValue(_position.coords.latitude)); - response.put(self.getAttributes().getItems()[1].setValue(_position.coords.longitude)); + response.put(self.getOutAttributes().getItems()[0].setValue(_position.coords.latitude)); + response.put(self.getOutAttributes().getItems()[1].setValue(_position.coords.longitude)); self.sendResponse(response, _function); }, function(error) { diff --git a/js/config.js b/js/config.js index 4599fb450ae076969efd60982b304894c6c3af5d..18903f7c908904667db8ba10590249aaf39b0c5a 100644 --- a/js/config.js +++ b/js/config.js @@ -20,9 +20,7 @@ requirejs.config({ conditionList: 'modules/subscriber/condition/conditionList', conditionMethod: 'modules/subscriber/condition/conditionMethod', equals: 'modules/subscriber/condition/equals', - unequals: 'modules/subscriber/condition/unequals', - interpreterDescription: 'modules/descriptions/interpreterDescription', - widgetDescription: 'modules/descriptions/widgetDescription', + unequals: 'modules/subscriber/condition/unequals', discoverer: 'modules/discoverer/discoverer', translation: 'modules/discoverer/translation', interpreter: 'modules/interpreter/interpreter', diff --git a/js/modules/aggregator/aggregator.js b/js/modules/aggregator/aggregator.js index 5bc1abde455704b8e12d02f451fbee9b49f2128a..afd3ca8d6f7d6aad12d59d77e87f28d54b46436e 100644 --- a/js/modules/aggregator/aggregator.js +++ b/js/modules/aggregator/aggregator.js @@ -7,10 +7,10 @@ */ define(['easejs', 'MathUuid','widget', 'attribute', 'attributeList', 'subscriber', - 'subscriberList', 'callbackList', 'storage', 'widgetDescription', 'interpreter', 'interpretation'], + 'subscriberList', 'callbackList', 'storage', 'interpreter', 'interpretation'], function(easejs, MathUuid, Widget, Attribute, AttributeList, Subscriber, SubscriberList, - CallbackList, Storage, WidgetDescription, Interpreter, Interpretation){ + CallbackList, Storage, Interpreter, Interpretation){ var Class = easejs.Class; var Aggregator = Class('Aggregator'). @@ -160,14 +160,14 @@ define(['easejs', 'MathUuid','widget', * @alias initAttributes * @memberof Aggregator# */ - 'protected initAttributes' : function(){ + 'protected initOutAttributes' : function(){ if(this.widgets.length > 0){ var widgetIdList = this.widgets; for(var i in widgetIdList){ var widgetId = widgetIdList[i]; var widgetInstance = this.discoverer.getComponent(widgetId); if (widgetInstance) { - this.setAttributes(widgetInstance.queryAttributes()); + this.setOutAttributes(widgetInstance.queryAttributes()); } } } @@ -180,7 +180,7 @@ define(['easejs', 'MathUuid','widget', * @alias initConstantAttributes * @memberof Aggregator# */ - 'protected initConstantAttributes' : function(){ + 'protected initConstantOutAttributes' : function(){ if(this.widgets.length > 0){ var widgetIdList = this.widgets; for(var i in widgetIdList){ @@ -252,7 +252,7 @@ define(['easejs', 'MathUuid','widget', 'virtual protected setAggregatorAttributeValues' : function(_attributes) { for (var index in _attributes) { var theAttribute = _attributes[index]; - this.addAttribute(theAttribute); + this.addOutAttribute(theAttribute); } }, @@ -293,7 +293,7 @@ define(['easejs', 'MathUuid','widget', * @returns {AttributeList} */ 'public getCurrentData' : function(){ - return this.attributes; + return this.outAttributes; }, /** @@ -345,11 +345,11 @@ define(['easejs', 'MathUuid','widget', * @public * @alias addWidgetSubscription * @memberof Aggregator# - * @param {String|Widget|WidgetDescription} _widgetIdOrWidget Widget that should be subscribed. + * @param {String|Widget} _widgetIdOrWidget Widget that should be subscribed. * @param {CallbackList} _callbackList required Callbacks */ 'public addWidgetSubscription' : function(_widgetIdOrWidget, _callbackList){ - if (Class.isA(Widget, _widgetIdOrWidget) || Class.isA(WidgetDescription, _widgetIdOrWidget)) { + if (Class.isA(Widget, _widgetIdOrWidget)) { if (Class.isA(Widget, _widgetIdOrWidget) && (!_callbackList || !Class.isA(CallbackList, _callbackList))) { _callbackList = _widgetIdOrWidget.getCallbackList(); } @@ -366,7 +366,7 @@ define(['easejs', 'MathUuid','widget', var typeList = singleCallback.getAttributeTypes().getItems(); for(var y in typeList){ var singleType = typeList[y]; - this.addAttribute(singleType); + this.addOutAttribute(singleType); } } this.addWidget(_widgetIdOrWidget); @@ -412,8 +412,8 @@ define(['easejs', 'MathUuid','widget', } for(var i in list){ var x = list[i]; - if(Class.isA(Attribute, x ) && this.isAttribute(x)){ - this.addAttribute(x); + if(Class.isA(Attribute, x ) && this.isOutAttribute(x)){ + this.addOutAttribute(x); if(this.db){ this.store(x); } @@ -568,18 +568,19 @@ define(['easejs', 'MathUuid','widget', /** * - * @private + * @override + * @public * @alias doesSatisfyAttributeType * @param _attribute * @returns {boolean} */ - 'private doesSatisfyAttributeType': function(_attribute) { + 'override public doesSatisfyAttributeType': function(_attribute) { var componentUUIDs = this.getComponentUUIDs(); var doesSatisfy = false; for (var index in componentUUIDs) { var theComponent = this.discoverer.getComponent(componentUUIDs[index]); - if (theComponent.getDescription().doesSatisfyAttributeType(_attribute)) { + if (theComponent.doesSatisfyAttributeType(_attribute)) { doesSatisfy = true; } } @@ -611,7 +612,7 @@ define(['easejs', 'MathUuid','widget', // if the component was added before, ignore it if (!this.hasComponent(theComponent.getId())) { - var outAttributes = theComponent.getDescription().getOutAttributeTypes().getItems(); + var outAttributes = theComponent.getOutAttributes().getItems(); // if component is a widget and it wasn't added before, subscribe to its callbacks if (Class.isA(Widget, theComponent)) { @@ -622,7 +623,7 @@ define(['easejs', 'MathUuid','widget', for (var widgetOutAttributeIndex in outAttributes) { var widgetOutAttribute = outAttributes[widgetOutAttributeIndex]; // add the attribute type to the aggregators list of handled attribute types - if (!this.getAttributes().containsTypeOf(widgetOutAttribute)) this.addAttribute(widgetOutAttribute); + if (!this.getOutAttributes().containsTypeOf(widgetOutAttribute)) this.addOutAttribute(widgetOutAttribute); console.log("I can now satisfy attribute "+widgetOutAttribute+" with the help of "+theComponent.getName()+"! That was easy :)"); _unsatisfiedAttributes.removeAttributeWithTypeOf(widgetOutAttribute); } @@ -663,7 +664,7 @@ define(['easejs', 'MathUuid','widget', for (var unsatisfiedAttributeIndex in _unsatisfiedAttributes.getItems()) { var theUnsatisfiedAttribute = _unsatisfiedAttributes.getItems()[unsatisfiedAttributeIndex]; if (theUnsatisfiedAttribute.equalsTypeOf(interpreterOutAttribute)) { - this.addAttribute(theUnsatisfiedAttribute); + this.addOutAttribute(theUnsatisfiedAttribute); console.log("I can now satisfy attribute "+theUnsatisfiedAttribute+" with the help of "+theComponent.getName()+"! Great!"); this.interpretations.push(new Interpretation(theComponent.getId(), theComponent.getInAttributes(), new AttributeList().withItems([theUnsatisfiedAttribute]))); } @@ -672,8 +673,8 @@ define(['easejs', 'MathUuid','widget', } } else { console.log("Found interpreter but can't satisfy required attributes."); - for (var j in theComponent.getDescription().getInAttributeTypes().getItems()) { - console.log("Missing "+theComponent.getDescription().getInAttributeTypes().getItems()[j]+"."); + for (var j in theComponent.getInAttributes().getItems()) { + console.log("Missing "+theComponent.getInAttributes().getItems()[j]+"."); } } } @@ -692,7 +693,7 @@ define(['easejs', 'MathUuid','widget', * @memberof Aggregator# */ 'virtual public didFinishSetup': function() { - unsatisfiedAttributes = this.getAttributes().clone(); + unsatisfiedAttributes = this.getOutAttributes().clone(); // get all widgets that satisfy attribute types this.getComponentsForUnsatisfiedAttributeTypes(unsatisfiedAttributes, false, [Widget]); @@ -700,7 +701,7 @@ define(['easejs', 'MathUuid','widget', this.getComponentsForUnsatisfiedAttributeTypes(unsatisfiedAttributes, false, [Interpreter]); console.log("Unsatisfied attributes: "+unsatisfiedAttributes.size()); - console.log("Satisfied attributes: "+this.getAttributes().size()); + console.log("Satisfied attributes: "+this.getOutAttributes().size()); console.log("Interpretations "+this.interpretations.length); }, @@ -724,14 +725,14 @@ define(['easejs', 'MathUuid','widget', completedQueriesCounter++; if (completedQueriesCounter == self.widgets.length) { if (_callback && typeof(_callback) == 'function') { - _callback(self.getAttributes()); + _callback(self.getOutAttributes()); } } }); } } else { if (_callback && typeof(_callback) == 'function') { - _callback(self.getAttributes()); + _callback(self.getOutAttributes()); } } }, @@ -752,14 +753,14 @@ define(['easejs', 'MathUuid','widget', for (var index in this.interpretations) { var theInterpretation = this.interpretations[index]; var theInterpreterId = theInterpretation.interpreterId; - var interpretationInAttributeValues = this.getAttributes(theInterpretation.inAttributeTypes); - var interpretationOutAttributeValues = this.getAttributes(theInterpretation.outAttributeTypes); + var interpretationInAttributeValues = this.getOutAttributes(theInterpretation.inAttributeTypes); + var interpretationOutAttributeValues = this.getOutAttributes(theInterpretation.outAttributeTypes); self.interpretData(theInterpreterId, interpretationInAttributeValues, interpretationOutAttributeValues, function(_interpretedData) { for (var j in _interpretedData.getItems()) { var theInterpretedData = _interpretedData.getItems()[j]; - self.addAttribute(theInterpretedData); + self.addOutAttribute(theInterpretedData); if (self.db){ self.store(theInterpretedData); } @@ -768,14 +769,14 @@ define(['easejs', 'MathUuid','widget', completedQueriesCounter++; if (completedQueriesCounter == self.interpretations.length) { if (_callback && typeof(_callback) == 'function') { - _callback(self.getAttributes()); + _callback(self.getOutAttributes()); } } }); } } else { if (_callback && typeof(_callback) == 'function') { - _callback(self.getAttributes()); + _callback(self.getOutAttributes()); } } }, diff --git a/js/modules/descriptions/interpreterDescription.js b/js/modules/descriptions/interpreterDescription.js deleted file mode 100644 index 1e5b45a9a5d9cb65a5f607caab1e7d68b9a36e09..0000000000000000000000000000000000000000 --- a/js/modules/descriptions/interpreterDescription.js +++ /dev/null @@ -1,106 +0,0 @@ -/** - * This module represents the InterpreterDescription. - * It describes the most important information for the communication with a specific interpreter. - * - * @module InterpreterDescription - * @fileOverview - */ -define(['easejs','attributeList', 'widgetDescription'], - function(easejs,AttributeList, WidgetDescription){ - var Class = easejs.Class; - var InterpreterDescription = Class('InterpreterDescription'). - extend(WidgetDescription, { - /** - * @alias inAttributeTypes - * @private - * @type {AttributeTypeList} - * @memberof InterpreterDescription# - * @desc List of all Attributes that are expected for interpretation. - */ - 'private inAttributeTypes' : [], - - /** - * Constructor: Calls the constructor of the WidgetDescription - * and initializes the inAttributeTypes. - * - * @class InterpreterDescription - * @classdesc The description of an interpreter and the communication with it. - * @extends WidgetDescription - * @requires easejs - * @requires AttributeList - * @requires WidgetDescription - * @constructs InterpreterDescription - */ - 'override public __construct' : function(){ - this.__super(); - this.inAttributeTypes = new AttributeList(); - }, - - /** - * Builder for inAttributeType list - * - * @public - * @alias withInAttributeTypes - * @memberof InterpreterDescription# - * @param {(AttributeList|Array)} _inAttributeTypes List of AttributeType that are expected - * @returns {InterpreterDescription} - */ - 'public withInAttributeTypes' : function(_inAttributeTypes){ - this.setInAttributeTypes(_inAttributeTypes); - return this; - }, - - /** - * Builder for inAttributeType - * - * @public - * @alias withInAttributeType - * @memberof InterpreterDescription# - * @param {AttributeType} _inAttributeType AttributeType that are expected - * @returns {InterpreterDescription} - */ - 'public withInAttributeType' : function(_inAttributeType){ - this.setInAttributeType(_inAttributeType); - return this; - }, - - /** - * Returns inAttributeTypes of the interpreter - * - * @public - * @alias getInAttributeTypes - * @memberof InterpreterDescription# - * @returns {AttributeTypeList} - */ - 'public getInAttributeTypes' : function(){ - return this.inAttributeTypes; - }, - - /** - * Adds an inAttributeType to the list - * - * @public - * @alias setInAttributeType - * @memberof InterpreterDescription# - * @param {AttributeType} _inAttributeType AttributeType that are expected - */ - 'public setInAttributeType' : function(_inAttributeType){ - this.inAttributeTypes.put(_inAttributeType); - }, - - /** - * Adds inAttributeTypes that are expected - * - * @public - * @alias setInAttributeTypes - * @memberof InterpreterDescription# - * @param {(AttributeTypeList|Array)} _inAttributeTypes List of AttributeType that are expected - */ - 'public setInAttributeTypes' : function(_inAttributeTypes){ - this.inAttributeTypes.putAll(_inAttributeTypes); - } - - }); - - return InterpreterDescription; -}); \ No newline at end of file diff --git a/js/modules/descriptions/widgetDescription.js b/js/modules/descriptions/widgetDescription.js deleted file mode 100644 index 6bd148c23addb07432e6a3aebd48c6097b981832..0000000000000000000000000000000000000000 --- a/js/modules/descriptions/widgetDescription.js +++ /dev/null @@ -1,229 +0,0 @@ -/** - * This module represents the WidgetDescription. - * It describes the most important information for the communication with a specific widget. - * - * @module WidgetDescription - * @fileOverview - */ -define(['easejs', 'attributeList'], - function(easejs, AttributeList){ - var Class = easejs.Class; - var WidgetDescription = Class('WidgetDescription',{ - - /** - * @alias id - * @protected - * @type {string} - * @memberof WidgetDescription# - * @desc Id of the Widget that are described by this object. - */ - 'protected id' : '', - /** - * @alias name - * @protected - * @type {string} - * @memberof WidgetDescription# - * @desc Name of the Widget that are described by this object. - */ - 'protected name' : '', - /** - * @alias outAttributeTypes - * @protected - * @type {AttributeTypeList} - * @memberof WidgetDescription# - * @desc List of attributeTypes that are provided. - */ - 'protected outAttributeTypes' : [], - /** - * @alias callbackNames - * @protected - * @type {array} - * @memberof WidgetDescription# - * @desc Array of available callback names. - */ - 'protected callbackNames' : [], - - /** - * Constructor: Initializes the inAttributeTypes. - * - * @virtual - * @class WidgetDescription - * @classdesc The description of a Widget and the communication with it. - * @requires easejs - * @requires AttributeTypeList - * @constructs WidgetDescription - */ - 'virtual public __construct' : function(){ - this.outAttributeTypes = new AttributeList(); - }, - - /** - * Builder for name - * - * @public - * @alias withName - * @memberof WidgetDescription# - * @param {string} _name Name of the Widget that are described by this object. - * @returns {WidgetDescription} - */ - 'public withName' : function(_name){ - this.setName(_name); - return this; - }, - - /** - * Builder for id - * - * @public - * @alias withId - * @memberof WidgetDescription# - * @param {string} _id Id of the Widget that are described by this object. - * @returns {WidgetDescription} - */ - 'public withId' : function(_id){ - this.setId(_id); - return this; - }, - - /** - * Builder for outAttributeType list - * - * @public - * @alias withOutAttributeTypes - * @memberof WidgetDescription# - * @param {(AttributeTypeList|Array)} _outAttributeTypes List of AttributeType that are provided - * @returns {WidgetDescription} - */ - 'public withOutAttributeTypes' : function(_outAttributeTypes){ - this.setOutAttributeTypes(_outAttributeTypes); - return this; - }, - - /** - * Builder for outAttributeType - * - * @public - * @alias withInAttributeType - * @memberof WidgetDescription# - * @param {AttributeType} _outAttributeType AttributeType that are provided - * @returns {WidgetDescription} - */ - 'public withOutAttributeType' : function(_outAttributeType){ - this.setOutAttributeType(_outAttributeType); - return this; - }, - - /** - * Returns the name of the described widget. - * - * @public - * @alias getName - * @memberof WidgetDescription# - * @returns {String} - */ - 'public getName' : function(){ - return this.name; - }, - - /** - * Returns the id of the described widget. - * - * @public - * @alias getId - * @memberof WidgetDescription# - * @returns {String} - */ - 'public getId' : function(){ - return this.id; - }, - - /** - * Returns outAttributeTypes of the widget. - * - * @public - * @alias getOutAttributeTypes - * @memberof WidgetDescription# - * @returns {AttributeTypeList} - */ - 'public getOutAttributeTypes' : function(){ - return this.outAttributeTypes; - }, - - /** - * Sets the name of the described widget. - * - * @public - * @alias setName - * @memberof WidgetDescription# - * @params {String} _name Name of the described widget - */ - 'public setName' : function(_name){ - if(typeof _name === 'string'){ - this.name = _name; - } - }, - - /** - * Sets the id of the described widget. - * - * @public - * @alias setId - * @memberof WidgetDescription# - * @params {String} _id Id of the described widget - */ - 'public setId' : function(_id){ - if(typeof _id === 'string') { - this.id = _id; - } - }, - - /** - * Adds an outAttributeType to the list - * - * @public - * @alias addOutAttributeType - * @memberof WidgetDescription# - * @param {AttributeType} _outAttributeType AttributeType that are provided - */ - 'public addOutAttributeType' : function(_outAttributeType){ - this.outAttributeTypes.put(_outAttributeType); - }, - - /** - * Adds outAttributeTypes that are provided by the Widget - * - * @public - * @alias addOutAttributeTypes - * @memberof WidgetDescription# - * @param {(AttributeList|Array)} _outAttributeTypes List of AttributeType that are provided - */ - 'public addOutAttributeTypes' : function(_outAttributeTypes){ - this.outAttributeTypes.putAll(_outAttributeTypes); - }, - - 'public setCallbackNames' : function(_callbackNames) { - this.callbackNames = _callbackNames; - }, - - 'public addCallbackName' : function(_callbackName) { - this.callbackNames.push(_callbackName); - }, - - /** - * Returns true if the widget can satisfy the requested attribute type. - * - * @public - * @alias doesSatisfyAttributeType - * @memberof WidgetDescription# - * @param {AttributeType} _attribute - * @returns {boolean} - */ - - 'public doesSatisfyAttributeType': function(_attribute) { - return this.getOutAttributeTypes().containsTypeOf(_attribute); - } - }); - - return WidgetDescription; - -}); \ No newline at end of file diff --git a/js/modules/discoverer/discoverer.js b/js/modules/discoverer/discoverer.js index 5c2c511e6bdceff2a700c8d0e9fafbaab73a648d..5c4fc71904738ab2dc254ed397b237dc32aef315 100644 --- a/js/modules/discoverer/discoverer.js +++ b/js/modules/discoverer/discoverer.js @@ -17,7 +17,7 @@ define([ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggregator' ], fun * @memberof Discoverer# * @desc List of available Widgets. */ - 'private widgets' : {}, + 'private widgets' : [], /** * @alias aggregators @@ -26,16 +26,16 @@ define([ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggregator' ], fun * @memberof Discoverer# * @desc List of available Aggregators. */ - 'private aggregators' : {}, + 'private aggregators' : [], /** - * @alias interpreter + * @alias interpreters * @private * @type {Object} * @memberof Discoverer# * @desc List of available Interpreter. */ - 'private interpreter' : {}, + 'private interpreters' : [], /** * @alias translations @@ -44,7 +44,7 @@ define([ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggregator' ], fun * @memberof Discoverer# * @desc List of available attributeType translations (or synonyms). */ - 'private translations' : {}, + 'private translations' : [], /** * Constructor: All known components given in the associated functions will be registered as startup. @@ -57,7 +57,6 @@ define([ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggregator' ], fun */ 'public __construct' : function(_translations) { this.translations = _translations; - this.register(); }, /** @@ -73,53 +72,6 @@ define([ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggregator' ], fun 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. * @@ -129,10 +81,9 @@ define([ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggregator' ], fun * @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); - } + if (_component.getType() == "Widget" && this.getWidget(_component.getId()) == null) this.widgets.push(_component); + if (_component.getType() == "Interpreter" && this.getInterpreter(_component.getId()) == null) this.interpreters.push(_component); + if (_component.getType() == "Aggregator" && this.getAggregator(_component.getId()) == null) this.aggregators.push(_component); }, /** @@ -144,10 +95,17 @@ define([ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggregator' ], fun * @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); + for (var wi in this.widgets) { + var theWidget = this.widgets[wi]; + if (_id == theWidget.getId()) this.widgets.splice(wi, 1); + } + for (var ii in this.interpreters) { + var theInterpreter = this.interpreters[ii]; + if (_id == theInterpreter.getId()) this.interpreters.splice(ii, 1); + } + for (var ai in this.aggregators) { + var theAggregator= this.aggregators[ai]; + if (_id == theAggregator.getId()) this.aggregators.splice(ai, 1); } }, @@ -161,12 +119,11 @@ define([ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggregator' ], fun * @returns {?Widget} */ 'public getWidget' : function(_id) { - var widget = this.widgets[_id]; - if(!widget){ - delete(this.widgets[_id]); - return null; + for (var index in this.widgets) { + var theWidget = this.widgets[index]; + if (theWidget.getId() == _id) return theWidget; } - return widget; + return null; }, /** @@ -179,12 +136,11 @@ define([ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggregator' ], fun * @returns {Aggregator} */ 'public getAggregator' : function(_id) { - var aggregator = this.aggregators[_id]; - if(!aggregator ){ - delete(this.aggregators[_id]); - return null; + for (var index in this.aggregators) { + var theAggregator = this.aggregators[index]; + if (theAggregator.getId() == _id) return theAggregator; } - return aggregator; + return null; }, /** @@ -197,14 +153,32 @@ define([ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggregator' ], fun * @returns {Interpreter} */ 'public getInterpreter' : function(_id) { - var interpret = this.interpreter[_id]; - if(!interpret){ - delete(this.interpreter[_id]); - return null; + for (var index in this.interpreters) { + var theInterpreter = this.interpreters[index]; + if (theInterpreter.getId() == _id) return theInterpreter; } - return interpret; + return null; }, + /** + * Returns all registered components (widget, aggregator and interpreter). + * + * @public + * @alias getComponents + * @memberof Discoverer# + * @param {Array} _componentTypes Component types to get descriptions for. Defaults to Widget, Interpreter and Aggregator. + * @returns {Array} + */ + 'public getComponents' : function(_componentTypes) { + if (typeof _componentTypes == "undefined") _componentTypes = [Widget, Interpreter, Aggregator]; + var response = []; + if (jQuery.inArray(Widget, _componentTypes) != -1) response = response.concat(this.widgets); + if (jQuery.inArray(Aggregator, _componentTypes) != -1) response = response.concat(this.aggregators); + if (jQuery.inArray(Interpreter, _componentTypes) != -1) response = response.concat(this.interpreters); + return response; + }, + + /** * Returns the instance (widget, aggregator or interpreter) for the specified id. * @@ -230,78 +204,6 @@ define([ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggregator' ], fun return null; }, - /** - * 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 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 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; - }, - - /** - * 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; - }, - /** * Returns all components that have the specified attribute as * outAttribute. It can be chosen between the verification of @@ -325,13 +227,13 @@ define([ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggregator' ], fun list = _attributeList.getItems(); } if (typeof list != "undefined") { - 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())); + var components = this.getComponents(_componentTypes); + for (var i in components) { + var theComponent = components[i]; + if(_all && this.containsAllAttributes(theComponent, list)) { + componentList.push(theComponent); + } else if(!_all && this.containsAtLeastOneAttribute(theComponent, list)) { + componentList.push(theComponent); } } } @@ -359,14 +261,14 @@ define([ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggregator' ], fun * @private * @alias containsAllAttributes * @memberof Discoverer# - * @param {(WidgetDescription|InterpreterDescription)} _description description of a component + * @param {(WidgetDescription|InterpreterDescription)} _component description of a component * @param {Array} _list searched attributes * @returns {boolean} */ - 'private containsAllAttributes' : function(_description,_list) { + 'private containsAllAttributes' : function(_component, _list) { for ( var j in _list) { var attribute = _list[j]; - if (!_description.doesSatisfyAttributeType(attribute)) { + if (!_component.doesSatisfyAttributeType(attribute)) { return false; } } @@ -379,58 +281,19 @@ define([ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggregator' ], fun * @private * @alias containsAtLeastOneAttribute * @memberof Discoverer# - * @param {(WidgetDescription|InterpreterDescription)} _description description of a component + * @param {(WidgetDescription|InterpreterDescription)} _component description of a component * @param {Array} _list searched attributes * @returns {boolean} */ - 'private containsAtLeastOneAttribute' : function(_description, _list) { + 'private containsAtLeastOneAttribute' : function(_component, _list) { for (var j in _list) { var attribute = _list[j]; - if (_description.doesSatisfyAttributeType(attribute)) { + if (_component.doesSatisfyAttributeType(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; diff --git a/js/modules/interpreter/interpreter.js b/js/modules/interpreter/interpreter.js index e3aabf602a5db2331001223273f3eaef3adafd63..ec008930baec1ddd68dc1970fb9b5d872886ad16 100644 --- a/js/modules/interpreter/interpreter.js +++ b/js/modules/interpreter/interpreter.js @@ -4,10 +4,8 @@ * @module Interpreter * @fileOverview */ -define([ 'easejs', 'MathUuid', 'attribute', 'attributeList', - 'interpreterDescription', 'interpreterResult' ], - function(easejs, MathUuid, Attribute, AttributeList, - InterpreterDescription, InterpreterResult) { +define([ 'easejs', 'MathUuid', 'attribute', 'attributeList', 'interpreterResult' ], + function(easejs, MathUuid, Attribute, AttributeList, InterpreterResult) { var Class = easejs.Class; var AbstractClass = easejs.AbstractClass; var Interpreter = AbstractClass('Interpreter', @@ -410,6 +408,10 @@ define([ 'easejs', 'MathUuid', 'attribute', 'attributeList', 'public getOutAttributesWithInputParameters': function() { return this.outAttributes.getAttributesWithInputParameters(); + }, + + 'public doesSatisfyAttributeType': function(_attribute) { + return this.outAttributes.containsTypeOf(_attribute); } }); diff --git a/js/modules/widget/widget.js b/js/modules/widget/widget.js index cab418964be6fbddd8e51d86edd459fff8291117..61bec3bc98053693ac5e4b7896ded747f53b278c 100644 --- a/js/modules/widget/widget.js +++ b/js/modules/widget/widget.js @@ -5,11 +5,9 @@ * @fileOverview */ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', - 'attributeList', 'conditionList', - 'subscriber', 'subscriberList', 'widgetDescription'], + 'attributeList', 'conditionList', 'subscriber', 'subscriberList'], function(easejs, MathUuid, Callback, CallbackList, Attribute, - AttributeList, ConditionList, - Subscriber, SubscriberList, WidgetDescription) { + AttributeList, ConditionList, Subscriber, SubscriberList) { var AbstractClass = easejs.AbstractClass; var Class = easejs.Class; @@ -38,7 +36,7 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * @memberof Widget# * @desc All available Attributes and their values. */ - 'protected attributes' : [], + 'protected outAttributes' : [], /** * @alias oldAttributes * @protected @@ -47,7 +45,7 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * @desc This temporary variable is used for storing the old attribute values. * So these can be used to check conditions. */ - 'protected oldAttributes' : [], + 'protected oldOutAttributes' : [], /** * @alias constantAttributes * @protected @@ -55,7 +53,7 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * @memberof Widget# * @desc All available constant Attributes and their values. */ - 'protected constantAttributes' : [], + 'protected constantOutAttributes' : [], /** * @alias callbacks * @protected @@ -99,7 +97,6 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * @requires ConditionList * @requires Subscriber * @requires SubscriberList - * @requires WidgetDescription * @requires Discoverer * @constructs Widget */ @@ -107,8 +104,8 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', this.id = Math.uuid(); this.discoverer = _discoverer; this.register(); - this.attributes = new AttributeList(); - this.constantAttributes = new AttributeList(); + this.outAttributes = new AttributeList(); + this.constantOutAttributes = new AttributeList(); this.subscribers = new SubscriberList(); this.callbacks = new CallbackList(); this.init(_attributeTypes); @@ -160,11 +157,11 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * @memberof Widget# * @returns {AttributeList} */ - 'public getAttributes' : function(_attributeList) { + 'public getOutAttributes' : function(_attributeList) { if (Class.isA(AttributeList, _attributeList)) { - return this.attributes.getSubset(_attributeList); + return this.outAttributes.getSubset(_attributeList); } else { - return this.attributes; + return this.outAttributes; } }, @@ -177,11 +174,11 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * @memberof Widget# * @returns {AttributeList} */ - 'public getConstantAttributes' : function(_attributeList) { + 'public getConstantOutAttributes' : function(_attributeList) { if (Class.isA(AttributeList, _attributeList)) { - return this.constantAttributes.getSubset(_attributeList); + return this.constantOutAttributes.getSubset(_attributeList); } else { - return this.constantAttributes; + return this.constantOutAttributes; } }, @@ -192,7 +189,7 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * @returns {*} */ 'public getValueForAttributeWithTypeOf': function(_attributeType) { - return this.getAttributes().getAttributeWithTypeOf(_attributeType).getValue(); + return this.getOutAttributes().getAttributeWithTypeOf(_attributeType).getValue(); }, /** @@ -204,7 +201,7 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * @returns {AttributeList} */ 'public getOldAttributes' : function() { - return this.oldAttributes; + return this.oldOutAttributes; }, /** @@ -286,12 +283,10 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * @protected * @alias setAttributes * @memberof Widget# - * @param {(AttributeValueList|Array)} - * _attributes List or Array of - * AttributeValues + * @param {(AttributeList|Array)} _attributes List or Array of AttributeValues */ - 'protected setAttributes' : function(_attributes) { - var list = new Array(); + 'protected setOutAttributes' : function(_attributes) { + var list = []; if (_attributes instanceof Array) { list = _attributes.reduce(function(o, v, i) { o[i] = v; @@ -300,12 +295,12 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', } else if (Class.isA(AttributeValueList,_attributes)) { list = _attributes.getItems(); } - this.oldAttributes = this.attributes; + this.oldOutAttributes = this.outAttributes; for ( var i in list) { var attribute = list[i]; if (Class.isA(AttributeValue, attribute)) { attribute.setTimestamp(this.getCurrentTime()); - this.attributes.put(attribute); + this.outAttributes.put(attribute); var type = new AttributeType().withName(attribute.getName()) .withType(attribute.getType()) @@ -322,17 +317,17 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * updated. * * @public - * @alias addAttribute + * @alias addOutAttribute * @memberof Widget# * @param {Attribute} _attribute AttributeValue */ - 'public addAttribute' : function(_attribute, _multipleInstances) { + 'public addOutAttribute' : function(_attribute, _multipleInstances) { _multipleInstances = typeof _multipleInstances == "undefined" ? false : _multipleInstances; if (Class.isA(Attribute, _attribute)) { - if (!this.attributes.containsTypeOf(_attribute)) { - this.oldAttributes = this.attributes; + if (!this.outAttributes.containsTypeOf(_attribute)) { + this.oldOutAttributes = this.outAttributes; _attribute.setTimestamp(this.getCurrentTime()); - this.attributes.put(_attribute, _multipleInstances); + this.outAttributes.put(_attribute, _multipleInstances); } } }, @@ -342,14 +337,12 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * associated AttributeTypes. * * @protected - * @alias setConstantAttributes + * @alias setConstantOutAttributes * @memberof Widget# - * @param {(AttributeValueList|Array)} - * _constantAttributes List or Array of - * AttributeValues + * @param {(AttributeList|Array)} _constantAttributes List or Array of AttributeValues */ - 'protected setConstantAttributes' : function(_constantAttributes) { - var list = new Array(); + 'protected setConstantOutAttributes' : function(_constantAttributes) { + var list = []; if (_constantAttributes instanceof Array) { list = _constantAttributes; } else if (Class.isA(AttributeValueList,_constantAttributes)) { @@ -375,12 +368,11 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * updated. * * @protected - * @alias addConstantAttribute + * @alias addConstantOutAttribute * @memberof Widget# - * @param {AttributeValue} - * _constantAttribute AttributeValue + * @param {AttributeValue} _constantAttribute AttributeValue */ - 'protected addConstantAttribute' : function(_constantAttribute) { + 'protected addConstantOutAttribute' : function(_constantAttribute) { if (Class.isA(AttributeValue, _constantAttribute)) { if (!this.constantAttributes .contains(_constantAttribute)) { @@ -480,7 +472,7 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * @public * @alias removeSubscriber * @memberof Widget# - * @param {Subscriber} _subscriber Subscriber + * @param {Subscriber} _subscriberId Subscriber */ 'public removeSubscriber' : function(_subscriberId) { this.subscribers.removeSubscriberWithId(_subscriberId); @@ -503,14 +495,13 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * provided Attribute. * * @protected - * @alias isAttribute + * @alias isOutAttribute * @memberof Widget# - * @param {AttributeValue} - * _attribute + * @param {Attribute} _attribute * @returns {boolean} */ - 'protected isAttribute' : function(_attribute) { - return !!this.attributes.containsTypeOf(_attribute); + 'protected isOutAttribute' : function(_attribute) { + return !!this.outAttributes.containsTypeOf(_attribute); }, /** @@ -522,7 +513,7 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * @alias initAttributes * @memberof Widget# */ - 'abstract protected initAttributes' : [], + 'abstract protected initOutAttributes' : [], /** * Initializes the provided ConstantAttributes. @@ -533,7 +524,7 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * @alias initConstantAttributes * @memberof Widget# */ - 'abstract protected initConstantAttributes' : [], + 'abstract protected initConstantOutAttributes' : [], /** * Initializes the provided Callbacks. @@ -555,8 +546,8 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * @memberof Widget# */ 'protected init' : function(_attributeTypes) { - this.initAttributes(); - this.initConstantAttributes(); + this.initOutAttributes(); + this.initConstantOutAttributes(); this.initCallbacks(); this.didFinishInitialization(_attributeTypes); @@ -628,7 +619,7 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * @public * @alias putData * @memberof Widget# - * @param {(AttributeValueList|Array)} _data Data that should be entered. + * @param {(AttributeList|Array)} _data Data that should be entered. * */ 'virtual public putData' : function(_data) { @@ -640,8 +631,8 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', } for ( var i in list) { var x = list[i]; - if (Class.isA(Attribute, x) && this.isAttribute(x)) { - this.addAttribute(x); + if (Class.isA(Attribute, x) && this.isOutAttribute(x)) { + this.addOutAttribute(x); } } @@ -658,8 +649,8 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', */ 'public queryWidget' : function() { var response = new AttributeList(); - response.putAll(this.getAttributes()); - response.putAll(this.getConstantAttributes()); + response.putAll(this.getOutAttributes()); + response.putAll(this.getConstantOutAttributes()); return response; }, @@ -678,10 +669,7 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', this.queryGenerator(_function); } else { this.queryGenerator(); - var response = new AttributeList(); - response.putAll(this.getAttributes()); - response.putAll(this.getConstantAttributes()); - return response; + return this.queryWidget(); } }, @@ -691,19 +679,19 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * @protected * @alias sendToSubscriber * @memberof Widget# - * @param {string} _callbackName Name of the searched Callback. + * @param {string} _callback Name of the searched Callback. */ 'protected sendToSubscriber' : function(_callback) { if (_callback && Class.isA(Callback, _callback)) { var subscriberList = this.subscribers.getItems(); - for ( var i in subscriberList) { + for (var i in subscriberList) { var subscriber = subscriberList[i]; if (subscriber.getSubscriptionCallbacks().contains(_callback)) { if(this.dataValid(subscriber.getConditions())){ var subscriberInstance = this.discoverer.getComponent(subscriber.getSubscriberId()); var callSubset = _callback.getAttributeTypes(); var subscriberSubset = subscriber.getAttributesSubset(); - var data = this.attributes.getSubset(callSubset); + var data = this.outAttributes.getSubset(callSubset); if (subscriberSubset && subscriberSubset.size() > 0) { data = data.getSubset(subscriberSubset); } @@ -731,7 +719,7 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', } if (!_conditions.isEmpty()) { var items = _condition.getItems(); - for ( var i in items) { + for (var i in items) { var condition = items[i]; var conditionAttributeType = condition.getAttributeType(); var conditionAttributeTypeList = new AttributeTypeList() @@ -744,25 +732,6 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', return false; }, - /** - * Returns the description of this component. - * @virtual - * @public - * @alias getDescription - * @memberof Widget# - * @returns {WidgetDescription} - */ - 'virtual public getDescription' : function() { - var description = new WidgetDescription().withId(this.id).withName(this.name); - description.addOutAttributeTypes(this.attributes); - description.addOutAttributeTypes(this.constantAttributes); - var widgetCallbacks = this.callbacks.getItems(); - for(var i in widgetCallbacks) { - description.addCallbackName(widgetCallbacks[i].getName()); - } - return description; - }, - /** * Runs the context acquisition constantly in an interval. * Can be called by init. @@ -805,23 +774,20 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', 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; -// } -// }, + }, + /** + * Returns true if the widget can satisfy the requested attribute type. + * + * @public + * @alias doesSatisfyAttributeType + * @memberof Widget# + * @param {AttributeType} _attribute + * @returns {boolean} + */ + 'virtual public doesSatisfyAttributeType': function(_attribute) { + return this.outAttributes.containsTypeOf(_attribute); + } }); return Widget; diff --git a/qunitTest/aggregatorTest.js b/qunitTest/aggregatorTest.js index ce072d6ca72e047bacf50a55ab11e23befc80064..a77874bb80155c510b970813e1324dd6da2aa356 100644 --- a/qunitTest/aggregatorTest.js +++ b/qunitTest/aggregatorTest.js @@ -23,21 +23,21 @@ require(['configTest'], function() { assert.equal(widgetIds.length, 0,"Passed!: no subscribed Widgets" ); //subscription - var widgetDescriptions = discoverer.getDescriptions([contactJS.Widget]); + var widgets = discoverer.getComponents([contactJS.Widget]); var list = new contactJS.AttributeList().withItems([latitudeType, longitudeType]); var callList = new contactJS.CallbackList().withItems([new contactJS.Callback().withName('UPDATE').withAttributeTypes(list)]); - testAggregator.addWidgetSubscription(widgetDescriptions[0], callList); + testAggregator.addWidgetSubscription(widgets[0], callList); widgetIds = testAggregator.getWidgets(); assert.equal( widgetIds.length, 1,"subscribe Passed!: one subscribed Widget" ); - geoLocationWidget = discoverer.getComponent(widgetDescriptions[0].getId()); + geoLocationWidget = discoverer.getComponent(widgets[0].getId()); subscriber = geoLocationWidget.getSubscriber(); assert.equal(subscriber.size(), 1,"subscribe Passed!: one subscribed Widget in geolocationWidget too"); - var values = testAggregator.getAttributes(); + var values = testAggregator.getOutAttributes(); assert.equal( values.size(), 2, "Passed!: two available attributes" ); var latitude = values.getAttributeWithTypeOf(latitudeType); assert.equal(latitude.getName(), 'latitude',"subscribed Attributes Passed!: latitude exists" ); diff --git a/qunitTest/discovererTest.js b/qunitTest/discovererTest.js index dcbd9984a1d3de9c5c481449e0bca2e15302ddb1..0d729188303008c95677826a1479011f3948663b 100644 --- a/qunitTest/discovererTest.js +++ b/qunitTest/discovererTest.js @@ -12,20 +12,20 @@ require(['configTest'], function() { //initWidgets ->geoLocationWidget expected //tested with getWidgetDescriptions - 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" ); + var widgets = discoverer.getComponents([contactJS.Widget]); + assert.equal( widgets.length, 1,"getWidgetDescriptions passed!: One Widget is registered" ); + assert.equal( widgets[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 registered" ); - assert.equal( wDescs2[0].getName(), 'GeoLocationWidget',"getDescriptions passed!: Name of the registered Widget is the expected one" ); + var components = discoverer.getComponents(); + assert.equal( components.length, 1,"getDescriptions passed!: One Widget is registered" ); + assert.equal( components[0].getName(), 'GeoLocationWidget',"getDescriptions passed!: Name of the registered Widget is the expected one" ); //getWidgets - var widget = discoverer.getWidget(wDescs[0].getId()); + var widget = widgets[0]; assert.ok( widget,"getWidget passed!: an instance was returned" ); assert.equal( widget.getType(), "Widget","getWidget passed!: type ot the instance is Widget" ); assert.equal( widget.getName(), 'GeoLocationWidget',"getWidget passed!: name of the instance is te expected one" ); //same procedure with getComponent - var widget2 = discoverer.getComponent(wDescs[0].getId()); + var widget2 = components[0]; assert.ok( widget2,"getComponent passed!: an instance was returned" ); assert.equal( widget2.getType(), "Widget","getComponent passed!: type ot the instance is Widget" ); assert.equal( widget2.getName(), 'GeoLocationWidget',"getComponent passed!: name of the instance is te expected one" ); @@ -34,19 +34,19 @@ require(['configTest'], function() { new AddressInterpreter(discoverer); //tested with getWidgetDescriptions - 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" ); + var interpreters = discoverer.getComponents([contactJS.Interpreter]); + assert.equal( interpreters.length, 1,"getInterpreterDescriptions passed!: One Interpreter is registered" ); + assert.equal( interpreters[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 registered" ); + components = discoverer.getComponents(); + assert.equal( components.length, 2,"getDescriptions passed!: three instances are registered" ); //getWidgets - var interpreter = discoverer.getInterpreter(iDescs[0].getId()); + var interpreter = interpreters[0]; assert.ok( interpreter,"getInterpreter passed!: an instance was returned" ); assert.equal( interpreter.getType(), "Interpreter","getInterpreter passed!: type of the instance is Interpreter" ); assert.equal( interpreter.getName(), 'AddressInterpreter',"getInterpreter passed!: name of the instance is te expected one" ); //same procedure with getComponent - var interpreter2 = discoverer.getComponent(iDescs[0].getId()); + var interpreter2 = components[1]; assert.ok( interpreter2,"getComponent passed!: an instance was returned" ); assert.equal( interpreter2.getType(), "Interpreter","getComponent passed!: type ot the instance is Interpreter" ); assert.equal( interpreter2.getName(), 'AddressInterpreter',"getComponent passed!: name of the instance is te expected one" ); @@ -55,25 +55,25 @@ require(['configTest'], function() { new contactJS.Aggregator(discoverer, [ new contactJS.Attribute().withName('formattedAddress').withType('string') ]); + //tested with getWidgetDescriptions - var aDescs = discoverer.getDescriptions([contactJS.Aggregator]); - assert.equal( aDescs.length, 1,"getAggregatorDescriptions passed!: One Aggregator is registered" ); - assert.equal( aDescs[0].getName(), 'Aggregator',"getAggregatorDescriptions passed!: Name of the registered Interpreter is the expected one" ); + var aggregators = discoverer.getComponents([contactJS.Aggregator]); + assert.equal( aggregators.length, 1,"getAggregatorDescriptions passed!: One Aggregator is registered" ); + assert.equal( aggregators[0].getName(), 'Aggregator',"getAggregatorDescriptions passed!: Name of the registered Aggregator is the expected one" ); //same procedure with getDescriptions - var aDescs2 = discoverer.getDescriptions(); - assert.equal( aDescs2.length,3,"getDescriptions passed!: four instances are registered" ); + components = discoverer.getComponents(); + assert.equal( components.length, 3, "getDescriptions passed!: three instances are registered" ); //getWidgets - var aggregator = discoverer.getAggregator(aDescs[0].getId()); + var aggregator = aggregators[0]; assert.ok( aggregator,"getAggregator passed!: an instance was returned" ); assert.equal( aggregator.getType(), "Aggregator","getAggregator passed!: type of the instance is Aggregator" ); assert.equal( aggregator.getName(), 'Aggregator',"getAggregator passed!: name of the instance is the expected one" ); //same procedure with getComponent - var aggregator2 = discoverer.getComponent(aDescs[0].getId()); + var aggregator2 = components[1]; assert.ok( aggregator2,"getComponent passed!: an instance was returned" ); assert.equal( aggregator2.getType(), "Aggregator","getComponent passed!: type ot the instance is Aggregator" ); assert.equal( aggregator2.getName(), 'Aggregator',"getComponent passed!: name of the instance is the expected one" ); - - + //getComponentByAttribute var testParameter = new contactJS.Parameter().withKey('foo').withValue('bar'); var latitudeType = new contactJS.Attribute().withName('latitude').withType('double').withParameter(testParameter); @@ -108,8 +108,5 @@ require(['configTest'], function() { var list6 = discoverer.getComponentsByAttributes(array, true); assert.equal( list6.length, 0," getComponentsByAttributes passed!: returned 0 components which provided all attribute (two attributes were specified)" ); }); - - - }); }); \ No newline at end of file diff --git a/qunitTest/interpret_AggregatorInterpreterTest.js b/qunitTest/interpret_AggregatorInterpreterTest.js index 6c96a4d2835f2ec83b2fb5e74c238c93c0207cc7..0c9a13ebf1bc17da051a114ad0c9d3298961d316 100644 --- a/qunitTest/interpret_AggregatorInterpreterTest.js +++ b/qunitTest/interpret_AggregatorInterpreterTest.js @@ -15,7 +15,7 @@ require(['configTest'], function() { formattedAddressType ]); - var interpreter = discoverer.getDescriptions([contactJS.Interpreter]); + var interpreters = discoverer.getComponents([contactJS.Interpreter]); //put data into aggregator var latitudeValue = new contactJS.Attribute().withName('latitude').withType('double').withValue(52.3992404); @@ -33,7 +33,7 @@ require(['configTest'], function() { //call Interpreter var callFunktion = function(interpret){ - testAggregator.addAttribute(interpret.getAttributeWithTypeOf(formattedAddressType)); + testAggregator.addOutAttribute(interpret.getAttributeWithTypeOf(formattedAddressType)); var data2 = testAggregator.getCurrentData(); assert.equal( data2.size(), 3,"Passed!: three available attributes" ); var item = data2.getAttributeWithTypeOf(formattedAddressType); @@ -42,7 +42,7 @@ require(['configTest'], function() { assert.equal(item.getValue(), add ,"Passed!: interpreted data equals expected value" ); }; - testAggregator.interpretData(interpreter[0].getId(), typeList, new contactJS.AttributeList().withItems([formattedAddressType]), function (result) {callFunktion(result); QUnit.start();}); + testAggregator.interpretData(interpreters[0].getId(), typeList, new contactJS.AttributeList().withItems([formattedAddressType]), function (result) {callFunktion(result); QUnit.start();}); }); diff --git a/qunitTest/interpreterTest.js b/qunitTest/interpreterTest.js index ad95cfeb35b31028145f3dcf4239e7eae6560a02..f11c91aee8dd15503b27f4d427254e90ee3a8535 100644 --- a/qunitTest/interpreterTest.js +++ b/qunitTest/interpreterTest.js @@ -27,15 +27,6 @@ require(['configTest'], function() { assert.ok( outTypes.size() == 1,"Passed!: 1 defined outType in addressInterpreter" ); assert.ok( outTypes.getAttributeWithTypeOf(formattedAddress),"Passed!: formattedAddress exists" ); assert.ok( outTypes.getAttributeWithTypeOf(formattedAddress).equalsTypeOf(formattedAddress),"Passed!: formattedAddress equals expected type" ); - - //interpreterDescription - 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" ); - assert.equal ( desc.getInAttributeTypes().size(), 2, "Passed!: InterpreterDescription contains 2 inAttributes" ); - assert.equal ( desc.getOutAttributeTypes().size(), 1, "Passed!: InterpreterDescription contains 1 outAttributes" ); - //callInterpreter && getInterpretedData with callback var latitudeValue = new contactJS.Attribute().withName('latitude').withType('double').withValue(52.3992404); diff --git a/qunitTest/widgetTest.js b/qunitTest/widgetTest.js index b042e5895d4650b4b658ab02c0ea2b661814700d..257a6d2216674fc8c713bb59f92941b9b408c5be 100644 --- a/qunitTest/widgetTest.js +++ b/qunitTest/widgetTest.js @@ -15,9 +15,9 @@ require(['configTest'], function() { assert.equal( testWidget.getName(), 'GeoLocationWidget', "Passed!: name -> GeoLocationWidget" ); //attributeTypes - var types = testWidget.getAttributes(); + var types = testWidget.getOutAttributes(); assert.equal(types.size(), 2,"getWidgetAttributeTypes Passed!: two types were returned" ); - var constantTypes = testWidget.getConstantAttributes(); + var constantTypes = testWidget.getConstantOutAttributes(); assert.equal(constantTypes.size(), 0,"getWidgetConstantAttributeTypes Passed!: zero constantTypes was returned" ); //callbacks @@ -29,7 +29,7 @@ require(['configTest'], function() { assert.equal(subscriber.size(), 0,"getSubscriber Passed!: zero subscriber was returned" ); //attributes - var attributes = testWidget.getAttributes(); + var attributes = testWidget.getOutAttributes(); assert.equal(attributes.size(), 2,"queryAttributes Passed!: two attributes were returned" ); var latitude = attributes.getAttributeWithTypeOf(latitudeType); assert.equal(latitude.getName(), 'latitude',"queryAttributes Passed!: latitude exists" );