From c917e87c7577c74c8948a34fac193d683b682ad5 Mon Sep 17 00:00:00 2001 From: Tobias Moebert <moebert@uni-potsdam.de> Date: Thu, 23 Apr 2015 16:41:44 +0200 Subject: [PATCH] # merged AttributeType and AttributeValue into Attribute # merged AttributeTypeList and AttributeValueList into AttributeList --- build/contactJS.js | 20 +- dist/contactJS.js | 2085 ++++++++--------- examples/GeoLocationWidget.js | 225 +- examples/addressInterpreter.js | 185 +- js/config.js | 6 +- js/modules/abstractList.js | 15 - js/modules/aggregator/aggregator.js | 54 +- js/modules/aggregator/interpretation.js | 8 +- js/modules/aggregator/storage/storage.js | 60 +- js/modules/attribute/attribute.js | 386 +++ js/modules/attribute/attributeList.js | 324 +++ js/modules/attribute/attributeType.js | 251 -- js/modules/attribute/attributeTypeList.js | 181 -- js/modules/attribute/attributeValue.js | 179 -- js/modules/attribute/attributeValueList.js | 240 -- js/modules/attribute/parameterList.js | 3 +- .../descriptions/interpreterDescription.js | 10 +- js/modules/descriptions/widgetDescription.js | 6 +- js/modules/discoverer/discoverer.js | 6 +- js/modules/interpreter/interpreter.js | 89 +- js/modules/interpreter/interpreterResult.js | 4 +- js/modules/subscriber/callback.js | 40 +- js/modules/subscriber/callbackList.js | 72 +- js/modules/subscriber/condition/condition.js | 29 +- .../subscriber/condition/conditionList.js | 75 +- js/modules/subscriber/subscriber.js | 18 +- js/modules/subscriber/subscriberList.js | 86 +- js/modules/widget/widget.js | 57 +- qunitTest/aggregatorTest.js | 38 +- qunitTest/attributeTypeListTest.js | 36 +- qunitTest/attributeTypeTest.js | 9 +- qunitTest/attributeValueListTest.js | 16 +- qunitTest/attributeValueTest.js | 18 +- qunitTest/callbackListTest.js | 14 +- qunitTest/callbackTest.js | 12 +- qunitTest/conditionListTest.js | 15 +- qunitTest/conditionTest.js | 14 +- qunitTest/discovererTest.js | 9 +- .../interpret_AggregatorInterpreterTest.js | 29 +- qunitTest/interpreterTest.js | 49 +- qunitTest/notify_AggregatorWidgetTest.js | 10 +- qunitTest/storageTableContentTest.js | 24 +- qunitTest/storageTableTest.js | 19 +- qunitTest/subscriberListTest.js | 31 +- qunitTest/subscriberTest.js | 28 +- qunitTest/widgetTest.js | 25 +- 46 files changed, 2205 insertions(+), 2905 deletions(-) create mode 100644 js/modules/attribute/attribute.js create mode 100644 js/modules/attribute/attributeList.js delete mode 100644 js/modules/attribute/attributeType.js delete mode 100644 js/modules/attribute/attributeTypeList.js delete mode 100644 js/modules/attribute/attributeValue.js delete mode 100644 js/modules/attribute/attributeValueList.js diff --git a/build/contactJS.js b/build/contactJS.js index 81b2d5c..8a0ee33 100644 --- a/build/contactJS.js +++ b/build/contactJS.js @@ -1,10 +1,8 @@ define(['retrievalResult', 'storage', 'aggregator', - 'attributeType', - 'attributeValue', - 'attributeTypeList', - 'attributeValueList', + 'attribute', + 'attributeList', 'parameter', 'parameterList', 'condition', @@ -26,10 +24,8 @@ function(RetrievalResult, Storage, Aggregator, - AttributeType, - AttributeValue, - AttributeTypeList, - AttributeValueList, + Attribute, + AttributeList, Parameter, ParameterList, Condition, @@ -53,15 +49,13 @@ var contactJS = function(obj) { return obj; }; - contactJS.VERSION = '1.1.0'; + contactJS.VERSION = '1.2.0'; // Methods contactJS.RetrievalResult = RetrievalResult; contactJS.Storage = Storage; contactJS.Aggregator = Aggregator; - contactJS.AttributeType = AttributeType; - contactJS.AttributeValue = AttributeValue; - contactJS.AttributeTypeList = AttributeTypeList; - contactJS.AttributeValueList = AttributeValueList; + contactJS.Attribute = Attribute; + contactJS.AttributeList = AttributeList; contactJS.Parameter = Parameter; contactJS.ParameterList = ParameterList; contactJS.Condition = Condition; diff --git a/dist/contactJS.js b/dist/contactJS.js index 8683d1a..c5f48fd 100644 --- a/dist/contactJS.js +++ b/dist/contactJS.js @@ -520,8 +520,6 @@ define('abstractList',[ 'easejs' ], function(easejs) { * @requires easejs */ var AbstractList = AbstractClass('AbstractList', { - - /** * @alias items * @protected @@ -590,19 +588,6 @@ define('abstractList',[ 'easejs' ], function(easejs) { */ 'abstract public equals' : [ 'list' ], - /** - * Verifies whether an item exists for the specified key. - * - * @public - * @alias containsKey - * @memberof AbstractList# - * @param {string} _key Key that should be verified. - * @returns {boolean} - */ - 'public containsKey' : function(_key) { - return !!(typeof _key !== 'undefined' && typeof this.items[_key] !== 'undefined'); - }, - /** * Returns the item for the specified key. * @public @@ -865,8 +850,7 @@ define('parameterList',[ 'easejs', 'abstractList', 'parameter' ], * @requires AbstractList * @requires Parameter */ - var ParameterList = Class('ParameterList').extend(AbstractList,{ - + var ParameterList = Class('ParameterList').extend(AbstractList, { /** * @alias counter * @protected @@ -1010,854 +994,713 @@ define('parameterList',[ 'easejs', 'abstractList', 'parameter' ], /** * This module represents an AttributeType. * AttributeTypes defines name, type (string, double,...) an associated parameter of an attribute. - * + * * @module AttributeType * @fileOverview */ -define('attributeType',['easejs', +define('attribute',['easejs', 'parameterList'], function(easejs, - ParameterList){ - var Class = easejs.Class; - var AttributeType = Class('AttributeType',{ - /** - * @alias name - * @protected - * @type {string} - * @memberof AttributeType# - * @desc Name of the Attribute - */ - 'protected name' : '', - /** - * @alias type - * @protected - * @type {string} - * @memberof AttributeType# - * @desc Defines the type of the Attribute (i.e String, Double,...) - */ - 'protected type' : '', - /** - * @alias parameterList - * @protected - * @type {ParameterList} - * @memberof AttributeType# - * @desc Name of the Attribute - */ - 'protected parameterList' : [], + ParameterList){ - /** - * Constructor: Initializes the ParameterList. - * - * @class AttributeType - * @classdesc AttributeTypes defines name, type (string, double,...) an associated parameter of an attribute. - * @requires easejs - * @requires ParameterList - * @constructs AttributeType - */ - 'public __construct' : function(){ - this.parameterList = new ParameterList(); - }, + /** + * @class Attribute + * @classdesc AttributeValue extends AttributeTypes and adds the associated + * value. + * @requires easejs + * @requires ParameterList + */ + var Class = easejs.Class; + var Attribute = Class('Attribute',{ + /** + * @alias name + * @protected + * @type {string} + * @memberof AttributeType# + * @desc Name of the Attribute + */ + 'protected name' : '', - /** - * Builder for name. - * - * @public - * @alias withName - * @memberof AttributeType# - * @param {String} _name Name - * @returns {AttributeType} - */ - 'public withName' : function(_name){ - this.setName(_name); - return this; - }, + /** + * @alias type + * @protected + * @type {string} + * @memberof AttributeType# + * @desc Defines the type of the Attribute (i.e String, Double,...) + */ + 'protected type' : '', - /** - * Builder for type. - * - * @public - * @alias withType - * @memberof AttributeType# - * @param {String} _type Type - * @returns {AttributeType} - */ - 'public withType' : function(_type){ - this.setType(_type); - return this; - }, - - /** - * Builder for parameterList. - * - * @public - * @alias withParameters - * @memberof AttributeType# - * @param {(ParameterList|Array)} _parameterList ParameterList - * @returns {AttributeType} - */ - 'public withParameters' : function(_parameterList){ - this.setParameters(_parameterList); - return this; - }, - - /** - * Builder for one parameter. - * - * @public - * @alias withParameters - * @memberof AttributeType# - * @param {Parameter} _parameter Parameter - * @returns {AttributeType} - */ - 'public withParameter' : function(_parameter){ - this.addParameter(_parameter); - return this; - }, + /** + * @alias parameterList + * @protected + * @type {ParameterList} + * @memberof AttributeType# + * @desc Name of the Attribute + */ + 'protected parameterList' : [], - /** - * Returns the name. - * - * @public - * @alias getName - * @memberof AttributeType# - * @returns {string} - */ - 'public getName' : function(){ - return this.name; - }, - - /** - * Returns the type. - * - * @public - * @alias getType - * @memberof AttributeType# - * @returns {string} - */ - 'public getType' : function(){ - return this.type; - }, - - /** - * Returns the parameters. - * - * @public - * @alias getParameters - * @memberof AttributeType# - * @returns {ParameterList} - */ - 'public getParameters' : function(){ - return this.parameterList; - }, + /** + * @alias value + * @protected + * @type {string} + * @memberof AttributeValue# + */ + 'protected value' : 'NO_VALUE', - /** - * Sets the name. - * - * @public - * @alias setName - * @memberof AttributeType# - * @param {string} _name Name - */ - 'public setName' : function(_name){ - if(typeof _name === 'string'){ - this.name = _name; - } + /** + * @alias timestamp + * @protected + * @type {Date} + * @memberof AttributeValue# + * @desc Time when the value was set. + */ + 'protected timestamp' : '', + + /** + * Constructor: Initializes the ParameterList. + * + * @class AttributeType + * @classdesc AttributeTypes defines name, type (string, double,...) an associated parameter of an attribute. + * @requires easejs + * @requires ParameterList + * @constructs AttributeType + */ + 'public __construct' : function(){ + this.parameterList = new ParameterList(); }, - /** - * Sets the type. - * - * @public - * @alias setType - * @memberof AttributeType# - * @param {string} _type Type - */ - 'public setType' : function(_type){ - if(typeof _type === 'string'){ - this.type = _type; - } + /** + * Builder for name. + * + * @public + * @alias withName + * @memberof AttributeType# + * @param {String} _name Name + * @returns {AttributeType} + */ + 'public withName' : function(_name){ + this.setName(_name); + return this; }, - - /** - * Adds a parameter. - * - * @public - * @alias addParameter - * @memberof AttributeType# - * @param {Parameter} _parameter Parameter - */ - 'public addParameter' : function(_parameter){ - this.parameterList.put(_parameter); - }, - - /** - * Adds a list of Parameter. - * - * @public - * @alias setParameters - * @memberof AttributeType# - * @param {ParameterList} _parameters ParameterList - */ - 'public setParameters' : function(_parameters){ - this.parameterList.putAll(_parameters); - }, - 'public hasParameters' : function() { - return this.parameterList.size() > 0; + /** + * Builder for type. + * + * @public + * @alias withType + * @memberof AttributeType# + * @param {String} _type Type + * @returns {AttributeType} + */ + 'public withType' : function(_type){ + this.setType(_type); + return this; }, - /** - * Compares this instance with the given one. - * - * @virtual - * @public - * @alias equals - * @memberof AttributeType# - * @param {AttributeType} _attributeType AttributeType that should be compared - * @returns {boolean} - */ - 'virtual public equals' : function(_attributeType) { - if (Class.isA(AttributeType, _attributeType)) { - if (this.getName() == _attributeType.getName() && - this.getType() == _attributeType.getType() && - this.getParameters().equals(_attributeType.getParameters())) - return true; - } - return false; - }, + /** + * Builder for one parameter. + * + * @public + * @alias withParameters + * @memberof AttributeType# + * @param {Parameter} _parameter Parameter + * @returns {AttributeType} + */ + 'public withParameter' : function(_parameter){ + this.addParameter(_parameter); + return this; + }, - 'public hasInputParameter': function() { - return this.hasParameters() && this.parameterList.hasInputParameter(); + /** + * Builder for parameterList. + * + * @public + * @alias withParameters + * @memberof AttributeType# + * @param {(ParameterList|Array)} _parameterList ParameterList + * @returns {AttributeType} + */ + 'public withParameters' : function(_parameterList){ + this.setParameters(_parameterList); + return this; }, - /** - * Returns an identifier that uniquely describes the attribute type and its parameters. - * The identifier can be used to compare two attribute types. <br/> - * Format: (AttributeName:AttributeType)#[FirstParameterName:FirstParameterValue]… - * - * @public - * @alias toString - * @memberof AttributeType# - * @returns {String} - * @example (CI_USER_LOCATION_DISTANCE:FLOAT)#[CP_TARGET_LATITUDE:52][CP_TARGET_LONGITUDE:13][CP_UNIT:KILOMETERS] - */ - 'virtual public toString': function() { - var identifier = "("+this.name+":"+this.type+")"; - if (this.hasParameters()) { - identifier += "#"; - for (var index in this.parameterList.getItems()) { - var theParameter = this.parameterList.getItems()[index]; - identifier += theParameter.toString(); - } - } - return identifier; - } + /** + * Builder for value. + * + * @public + * @alias withValue + * @memberof AttributeValue# + * @param {String} _value value + * @returns {AttributeValue} + */ + 'public withValue' : function(_value) { + this.setValue(_value); + this.setTimestamp(Date.now()); + return this; + }, - }); + /** + * Builder for timestamp. + * + * @public + * @alias withTimestamp + * @memberof AttributeValue# + * @param {Date} _timestamp timestamp + * @returns {AttributeValue} + */ + 'public withTimestamp' : function(_timestamp) { + this.setTimestamp(_timestamp); + return this; + }, - return AttributeType; - -}); -/** - * This module represents an AttributeValue. AttributeValue extends - * AttributeTypes and adds the associated value. - * - * @module AttributeValue - * @fileOverview - */ -define('attributeValue',[ 'easejs', 'attributeType' ], function(easejs, AttributeType) { - var Class = easejs.Class; + /** + * Returns the name. + * + * @public + * @alias getName + * @memberof AttributeType# + * @returns {string} + */ + 'public getName' : function(){ + return this.name; + }, - /** - * @class AttributeValue - * @classdesc AttributeValue extends AttributeTypes and adds the associated - * value. - * @requires easejs - * @requires AttributeType - */ - var AttributeValue = Class('AttributeValue').extend( - AttributeType, - { - /** - * @alias value - * @protected - * @type {string} - * @memberof AttributeValue# - */ - 'protected value' : '', - /** - * @alias timestamp - * @protected - * @type {Date} - * @memberof AttributeValue# - * @desc Time when the value was set. - */ - 'protected timestamp' : '', + /** + * Returns the type. + * + * @public + * @alias getType + * @memberof AttributeType# + * @returns {string} + */ + 'public getType' : function(){ + return this.type; + }, - /** - * Builder for value. - * - * @public - * @alias withValue - * @memberof AttributeValue# - * @param {String} _value value - * @returns {AttributeValue} - */ - 'public withValue' : function(_value) { - this.setValue(_value); - this.setTimestamp(Date.now()); - return this; - }, + /** + * Returns the parameters. + * + * @public + * @alias getParameters + * @memberof AttributeType# + * @returns {ParameterList} + */ + 'public getParameters' : function(){ + return this.parameterList; + }, - /** - * Builder for timestamp. - * - * @public - * @alias withTimestamp - * @memberof AttributeValue# - * @param {Date} _timestamp timestamp - * @returns {AttributeValue} - */ - 'public withTimestamp' : function(_timestamp) { - this.setTimestamp(_timestamp); - return this; - }, + /** + * Sets the name. + * + * @public + * @alias setName + * @memberof AttributeType# + * @param {string} _name Name + */ + 'public setName' : function(_name){ + if(typeof _name === 'string'){ + this.name = _name; + } + }, - /** - * Sets the value. - * - * @public - * @alias setValue - * @memberof AttributeValue# - * @param {string} _value value - */ - 'public setValue' : function(_value) { - this.value = _value; - }, + /** + * Sets the type. + * + * @public + * @alias setType + * @memberof AttributeType# + * @param {string} _type Type + */ + 'public setType' : function(_type){ + if(typeof _type === 'string'){ + this.type = _type; + } + }, - /** - * Returns the value. - * - * @public - * @alias getValue - * @memberof AttributeValue# - * @returns {string} - */ - 'public getValue' : function() { - return this.value; - }, - - /** - * Sets the timestamp. - * - * @public - * @alias setTimestamp - * @memberof AttributeValue# - * @param {Date} _timestamp timestamp - */ - 'public setTimestamp' : function(_time) { - this.timestamp = _time; - }, + /** + * Adds a parameter. + * + * @public + * @alias addParameter + * @memberof AttributeType# + * @param {Parameter} _parameter Parameter + */ + 'public addParameter' : function(_parameter){ + this.parameterList.put(_parameter); + }, - /** - * Returns the timestamp. - * - * @public - * @alias getTimestamp - * @memberof AttributeValue# - * @returns {string} - */ - 'public getTimestamp' : function() { - return this.timestamp; - }, + /** + * Adds a list of Parameter. + * + * @public + * @alias setParameters + * @memberof AttributeType# + * @param {ParameterList} _parameters ParameterList + */ + 'public setParameters' : function(_parameters){ + this.parameterList.putAll(_parameters); + }, - /** - * Compares this instance with the given one. - * - * @public - * @alias equals - * @memberof AttributeValue# - * @param {AttributeValue} _attributeValue AttributeValue that should be compared - * @returns {boolean} - */ - 'override public equals' : function(_attributeValue) { - if (Class.isA(AttributeValue, _attributeValue)) { - if (_attributeValue.getAttributeType().equals(this.getAttributeType()) && - _attributeValue.getValue() == this.getValue()) { - return true; - } - } - return false; - }, + /** + * Returns true if the attribute is parameterized. + * + * @public + * @alias hasParameters + * @memberof Attribute# + * @returns {boolean} + */ + 'public hasParameters' : function() { + return this.parameterList.size() > 0; + }, - /** - * Returns the AttributeType of an AttributeValue. - * - * @public - * @alias getAttributeType - * @memberof AttributeValue# - * @returns {AttributeType} - */ - 'public getAttributeType' : function() { - return new AttributeType().withName(this.name) - .withType(this.type).withParameters( - this.parameterList); - }, + /** + * Sets the value. + * + * @public + * @alias setValue + * @memberof AttributeValue# + * @param {string} _value value + */ + 'public setValue' : function(_value) { + this.value = _value; + }, - /** - * Builds a new AttributeValue from the given type. - * - * @public - * @alias buildFromAttributeType - * @memberof AttributeValue# - * @param {AttributeType} _attributeType AttributeType for build process. - * @returns {AttributeValue} - */ - 'public buildFromAttributeType' : function(_attributeType) { - if (Class.isA(AttributeType, _attributeType)) { - return new AttributeValue().withName(_attributeType.getName()) - .withType(_attributeType.getType()).withParameters(_attributeType.getParameters()).withValue('NO_VALUE'); - } - return null; - }, + /** + * Returns the value. + * + * @public + * @alias getValue + * @memberof AttributeValue# + * @returns {string} + */ + 'public getValue' : function() { + return this.value; + }, - /** - * Returns a string that describes the attribute type and its value. - * - * @public - * @override - * @alias toString - * @memberof AttributeValue# - * @returns {string} - */ - 'override public toString': function() { - return this.__super().toString()+":"+this.getValue(); - } - }); + /** + * Sets the timestamp. + * + * @public + * @alias setTimestamp + * @memberof AttributeValue# + * @param {Date} _timestamp timestamp + */ + 'public setTimestamp' : function(_time) { + this.timestamp = _time; + }, - return AttributeValue; -}); -/** - * This module represents an AttributeTypeList. It is a subclass of AbstractList. - * - * @module AttributeTypeList - * @fileOverview - */ -define('attributeTypeList',[ 'easejs', 'abstractList', 'attributeType', 'parameterList' ], - function(easejs, AbstractList, AttributeType, ParameterList) { - var Class = easejs.Class; - /** - * @class AttributeTypeList - * @classdesc This class represents a list for AttributeType. - * @extends AbstractList - * @requires easejs - * @requires AbstractList - * @requires AttributeType - */ - var AttributeTypeList = Class('AttributeTypeList').extend(AbstractList, { + /** + * Returns the timestamp. + * + * @public + * @alias getTimestamp + * @memberof AttributeValue# + * @returns {string} + */ + 'public getTimestamp' : function() { + return this.timestamp; + }, - /** - * @alias items - * @protected - * @type {AttributeTypeList} - * @memberof AttributeTypeList# - * @desc ItemList - */ - 'protected items' : [], + /** + * + * @public + * @alias hasInputParameter + * @memberof Attribute# + * @returns {boolean} + */ + 'public hasInputParameter': function() { + return this.hasParameters() && this.parameterList.hasInputParameter(); + }, - /** - * Builder for item list. - * - * @public - * @alias withItems - * @memberof AttributeTypeList# - * @param {(AttributeTypeList)} _attributeTypeList AttributeTypeList - * @returns {AttributeTypeList} - */ - 'public withItems' : function(_attributeTypeList) { - var list = []; - if (_attributeTypeList instanceof Array) { - list = _attributeTypeList; - } else if (Class.isA(AttributeTypeList, _attributeTypeList)) { - list = _attributeTypeList.getItems(); - } - this.items = list; - return this; - }, + /** + * Compares this instance with the given one. + * + * @public + * @alias equalsTypeOf + * @memberof Attribute# + * @param {Attribute} _attribute Attribute that should be compared. + * @returns {boolean} + */ + 'public equalsTypeOf' : function(_attribute) { + if (Class.isA(Attribute, _attribute)) { + if (this.getName() == _attribute.getName() && this.getType() == _attribute.getType() && this.getParameters().equals(_attribute.getParameters())) { + return true; + } + } + return false; + }, - /** - * Adds the specified item to the itemList. - * - * @public - * @alias put - * @memberof AttributeTypeList# - * @param {AttributeType} _attributeType AttributeType - */ - 'public put' : function(_attributeType, _multipleInstances) { - var _multipleInstances = typeof _multipleInstances == "undefined" ? false : _multipleInstances; - if (Class.isA(AttributeType, _attributeType)) { - if (_multipleInstances || !(this.contains(_attributeType))) { - this.items.push(_attributeType); - } - } - }, + /** + * + * + * @public + * @alias equalsValueOf + * @memberof Attribute# + * @param _attribute + * @returns {boolean} + */ + 'public equalsValueOf' : function(_attribute) { + if (Class.isA(Attribute, _attribute)) { + if (this.equalsTypeOf(_attribute) && this.getValue() == _attribute.getValue()) { + return true; + } + } + return false; + }, - /** - * Adds all items in the specified list to the - * itemList. - * - * @public - * @alias putAll - * @memberof AttributeTypeList# - * @param {(AttributeTypeList|Array)} _attributeTypeList AttributeTypeList - */ - 'public putAll' : function(_attributeTypeList) { - var list = []; - if (_attributeTypeList instanceof Array) { - list = _attributeTypeList; - } else if (Class.isA(AttributeTypeList, _attributeTypeList)) { - list = _attributeTypeList.getItems(); - } - for ( var i in list) { - this.put(list[i]); - } - }, + /** + * Returns an identifier that uniquely describes the attribute type and its parameters. + * The identifier can be used to compare two attribute types. <br/> + * Format: (AttributeName:AttributeType)#[FirstParameterName:FirstParameterValue]… + * + * @public + * @alias toString + * @memberof AttributeType# + * @returns {String} + * @example (CI_USER_LOCATION_DISTANCE:FLOAT)#[CP_TARGET_LATITUDE:52][CP_TARGET_LONGITUDE:13][CP_UNIT:KILOMETERS] + */ + 'public toString': function(_typeOnly) { + var identifier = "("+this.name+":"+this.type+")"; + if (this.hasParameters()) { + identifier += "#"; + for (var index in this.parameterList.getItems()) { + var theParameter = this.parameterList.getItems()[index]; + identifier += theParameter.toString(); + } + } + if (!_typeOnly) identifier += ":"+this.getValue(); + return identifier; + } + }); - /** - * Verifies whether the given item is included - * in this list. - * - * @public - * @alias contains - * @memberof AttributeTypeList# - * @param {AttributeType} _item AttributeType that should be verified. - * @returns {boolean} - */ - 'public contains' : function(_item) { - if (Class.isA(AttributeType, _item)) { - for (var index in this.items) { - var tmp = this.items[index]; - if (tmp.equals(_item)) { - return true; - } - } - } - return false; - }, + return Attribute; + }); +/** + * This module represents an AttributeList. It is a subclass of AbstractList. + * + * @module AttributeList + * @fileOverview + */ +define('attributeList',['easejs', 'abstractList', 'attribute', 'parameterList' ], + function(easejs, AbstractList, Attribute, ParameterList) { + var Class = easejs.Class; - /** - * Compare the specified AttributeTypeList with this instance. - * - * @public - * @alias equals - * @memberof AttributeTypeList# - * @param {AttributeTypeList} _list AttributeTypeList that should be compared. - * @returns {boolean} - */ - 'public equals' : function(_list) { - if (Class.isA(AttributeTypeList, _list) && _list.size() == this.size()) { - for (var index in _list.getItems()) { - var theAttributeType = _list.getItems()[index]; - if (!this.contains(theAttributeType)) return false; - } - return true; - } - return false; - }, + /** + * @class AttributeList + * @classdesc This class represents a list for Attribute. + * @extends AbstractList + * @requires easejs + * @requires AbstractList + * @requires Attribute + */ + var AttributeList = Class('AttributeList').extend(AbstractList, { + /** + * @alias items + * @protected + * @type {Array.<Attribute>} + * @memberof AttributeList# + * @desc ItemList + */ + 'protected items' : [], - /** - * Creates a clone of the current list. - * - * @public - * @alias clone - * @memberof AttributeTypeList# - * @returns {AttributeTypeList} - */ - 'public clone': function() { - var newList = new AttributeTypeList(); - for (var index in this.items) { - var oldAttributeType = this.items[index]; - var newAttributeType = new AttributeType(). - withName(oldAttributeType.getName()). - withType(oldAttributeType.getType()). - withParameters(oldAttributeType.getParameters()); - newList.put(newAttributeType); + /** + * Builder for item list. + * + * @public + * @alias withItems + * @memberof AttributeList# + * @param {(AttributeList)} _attributeList AttributeList + * @returns {AttributeList} + */ + 'public withItems' : function(_attributeList) { + var list = []; + if (_attributeList instanceof Array) { + list = _attributeList; + } else if (Class.isA(AttributeList, _attributeList)) { + list = _attributeList.getItems(); } - return newList; + this.items = list; + return this; }, - 'public removeAttributeType': function(_attributeType, _allOccurrences) { - _allOccurrences = typeof _allOccurrences == "undefined" ? false : _allOccurrences; - for (var index in this.items) { - var theAttributeType = this.items[index]; - if (theAttributeType.equals(_attributeType)) { - this.items.splice(index, 1); - } - } - if (_allOccurrences && this.contains(_attributeType)) this.removeAttributeType(_attributeType, _allOccurrences); - }, + /** + * Adds the specified item to the itemList. + * + * @public + * @alias put + * @memberof AttributeList# + * @param {AttributeType} _attribute AttributeType + * @param {boolean} _multipleInstances + */ + 'public put' : function(_attribute, _multipleInstances) { + _multipleInstances = typeof _multipleInstances == "undefined" ? false : _multipleInstances; + if (Class.isA(Attribute, _attribute)) { + if (_multipleInstances || !(this.containsTypeOf(_attribute))) { + this.items.push(_attribute); + } else { + this.updateValue(_attribute); + } + } + }, - 'public hasAttributesWithInputParameters': function() { - for (var index in this.items) { - var theAttributeType = this.items[index]; - if (theAttributeType.hasInputParameter()) return true; - } - return false; - }, + /** + * Adds all items in the specified list to the + * itemList. + * + * @public + * @alias putAll + * @memberof AttributeList# + * @param {(AttributeList|Array)} _attributeList AttributeList + */ + 'public putAll' : function(_attributeList) { + var list = []; + if (_attributeList instanceof Array) { + list = _attributeList; + } else if (Class.isA(AttributeList, _attributeList)) { + list = _attributeList.getItems(); + } + for ( var i in list) { + this.put(list[i]); + } + }, - 'public getAttributesWithInputParameters': function() { - var list = new AttributeTypeList(); - for (var index in this.items) { - var theAttributeType = this.items[index]; - if (theAttributeType.hasInputParameter()) list.put(theAttributeType); - } - return list; - } - }); + /** + * + * @param {Attribute} _attribute + * @param {?boolean} _typeOnly + * @returns {*} + */ + 'public contains': function(_attribute, _typeOnly) { + _typeOnly = typeof _typeOnly == "undefined" ? false : _typeOnly; + return _typeOnly ? this.containsTypeOf(_attribute) : this.containsValueOf(_attribute); + }, - return AttributeTypeList; - }); -/** - * This module represents a AttributeValueList. It is a subclass of - * AbstractList. - * - * @module AttributeValueList - * @fileOverview - */ -define('attributeValueList',['easejs', 'abstractList', 'attributeValue', 'attributeType', 'attributeTypeList', 'parameterList'], - function(easejs, AbstractList, AttributeValue, AttributeType, AttributeTypeList, ParameterList) { - var Class = easejs.Class; + /** + * Verifies whether the given item is included + * in this list. + * + * @public + * @alias containsTypeOf + * @memberof AttributeList# + * @param {AttributeType} _attribute AttributeType that should be verified. + * @returns {boolean} + */ + 'public containsTypeOf' : function(_attribute) { + if (Class.isA(Attribute, _attribute)) { + for (var index in this.items) { + var tmp = this.items[index]; + if (tmp.equalsTypeOf(_attribute)) { + return true; + } + } + } + return false; + }, - /** - * @class AttributeValueList - * @classdesc This class represents a list for AttributeValue. - * @extends AbstractList - * @requires easejs - * @requires AbstractList - * @requires AttributeValue - * @requires AttributeType - * @requires AttributeTypeList) - */ - var AttributeValueList = Class('AttributeValueList').extend(AbstractList,{ + /** + * Verifies whether the given item is included + * in the list. + * + * @public + * @alias containsValueOf + * @memberof AttributeList# + * @param {Attribute} _attribute AttributeValue that should be verified. + * @returns {boolean} + */ + 'public containsValueOf' : function(_attribute) { + if (Class.isA(Attribute, _attribute)) { + for (var index in this.items) { + var tmp = this.items[index]; + if (tmp.equalsValueOf(_attribute)) { + return true; + } + } + } + return false; + }, - /** - * @alias items - * @protected - * @type {AttributeValueList} - * @memberof AttributeValueList# - * @desc ItemList. - */ - 'protected items' : [], + 'public equals': function(_attributeList, _typeOnly) { + _typeOnly = typeof _typeOnly == "undefined" ? false : _typeOnly; + return _typeOnly ? this.equalsAllTypesOf(_attributeList) : this.equalsAllValuesOf(_attributeList); + }, - /** - * Builder for item list. - * - * @public - * @alias withItems - * @memberof AttributeValueList# - * @param {(AttributeValueListst|Array)} _attributeValueList AttributeValueList - * @returns {AttributeValueList} - */ - 'public withItems' : function(_attributeValueList) { - var list = []; - if (_attributeValueList instanceof Array) { - list = _attributeValueList; - } else if (Class.isA(AttributeValueList, - _attributeValueList)) { - list = _attributeValueList.getItems(); - } - this.items = list; - return this; - }, + /** + * Compare the specified AttributeList with this instance. + * + * @public + * @alias equals + * @memberof AttributeList# + * @param {AttributeList} _attributeList AttributeList that should be compared. + * @returns {boolean} + */ + 'public equalsAllTypesOf' : function(_attributeList) { + if (Class.isA(AttributeList, _attributeList) && _attributeList.size() == this.size()) { + for (var index in _attributeList.getItems()) { + var theAttributeType = _attributeList.getItems()[index]; + if (!this.containsTypeOf(theAttributeType)) return false; + } + return true; + } + return false; + }, - /** - * Add the specified item to this itemList. - * - * @public - * @alias put - * @memberof AttributeValueList# - * @param {AttributeValue} _attributeValue AttributeValue - */ - 'public put' : function(_attributeValue, _multipleInstances) { - if (Class.isA(AttributeValue, _attributeValue)) { - if (_multipleInstances || !(this.containsAttributeType(_attributeValue.getAttributeType()))) { - this.items.push(_attributeValue); - } else { - this.updateValue(_attributeValue); - } - } - }, + /** + * Compare the specified AttributeList with + * this instance. + * + * @public + * @alias equals + * @memberof AttributeList# + * @param {AttributeList} _attributeList AttributeList that should be compared. + * @returns {boolean} + */ + 'public equalsAllValuesOf' : function(_attributeList) { + if (Class.isA(AttributeList, _attributeList) && _attributeList.size() == this.size()) { + for (var index in _attributeList.getItems()) { + var theAttribute = _attributeList.getItems()[index]; + if (!this.containsValueOf(theAttribute)) return false; + } + return true; + } + return false; + }, - /** - * Adds all items in the specified list to this. - * itemList - * - * @public - * @alias putAll - * @memberof AttributeValueList# - * @param {AttributeValueList} _attributeValueList AttributeValueList - */ - 'public putAll' : function(_attributeValueList) { - var list = []; - if (_attributeValueList instanceof Array) { - list = _attributeValueList; - } else if (Class.isA(AttributeValueList, _attributeValueList)) { - list = _attributeValueList.getItems(); - } - for (var i in list) { - this.put(list[i]); - } - }, + /** + * Returns only this values that matches to the + * given type. + * + * @public + * @alias getSubset + * @memberof AttributeList# + * @param {(AttributeList|Array)} _attributeList Attributes that should be returned. + * @returns {AttributeList} + */ + 'public getSubset' : function(_attributeList) { + var response = new AttributeList(); + var list = []; + if (_attributeList instanceof Array) { + list = _attributeList; + } else if (Class.isA(AttributeList, _attributeList)) { + list = _attributeList.getItems(); + } + for (var i in list) { + var attribute = list[i]; + if (Class.isA(Attribute, attribute)) { + var attribute = this.getAttributeWithTypeOf(attribute); + if (typeof attribute != "undefined") { + response.put(attribute); + } + } + } + return response; + }, - /** - * Verifies whether the given item is included - * in the list. - * - * @public - * @alias contains - * @memberof AttributeValueList# - * @param {AttributeValue} _attributeValue AttributeValue that should be verified. - * @returns {boolean} - */ - 'public contains' : function(_attributeValue) { - if (Class.isA(AttributeValue, _attributeValue)) { - for (var index in this.items) { - var tmp = this.items[index]; - if (tmp.equals(_attributeValue)) { - return true; - } - } - } - return false; - }, + /** + * Returns a subset without the given types. + * + * @public + * @alias getSubsetWithoutItems + * @memberof AttributeList# + * @param {(AttributeList|Array)} _attributeList AttributeTypes that should not be included + * @returns {AttributeList} + */ + 'public getSubsetWithoutItems' : function(_attributeList) { + var response = this; + var list = []; + if (_attributeList instanceof Array) { + list = _attributeList; + } else if (Class.isA(AttributeList, _attributeList)) { + list = _attributeList.getItems(); + } + for (var i in list) { + var attribute = list[i]; + if (Class.isA(Attribute, attribute)) { + response.removeAttributeWithTypeOf(attribute); + } + } + return response; + }, - 'public containsAttributeType': function(_attributeType) { - if (Class.isA(AttributeType, _attributeType)) { - for (var index in this.items) { - var tmp = this.items[index].getAttributeType(); - if (tmp.equals(_attributeType)) { - return true; - } - } - } - return false; - }, + /** + * Creates a clone of the current list. + * + * @public + * @alias clone + * @memberof AttributeList# + * @returns {AttributeList} + */ + 'public clone': function(_typeOnly) { + var newList = new AttributeList(); + for (var index in this.items) { + var oldAttribute = this.items[index]; + var newAttribute = new Attribute().withName(oldAttribute.getName()).withType(oldAttribute.getType()).withParameters(oldAttribute.getParameters()); + if (!_typeOnly) newAttribute.setValue(oldAttribute.getValue()); + newList.put(newAttribute); + } + return newList; + }, - /** - * Compare the specified AttributeValueList with - * this instance. - * - * @public - * @alias equals - * @memberof AttributeValueList# - * @param {AttributeValueList} _list AttributeValueList that should be compared. - * @returns {boolean} - */ - 'public equals' : function(_list) { - if (Class.isA(AttributeValueList, _list) && _list.size() == this.size()) { - for (var index in _list.getItems()) { - var theAttributeValue = _list.getItems()[index]; - if (!this.contains(theAttributeValue)) return false; - } - return true; - } - return false; - }, + 'public removeAttributeWithTypeOf': function(_attribute, _allOccurrences) { + _allOccurrences = typeof _allOccurrences == "undefined" ? false : _allOccurrences; + for (var index in this.items) { + var theAttribute = this.items[index]; + if (theAttribute.equalsTypeOf(_attribute)) { + this.items.splice(index, 1); + } + } + if (_allOccurrences && this.contains(_attribute)) this.removeAttributeWithTypeOf(_attribute, _allOccurrences); + }, - /** - * Returns only this values that matches to the - * given type. - * - * @public - * @alias getSubset - * @memberof AttributeValueList# - * @param {(AttributeTypeList|Array)} _attributeTypeList AttributeTypes that should be returned. - * @returns {AttributeValueList} - */ - 'public getSubset' : function(_attributeTypeList) { - var response = new AttributeValueList(); - var list = []; - if (_attributeTypeList instanceof Array) { - list = _attributeTypeList; - } else if (Class.isA(AttributeTypeList, _attributeTypeList)) { - list = _attributeTypeList.getItems(); - } - for ( var i in list) { - var attributeType = list[i]; - if (Class.isA(AttributeType, attributeType)) { - var attribute = this.getValueObjectForAttributeType(attributeType); - if (typeof attribute != "undefined") { - response.put(attribute); - } - } - } - return response; - }, - - /** - * Returns a subset without the given types. - * - * @public - * @alias getSubsetWithoutItems - * @memberof AttributeValueList# - * @param {(AttributeTypeList|Array)} _attributeTypeList AttributeTypes that should not be included - * @returns {AttributeValueList} - */ - 'public getSubsetWithoutItems' : function(_attributeTypeList) { - var response = this; - var list = []; - if (_attributeTypeList instanceof Array) { - list = _attributeTypeList; - } else if (Class.isA(AttributeTypeList, _attributeTypeList)) { - list = _attributeTypeList.getItems(); - } - for (var i in list) { - var attributeType = list[i]; - if (Class.isA(AttributeType, attributeType)) { - response.removeAttributeValuesWithAttributeType(attributeType); - } - } - return response; - }, + 'public hasAttributesWithInputParameters': function() { + for (var index in this.items) { + var theAttribute = this.items[index]; + if (theAttribute.hasInputParameter()) return true; + } + return false; + }, - /** - * Returns the attribute value that matches the provided attribute type. - * - * @public - * @alias getValueForAttributeType - * @memberof AttributeValueList# - * @param {AttributeType} _attributeType - * @returns {AttributeValue} - */ - 'public getValueForAttributeType': function(_attributeType) { - return this.getValueObjectForAttributeType(_attributeType).getValue(); + 'public getAttributesWithInputParameters': function() { + var list = new AttributeList(); + for (var index in this.items) { + var theAttribute = this.items[index]; + if (theAttribute.hasInputParameter()) list.put(theAttribute); + } + return list; }, - 'public getValueObjectForAttributeType': function(_attributeType) { - for (var index in this.getItems()) { - var theAttributeValue = this.getItems()[index]; - if (theAttributeValue.getAttributeType().equals(_attributeType)) return theAttributeValue; - } - }, + /** + * Returns the attribute value that matches the provided attribute type. + * + * @public + * @alias getValueForAttributeWithTypeOf + * @memberof AttributeList# + * @param {AttributeType} _attribute + * @returns {Attribute} + */ + 'public getValueForAttributeWithTypeOf': function(_attribute) { + return this.getAttributeWithTypeOf(_attribute).getValue(); + }, - 'public removeAttributeValuesWithAttributeType': function(_attributeType) { - for (var index in this.items) { - var theAttributeValue = this.items[index]; - if (theAttributeValue.getAttributeType().equals(_attributeType)) this.items.splice(index, 1); - } - }, + 'public getAttributeWithTypeOf': function(_attribute) { + for (var index in this.getItems()) { + var theAttribute = this.getItems()[index]; + if (theAttribute.equalsTypeOf(_attribute)) return theAttribute; + } + }, - 'public updateValue': function(_attributeValue) { - for (var index in this.items) { - var theAttributeValue = this.items[index]; - if (theAttributeValue.getAttributeType().equals(_attributeValue.getAttributeType())) this.items[index] = _attributeValue; - } - } - }); + 'public updateValue': function(_attribute) { + for (var index in this.items) { + var theAttribute = this.items[index]; + if (theAttribute.equalsTypeOf(_attribute)) this.items[index] = _attribute; + } + } - return AttributeValueList; - }); + }); + + return AttributeList; +}); /** * This module representing a Storage. * The Storage handles the access to the database. @@ -1865,9 +1708,9 @@ define('attributeValueList',['easejs', 'abstractList', 'attributeValue', 'attrib * @module Widget * @fileOverview */ -define('storage',['easejs', 'attributeValue', 'attributeValueList', 'attributeType', +define('storage',['easejs', 'attribute', 'attributeList', 'retrievalResult', 'parameter', 'parameterList'], - function( easejs, AttributeValue, AttributeValueList, AttributeType, + function( easejs, Attribute, AttributeList, RetrievalResult, Parameter, ParameterList){ var Class = easejs.Class; var Storage = Class('Storage', @@ -1892,7 +1735,7 @@ define('storage',['easejs', 'attributeValue', 'attributeValueList', 'attributeTy /** * @alias data * @private - * @type {AttributeValueList} + * @type {AttributeList} * @memberof Storage# * @desc Cache before storing the new data in the database. */ @@ -1948,8 +1791,8 @@ define('storage',['easejs', 'attributeValue', 'attributeValueList', 'attributeTy * @class Storage * @classdesc Storage handles the access to the database. * @requires easejs - * @requires AttributeValue - * @requires AttributeValueList + * @requires Attribute + * @requires AttributeList * @requires Parameter * @requires ParameterList * @requires RetrievalResult @@ -1959,7 +1802,7 @@ define('storage',['easejs', 'attributeValue', 'attributeValueList', 'attributeTy 'public __construct' : function(_name, _time, _counter){ this.initStorage(_name); this.attributes = new RetrievalResult(); - this.data = new AttributeValueList(); + this.data = new AttributeList(); this.dataCount = 0; this.lastFlush = new Date(); if(_time && _time === parseInt(_time) && _time!=0) @@ -2042,18 +1885,18 @@ define('storage',['easejs', 'attributeValue', 'attributeValueList', 'attributeTy * @private * @alias insertIntoTable * @memberof Storage# - * @param {AttributeValue} _attributeValue Attribute that should be stored. + * @param {Attribute} _attribute Attribute that should be stored. * @param {?function} _function For alternative actions, if an asynchronous function is used. */ - 'private insertIntoTable' : function(_attributeValue, _function){ - if(this.db && _attributeValue && Class.isA(AttributeValue, _attributeValue)){ - var tableName = this.tableName(_attributeValue); + 'private insertIntoTable' : function(_attribute, _function){ + if(this.db && _attribute && Class.isA(Attribute, _attribute)){ + var tableName = this.tableName(_attribute); var statement = 'INSERT INTO "' + tableName + '" (value_, type_, created_) VALUES ("' - + _attributeValue.getValue() + '", "' - + _attributeValue.getType() + '", "' - + _attributeValue.getTimestamp() + '")'; - console.log('INSERT INTO "'+tableName+'" VALUES ('+_attributeValue.getValue()+", "+_attributeValue.getType()+", "+_attributeValue.getTimestamp()); + + _attribute.getValue() + '", "' + + _attribute.getType() + '", "' + + _attribute.getTimestamp() + '")'; + console.log('INSERT INTO "'+tableName+'" VALUES ('+_attribute.getValue()+", "+_attribute.getType()+", "+_attribute.getTimestamp()); if(_function && typeof(_function) == 'function'){ this.db.transaction(function(tx){tx.executeSql(statement);}, this.errorCB, _function); } else { @@ -2158,7 +2001,7 @@ define('storage',['easejs', 'attributeValue', 'attributeValueList', 'attributeTy * @returns {boolean} */ 'private tableExists' : function(_attribute){ - if(Class.isA(AttributeValue, _attribute) || Class.isA(AttributeType, _attribute)){ + if(Class.isA(Attribute, _attribute)){ var name = this.tableName(_attribute); return this.attributeNames.indexOf(name) > -1; } else if(typeof _attribute === 'string'){ @@ -2177,11 +2020,16 @@ define('storage',['easejs', 'attributeValue', 'attributeValueList', 'attributeTy * @param {?function} _function For additional actions, if an asynchronous function is used. */ 'public retrieveAttributes' : function(_tableName, _function){ + console.log("retrieveAttributes from "+_tableName); + if(this.db){ var self = this; self.flushStorage(); - this.db.transaction(function(_tx){self.queryValues(_tx,_tableName,self, _function);}, - function(error){self.errorCB(error);} ); + this.db.transaction(function(_tx) { + self.queryValues(_tx,_tableName,self, _function); + }, function(error) { + self.errorCB(error); + }); } }, @@ -2197,9 +2045,10 @@ define('storage',['easejs', 'attributeValue', 'attributeValueList', 'attributeTy * @param {@this} self * @param {?function} _function For additional actions, if an asynchronous function is used. */ - 'private queryValues' : function(_tx,_tableName,self, _function){ - if(self.tableExists(_tableName)){ - var statement = 'SELECT * FROM ' + _tableName; + 'private queryValues' : function(_tx, _tableName, self, _function){ + if(self.tableExists(_tableName)){ + console.log('SELECT * FROM "' +_tableName+"'"); + var statement = 'SELECT * FROM "' + _tableName+'"'; _tx.executeSql(statement, [], function(_tx,results){self.queryValuesSuccess(_tx,results,_tableName, self, _function);}, function(error){self.errorCB(error);}); @@ -2228,7 +2077,7 @@ define('storage',['easejs', 'attributeValue', 'attributeValueList', 'attributeTy var attributeName = this.resolveAttributeName(_tableName); var parameterList = this.resolveParameters(_tableName); for(var i=0; i<len; i++){ - var attribute = new AttributeValue(). + var attribute = new Attribute(). withName(attributeName).withValue(results.rows.item(i).value_). withType(results.rows.item(i).type_). withTimestamp(results.rows.item(i).created_). @@ -2271,11 +2120,11 @@ define('storage',['easejs', 'attributeValue', 'attributeValueList', 'attributeTy * @private * @alias addData * @memberof Storage# - * @param {AttributeValue} _attributeValue Value that should be stored. + * @param {Attribute} _attribute Value that should be stored. */ - 'private addData' : function(_attributeValue){ - if(Class.isA(AttributeValue, _attributeValue)){ - this.data.put(_attributeValue); + 'private addData' : function(_attribute){ + if(Class.isA(Attribute, _attribute)){ + this.data.put(_attribute); this.dataCount++; } }, @@ -2307,7 +2156,7 @@ define('storage',['easejs', 'attributeValue', 'attributeValueList', 'attributeTy * @memberof Storage# */ 'private resetForFlush' : function(){ - this.data = new AttributeValueList(); + this.data = new AttributeList(); this.dataCount = 0; this.lastFlush = new Date(); }, @@ -2395,7 +2244,7 @@ define('storage',['easejs', 'attributeValue', 'attributeValueList', 'attributeTy * @returns{String} */ 'private tableName' : function(_attribute){ - return _attribute.getAttributeType().toString(); + return _attribute.toString(true); }, /** @@ -2443,8 +2292,8 @@ define('storage',['easejs', 'attributeValue', 'attributeValueList', 'attributeTy * @module Callback * @fileOverview */ -define('callback',['easejs', 'attributeType', 'attributeTypeList'], - function(easejs, AttributeType, AttributeTypeList){ +define('callback',['easejs', 'attribute', 'attributeList'], + function(easejs, Attribute, AttributeList){ var Class = easejs.Class; var Callback = Class('Callback', @@ -2481,7 +2330,7 @@ define('callback',['easejs', 'attributeType', 'attributeTypeList'], */ 'public __construct': function() { - this.attributeTypes = new AttributeTypeList(); + this.attributeTypes = new AttributeList(); }, /** @@ -2556,19 +2405,19 @@ define('callback',['easejs', 'attributeType', 'attributeTypeList'], * @public * @alias setAttributeTypes * @memberof Callback# - * @param {AttributeTypeList} _attributeTypes AttributeTypeList + * @param {AttributeList} _attributes AttributeTypeList */ - 'public setAttributeTypes' : function(_attributeTypes){ + 'public setAttributeTypes' : function(_attributes){ var list = []; - if(_attributeTypes instanceof Array){ - list = _attributeTypes; - } else if (Class.isA( AttributeTypeList, _attributeTypes)) { - list = _attributeTypes.getItems(); + if(_attributes instanceof Array){ + list = _attributes; + } else if (Class.isA( AttributeList, _attributes)) { + list = _attributes.getItems(); } for(var i in list){ - var attributeType = list[i]; - if(Class.isA( AttributeType, attributeType )){ - this.attributeTypes.put(attributeType); + var theAttribute = list[i]; + if(Class.isA(Attribute, theAttribute)){ + this.attributeTypes.put(theAttribute); } } }, @@ -2579,14 +2428,14 @@ define('callback',['easejs', 'attributeType', 'attributeTypeList'], * @public * @alias addAttributeType * @memberof Callback# - * @param {AttributeType} _attributeType AttributeType + * @param {AttributeType} _attribute AttributeType */ - 'public addAttributeType' : function(_attributeType){ - if(Class.isA( AttributeType, _attributeType )){ - if(!this.attributeTypes.contains(_attributeType)){ - this.attributeTypes.put(_attributeType); + 'public addAttributeType' : function(_attribute){ + if(Class.isA(Attribute, _attribute )){ + if(!this.attributeTypes.containsTypeOf(_attribute)){ + this.attributeTypes.put(_attribute); } - }; + } }, /** @@ -2598,9 +2447,9 @@ define('callback',['easejs', 'attributeType', 'attributeTypeList'], * @param {AttributeType} _attributeType AttributeType */ 'public removeAttributeType' : function(_attributeType){ - if(Class.isA( AttributeType, _attributeType )){ + if(Class.isA(Attribute, _attributeType )){ this.attributeTypes.removeItem(_attributeType.getName()); - }; + } }, /** @@ -2647,9 +2496,7 @@ define('callbackList',['easejs', 'abstractList', 'callback'], * @requires AbstractList * @requires Callback */ - var CallbackList = Class('CallbackList'). - extend(AbstractList,{ - + var CallbackList = Class('CallbackList').extend(AbstractList,{ /** * @alias counter * @protected @@ -2677,18 +2524,10 @@ define('callbackList',['easejs', 'abstractList', 'callback'], * @returns {CallbackList} */ 'public withItems': function(_callbackList){ - var list = []; - if(_callbackList instanceof Array){ - list = _callbackList; + if (_callbackList instanceof Array) { + this.items = _callbackList; } else if (Class.isA(CallbackList, _callbackList)) { - list = _callbackList.getItems(); - } - for(var i in list){ - var callback = list[i]; - if(Class.isA( Callback, callback )){ - this.items[callback.getName()] = callback; - this.counter++; - } + this.items = _callbackList.getItems(); } return this; }, @@ -2702,11 +2541,10 @@ define('callbackList',['easejs', 'abstractList', 'callback'], * @param {Callback} _callback Callback */ 'public put' : function(_callback){ - if(Class.isA(Callback, _callback)){ - if(!(this.containsKey(_callback.getName()))){ - this.counter++; + if (Class.isA(Callback, _callback)) { + if (!(this.contains(_callback))) { + this.items.push(_callback); } - this.items[_callback.getName()] = _callback; } }, @@ -2721,19 +2559,13 @@ define('callbackList',['easejs', 'abstractList', 'callback'], */ 'public putAll' : function(_callbackList){ var list = []; - if(_callbackList instanceof Array){ + if (_callbackList instanceof Array) { list = _callbackList; - } else if (Class.isA(CallbackList, _callbackList)) { + } else if (Class.isA(CallbackList, _callbackList)) { list = _callbackList.getItems(); } - for(var i in list){ - var callback = list[i]; - if(Class.isA(Callback, callback)){ - if(!(this.containsKey(callback.getName()))){ - this.counter++; - } - this.items[callback.getName()] = callback; - } + for (var i in list) { + this.put(list[i]); } }, @@ -2744,16 +2576,18 @@ define('callbackList',['easejs', 'abstractList', 'callback'], * @public * @alias contains * @memberof CallbackList# - * @param {Callback} _item CallbackType that should be verified. + * @param {Callback} _callback CallbackType that should be verified. * @returns {boolean} */ - 'public contains' : function(_item){ - if(Class.isA(Callback,_item)){ - var tmp = this.getItem(_item.getName()); - if(!(typeof tmp === 'undefined') && tmp.equals(_item)){ - return true; + 'public contains' : function(_callback){ + if (Class.isA(Callback, _callback)) { + for (var index in this.items) { + var tmp = this.items[index]; + if (tmp.equals(_callback)) { + return true; + } } - } + } return false; }, @@ -2762,20 +2596,17 @@ define('callbackList',['easejs', 'abstractList', 'callback'], * @public * @alias equals * @memberof CallbackList# - * @param {CallbackList} _list CallbackList that should be compared. + * @param {CallbackList} _callbackList CallbackList that should be compared. * @returns {boolean} */ - 'public equals' : function(_list){ - if(Class.isA(CallbackList,_list) && _list.size() == this.size()){ - var items = _list.getItems(); - for(var i in items){ - var item = items[i]; - if(!this.contains(item)){ - return false; - } + 'public equals' : function(_callbackList){ + if (Class.isA(CallbackList, _callbackList) && _callbackList.size() == this.size()) { + for (var index in _callbackList.getItems()) { + var theCallback = _callbackList.getItems()[index]; + if (!this.contains(theCallback)) return false; } return true; - } + } return false; } @@ -2827,8 +2658,8 @@ define('conditionMethod',['easejs'], * @module Condition * @fileOverview */ -define('condition',['easejs','attributeType','attributeValue', 'conditionMethod'], - function(easejs, AttributeType, AttributeValue, ConditionMethod){ +define('condition',['easejs','attribute', 'conditionMethod'], + function(easejs, Attribute, ConditionMethod){ var Class = easejs.Class; /** * @class Condition @@ -2947,11 +2778,11 @@ define('condition',['easejs','attributeType','attributeValue', 'conditionMethod' * @public * @alias setAttributeType * @memberof Condition# - * @param {AttributeType} _attributeType AttributeType + * @param {Attribute} _attribute AttributeType */ - 'public setAttributeType' : function(_attributeType){ - if(Class.isA(AttributeType,_attributeType)){ - this.attributeType = _attributeType; + 'public setAttributeType' : function(_attribute){ + if(Class.isA(Attribute, _attribute)){ + this.attributeType = _attribute; } }, @@ -3035,21 +2866,20 @@ define('condition',['easejs','attributeType','attributeValue', 'conditionMethod' * @public * @alias compare * @memberof Condition# - * @param {AttributeValue} _newAttributeValue new Attribute that should be compared - * @param {AttributeValue} _oldAttributeValue old Attribute + * @param {Attribute} _newAttributeValue new Attribute that should be compared + * @param {Attribute} _oldAttributeValue old Attribute * @returns {boolean} */ 'public compare' : function(_newAttributeValue, _oldAttributeValue){ - if(!this.attributeType.equals(_newAttributeValue.getAttributeType()) - && !this.attributeType.equals(_oldAttributeValue.getAttributeType())){ + if(!this.attributeType.equalsTypeOf(_newAttributeValue)&& !this.attributeType.equalsTypeOf(_oldAttributeValue)){ return false; - }; + } if(!this.comparisonMethod){ return false; - }; - if(Class.isA(AttributeValue,_newAttributeValue) && Class.isA(AttributeValue,_oldAttributeValue)){ + } + if(Class.isA(Attribute, _newAttributeValue) && Class.isA(Attribute, _oldAttributeValue)){ return this.comparisonMethod.process(this.referenceValue, _newAttributeValue.getValue(), _oldAttributeValue.getValue()); - }; + } return false; }, @@ -3066,7 +2896,7 @@ define('condition',['easejs','attributeType','attributeValue', 'conditionMethod' if(Class.isA(Condition, _condition)){ if(_condition.getName() == this.getName() && _condition.getReferenceValue() == this.getReferenceValue() - && _condition.getAttributeType().equals(this.attributeType) + && _condition.getAttributeType().equalsTypeOf(this.attributeType) && _condition.getComparisonMethod() === this.comparisonMethod){ return true; }; @@ -3127,18 +2957,10 @@ define('conditionList',['easejs','abstractList', 'condition'], * @returns {ConditionList} */ 'public withItems': function(_conditionList){ - var list = new Array(); - if(_conditionList instanceof Array){ - list = _conditionList; + if (_conditionList instanceof Array) { + this.items = _conditionList; } else if (Class.isA(ConditionList, _conditionList)) { - list = _conditionList.getItems(); - } - for(var i in list){ - var condition = list[i]; - if(Class.isA( Condition, condition )){ - this.items[condition.getName()] = condition; - this.counter++; - } + this.items = _conditionList.getItems(); } return this; }, @@ -3152,11 +2974,9 @@ define('conditionList',['easejs','abstractList', 'condition'], * @param {Condition} _condition Condition */ 'public put' : function(_condition){ - if(Class.isA(Condition, _condition)){ - if(!(this.containsKey(_condition.getName()))){ - this.counter++; - } - this.items[_condition.getName()] = _condition; + if (Class.isA(Condition, _condition)) { + if (!(this.contains(_condition))) { + this.items.push(_condition);} } }, @@ -3170,20 +2990,14 @@ define('conditionList',['easejs','abstractList', 'condition'], * @param {(ConditioneList|Array)} _conditionList ConditionList */ 'public putAll' : function(_conditionList){ - var list = new Array(); - if(_conditionList instanceof Array){ + var list = []; + if (_conditionList instanceof Array) { list = _conditionList; - } else if (Class.isA(ConditionList, _conditionList)) { + } else if (Class.isA(ConditionList, _conditionList)) { list = _conditionList.getItems(); } - for(var i in list){ - var condition = list[i]; - if(Class.isA(Condition, condition)){ - if(!(this.containsKey(condition.getName()))){ - this.counter++; - } - this.items[condition.getName()] = condition; - } + for (var i in list) { + this.put(list[i]); } }, @@ -3194,16 +3008,18 @@ define('conditionList',['easejs','abstractList', 'condition'], * @public * @alias contains * @memberof ConditionList# - * @param {Condition} _item Condition that should be verified. + * @param {Condition} _condition Condition that should be verified. * @returns {boolean} */ - 'public contains' : function(_item){ - if(Class.isA(Condition,_item)){ - var tmp = this.getItem(_item.getName()); - if(!(typeof tmp === 'undefined') && tmp.equals(_item)){ - return true; + 'public contains' : function(_condition){ + if (Class.isA(Condition, _condition)) { + for (var index in this.items) { + var theCondition = this.items[index]; + if (theCondition.equals(_condition)) { + return true; + } } - } + } return false; }, @@ -3213,24 +3029,19 @@ define('conditionList',['easejs','abstractList', 'condition'], * @public * @alias equals * @memberof ConditionList# - * @param {ConditionList} _list ConditionList that should be compared. + * @param {ConditionList} _conditionList ConditionList that should be compared. * @returns {boolean} */ - 'public equals' : function(_list){ - if(Class.isA(ConditionList,_list) && _list.size() == this.size()){ - var items = _list.getItems(); - for(var i in items){ - var item = items[i]; - if(!this.contains(item)){ - return false; - } + 'public equals' : function(_conditionList){ + if (Class.isA(ConditionList, _conditionList) && _conditionList.size() == this.size()) { + for (var index in _conditionList.getItems()) { + var theCondition = _conditionList.getItems()[index]; + if (!this.contains(theCondition)) return false; } return true; - } + } return false; - }, - - + } }); @@ -3242,8 +3053,8 @@ define('conditionList',['easejs','abstractList', 'condition'], * @module Subscriber * @fileOverview */ -define('subscriber',['easejs', 'attributeTypeList', 'callbackList', 'condition', 'conditionList'], - function(easejs, AttributeTypeList, CallbackList, Condition, ConditionList){ +define('subscriber',['easejs', 'attributeList', 'callbackList', 'condition', 'conditionList'], + function(easejs, AttributeList, CallbackList, Condition, ConditionList){ /* * Callback: name and associated Attributes @@ -3311,8 +3122,8 @@ define('subscriber',['easejs', 'attributeTypeList', 'callbackList', 'condition', 'virtual public __construct': function() { this.subscriptionCallbacks = new CallbackList(); - this.subscriptionCallbacks = new AttributeTypeList(); - this.attributesSubset = new AttributeTypeList(); + this.subscriptionCallbacks = new AttributeList(); + this.attributesSubset = new AttributeList(); this.conditions = new ConditionList(); }, @@ -3410,7 +3221,7 @@ define('subscriber',['easejs', 'attributeTypeList', 'callbackList', 'condition', 'public setSubscriberName' : function(_subscriberName){ if(typeof _subscriberName === 'string'){ this.subscriberName = _subscriberName; - }; + } }, @@ -3463,7 +3274,7 @@ define('subscriber',['easejs', 'attributeTypeList', 'callbackList', 'condition', 'public setSubscriptionCallbacks' : function(_subscriptionCallbacks){ if(Class.isA(CallbackList, _subscriptionCallbacks)){ this.subscriptionCallbacks = _subscriptionCallbacks; - }; + } }, /** @@ -3484,12 +3295,12 @@ define('subscriber',['easejs', 'attributeTypeList', 'callbackList', 'condition', * @public * @alias setAttributesSubset * @memberof Subscriber# - * @param {AttributeTypeList} _attributesSubset attributesSubset + * @param {AttributeList} _attributesSubset attributesSubset */ 'public setAttributesSubset' : function(_attributesSubset){ - if(Class.isA(AttributeTypeList, _attributesSubset)){ + if(Class.isA(AttributeList, _attributesSubset)){ this.attributesSubset = _attributesSubset; - }; + } }, /** @@ -3628,23 +3439,14 @@ define('subscriberList',['easejs', 'abstractList', 'subscriber'], * @public * @alias withItems * @memberof SubscriberList# - * @param {(SubscriberList|Array)} - * _subscriberList SubscriberList + * @param {(SubscriberList|Array)} _subscriberList SubscriberList * @returns {SubscriberList} */ 'public withItems': function(_subscriberList){ - var list = new Array(); - if(_subscriberList instanceof Array){ - list = _subscriberList; - } else if (Class.isA( SubscriberList, _subscriberList)) { - list = _subscriberList.getItems(); - } - for(var i in list){ - var subscriber = list[i]; - if(Class.isA( Subscriber, subscriber )){ - this.items[subscriber.getSubscriberId()] = subscriber; - this.counter++; - } + if (_subscriberList instanceof Array) { + this.items = _subscriberList; + } else if (Class.isA(SubscriberList, _subscriberList)) { + this.items = _subscriberList.getItems(); } return this; }, @@ -3655,15 +3457,12 @@ define('subscriberList',['easejs', 'abstractList', 'subscriber'], * @public * @alias put * @memberof SubscriberList# - * @param {Subscriber} - * _subscriber Subscriber + * @param {Subscriber} _subscriber Subscriber */ 'public put' : function(_subscriber){ - if(Class.isA(Subscriber, _subscriber)){ - if(!(this.containsKey(_subscriber.getSubscriberId()))){ - this.counter++; - } - this.items[_subscriber.getSubscriberId()] = _subscriber; + if (Class.isA(Subscriber, _subscriber)) { + if (!(this.contains(_subscriber))) { + this.items.push(_subscriber);} } }, @@ -3676,20 +3475,14 @@ define('subscriberList',['easejs', 'abstractList', 'subscriber'], * @param {(SubscriberList|Array)} _subscriberList SubscriberList */ 'public putAll' : function(_subscriberList){ - var list = new Array(); - if(_subscriberList instanceof Array){ + var list = []; + if (_subscriberList instanceof Array) { list = _subscriberList; - } else if (Class.isA(SubscriberList, _subscriberList)) { + } else if (Class.isA(SubscriberList, _subscriberList)) { list = _subscriberList.getItems(); } - for(var i in list){ - var subscriber = list[i]; - if(Class.isA(Subscriber, subscriber)){ - if(!(this.containsKey(subscriber.getSubscriberId()))){ - this.counter++; - } - this.items[subscriber.getSubscriberId()] = subscriber; - } + for (var i in list) { + this.put(list[i]); } }, @@ -3699,17 +3492,18 @@ define('subscriberList',['easejs', 'abstractList', 'subscriber'], * @public * @alias contains * @memberof SubscriberList# - * @param {Subscriber} - * _item Subscriber that should be verified. + * @param {Subscriber}_subscriber Subscriber that should be verified. * @returns {boolean} */ - 'public contains' : function(_item){ - if(Class.isA(Subscriber,_item)){ - var tmp = this.getItem(_item.getSubscriberId()); - if(!(typeof tmp === 'undefined') && tmp.equals(_item)){ - return true; + 'public contains' : function(_subscriber){ + if (Class.isA(Subscriber, _subscriber)) { + for (var index in this.items) { + var tmp = this.items[index]; + if (tmp.equals(_subscriber)) { + return true; + } } - } + } return false; }, @@ -3718,23 +3512,26 @@ define('subscriberList',['easejs', 'abstractList', 'subscriber'], * @public * @alias equals * @memberof SubscriberList# - * @param {SubscriberList} _list SubscriberList that should be compared. + * @param {SubscriberList} _subscriberList SubscriberList that should be compared. * @returns {boolean} */ - 'public equals' : function(_list){ - if(Class.isA(SubscriberList,_list) && _list.size() == this.size()){ - var items = _list.getItems(); - for(var i in items){ - var item = items[i]; - if(!this.contains(item)){ - return false; - } + 'public equals' : function(_subscriberList) { + if (Class.isA(SubscriberList, _subscriberList) && _subscriberList.size() == this.size()) { + for (var index in _subscriberList.getItems()) { + var theSubscriber = _subscriberList.getItems()[index]; + if (!this.contains(theSubscriber)) return false; } return true; - } + } return false; }, + 'public removeSubscriberWithId': function(_subscriberId) { + for (var index in this.items) { + var theSubscriber = this.items[index]; + if (theSubscriber.getSubscriberId() == _subscriberId) this.items.splice(index, 1); + } + } }); return SubscriberList; @@ -3746,8 +3543,8 @@ define('subscriberList',['easejs', 'abstractList', 'subscriber'], * @module WidgetDescription * @fileOverview */ -define('widgetDescription',['easejs', 'attributeTypeList'], - function(easejs, AttributeTypeList){ +define('widgetDescription',['easejs', 'attributeList'], + function(easejs, AttributeList){ var Class = easejs.Class; var WidgetDescription = Class('WidgetDescription',{ @@ -3795,7 +3592,7 @@ define('widgetDescription',['easejs', 'attributeTypeList'], * @constructs WidgetDescription */ 'virtual public __construct' : function(){ - this.outAttributeTypes = new AttributeTypeList(); + this.outAttributeTypes = new AttributeList(); }, /** @@ -3973,11 +3770,11 @@ define('widgetDescription',['easejs', 'attributeTypeList'], * @module Widget * @fileOverview */ -define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeType', - 'attributeValue', 'attributeTypeList', 'attributeValueList', 'conditionList', +define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', + 'attributeList', 'conditionList', 'subscriber', 'subscriberList', 'widgetDescription'], - function(easejs, MathUuid, Callback, CallbackList, AttributeType, - AttributeValue, AttributeTypeList, AttributeValueList, ConditionList, + function(easejs, MathUuid, Callback, CallbackList, Attribute, + AttributeList, ConditionList, Subscriber, SubscriberList, WidgetDescription) { var AbstractClass = easejs.AbstractClass; @@ -4094,10 +3891,10 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeTy this.id = Math.uuid(); this.discoverer = _discoverer; this.register(); - this.attributeTypes = new AttributeTypeList(); - this.constantAttributeTypes = new AttributeTypeList(); - this.attributes = new AttributeValueList(); - this.constantAttributes = new AttributeValueList(); + this.attributeTypes = new AttributeList(); + this.constantAttributeTypes = new AttributeList(); + this.attributes = new AttributeList(); + this.constantAttributes = new AttributeList(); this.subscribers = new SubscriberList(); this.callbacks = new CallbackList(); this.init(_attributeTypes); @@ -4160,7 +3957,7 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeTy * @public * @alias getWidgetConstantAttributeTypes * @memberof Widget# - * @returns {AttributeTypeList} + * @returns {AttributeList} */ 'public getWidgetConstantAttributeTypes' : function() { return this.constantAttributeTypes; @@ -4172,12 +3969,12 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeTy * @public * @alias getAttributes * @memberof Widget# - * @param {AttributeTypeList} _attributeTypeList - * @returns {AttributeValueList} + * @param {AttributeList} _attributeList + * @returns {AttributeList} */ - 'public getAttributeValues' : function(_attributeTypeList) { - if (Class.isA(AttributeTypeList, _attributeTypeList)) { - return this.attributes.getSubset(_attributeTypeList); + 'public getAttributeValues' : function(_attributeList) { + if (Class.isA(AttributeList, _attributeList)) { + return this.attributes.getSubset(_attributeList); } else { return this.attributes; } @@ -4199,7 +3996,7 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeTy * @private * @alias getOldAttributes * @memberof Widget# - * @returns {AttributeValueList} + * @returns {AttributeList} */ 'public getOldAttributes' : function() { return this.oldAttributes; @@ -4211,7 +4008,7 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeTy * @public * @alias getConstantAttributes * @memberof Widget# - * @returns {AttributeValueList} + * @returns {AttributeList} */ 'public getConstantAttributes' : function() { return this.constantAttributes; @@ -4334,14 +4131,13 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeTy * @public * @alias addAttribute * @memberof Widget# - * @param {AttributeValue} - * _attribute AttributeValue + * @param {Attribute} _attribute AttributeValue */ 'public addAttribute' : function(_attribute) { - if (Class.isA(AttributeValue, _attribute)) { + if (Class.isA(Attribute, _attribute)) { if (!this.attributes.contains(_attribute)) { - var type = new AttributeType().withName(_attribute.getName()) + var type = new Attribute().withName(_attribute.getName()) .withType(_attribute.getType()) .withParameters(_attribute.getParameters()); this.attributeTypes.put(type); @@ -4500,7 +4296,7 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeTy * @param {Subscriber} _subscriber Subscriber */ 'public removeSubscriber' : function(_subscriberId) { - this.subscribers.removeItem(_subscriberId); + this.subscribers.removeSubscriberWithId(_subscriberId); }, /** @@ -4527,7 +4323,7 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeTy * @returns {boolean} */ 'protected isAttribute' : function(_attribute) { - return !!this.attributeTypes.contains(_attribute.getAttributeType()); + return !!this.attributeTypes.containsTypeOf(_attribute); }, /** @@ -4652,12 +4448,12 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeTy var list = []; if (_data instanceof Array) { list = _data; - } else if (Class.isA(AttributeValueList, _data)) { + } else if (Class.isA(AttributeList, _data)) { list = _data.getItems(); } for ( var i in list) { var x = list[i]; - if (Class.isA(AttributeValue, x) && this.isAttribute(x)) { + if (Class.isA(Attribute, x) && this.isAttribute(x)) { this.addAttribute(x); } } @@ -4671,10 +4467,10 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeTy * @public * @alias queryWidget * @memberof Widget# - * @returns {AttributeValueList} + * @returns {AttributeList} */ 'public queryWidget' : function() { - var response = new AttributeValueList(); + var response = new AttributeList(); response.putAll(this.getAttributeValues()); response.putAll(this.getConstantAttributes()); return response; @@ -4688,14 +4484,14 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeTy * @alias updateAndQueryWidget * @memberof Widget# * @param {?function} _function For alternative actions, because an asynchronous function can be used. - * @returns {?AttributeValueList} + * @returns {?AttributeList} */ 'virtual public updateAndQueryWidget' : function(_function) { if(_function && typeof(_function) === 'function'){ this.queryGenerator(_function); } else { this.queryGenerator(); - var response = new AttributeValueList(); + var response = new AttributeList(); response.putAll(this.getAttributeValues()); response.putAll(this.getConstantAttributes()); return response; @@ -4715,7 +4511,7 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeTy var subscriberList = this.subscribers.getItems(); for ( var i in subscriberList) { var subscriber = subscriberList[i]; - if (subscriber.getSubscriptionCallbacks().containsKey( _callback.getName())) { + if (subscriber.getSubscriptionCallbacks().contains(_callback)) { if(this.dataValid(subscriber.getConditions())){ var subscriberInstance = this.discoverer.getComponent(subscriber.getSubscriberId()); var callSubset = _callback.getAttributeTypes(); @@ -4850,8 +4646,8 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeTy * @module InterpreterDescription * @fileOverview */ -define('interpreterDescription',['easejs','attributeTypeList','widgetDescription'], - function(easejs,AttributeTypeList,WidgetDescription){ +define('interpreterDescription',['easejs','attributeList', 'widgetDescription'], + function(easejs,AttributeList, WidgetDescription){ var Class = easejs.Class; var InterpreterDescription = Class('InterpreterDescription'). extend(WidgetDescription, { @@ -4872,13 +4668,13 @@ define('interpreterDescription',['easejs','attributeTypeList','widgetDescription * @classdesc The description of an interpreter and the communication with it. * @extends WidgetDescription * @requires easejs - * @requires AttributeTypeList + * @requires AttributeList * @requires WidgetDescription * @constructs InterpreterDescription */ 'override public __construct' : function(){ this.__super(); - this.inAttributeTypes = new AttributeTypeList(); + this.inAttributeTypes = new AttributeList(); }, /** @@ -4887,7 +4683,7 @@ define('interpreterDescription',['easejs','attributeTypeList','widgetDescription * @public * @alias withInAttributeTypes * @memberof InterpreterDescription# - * @param {(AttributeTypeList|Array)} _inAttributeTypes List of AttributeType that are expected + * @param {(AttributeList|Array)} _inAttributeTypes List of AttributeType that are expected * @returns {InterpreterDescription} */ 'public withInAttributeTypes' : function(_inAttributeTypes){ @@ -4955,8 +4751,8 @@ define('interpreterDescription',['easejs','attributeTypeList','widgetDescription * @module InterpreterResult * @fileOverview */ -define('interpreterResult',['easejs', 'attributeValueList'], - function(easejs, AttributeValueList){ +define('interpreterResult',['easejs', 'attributeList'], + function(easejs, AttributeList){ var Class = easejs.Class; var InterpreterResult = Class('InterpreterResult',{ @@ -5140,10 +4936,10 @@ define('interpreterResult',['easejs', 'attributeValueList'], * @module Interpreter * @fileOverview */ -define('interpreter',[ 'easejs', 'MathUuid', 'attributeType', 'attributeTypeList', - 'attributeValue', 'attributeValueList', 'interpreterDescription', 'interpreterResult' ], - function(easejs, MathUuid, AttributeType, AttributeTypeList, - AttributeValue, AttributeValueList, InterpreterDescription, InterpreterResult) { +define('interpreter',[ 'easejs', 'MathUuid', 'attribute', 'attributeList', + 'interpreterDescription', 'interpreterResult' ], + function(easejs, MathUuid, Attribute, AttributeList, + InterpreterDescription, InterpreterResult) { var Class = easejs.Class; var AbstractClass = easejs.AbstractClass; var Interpreter = AbstractClass('Interpreter', @@ -5167,7 +4963,7 @@ define('interpreter',[ 'easejs', 'MathUuid', 'attributeType', 'attributeTypeList /** * @alias inAttributeTypes * @protected - * @type {AttributeTypeList} + * @type {AttributeList} * @memberof Interpreter# * @desc Types of all attributes that can be handled. */ @@ -5175,7 +4971,7 @@ define('interpreter',[ 'easejs', 'MathUuid', 'attributeType', 'attributeTypeList /** * @alias outAttributeTypes * @protected - * @type {AttributeTypeList} + * @type {AttributeList} * @memberof Interpreter# * @desc Types of all attributes that will be returned. */ @@ -5183,7 +4979,7 @@ define('interpreter',[ 'easejs', 'MathUuid', 'attributeType', 'attributeTypeList /** * @alias inAttributeValues * @protected - * @type {AttributeValueList} + * @type {AttributeList} * @memberof Interpreter# * @desc List of the data that should be interpreted. */ @@ -5191,7 +4987,7 @@ define('interpreter',[ 'easejs', 'MathUuid', 'attributeType', 'attributeTypeList /** * @alias outAttributeValues * @protected - * @type {AttributeValueList} + * @type {AttributeList} * @memberof Interpreter# * @desc List of interpreted data. */ @@ -5221,10 +5017,8 @@ define('interpreter',[ 'easejs', 'MathUuid', 'attributeType', 'attributeTypeList * @classdesc The Widget handles the access to sensors. * @requires easejs * @requires MathUuid - * @requires AttributeType - * @requires AttributeValue - * @requires AttributeTypeList - * @requires AttributeValueList + * @requires Attribute + * @requires AttributeList * @requires InterpreterDescription * @constructs Interpreter */ @@ -5232,10 +5026,10 @@ define('interpreter',[ 'easejs', 'MathUuid', 'attributeType', 'attributeTypeList this.id = Math.uuid(); this.discoverer = _discoverer; this.register(); - this.inAttributeTypes = new AttributeTypeList(); - this.outAttributeTypes = new AttributeTypeList(); - this.inAttributeValues = new AttributeValueList(); - this.outAttributeValues = new AttributeValueList(); + this.inAttributeTypes = new AttributeList(); + this.outAttributeTypes = new AttributeList(); + this.inAttributeValues = new AttributeList(); + this.outAttributeValues = new AttributeList(); this.initInterpreter(); }, @@ -5333,7 +5127,7 @@ define('interpreter',[ 'easejs', 'MathUuid', 'attributeType', 'attributeTypeList * @param {ParameterList|Array} _parameter Parameter of the attribute. */ 'protected setInAttribute' : function(_name, _type, _value, _parameters) { - var attributeValue = new AttributeValue().withName(_name) + var attributeValue = new Attribute().withName(_name) .withValue(_value).withType(_type).withParameters(_parameters); if (this.isInAttribute(attributeValue)) { this.inAttributeValues.put(attributeValue); @@ -5346,10 +5140,10 @@ define('interpreter',[ 'easejs', 'MathUuid', 'attributeType', 'attributeTypeList * @protected * @alias setInAttributeValues * @memberof Interpreter# - * @param {(AttributeValueList|Array)} _attributeValueList Attributes to set. + * @param {(AttributeList|Array)} _attributeList Attributes to set. */ - 'protected setInAttributeValues' : function(_attributeValueList) { - this.inAttributeValues = new AttributeValueList().withItems(_attributeValueList); + 'protected setInAttributeValues' : function(_attributeList) { + this.inAttributeValues = new AttributeList().withItems(_attributeList); }, /** * Verifies whether the specified attribute is contained in inAttributeList. @@ -5361,7 +5155,7 @@ define('interpreter',[ 'easejs', 'MathUuid', 'attributeType', 'attributeTypeList * @return {boolean} */ 'protected isInAttribute' : function(_attribute) { - return !!this.inAttributeTypes.contains(_attribute.getAttributeType()); + return !!this.inAttributeTypes.containsTypeOf(_attribute); }, /** @@ -5405,7 +5199,7 @@ define('interpreter',[ 'easejs', 'MathUuid', 'attributeType', 'attributeTypeList * @return {boolean} */ 'protected isOutAttribute' : function(_attribute) { - return !!this.outAttributeTypes.contains(_attribute.getAttributeType()); + return !!this.outAttributeTypes.containsTypeOf(_attribute); }, /** @@ -5414,19 +5208,20 @@ define('interpreter',[ 'easejs', 'MathUuid', 'attributeType', 'attributeTypeList * @public * @alias callInterpreter * @memberof Interpreter# - * @param {AttributeValueList} _inAttributeValues Data that should be interpreted. + * @param {AttributeList} _inAttributeValues Data that should be interpreted. + * @param {AttributeList} _outAttributeValues * @param {?function} _function For additional actions, if an asynchronous function is used. */ 'public callInterpreter' : function(_inAttributeValues, _outAttributeValues, _function) { var self = this; - if (!_inAttributeValues || !this.canHandleInAttributeValues(_inAttributeValues)) throw "Empty input attribute list or unhandled input attribute."; - if (!_outAttributeValues || !this.canHandleOutAttributeValues(_outAttributeValues)) throw "Empty output attribute list or unhandled output attribute."; + if (!_inAttributeValues || !this.canHandleInAttributes(_inAttributeValues)) throw "Empty input attribute list or unhandled input attribute."; + if (!_outAttributeValues || !this.canHandleOutAttributes(_outAttributeValues)) throw "Empty output attribute list or unhandled output attribute."; this.interpretData(_inAttributeValues, _outAttributeValues, function(interpretedData) { - var response = new AttributeValueList().withItems(interpretedData); + var response = new AttributeList().withItems(interpretedData); - if (!self.canHandleOutAttributeValues(response)) throw "Unhandled output attribute generated."; + if (!self.canHandleOutAttributes(response)) throw "Unhandled output attribute generated."; self.setInAttributeValues(_inAttributeValues); self.lastInterpretation = new Date(); @@ -5445,27 +5240,27 @@ define('interpreter',[ 'easejs', 'MathUuid', 'attributeType', 'attributeTypeList * @public * @alias interpretData * @memberof Interpreter# - * @param {AttributeValueList} _data Data that should be interpreted. + * @param {AttributeList} _data Data that should be interpreted. * @param {?function} _function For additional actions, if an asynchronous function is used. */ - 'abstract protected interpretData' : ['_inAttributeValues', '_outAttributeValues', '_callback'], + 'abstract protected interpretData' : ['_inAttributes', '_outAttributes', '_callback'], /** * Checks whether the specified data match the expected. * * @protected - * @alias canHandleInAttributeValues + * @alias canHandleInAttributes * @memberof Interpreter# - * @param {AttributeValueList|Array.<AttributeValue>} _inAttributeValues Data that should be verified. + * @param {AttributeList|Array.<Attribute>} _inAttributes Data that should be verified. */ - 'protected canHandleInAttributeValues' : function(_inAttributeValues) { + 'protected canHandleInAttributes' : function(_inAttributes) { var list = []; - if (_inAttributeValues instanceof Array) { - list = _inAttributeValues; - } else if (Class.isA(AttributeValueList, _inAttributeValues)) { - list = _inAttributeValues.getItems(); + if (_inAttributes instanceof Array) { + list = _inAttributes; + } else if (Class.isA(AttributeList, _inAttributes)) { + list = _inAttributes.getItems(); } - if (list.length == 0 || _inAttributeValues.size() != this.getInAttributeTypes().size()) { + if (list.length == 0 || _inAttributes.size() != this.getInAttributeTypes().size()) { return false; } for ( var i in list) { @@ -5481,18 +5276,18 @@ define('interpreter',[ 'easejs', 'MathUuid', 'attributeType', 'attributeTypeList * Checks whether the specified data match the expected. * * @protected - * @alias canHandle + * @alias canHandleOutAttributes * @memberof Interpreter# - * @param {AttributeValueList|Array.<AttributeValue>} _outAttributeValues Data that should be verified. + * @param {AttributeList|Array.<Attribute>} _outAttributes Data that should be verified. */ - 'protected canHandleOutAttributeValues' : function(_outAttributeValues) { + 'protected canHandleOutAttributes' : function(_outAttributes) { var list = []; - if (_outAttributeValues instanceof Array) { - list = _outAttributeValues; - } else if (Class.isA(AttributeValueList, _outAttributeValues)) { - list = _outAttributeValues.getItems(); + if (_outAttributes instanceof Array) { + list = _outAttributes; + } else if (Class.isA(AttributeList, _outAttributes)) { + list = _outAttributes.getItems(); } - if (list.length == 0 || _outAttributeValues.size() != this.getOutAttributeTypes().size()) { + if (list.length == 0 || _outAttributes.size() != this.getOutAttributeTypes().size()) { return false; } for ( var i in list) { @@ -5594,13 +5389,13 @@ define('interpreter',[ 'easejs', 'MathUuid', 'attributeType', 'attributeTypeList /** * Created by tobias on 15.04.15. */ -define('interpretation',['easejs', 'interpreter', 'attributeTypeList'], - function(easejs, Interpreter, AttributeTypeList) { +define('interpretation',['easejs', 'interpreter', 'attributeList'], + function(easejs, Interpreter, AttributeList) { var Class = easejs.Class; var Interpretation = Class('Interpretation', { 'public interpreterId' : null, - 'public inAttributeTypes' : new AttributeTypeList(), - 'public outAttributeTypes' : new AttributeTypeList(), + 'public inAttributeTypes' : new AttributeList(), + 'public outAttributeTypes' : new AttributeList(), 'public __construct' : function(_interpreterId, _inAttributes, _outAttributes){ this.interpreterId = _interpreterId; @@ -5621,11 +5416,11 @@ define('interpretation',['easejs', 'interpreter', 'attributeTypeList'], * @fileOverview */ define('aggregator',['easejs', 'MathUuid','widget', - 'attributeType', 'attributeValue', 'attributeValueList', 'subscriber', - 'subscriberList', 'callbackList', 'storage', 'widgetDescription', 'interpreter', 'attributeTypeList', 'interpretation'], - function(easejs, MathUuid, Widget, AttributeType, - AttributeValue, AttributeValueList, Subscriber, SubscriberList, - CallbackList, Storage, WidgetDescription, Interpreter, AttributeTypeList, Interpretation){ + 'attribute', 'attributeList', 'subscriber', + 'subscriberList', 'callbackList', 'storage', 'widgetDescription', 'interpreter', 'interpretation'], + function(easejs, MathUuid, Widget, Attribute, + AttributeList, Subscriber, SubscriberList, + CallbackList, Storage, WidgetDescription, Interpreter, Interpretation){ var Class = easejs.Class; var Aggregator = Class('Aggregator'). @@ -5684,8 +5479,8 @@ define('aggregator',['easejs', 'MathUuid','widget', * @requires MathUuid * @requires CallbackList * @requires AttributeType - * @requires AttributeValue - * @requires AttributeValueList + * @requires Attribute + * @requires AttributeList * @requires Subscriber * @requires SubscriberList * @requires Storage @@ -5720,13 +5515,13 @@ define('aggregator',['easejs', 'MathUuid','widget', * @protected * @alias addAttributeType * @memberof Aggregator# - * @param {AttributeType} _attributeType attributeType + * @param {AttributeType} _attribute attributeType + * @param {boolean} _multipleInstances */ - 'protected addAttributeType' : function(_attributeType, _multipleInstances){ - if(Class.isA( AttributeType, _attributeType )){ - this.attributeTypes.put(_attributeType, _multipleInstances); - var attVal = new AttributeValue().buildFromAttributeType(_attributeType); - this.attributes.put(attVal, _multipleInstances); + 'protected addAttributeType' : function(_attribute, _multipleInstances){ + if(Class.isA(Attribute, _attribute )){ + this.attributeTypes.put(_attribute, _multipleInstances); + this.attributes.put(_attribute, _multipleInstances); } }, @@ -5881,10 +5676,10 @@ define('aggregator',['easejs', 'MathUuid','widget', * @alias setAggregatorAttributeValues * @memberof Aggregator# */ - 'virtual protected setAggregatorAttributeValues' : function(_attributeTypes) { - for (var index in _attributeTypes) { - var theAttributeType = _attributeTypes[index]; - this.addAttribute(new AttributeValue().buildFromAttributeType(theAttributeType)); + 'virtual protected setAggregatorAttributeValues' : function(_attributes) { + for (var index in _attributes) { + var theAttribute = _attributes[index]; + this.addAttribute(theAttribute); } }, @@ -5925,7 +5720,7 @@ define('aggregator',['easejs', 'MathUuid','widget', * @returns {AttributeValueList} */ 'public getCurrentData' : function(){ - var response = new AttributeValueList(); + var response = new AttributeList(); response.putAll(this.attributes); return response; }, @@ -6035,18 +5830,18 @@ define('aggregator',['easejs', 'MathUuid','widget', * @public * @alias putData * @memberof Aggregator# - * @param {(AttributeValueList|Array)} _data data that shall be input + * @param {(AttributeList|Array)} _data data that shall be input */ 'override public putData' : function(_data){ var list = []; if(_data instanceof Array){ list = _data; - } else if (Class.isA(AttributeValueList, _data)) { + } else if (Class.isA(AttributeList, _data)) { list = _data.getItems(); } for(var i in list){ var x = list[i]; - if(Class.isA( AttributeValue, x ) && this.isAttribute(x)){ + if(Class.isA(Attribute, x ) && this.isAttribute(x)){ this.addAttribute(x); if(this.db){ this.store(x); @@ -6228,7 +6023,7 @@ define('aggregator',['easejs', 'MathUuid','widget', * @private * @alias getComponentsForUnsatisfiedAttributeTypes * @memberof Aggregator# - * @param {AttributeTypeList} _unsatisfiedAttributes A list of attributes that components should be searched for. + * @param {AttributeList} _unsatisfiedAttributes A list of attributes that components should be searched for. * @param {boolean} _all If true all attributes must be satisfied by a single component. * @param {Array} _componentTypes An array of components classes that should be searched for (e.g. Widget, Interpreter and Aggregator). */ @@ -6258,7 +6053,7 @@ define('aggregator',['easejs', 'MathUuid','widget', // add the attribute type to the aggregators list of handled attribute types if (!this.getAttributeTypes().contains(widgetOutAttribute)) this.addAttributeType(widgetOutAttribute); console.log("I can now satisfy attribute "+widgetOutAttribute+" with the help of "+theComponent.getName()+"! That was easy :)"); - _unsatisfiedAttributes.removeAttributeType(widgetOutAttribute); + _unsatisfiedAttributes.removeAttributeWithTypeOf(widgetOutAttribute); } } else if (Class.isA(Interpreter, theComponent)) { // if the component is an interpreter and all its in attributes can be satisfied, add the interpreter console.log("It's an interpreter."); @@ -6275,7 +6070,7 @@ define('aggregator',['easejs', 'MathUuid','widget', // if required attribute is not already satisfied by the aggregator search for components that do if (!this.doesSatisfyAttributeType(theInAttribute)) { console.log("It seems that I can't satisfy "+theInAttribute+", but I will search for components that can."); - var newAttributeList = new AttributeTypeList(); + var newAttributeList = new AttributeList(); newAttributeList.put(theInAttribute); this.getComponentsForUnsatisfiedAttributeTypes(newAttributeList, false, [Widget, Interpreter]); // if the attribute still can't be satisfied drop the interpreter @@ -6296,13 +6091,13 @@ define('aggregator',['easejs', 'MathUuid','widget', // add the attribute type to the aggregators list of handled attribute types for (var unsatisfiedAttributeIndex in _unsatisfiedAttributes.getItems()) { var theUnsatisfiedAttribute = _unsatisfiedAttributes.getItems()[unsatisfiedAttributeIndex]; - if (theUnsatisfiedAttribute.equals(interpreterOutAttribute)) { + if (theUnsatisfiedAttribute.equalsTypeOf(interpreterOutAttribute)) { this.addAttributeType(theUnsatisfiedAttribute); console.log("I can now satisfy attribute "+theUnsatisfiedAttribute+" with the help of "+theComponent.getName()+"! Great!"); - this.interpretations.push(new Interpretation(theComponent.getId(), theComponent.getInAttributeTypes(), new AttributeTypeList().withItems([theUnsatisfiedAttribute]))); + this.interpretations.push(new Interpretation(theComponent.getId(), theComponent.getInAttributeTypes(), new AttributeList().withItems([theUnsatisfiedAttribute]))); } } - _unsatisfiedAttributes.removeAttributeType(interpreterOutAttribute, true); + _unsatisfiedAttributes.removeAttributeWithTypeOf(interpreterOutAttribute, true); } } else { console.log("Found interpreter but can't satisfy required attributes."); @@ -6525,8 +6320,8 @@ define('unequals',['easejs', 'conditionMethod'], * @module Discoverer * @fileOverview */ -define('discoverer',[ 'easejs', 'attributeTypeList', 'widget', 'interpreter', 'aggregator' ], function(easejs, - AttributeTypeList, Widget, Interpreter, Aggregator) { +define('discoverer',[ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggregator' ], function(easejs, + AttributeList, Widget, Interpreter, Aggregator) { var Class = easejs.Class; var Discoverer = Class('Discoverer', { @@ -6832,7 +6627,7 @@ define('discoverer',[ 'easejs', 'attributeTypeList', 'widget', 'interpreter', 'a if (typeof _componentTypes == "undefined") _componentTypes = [Widget, Interpreter, Aggregator]; if (_attributeTypeList instanceof Array) { list = _attributeTypeList; - } else if (Class.isA(AttributeTypeList, _attributeTypeList)) { + } else if (Class.isA(AttributeList, _attributeTypeList)) { list = _attributeTypeList.getItems(); } if (typeof list != "undefined") { @@ -6937,10 +6732,8 @@ define('discoverer',[ 'easejs', 'attributeTypeList', 'widget', 'interpreter', 'a define('contactJS',['retrievalResult', 'storage', 'aggregator', - 'attributeType', - 'attributeValue', - 'attributeTypeList', - 'attributeValueList', + 'attribute', + 'attributeList', 'parameter', 'parameterList', 'condition', @@ -6962,10 +6755,8 @@ define('discoverer',[ 'easejs', 'attributeTypeList', 'widget', 'interpreter', 'a function(RetrievalResult, Storage, Aggregator, - AttributeType, - AttributeValue, - AttributeTypeList, - AttributeValueList, + Attribute, + AttributeList, Parameter, ParameterList, Condition, @@ -6989,15 +6780,13 @@ define('discoverer',[ 'easejs', 'attributeTypeList', 'widget', 'interpreter', 'a var contactJS = function(obj) { return obj; }; - contactJS.VERSION = '1.1.0'; + contactJS.VERSION = '1.2.0'; // Methods contactJS.RetrievalResult = RetrievalResult; contactJS.Storage = Storage; contactJS.Aggregator = Aggregator; - contactJS.AttributeType = AttributeType; - contactJS.AttributeValue = AttributeValue; - contactJS.AttributeTypeList = AttributeTypeList; - contactJS.AttributeValueList = AttributeValueList; + contactJS.Attribute = Attribute; + contactJS.AttributeList = AttributeList; contactJS.Parameter = Parameter; contactJS.ParameterList = ParameterList; contactJS.Condition = Condition; diff --git a/examples/GeoLocationWidget.js b/examples/GeoLocationWidget.js index 072c760..136872c 100644 --- a/examples/GeoLocationWidget.js +++ b/examples/GeoLocationWidget.js @@ -1,173 +1,62 @@ /** - * This module represents a GeoLocationWidget. It is a subclass of Widget. - * - * @module GeoLocationWidget - * @fileOverview + * Created by tobias on 25.04.15. */ -define([ 'easejs', 'contactJS' ], - function(easejs, contactJS) { - - var Class = easejs.Class; - /** - * @class GeoLocationWidget - * @classdesc This Widget provides the current position of the - * device. - * @extends Widget - * @requires easejs - * @requires Widget - * @requires AttributeType - * @requires AttributeValue - * @requires AttributeTypeList - * @requires AttributeValueList - * @requires Callback - * @requires Parameter - */ - - var GeoLocationWidget = Class('GeoLocationWidget').extend(contactJS.Widget,{ - - /** - * @alias name - * @public - * @type {string} - * @memberof GeoLocationWidget# - * @desc Name of the Widget. In this case: GeoLocationWidget - */ - 'public name' : 'GeoLocationWidget', - - /** - * Initializes attributes. For this class: Latitude and - * Longitude - * - * @protected - * @alias initAttributes - * @memberof GeoLocationWidget# - */ - 'protected initAttributes' : function() { - var latitude = new contactJS.AttributeValue().withName('latitude') - .withType('double') - .withValue('undefined'); - this.addAttribute(latitude); - var longitude = new contactJS.AttributeValue().withName('longitude') - .withType('double') - .withValue('undefined'); - this.addAttribute(longitude); - }, - - /** - * Initializes constantAttributes. For this class: no - * constantAttributes available - * - * @protected - * @alias initConstantAttributes - * @memberof GeoLocationWidget# - */ - 'protected initConstantAttributes' : function() { - }, - - /** - * Initializes Callbacks. For this class: - * UPDATE (latitude and longitude) - * - * @protected - * @alias initCallbacks - * @memberof GeoLocationWidget# - */ - 'protected initCallbacks' : function() { - var list = new contactJS.AttributeTypeList(); - list.put(this.getAttributeTypes().getItem("(latitude:double)")); - list.put(this.getAttributeTypes().getItem("(longitude:double)")); - var call = new contactJS.Callback().withName('UPDATE').withAttributeTypes(list); - this.addCallback(call); - }, - - 'override public notify' : function() { - var callbacks = this.getCallbackList().getItems(); - for(var i in callbacks){ - this.sendToSubscriber(callbacks[i]); - } - }, - - /** - * Implements queryGenerator(). Query latitude and - * longitude by calling - * navigator.geolocation.getCurrentPosition(). - * - * @override - * @protected - * @alias queryGenerator - * @memberof GeoLocationWidget# - */ - 'override protected queryGenerator' : function(_function) { - var self = this; - if(navigator.geolocation){ - navigator.geolocation.getCurrentPosition(function(_position) { - self.onSuccess(_position, self, _function); - }, function(error) { - self.onError(error, self, _function); - }); - } else { - alert("Keine Ortung moeglich"); - } - - }, - - /** - * Success function for navigator.geolocation.getCurrentPosition() used in - * queryGenerator(). Stores the values in the associated attributes. - * - * @callback - * @private - * @alias onSuccess - * @memberof GeoLocationWidget# - * @param _position - * @param {this} self - */ - 'private onSuccess' : function(_position, self, _function) { - var latitude = new contactJS.AttributeValue().withName('latitude') - .withType('double') - .withValue(_position.coords.latitude); - var longitude = new contactJS.AttributeValue().withName('longitude') - .withType('double') - .withValue(_position.coords.longitude); - - var response = new contactJS.AttributeValueList(); - response.put(latitude); - response.put(longitude); - self.putData(response); - self.notify(); - if (_function && typeof(_function) == 'function'){ - _function(); - } - }, +define(['easejs', 'contactJS'], function (easejs, contactJS) { + var Class = easejs.Class; + + var GeoLocationWidget = Class('GeoLocationWidget').extend(contactJS.Widget, { + 'public name': 'GeoLocationWidget', + + 'protected initAttributes': function () { + var latitude = new contactJS.Attribute() + .withName('latitude') + .withType('double'); + + var longitude = new contactJS.Attribute() + .withName('longitude') + .withType('double'); + + this.addAttribute(latitude); + this.addAttribute(longitude); + }, + + 'protected initConstantAttributes': function () { + + }, + + 'protected initCallbacks': function () { + this.addCallback(new contactJS.Callback().withName('UPDATE').withAttributeTypes(this.getAttributeTypes())); + }, + + 'override protected queryGenerator': function (_function) { + var self = this; + var response = new contactJS.AttributeList(); + + if(navigator.geolocation){ + navigator.geolocation.getCurrentPosition(function(_position) { + response.put(self.getAttributeValues().getItems()[0].setValue(_position.coords.latitude)); + response.put(self.getAttributeValues().getItems()[1].setValue(_position.coords.longitude)); + + self.sendResponse(response, _function); + }, function(error) { + //TODO: handle error + self.sendResponse(response, _function); + }); + } else { + //TODO: handle error + self.sendResponse(response, _function); + } + }, - /** - * Error function for navigator.geolocation.getCurrentPosition() used in - * queryGenerator(). - * - * @callback - * @private - * @alias onError - * @memberof GeoLocationWidget# - * @param error - * @param {this} self - */ - 'private onError' : function(error, self, _function) { - var latitude = new contactJS.AttributeValue().withName('latitude') - .withType('double') - .withValue("request_error"); - var longitude = new contactJS.AttributeValue().withName('longitude') - .withType('double') - .withValue("request_error"); + 'private sendResponse': function(response, _function) { + this.putData(response); + this.notify(); - var response = new contactJS.AttributeValueList(); - response.put(latitude); - response.put(longitude); - self.putData(response); - self.notify(); - if (_function && typeof(_function) == 'function'){ - _function(); - } + if (_function && typeof(_function) == 'function') { + _function(); } - }); - return GeoLocationWidget; - }); \ No newline at end of file + } + }); + + return GeoLocationWidget; +}); \ No newline at end of file diff --git a/examples/addressInterpreter.js b/examples/addressInterpreter.js index 8b8d422..3597878 100644 --- a/examples/addressInterpreter.js +++ b/examples/addressInterpreter.js @@ -1,162 +1,61 @@ /** - * This module representing an AddressInterpreter. - * - * @module AddressInterpreter - * @fileOverview + * Created by tobias on 25.03.15. */ -define(['easejs', 'jquery', 'contactJS'], - function(easejs, $, contactJS) { +define(['easejs', 'contactJS'], + function(easejs, contactJS) { var Class = easejs.Class; - /** - * @class AddressInterpreter - * @classdesc This Widget returns the address of specified coordinates. - * @extends Interpreter - * @requires easejs - * @requires jquery - * @requires Interpreter - * @requires AttributeType - * @requires AttributeValue - * @requires Parameter - */ - var AddressInterpreter = Class('AddressInterpreter').extend(contactJS.Interpreter,{ - /** - * @alias name - * @public - * @type {String} - * @memberof AddressInterpreter# - * @desc Name of the Interpreter. In this case: AddressInterpreter - */ + + var AddressInterpreter = Class('AddressInterpreter').extend(contactJS.Interpreter, { 'public name' : 'AddressInterpreter', - /** - * @alias adress - * @private - * @type {Array} - * @memberof AddressInterpreter# - */ - 'private address' : [], - /** - * Initializes inAttributes. For this class: Latitude and - * Longitude - * - * @protected - * @alias initInAttributes - * @memberof AddressInterpreter# - */ 'protected initInAttributes' : function() { - var latitude = new contactJS.AttributeType() - .withName('latitude').withType('double'); - this.inAttributeTypes.put(latitude); - var longitude = new contactJS.AttributeType() - .withName('longitude').withType('double'); - this.inAttributeTypes.put(longitude); + this.inAttributeTypes.put( + new contactJS.Attribute() + .withName('latitude') + .withType('double') + ); + + this.inAttributeTypes.put( + new contactJS.Attribute() + .withName('longitude') + .withType('double') + ); }, - /** - * Initializes outAttributes. For this class: Address as String - * - * @protected - * @alias initOutAttributes - * @memberof AddressInterpreter# - */ 'protected initOutAttributes' : function() { - var formattedAddress = new contactJS.AttributeType() + this.outAttributeTypes.put( + new contactJS.Attribute() .withName('formattedAddress') - .withType('string'); - this.outAttributeTypes.put(formattedAddress); + .withType('string') + ); }, - /** - * Changes coordinates to address - * - * @protected - * @alias interpretData - * @memberof AddressInterpreter# - * @param {AttributeValueList} _data list of data that should be interpreted - * @param {?function} _function for additional actions, if an asynchronous function is used - */ - 'protected interpretData' : function(_data, _function) { - if(navigator.onLine){ - var self = this; - var lat = _data.getItem('(latitude:double)'); - var lng = _data.getItem('(longitude:double)'); - if (lat.getValue() && lng.getValue()) { - var url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=" - + lat.getValue()+ ","+ lng.getValue()+ "&sensor=false"; - $.getJSON(url, function(json) {self.createAddress(json, self.response, self, _function);}); - } - } else { - alert("Keine Internetverbindung verfuegbar"); - } - }, + 'protected interpretData' : function(_inAttributeValues, _outAttributeValues, _callback) { + var addressValue = _outAttributeValues.getItems()[0]; - /** - * Success function for callback createAddress() used in interpretData(). - * Sets the outAttributes. - * - * @callback - * @private - * @alias response - * @memberof AddressInterpreter# - * @param {AddressInterpreter} self - * @param {?function} _function for additional actions, if an asynchronous function is used - - */ - 'private response' : function(self, _function) { - self.setOutAttribute('formattedAddress','string', self.address["formatted_address"]); - if (_function && typeof(_function) == 'function'){ - _function(); - } - }, + var latitude = _inAttributeValues.getValueForAttributeWithTypeOf(this.inAttributeTypes.getItems()[0]); + var longitude = _inAttributeValues.getValueForAttributeWithTypeOf(this.inAttributeTypes.getItems()[1]); - /** - * Creates the address. - * - * @callback - * @private - * @alias createAddress - * @memberof AddressInterpreter# - * @param {Array} json - * @param {function} _function for additional actions, because an asynchronous function is used - * @param {AddressInterpreter} self for usage in callback - * @param {?function} secondFunction for additional actions, if an asynchronous function is used - */ - 'private createAddress' : function(json, _function, self, secondFunction) { - if (!self.checkStatus(json)){ - alert("Keine Adresse ermittelbar"); + if(navigator.onLine){ + if (latitude && longitude) { + var url = "http://maps.googleapis.com/maps/api/geocode/json?latlng="+latitude+","+longitude+"&sensor=false"; + $.getJSON(url, function(json) { + if (!json["status"] == ("OK")) { + //TODO: handle error case + addressValue.setValue("NO_VALUE"); + } else { + addressValue.setValue(json["results"][0]["formatted_address"]); + } + _callback([addressValue]); + }); + } } else { - self.address['formatted_address'] = self.googleGetAddress(json, self); - _function(self, secondFunction); + //TODO: handle error case + addressValue.setValue("NO_VALUE"); + _callback([addressValue]); } - }, - - /** - * Check status. - * - * @private - * @alias checkStatus - * @memberof AddressInterpreter# - * @param {Array} json - */ - 'private checkStatus' : function(json) { - return json["status"] == "OK"; - - }, - - /** - * Stores address in array. - * - * @private - * @alias googleGetAddress - * @memberof AddressInterpreter# - * @param {Array} json - * @param {AddressInterpreter} self - */ - 'private googleGetAddress' : function(json, - self) { - return json["results"][0]["formatted_address"]; } - }); + }); return AddressInterpreter; - }); \ No newline at end of file + }); \ No newline at end of file diff --git a/js/config.js b/js/config.js index 398dda8..42f3acb 100644 --- a/js/config.js +++ b/js/config.js @@ -12,10 +12,8 @@ requirejs.config({ storage: 'modules/aggregator/storage/storage', aggregator: 'modules/aggregator/aggregator', interpretation: 'modules/aggregator/interpretation', - attributeType: 'modules/attribute/attributeType', - attributeValue: 'modules/attribute/attributeValue', - attributeTypeList: 'modules/attribute/attributeTypeList', - attributeValueList: 'modules/attribute/attributeValueList', + attribute: 'modules/attribute/attribute', + attributeList: 'modules/attribute/attributeList', parameter: 'modules/attribute/parameter', parameterList: 'modules/attribute/parameterList', condition: 'modules/subscriber/condition/condition', diff --git a/js/modules/abstractList.js b/js/modules/abstractList.js index 04a65f0..03d78ed 100644 --- a/js/modules/abstractList.js +++ b/js/modules/abstractList.js @@ -13,8 +13,6 @@ define([ 'easejs' ], function(easejs) { * @requires easejs */ var AbstractList = AbstractClass('AbstractList', { - - /** * @alias items * @protected @@ -83,19 +81,6 @@ define([ 'easejs' ], function(easejs) { */ 'abstract public equals' : [ 'list' ], - /** - * Verifies whether an item exists for the specified key. - * - * @public - * @alias containsKey - * @memberof AbstractList# - * @param {string} _key Key that should be verified. - * @returns {boolean} - */ - 'public containsKey' : function(_key) { - return !!(typeof _key !== 'undefined' && typeof this.items[_key] !== 'undefined'); - }, - /** * Returns the item for the specified key. * @public diff --git a/js/modules/aggregator/aggregator.js b/js/modules/aggregator/aggregator.js index 3c44715..cf4ea5a 100644 --- a/js/modules/aggregator/aggregator.js +++ b/js/modules/aggregator/aggregator.js @@ -6,11 +6,11 @@ * @fileOverview */ define(['easejs', 'MathUuid','widget', - 'attributeType', 'attributeValue', 'attributeValueList', 'subscriber', - 'subscriberList', 'callbackList', 'storage', 'widgetDescription', 'interpreter', 'attributeTypeList', 'interpretation'], - function(easejs, MathUuid, Widget, AttributeType, - AttributeValue, AttributeValueList, Subscriber, SubscriberList, - CallbackList, Storage, WidgetDescription, Interpreter, AttributeTypeList, Interpretation){ + 'attribute', 'attributeList', 'subscriber', + 'subscriberList', 'callbackList', 'storage', 'widgetDescription', 'interpreter', 'interpretation'], + function(easejs, MathUuid, Widget, Attribute, + AttributeList, Subscriber, SubscriberList, + CallbackList, Storage, WidgetDescription, Interpreter, Interpretation){ var Class = easejs.Class; var Aggregator = Class('Aggregator'). @@ -69,8 +69,8 @@ define(['easejs', 'MathUuid','widget', * @requires MathUuid * @requires CallbackList * @requires AttributeType - * @requires AttributeValue - * @requires AttributeValueList + * @requires Attribute + * @requires AttributeList * @requires Subscriber * @requires SubscriberList * @requires Storage @@ -105,13 +105,13 @@ define(['easejs', 'MathUuid','widget', * @protected * @alias addAttributeType * @memberof Aggregator# - * @param {AttributeType} _attributeType attributeType + * @param {AttributeType} _attribute attributeType + * @param {boolean} _multipleInstances */ - 'protected addAttributeType' : function(_attributeType, _multipleInstances){ - if(Class.isA( AttributeType, _attributeType )){ - this.attributeTypes.put(_attributeType, _multipleInstances); - var attVal = new AttributeValue().buildFromAttributeType(_attributeType); - this.attributes.put(attVal, _multipleInstances); + 'protected addAttributeType' : function(_attribute, _multipleInstances){ + if(Class.isA(Attribute, _attribute )){ + this.attributeTypes.put(_attribute, _multipleInstances); + this.attributes.put(_attribute, _multipleInstances); } }, @@ -266,10 +266,10 @@ define(['easejs', 'MathUuid','widget', * @alias setAggregatorAttributeValues * @memberof Aggregator# */ - 'virtual protected setAggregatorAttributeValues' : function(_attributeTypes) { - for (var index in _attributeTypes) { - var theAttributeType = _attributeTypes[index]; - this.addAttribute(new AttributeValue().buildFromAttributeType(theAttributeType)); + 'virtual protected setAggregatorAttributeValues' : function(_attributes) { + for (var index in _attributes) { + var theAttribute = _attributes[index]; + this.addAttribute(theAttribute); } }, @@ -310,7 +310,7 @@ define(['easejs', 'MathUuid','widget', * @returns {AttributeValueList} */ 'public getCurrentData' : function(){ - var response = new AttributeValueList(); + var response = new AttributeList(); response.putAll(this.attributes); return response; }, @@ -420,18 +420,18 @@ define(['easejs', 'MathUuid','widget', * @public * @alias putData * @memberof Aggregator# - * @param {(AttributeValueList|Array)} _data data that shall be input + * @param {(AttributeList|Array)} _data data that shall be input */ 'override public putData' : function(_data){ var list = []; if(_data instanceof Array){ list = _data; - } else if (Class.isA(AttributeValueList, _data)) { + } else if (Class.isA(AttributeList, _data)) { list = _data.getItems(); } for(var i in list){ var x = list[i]; - if(Class.isA( AttributeValue, x ) && this.isAttribute(x)){ + if(Class.isA(Attribute, x ) && this.isAttribute(x)){ this.addAttribute(x); if(this.db){ this.store(x); @@ -613,7 +613,7 @@ define(['easejs', 'MathUuid','widget', * @private * @alias getComponentsForUnsatisfiedAttributeTypes * @memberof Aggregator# - * @param {AttributeTypeList} _unsatisfiedAttributes A list of attributes that components should be searched for. + * @param {AttributeList} _unsatisfiedAttributes A list of attributes that components should be searched for. * @param {boolean} _all If true all attributes must be satisfied by a single component. * @param {Array} _componentTypes An array of components classes that should be searched for (e.g. Widget, Interpreter and Aggregator). */ @@ -643,7 +643,7 @@ define(['easejs', 'MathUuid','widget', // add the attribute type to the aggregators list of handled attribute types if (!this.getAttributeTypes().contains(widgetOutAttribute)) this.addAttributeType(widgetOutAttribute); console.log("I can now satisfy attribute "+widgetOutAttribute+" with the help of "+theComponent.getName()+"! That was easy :)"); - _unsatisfiedAttributes.removeAttributeType(widgetOutAttribute); + _unsatisfiedAttributes.removeAttributeWithTypeOf(widgetOutAttribute); } } else if (Class.isA(Interpreter, theComponent)) { // if the component is an interpreter and all its in attributes can be satisfied, add the interpreter console.log("It's an interpreter."); @@ -660,7 +660,7 @@ define(['easejs', 'MathUuid','widget', // if required attribute is not already satisfied by the aggregator search for components that do if (!this.doesSatisfyAttributeType(theInAttribute)) { console.log("It seems that I can't satisfy "+theInAttribute+", but I will search for components that can."); - var newAttributeList = new AttributeTypeList(); + var newAttributeList = new AttributeList(); newAttributeList.put(theInAttribute); this.getComponentsForUnsatisfiedAttributeTypes(newAttributeList, false, [Widget, Interpreter]); // if the attribute still can't be satisfied drop the interpreter @@ -681,13 +681,13 @@ define(['easejs', 'MathUuid','widget', // add the attribute type to the aggregators list of handled attribute types for (var unsatisfiedAttributeIndex in _unsatisfiedAttributes.getItems()) { var theUnsatisfiedAttribute = _unsatisfiedAttributes.getItems()[unsatisfiedAttributeIndex]; - if (theUnsatisfiedAttribute.equals(interpreterOutAttribute)) { + if (theUnsatisfiedAttribute.equalsTypeOf(interpreterOutAttribute)) { this.addAttributeType(theUnsatisfiedAttribute); console.log("I can now satisfy attribute "+theUnsatisfiedAttribute+" with the help of "+theComponent.getName()+"! Great!"); - this.interpretations.push(new Interpretation(theComponent.getId(), theComponent.getInAttributeTypes(), new AttributeTypeList().withItems([theUnsatisfiedAttribute]))); + this.interpretations.push(new Interpretation(theComponent.getId(), theComponent.getInAttributeTypes(), new AttributeList().withItems([theUnsatisfiedAttribute]))); } } - _unsatisfiedAttributes.removeAttributeType(interpreterOutAttribute, true); + _unsatisfiedAttributes.removeAttributeWithTypeOf(interpreterOutAttribute, true); } } else { console.log("Found interpreter but can't satisfy required attributes."); diff --git a/js/modules/aggregator/interpretation.js b/js/modules/aggregator/interpretation.js index b18b1f0..21a5a10 100644 --- a/js/modules/aggregator/interpretation.js +++ b/js/modules/aggregator/interpretation.js @@ -1,13 +1,13 @@ /** * Created by tobias on 15.04.15. */ -define(['easejs', 'interpreter', 'attributeTypeList'], - function(easejs, Interpreter, AttributeTypeList) { +define(['easejs', 'interpreter', 'attributeList'], + function(easejs, Interpreter, AttributeList) { var Class = easejs.Class; var Interpretation = Class('Interpretation', { 'public interpreterId' : null, - 'public inAttributeTypes' : new AttributeTypeList(), - 'public outAttributeTypes' : new AttributeTypeList(), + 'public inAttributeTypes' : new AttributeList(), + 'public outAttributeTypes' : new AttributeList(), 'public __construct' : function(_interpreterId, _inAttributes, _outAttributes){ this.interpreterId = _interpreterId; diff --git a/js/modules/aggregator/storage/storage.js b/js/modules/aggregator/storage/storage.js index 31d84c3..7ecd5d4 100644 --- a/js/modules/aggregator/storage/storage.js +++ b/js/modules/aggregator/storage/storage.js @@ -5,9 +5,9 @@ * @module Widget * @fileOverview */ -define(['easejs', 'attributeValue', 'attributeValueList', 'attributeType', +define(['easejs', 'attribute', 'attributeList', 'retrievalResult', 'parameter', 'parameterList'], - function( easejs, AttributeValue, AttributeValueList, AttributeType, + function( easejs, Attribute, AttributeList, RetrievalResult, Parameter, ParameterList){ var Class = easejs.Class; var Storage = Class('Storage', @@ -32,7 +32,7 @@ define(['easejs', 'attributeValue', 'attributeValueList', 'attributeType', /** * @alias data * @private - * @type {AttributeValueList} + * @type {AttributeList} * @memberof Storage# * @desc Cache before storing the new data in the database. */ @@ -88,8 +88,8 @@ define(['easejs', 'attributeValue', 'attributeValueList', 'attributeType', * @class Storage * @classdesc Storage handles the access to the database. * @requires easejs - * @requires AttributeValue - * @requires AttributeValueList + * @requires Attribute + * @requires AttributeList * @requires Parameter * @requires ParameterList * @requires RetrievalResult @@ -99,7 +99,7 @@ define(['easejs', 'attributeValue', 'attributeValueList', 'attributeType', 'public __construct' : function(_name, _time, _counter){ this.initStorage(_name); this.attributes = new RetrievalResult(); - this.data = new AttributeValueList(); + this.data = new AttributeList(); this.dataCount = 0; this.lastFlush = new Date(); if(_time && _time === parseInt(_time) && _time!=0) @@ -182,18 +182,18 @@ define(['easejs', 'attributeValue', 'attributeValueList', 'attributeType', * @private * @alias insertIntoTable * @memberof Storage# - * @param {AttributeValue} _attributeValue Attribute that should be stored. + * @param {Attribute} _attribute Attribute that should be stored. * @param {?function} _function For alternative actions, if an asynchronous function is used. */ - 'private insertIntoTable' : function(_attributeValue, _function){ - if(this.db && _attributeValue && Class.isA(AttributeValue, _attributeValue)){ - var tableName = this.tableName(_attributeValue); + 'private insertIntoTable' : function(_attribute, _function){ + if(this.db && _attribute && Class.isA(Attribute, _attribute)){ + var tableName = this.tableName(_attribute); var statement = 'INSERT INTO "' + tableName + '" (value_, type_, created_) VALUES ("' - + _attributeValue.getValue() + '", "' - + _attributeValue.getType() + '", "' - + _attributeValue.getTimestamp() + '")'; - console.log('INSERT INTO "'+tableName+'" VALUES ('+_attributeValue.getValue()+", "+_attributeValue.getType()+", "+_attributeValue.getTimestamp()); + + _attribute.getValue() + '", "' + + _attribute.getType() + '", "' + + _attribute.getTimestamp() + '")'; + console.log('INSERT INTO "'+tableName+'" VALUES ('+_attribute.getValue()+", "+_attribute.getType()+", "+_attribute.getTimestamp()); if(_function && typeof(_function) == 'function'){ this.db.transaction(function(tx){tx.executeSql(statement);}, this.errorCB, _function); } else { @@ -298,7 +298,7 @@ define(['easejs', 'attributeValue', 'attributeValueList', 'attributeType', * @returns {boolean} */ 'private tableExists' : function(_attribute){ - if(Class.isA(AttributeValue, _attribute) || Class.isA(AttributeType, _attribute)){ + if(Class.isA(Attribute, _attribute)){ var name = this.tableName(_attribute); return this.attributeNames.indexOf(name) > -1; } else if(typeof _attribute === 'string'){ @@ -317,11 +317,16 @@ define(['easejs', 'attributeValue', 'attributeValueList', 'attributeType', * @param {?function} _function For additional actions, if an asynchronous function is used. */ 'public retrieveAttributes' : function(_tableName, _function){ + console.log("retrieveAttributes from "+_tableName); + if(this.db){ var self = this; self.flushStorage(); - this.db.transaction(function(_tx){self.queryValues(_tx,_tableName,self, _function);}, - function(error){self.errorCB(error);} ); + this.db.transaction(function(_tx) { + self.queryValues(_tx,_tableName,self, _function); + }, function(error) { + self.errorCB(error); + }); } }, @@ -337,9 +342,10 @@ define(['easejs', 'attributeValue', 'attributeValueList', 'attributeType', * @param {@this} self * @param {?function} _function For additional actions, if an asynchronous function is used. */ - 'private queryValues' : function(_tx,_tableName,self, _function){ - if(self.tableExists(_tableName)){ - var statement = 'SELECT * FROM ' + _tableName; + 'private queryValues' : function(_tx, _tableName, self, _function){ + if(self.tableExists(_tableName)){ + console.log('SELECT * FROM "' +_tableName+"'"); + var statement = 'SELECT * FROM "' + _tableName+'"'; _tx.executeSql(statement, [], function(_tx,results){self.queryValuesSuccess(_tx,results,_tableName, self, _function);}, function(error){self.errorCB(error);}); @@ -368,7 +374,7 @@ define(['easejs', 'attributeValue', 'attributeValueList', 'attributeType', var attributeName = this.resolveAttributeName(_tableName); var parameterList = this.resolveParameters(_tableName); for(var i=0; i<len; i++){ - var attribute = new AttributeValue(). + var attribute = new Attribute(). withName(attributeName).withValue(results.rows.item(i).value_). withType(results.rows.item(i).type_). withTimestamp(results.rows.item(i).created_). @@ -411,11 +417,11 @@ define(['easejs', 'attributeValue', 'attributeValueList', 'attributeType', * @private * @alias addData * @memberof Storage# - * @param {AttributeValue} _attributeValue Value that should be stored. + * @param {Attribute} _attribute Value that should be stored. */ - 'private addData' : function(_attributeValue){ - if(Class.isA(AttributeValue, _attributeValue)){ - this.data.put(_attributeValue); + 'private addData' : function(_attribute){ + if(Class.isA(Attribute, _attribute)){ + this.data.put(_attribute); this.dataCount++; } }, @@ -447,7 +453,7 @@ define(['easejs', 'attributeValue', 'attributeValueList', 'attributeType', * @memberof Storage# */ 'private resetForFlush' : function(){ - this.data = new AttributeValueList(); + this.data = new AttributeList(); this.dataCount = 0; this.lastFlush = new Date(); }, @@ -535,7 +541,7 @@ define(['easejs', 'attributeValue', 'attributeValueList', 'attributeType', * @returns{String} */ 'private tableName' : function(_attribute){ - return _attribute.getAttributeType().toString(); + return _attribute.toString(true); }, /** diff --git a/js/modules/attribute/attribute.js b/js/modules/attribute/attribute.js new file mode 100644 index 0000000..3c81850 --- /dev/null +++ b/js/modules/attribute/attribute.js @@ -0,0 +1,386 @@ +/** + * This module represents an AttributeType. + * AttributeTypes defines name, type (string, double,...) an associated parameter of an attribute. + * + * @module AttributeType + * @fileOverview + */ +define(['easejs', + 'parameterList'], + function(easejs, + ParameterList){ + + /** + * @class Attribute + * @classdesc AttributeValue extends AttributeTypes and adds the associated + * value. + * @requires easejs + * @requires ParameterList + */ + var Class = easejs.Class; + var Attribute = Class('Attribute',{ + /** + * @alias name + * @protected + * @type {string} + * @memberof AttributeType# + * @desc Name of the Attribute + */ + 'protected name' : '', + + /** + * @alias type + * @protected + * @type {string} + * @memberof AttributeType# + * @desc Defines the type of the Attribute (i.e String, Double,...) + */ + 'protected type' : '', + + /** + * @alias parameterList + * @protected + * @type {ParameterList} + * @memberof AttributeType# + * @desc Name of the Attribute + */ + 'protected parameterList' : [], + + /** + * @alias value + * @protected + * @type {string} + * @memberof AttributeValue# + */ + 'protected value' : 'NO_VALUE', + + /** + * @alias timestamp + * @protected + * @type {Date} + * @memberof AttributeValue# + * @desc Time when the value was set. + */ + 'protected timestamp' : '', + + /** + * Constructor: Initializes the ParameterList. + * + * @class AttributeType + * @classdesc AttributeTypes defines name, type (string, double,...) an associated parameter of an attribute. + * @requires easejs + * @requires ParameterList + * @constructs AttributeType + */ + 'public __construct' : function(){ + this.parameterList = new ParameterList(); + }, + + /** + * Builder for name. + * + * @public + * @alias withName + * @memberof AttributeType# + * @param {String} _name Name + * @returns {AttributeType} + */ + 'public withName' : function(_name){ + this.setName(_name); + return this; + }, + + /** + * Builder for type. + * + * @public + * @alias withType + * @memberof AttributeType# + * @param {String} _type Type + * @returns {AttributeType} + */ + 'public withType' : function(_type){ + this.setType(_type); + return this; + }, + + /** + * Builder for one parameter. + * + * @public + * @alias withParameters + * @memberof AttributeType# + * @param {Parameter} _parameter Parameter + * @returns {AttributeType} + */ + 'public withParameter' : function(_parameter){ + this.addParameter(_parameter); + return this; + }, + + /** + * Builder for parameterList. + * + * @public + * @alias withParameters + * @memberof AttributeType# + * @param {(ParameterList|Array)} _parameterList ParameterList + * @returns {AttributeType} + */ + 'public withParameters' : function(_parameterList){ + this.setParameters(_parameterList); + return this; + }, + + /** + * Builder for value. + * + * @public + * @alias withValue + * @memberof AttributeValue# + * @param {String} _value value + * @returns {AttributeValue} + */ + 'public withValue' : function(_value) { + this.setValue(_value); + this.setTimestamp(Date.now()); + return this; + }, + + /** + * Builder for timestamp. + * + * @public + * @alias withTimestamp + * @memberof AttributeValue# + * @param {Date} _timestamp timestamp + * @returns {AttributeValue} + */ + 'public withTimestamp' : function(_timestamp) { + this.setTimestamp(_timestamp); + return this; + }, + + /** + * Returns the name. + * + * @public + * @alias getName + * @memberof AttributeType# + * @returns {string} + */ + 'public getName' : function(){ + return this.name; + }, + + /** + * Returns the type. + * + * @public + * @alias getType + * @memberof AttributeType# + * @returns {string} + */ + 'public getType' : function(){ + return this.type; + }, + + /** + * Returns the parameters. + * + * @public + * @alias getParameters + * @memberof AttributeType# + * @returns {ParameterList} + */ + 'public getParameters' : function(){ + return this.parameterList; + }, + + /** + * Sets the name. + * + * @public + * @alias setName + * @memberof AttributeType# + * @param {string} _name Name + */ + 'public setName' : function(_name){ + if(typeof _name === 'string'){ + this.name = _name; + } + }, + + /** + * Sets the type. + * + * @public + * @alias setType + * @memberof AttributeType# + * @param {string} _type Type + */ + 'public setType' : function(_type){ + if(typeof _type === 'string'){ + this.type = _type; + } + }, + + /** + * Adds a parameter. + * + * @public + * @alias addParameter + * @memberof AttributeType# + * @param {Parameter} _parameter Parameter + */ + 'public addParameter' : function(_parameter){ + this.parameterList.put(_parameter); + }, + + /** + * Adds a list of Parameter. + * + * @public + * @alias setParameters + * @memberof AttributeType# + * @param {ParameterList} _parameters ParameterList + */ + 'public setParameters' : function(_parameters){ + this.parameterList.putAll(_parameters); + }, + + /** + * Returns true if the attribute is parameterized. + * + * @public + * @alias hasParameters + * @memberof Attribute# + * @returns {boolean} + */ + 'public hasParameters' : function() { + return this.parameterList.size() > 0; + }, + + /** + * Sets the value. + * + * @public + * @alias setValue + * @memberof AttributeValue# + * @param {string} _value value + */ + 'public setValue' : function(_value) { + this.value = _value; + }, + + /** + * Returns the value. + * + * @public + * @alias getValue + * @memberof AttributeValue# + * @returns {string} + */ + 'public getValue' : function() { + return this.value; + }, + + /** + * Sets the timestamp. + * + * @public + * @alias setTimestamp + * @memberof AttributeValue# + * @param {Date} _timestamp timestamp + */ + 'public setTimestamp' : function(_time) { + this.timestamp = _time; + }, + + /** + * Returns the timestamp. + * + * @public + * @alias getTimestamp + * @memberof AttributeValue# + * @returns {string} + */ + 'public getTimestamp' : function() { + return this.timestamp; + }, + + /** + * + * @public + * @alias hasInputParameter + * @memberof Attribute# + * @returns {boolean} + */ + 'public hasInputParameter': function() { + return this.hasParameters() && this.parameterList.hasInputParameter(); + }, + + /** + * Compares this instance with the given one. + * + * @public + * @alias equalsTypeOf + * @memberof Attribute# + * @param {Attribute} _attribute Attribute that should be compared. + * @returns {boolean} + */ + 'public equalsTypeOf' : function(_attribute) { + if (Class.isA(Attribute, _attribute)) { + if (this.getName() == _attribute.getName() && this.getType() == _attribute.getType() && this.getParameters().equals(_attribute.getParameters())) { + return true; + } + } + return false; + }, + + /** + * + * + * @public + * @alias equalsValueOf + * @memberof Attribute# + * @param _attribute + * @returns {boolean} + */ + 'public equalsValueOf' : function(_attribute) { + if (Class.isA(Attribute, _attribute)) { + if (this.equalsTypeOf(_attribute) && this.getValue() == _attribute.getValue()) { + return true; + } + } + return false; + }, + + /** + * Returns an identifier that uniquely describes the attribute type and its parameters. + * The identifier can be used to compare two attribute types. <br/> + * Format: (AttributeName:AttributeType)#[FirstParameterName:FirstParameterValue]… + * + * @public + * @alias toString + * @memberof AttributeType# + * @returns {String} + * @example (CI_USER_LOCATION_DISTANCE:FLOAT)#[CP_TARGET_LATITUDE:52][CP_TARGET_LONGITUDE:13][CP_UNIT:KILOMETERS] + */ + 'public toString': function(_typeOnly) { + var identifier = "("+this.name+":"+this.type+")"; + if (this.hasParameters()) { + identifier += "#"; + for (var index in this.parameterList.getItems()) { + var theParameter = this.parameterList.getItems()[index]; + identifier += theParameter.toString(); + } + } + if (!_typeOnly) identifier += ":"+this.getValue(); + return identifier; + } + }); + + return Attribute; + + }); \ No newline at end of file diff --git a/js/modules/attribute/attributeList.js b/js/modules/attribute/attributeList.js new file mode 100644 index 0000000..8fbf583 --- /dev/null +++ b/js/modules/attribute/attributeList.js @@ -0,0 +1,324 @@ +/** + * This module represents an AttributeList. It is a subclass of AbstractList. + * + * @module AttributeList + * @fileOverview + */ +define(['easejs', 'abstractList', 'attribute', 'parameterList' ], + function(easejs, AbstractList, Attribute, ParameterList) { + var Class = easejs.Class; + + /** + * @class AttributeList + * @classdesc This class represents a list for Attribute. + * @extends AbstractList + * @requires easejs + * @requires AbstractList + * @requires Attribute + */ + var AttributeList = Class('AttributeList').extend(AbstractList, { + /** + * @alias items + * @protected + * @type {Array.<Attribute>} + * @memberof AttributeList# + * @desc ItemList + */ + 'protected items' : [], + + /** + * Builder for item list. + * + * @public + * @alias withItems + * @memberof AttributeList# + * @param {(AttributeList)} _attributeList AttributeList + * @returns {AttributeList} + */ + 'public withItems' : function(_attributeList) { + var list = []; + if (_attributeList instanceof Array) { + list = _attributeList; + } else if (Class.isA(AttributeList, _attributeList)) { + list = _attributeList.getItems(); + } + this.items = list; + return this; + }, + + /** + * Adds the specified item to the itemList. + * + * @public + * @alias put + * @memberof AttributeList# + * @param {AttributeType} _attribute AttributeType + * @param {boolean} _multipleInstances + */ + 'public put' : function(_attribute, _multipleInstances) { + _multipleInstances = typeof _multipleInstances == "undefined" ? false : _multipleInstances; + if (Class.isA(Attribute, _attribute)) { + if (_multipleInstances || !(this.containsTypeOf(_attribute))) { + this.items.push(_attribute); + } else { + this.updateValue(_attribute); + } + } + }, + + /** + * Adds all items in the specified list to the + * itemList. + * + * @public + * @alias putAll + * @memberof AttributeList# + * @param {(AttributeList|Array)} _attributeList AttributeList + */ + 'public putAll' : function(_attributeList) { + var list = []; + if (_attributeList instanceof Array) { + list = _attributeList; + } else if (Class.isA(AttributeList, _attributeList)) { + list = _attributeList.getItems(); + } + for ( var i in list) { + this.put(list[i]); + } + }, + + /** + * + * @param {Attribute} _attribute + * @param {?boolean} _typeOnly + * @returns {*} + */ + 'public contains': function(_attribute, _typeOnly) { + _typeOnly = typeof _typeOnly == "undefined" ? false : _typeOnly; + return _typeOnly ? this.containsTypeOf(_attribute) : this.containsValueOf(_attribute); + }, + + /** + * Verifies whether the given item is included + * in this list. + * + * @public + * @alias containsTypeOf + * @memberof AttributeList# + * @param {AttributeType} _attribute AttributeType that should be verified. + * @returns {boolean} + */ + 'public containsTypeOf' : function(_attribute) { + if (Class.isA(Attribute, _attribute)) { + for (var index in this.items) { + var tmp = this.items[index]; + if (tmp.equalsTypeOf(_attribute)) { + return true; + } + } + } + return false; + }, + + /** + * Verifies whether the given item is included + * in the list. + * + * @public + * @alias containsValueOf + * @memberof AttributeList# + * @param {Attribute} _attribute AttributeValue that should be verified. + * @returns {boolean} + */ + 'public containsValueOf' : function(_attribute) { + if (Class.isA(Attribute, _attribute)) { + for (var index in this.items) { + var tmp = this.items[index]; + if (tmp.equalsValueOf(_attribute)) { + return true; + } + } + } + return false; + }, + + 'public equals': function(_attributeList, _typeOnly) { + _typeOnly = typeof _typeOnly == "undefined" ? false : _typeOnly; + return _typeOnly ? this.equalsAllTypesOf(_attributeList) : this.equalsAllValuesOf(_attributeList); + }, + + /** + * Compare the specified AttributeList with this instance. + * + * @public + * @alias equals + * @memberof AttributeList# + * @param {AttributeList} _attributeList AttributeList that should be compared. + * @returns {boolean} + */ + 'public equalsAllTypesOf' : function(_attributeList) { + if (Class.isA(AttributeList, _attributeList) && _attributeList.size() == this.size()) { + for (var index in _attributeList.getItems()) { + var theAttributeType = _attributeList.getItems()[index]; + if (!this.containsTypeOf(theAttributeType)) return false; + } + return true; + } + return false; + }, + + /** + * Compare the specified AttributeList with + * this instance. + * + * @public + * @alias equals + * @memberof AttributeList# + * @param {AttributeList} _attributeList AttributeList that should be compared. + * @returns {boolean} + */ + 'public equalsAllValuesOf' : function(_attributeList) { + if (Class.isA(AttributeList, _attributeList) && _attributeList.size() == this.size()) { + for (var index in _attributeList.getItems()) { + var theAttribute = _attributeList.getItems()[index]; + if (!this.containsValueOf(theAttribute)) return false; + } + return true; + } + return false; + }, + + /** + * Returns only this values that matches to the + * given type. + * + * @public + * @alias getSubset + * @memberof AttributeList# + * @param {(AttributeList|Array)} _attributeList Attributes that should be returned. + * @returns {AttributeList} + */ + 'public getSubset' : function(_attributeList) { + var response = new AttributeList(); + var list = []; + if (_attributeList instanceof Array) { + list = _attributeList; + } else if (Class.isA(AttributeList, _attributeList)) { + list = _attributeList.getItems(); + } + for (var i in list) { + var attribute = list[i]; + if (Class.isA(Attribute, attribute)) { + var attribute = this.getAttributeWithTypeOf(attribute); + if (typeof attribute != "undefined") { + response.put(attribute); + } + } + } + return response; + }, + + /** + * Returns a subset without the given types. + * + * @public + * @alias getSubsetWithoutItems + * @memberof AttributeList# + * @param {(AttributeList|Array)} _attributeList AttributeTypes that should not be included + * @returns {AttributeList} + */ + 'public getSubsetWithoutItems' : function(_attributeList) { + var response = this; + var list = []; + if (_attributeList instanceof Array) { + list = _attributeList; + } else if (Class.isA(AttributeList, _attributeList)) { + list = _attributeList.getItems(); + } + for (var i in list) { + var attribute = list[i]; + if (Class.isA(Attribute, attribute)) { + response.removeAttributeWithTypeOf(attribute); + } + } + return response; + }, + + /** + * Creates a clone of the current list. + * + * @public + * @alias clone + * @memberof AttributeList# + * @returns {AttributeList} + */ + 'public clone': function(_typeOnly) { + var newList = new AttributeList(); + for (var index in this.items) { + var oldAttribute = this.items[index]; + var newAttribute = new Attribute().withName(oldAttribute.getName()).withType(oldAttribute.getType()).withParameters(oldAttribute.getParameters()); + if (!_typeOnly) newAttribute.setValue(oldAttribute.getValue()); + newList.put(newAttribute); + } + return newList; + }, + + 'public removeAttributeWithTypeOf': function(_attribute, _allOccurrences) { + _allOccurrences = typeof _allOccurrences == "undefined" ? false : _allOccurrences; + for (var index in this.items) { + var theAttribute = this.items[index]; + if (theAttribute.equalsTypeOf(_attribute)) { + this.items.splice(index, 1); + } + } + if (_allOccurrences && this.contains(_attribute)) this.removeAttributeWithTypeOf(_attribute, _allOccurrences); + }, + + 'public hasAttributesWithInputParameters': function() { + for (var index in this.items) { + var theAttribute = this.items[index]; + if (theAttribute.hasInputParameter()) return true; + } + return false; + }, + + 'public getAttributesWithInputParameters': function() { + var list = new AttributeList(); + for (var index in this.items) { + var theAttribute = this.items[index]; + if (theAttribute.hasInputParameter()) list.put(theAttribute); + } + return list; + }, + + /** + * Returns the attribute value that matches the provided attribute type. + * + * @public + * @alias getValueForAttributeWithTypeOf + * @memberof AttributeList# + * @param {AttributeType} _attribute + * @returns {Attribute} + */ + 'public getValueForAttributeWithTypeOf': function(_attribute) { + return this.getAttributeWithTypeOf(_attribute).getValue(); + }, + + 'public getAttributeWithTypeOf': function(_attribute) { + for (var index in this.getItems()) { + var theAttribute = this.getItems()[index]; + if (theAttribute.equalsTypeOf(_attribute)) return theAttribute; + } + }, + + 'public updateValue': function(_attribute) { + for (var index in this.items) { + var theAttribute = this.items[index]; + if (theAttribute.equalsTypeOf(_attribute)) this.items[index] = _attribute; + } + } + + }); + + return AttributeList; +}); \ No newline at end of file diff --git a/js/modules/attribute/attributeType.js b/js/modules/attribute/attributeType.js deleted file mode 100644 index 18f78b3..0000000 --- a/js/modules/attribute/attributeType.js +++ /dev/null @@ -1,251 +0,0 @@ -/** - * This module represents an AttributeType. - * AttributeTypes defines name, type (string, double,...) an associated parameter of an attribute. - * - * @module AttributeType - * @fileOverview - */ -define(['easejs', - 'parameterList'], - function(easejs, - ParameterList){ - var Class = easejs.Class; - var AttributeType = Class('AttributeType',{ - /** - * @alias name - * @protected - * @type {string} - * @memberof AttributeType# - * @desc Name of the Attribute - */ - 'protected name' : '', - /** - * @alias type - * @protected - * @type {string} - * @memberof AttributeType# - * @desc Defines the type of the Attribute (i.e String, Double,...) - */ - 'protected type' : '', - /** - * @alias parameterList - * @protected - * @type {ParameterList} - * @memberof AttributeType# - * @desc Name of the Attribute - */ - 'protected parameterList' : [], - - /** - * Constructor: Initializes the ParameterList. - * - * @class AttributeType - * @classdesc AttributeTypes defines name, type (string, double,...) an associated parameter of an attribute. - * @requires easejs - * @requires ParameterList - * @constructs AttributeType - */ - 'public __construct' : function(){ - this.parameterList = new ParameterList(); - }, - - /** - * Builder for name. - * - * @public - * @alias withName - * @memberof AttributeType# - * @param {String} _name Name - * @returns {AttributeType} - */ - 'public withName' : function(_name){ - this.setName(_name); - return this; - }, - - /** - * Builder for type. - * - * @public - * @alias withType - * @memberof AttributeType# - * @param {String} _type Type - * @returns {AttributeType} - */ - 'public withType' : function(_type){ - this.setType(_type); - return this; - }, - - /** - * Builder for parameterList. - * - * @public - * @alias withParameters - * @memberof AttributeType# - * @param {(ParameterList|Array)} _parameterList ParameterList - * @returns {AttributeType} - */ - 'public withParameters' : function(_parameterList){ - this.setParameters(_parameterList); - return this; - }, - - /** - * Builder for one parameter. - * - * @public - * @alias withParameters - * @memberof AttributeType# - * @param {Parameter} _parameter Parameter - * @returns {AttributeType} - */ - 'public withParameter' : function(_parameter){ - this.addParameter(_parameter); - return this; - }, - - /** - * Returns the name. - * - * @public - * @alias getName - * @memberof AttributeType# - * @returns {string} - */ - 'public getName' : function(){ - return this.name; - }, - - /** - * Returns the type. - * - * @public - * @alias getType - * @memberof AttributeType# - * @returns {string} - */ - 'public getType' : function(){ - return this.type; - }, - - /** - * Returns the parameters. - * - * @public - * @alias getParameters - * @memberof AttributeType# - * @returns {ParameterList} - */ - 'public getParameters' : function(){ - return this.parameterList; - }, - - /** - * Sets the name. - * - * @public - * @alias setName - * @memberof AttributeType# - * @param {string} _name Name - */ - 'public setName' : function(_name){ - if(typeof _name === 'string'){ - this.name = _name; - } - }, - - /** - * Sets the type. - * - * @public - * @alias setType - * @memberof AttributeType# - * @param {string} _type Type - */ - 'public setType' : function(_type){ - if(typeof _type === 'string'){ - this.type = _type; - } - }, - - /** - * Adds a parameter. - * - * @public - * @alias addParameter - * @memberof AttributeType# - * @param {Parameter} _parameter Parameter - */ - 'public addParameter' : function(_parameter){ - this.parameterList.put(_parameter); - }, - - /** - * Adds a list of Parameter. - * - * @public - * @alias setParameters - * @memberof AttributeType# - * @param {ParameterList} _parameters ParameterList - */ - 'public setParameters' : function(_parameters){ - this.parameterList.putAll(_parameters); - }, - - 'public hasParameters' : function() { - return this.parameterList.size() > 0; - }, - - /** - * Compares this instance with the given one. - * - * @virtual - * @public - * @alias equals - * @memberof AttributeType# - * @param {AttributeType} _attributeType AttributeType that should be compared - * @returns {boolean} - */ - 'virtual public equals' : function(_attributeType) { - if (Class.isA(AttributeType, _attributeType)) { - if (this.getName() == _attributeType.getName() && - this.getType() == _attributeType.getType() && - this.getParameters().equals(_attributeType.getParameters())) - return true; - } - return false; - }, - - 'public hasInputParameter': function() { - return this.hasParameters() && this.parameterList.hasInputParameter(); - }, - - /** - * Returns an identifier that uniquely describes the attribute type and its parameters. - * The identifier can be used to compare two attribute types. <br/> - * Format: (AttributeName:AttributeType)#[FirstParameterName:FirstParameterValue]… - * - * @public - * @alias toString - * @memberof AttributeType# - * @returns {String} - * @example (CI_USER_LOCATION_DISTANCE:FLOAT)#[CP_TARGET_LATITUDE:52][CP_TARGET_LONGITUDE:13][CP_UNIT:KILOMETERS] - */ - 'virtual public toString': function() { - var identifier = "("+this.name+":"+this.type+")"; - if (this.hasParameters()) { - identifier += "#"; - for (var index in this.parameterList.getItems()) { - var theParameter = this.parameterList.getItems()[index]; - identifier += theParameter.toString(); - } - } - return identifier; - } - - }); - - return AttributeType; - -}); \ No newline at end of file diff --git a/js/modules/attribute/attributeTypeList.js b/js/modules/attribute/attributeTypeList.js deleted file mode 100644 index d720139..0000000 --- a/js/modules/attribute/attributeTypeList.js +++ /dev/null @@ -1,181 +0,0 @@ -/** - * This module represents an AttributeTypeList. It is a subclass of AbstractList. - * - * @module AttributeTypeList - * @fileOverview - */ -define([ 'easejs', 'abstractList', 'attributeType', 'parameterList' ], - function(easejs, AbstractList, AttributeType, ParameterList) { - var Class = easejs.Class; - /** - * @class AttributeTypeList - * @classdesc This class represents a list for AttributeType. - * @extends AbstractList - * @requires easejs - * @requires AbstractList - * @requires AttributeType - */ - var AttributeTypeList = Class('AttributeTypeList').extend(AbstractList, { - - /** - * @alias items - * @protected - * @type {AttributeTypeList} - * @memberof AttributeTypeList# - * @desc ItemList - */ - 'protected items' : [], - - /** - * Builder for item list. - * - * @public - * @alias withItems - * @memberof AttributeTypeList# - * @param {(AttributeTypeList)} _attributeTypeList AttributeTypeList - * @returns {AttributeTypeList} - */ - 'public withItems' : function(_attributeTypeList) { - var list = []; - if (_attributeTypeList instanceof Array) { - list = _attributeTypeList; - } else if (Class.isA(AttributeTypeList, _attributeTypeList)) { - list = _attributeTypeList.getItems(); - } - this.items = list; - return this; - }, - - /** - * Adds the specified item to the itemList. - * - * @public - * @alias put - * @memberof AttributeTypeList# - * @param {AttributeType} _attributeType AttributeType - */ - 'public put' : function(_attributeType, _multipleInstances) { - var _multipleInstances = typeof _multipleInstances == "undefined" ? false : _multipleInstances; - if (Class.isA(AttributeType, _attributeType)) { - if (_multipleInstances || !(this.contains(_attributeType))) { - this.items.push(_attributeType); - } - } - }, - - /** - * Adds all items in the specified list to the - * itemList. - * - * @public - * @alias putAll - * @memberof AttributeTypeList# - * @param {(AttributeTypeList|Array)} _attributeTypeList AttributeTypeList - */ - 'public putAll' : function(_attributeTypeList) { - var list = []; - if (_attributeTypeList instanceof Array) { - list = _attributeTypeList; - } else if (Class.isA(AttributeTypeList, _attributeTypeList)) { - list = _attributeTypeList.getItems(); - } - for ( var i in list) { - this.put(list[i]); - } - }, - - /** - * Verifies whether the given item is included - * in this list. - * - * @public - * @alias contains - * @memberof AttributeTypeList# - * @param {AttributeType} _item AttributeType that should be verified. - * @returns {boolean} - */ - 'public contains' : function(_item) { - if (Class.isA(AttributeType, _item)) { - for (var index in this.items) { - var tmp = this.items[index]; - if (tmp.equals(_item)) { - return true; - } - } - } - return false; - }, - - - /** - * Compare the specified AttributeTypeList with this instance. - * - * @public - * @alias equals - * @memberof AttributeTypeList# - * @param {AttributeTypeList} _list AttributeTypeList that should be compared. - * @returns {boolean} - */ - 'public equals' : function(_list) { - if (Class.isA(AttributeTypeList, _list) && _list.size() == this.size()) { - for (var index in _list.getItems()) { - var theAttributeType = _list.getItems()[index]; - if (!this.contains(theAttributeType)) return false; - } - return true; - } - return false; - }, - - /** - * Creates a clone of the current list. - * - * @public - * @alias clone - * @memberof AttributeTypeList# - * @returns {AttributeTypeList} - */ - 'public clone': function() { - var newList = new AttributeTypeList(); - for (var index in this.items) { - var oldAttributeType = this.items[index]; - var newAttributeType = new AttributeType(). - withName(oldAttributeType.getName()). - withType(oldAttributeType.getType()). - withParameters(oldAttributeType.getParameters()); - newList.put(newAttributeType); - } - return newList; - }, - - 'public removeAttributeType': function(_attributeType, _allOccurrences) { - _allOccurrences = typeof _allOccurrences == "undefined" ? false : _allOccurrences; - for (var index in this.items) { - var theAttributeType = this.items[index]; - if (theAttributeType.equals(_attributeType)) { - this.items.splice(index, 1); - } - } - if (_allOccurrences && this.contains(_attributeType)) this.removeAttributeType(_attributeType, _allOccurrences); - }, - - 'public hasAttributesWithInputParameters': function() { - for (var index in this.items) { - var theAttributeType = this.items[index]; - if (theAttributeType.hasInputParameter()) return true; - } - return false; - }, - - 'public getAttributesWithInputParameters': function() { - var list = new AttributeTypeList(); - for (var index in this.items) { - var theAttributeType = this.items[index]; - if (theAttributeType.hasInputParameter()) list.put(theAttributeType); - } - return list; - } - }); - - return AttributeTypeList; - }); \ No newline at end of file diff --git a/js/modules/attribute/attributeValue.js b/js/modules/attribute/attributeValue.js deleted file mode 100644 index 9fa6abb..0000000 --- a/js/modules/attribute/attributeValue.js +++ /dev/null @@ -1,179 +0,0 @@ -/** - * This module represents an AttributeValue. AttributeValue extends - * AttributeTypes and adds the associated value. - * - * @module AttributeValue - * @fileOverview - */ -define([ 'easejs', 'attributeType' ], function(easejs, AttributeType) { - var Class = easejs.Class; - - /** - * @class AttributeValue - * @classdesc AttributeValue extends AttributeTypes and adds the associated - * value. - * @requires easejs - * @requires AttributeType - */ - var AttributeValue = Class('AttributeValue').extend( - AttributeType, - { - /** - * @alias value - * @protected - * @type {string} - * @memberof AttributeValue# - */ - 'protected value' : '', - /** - * @alias timestamp - * @protected - * @type {Date} - * @memberof AttributeValue# - * @desc Time when the value was set. - */ - 'protected timestamp' : '', - - /** - * Builder for value. - * - * @public - * @alias withValue - * @memberof AttributeValue# - * @param {String} _value value - * @returns {AttributeValue} - */ - 'public withValue' : function(_value) { - this.setValue(_value); - this.setTimestamp(Date.now()); - return this; - }, - - /** - * Builder for timestamp. - * - * @public - * @alias withTimestamp - * @memberof AttributeValue# - * @param {Date} _timestamp timestamp - * @returns {AttributeValue} - */ - 'public withTimestamp' : function(_timestamp) { - this.setTimestamp(_timestamp); - return this; - }, - - /** - * Sets the value. - * - * @public - * @alias setValue - * @memberof AttributeValue# - * @param {string} _value value - */ - 'public setValue' : function(_value) { - this.value = _value; - }, - - /** - * Returns the value. - * - * @public - * @alias getValue - * @memberof AttributeValue# - * @returns {string} - */ - 'public getValue' : function() { - return this.value; - }, - - /** - * Sets the timestamp. - * - * @public - * @alias setTimestamp - * @memberof AttributeValue# - * @param {Date} _timestamp timestamp - */ - 'public setTimestamp' : function(_time) { - this.timestamp = _time; - }, - - /** - * Returns the timestamp. - * - * @public - * @alias getTimestamp - * @memberof AttributeValue# - * @returns {string} - */ - 'public getTimestamp' : function() { - return this.timestamp; - }, - - /** - * Compares this instance with the given one. - * - * @public - * @alias equals - * @memberof AttributeValue# - * @param {AttributeValue} _attributeValue AttributeValue that should be compared - * @returns {boolean} - */ - 'override public equals' : function(_attributeValue) { - if (Class.isA(AttributeValue, _attributeValue)) { - if (_attributeValue.getAttributeType().equals(this.getAttributeType()) && - _attributeValue.getValue() == this.getValue()) { - return true; - } - } - return false; - }, - - /** - * Returns the AttributeType of an AttributeValue. - * - * @public - * @alias getAttributeType - * @memberof AttributeValue# - * @returns {AttributeType} - */ - 'public getAttributeType' : function() { - return new AttributeType().withName(this.name) - .withType(this.type).withParameters( - this.parameterList); - }, - - /** - * Builds a new AttributeValue from the given type. - * - * @public - * @alias buildFromAttributeType - * @memberof AttributeValue# - * @param {AttributeType} _attributeType AttributeType for build process. - * @returns {AttributeValue} - */ - 'public buildFromAttributeType' : function(_attributeType) { - if (Class.isA(AttributeType, _attributeType)) { - return new AttributeValue().withName(_attributeType.getName()) - .withType(_attributeType.getType()).withParameters(_attributeType.getParameters()).withValue('NO_VALUE'); - } - return null; - }, - - /** - * Returns a string that describes the attribute type and its value. - * - * @public - * @override - * @alias toString - * @memberof AttributeValue# - * @returns {string} - */ - 'override public toString': function() { - return this.__super().toString()+":"+this.getValue(); - } - }); - - return AttributeValue; -}); \ No newline at end of file diff --git a/js/modules/attribute/attributeValueList.js b/js/modules/attribute/attributeValueList.js deleted file mode 100644 index 5280c6c..0000000 --- a/js/modules/attribute/attributeValueList.js +++ /dev/null @@ -1,240 +0,0 @@ -/** - * This module represents a AttributeValueList. It is a subclass of - * AbstractList. - * - * @module AttributeValueList - * @fileOverview - */ -define(['easejs', 'abstractList', 'attributeValue', 'attributeType', 'attributeTypeList', 'parameterList'], - function(easejs, AbstractList, AttributeValue, AttributeType, AttributeTypeList, ParameterList) { - var Class = easejs.Class; - - /** - * @class AttributeValueList - * @classdesc This class represents a list for AttributeValue. - * @extends AbstractList - * @requires easejs - * @requires AbstractList - * @requires AttributeValue - * @requires AttributeType - * @requires AttributeTypeList) - */ - var AttributeValueList = Class('AttributeValueList').extend(AbstractList,{ - - /** - * @alias items - * @protected - * @type {AttributeValueList} - * @memberof AttributeValueList# - * @desc ItemList. - */ - 'protected items' : [], - - /** - * Builder for item list. - * - * @public - * @alias withItems - * @memberof AttributeValueList# - * @param {(AttributeValueListst|Array)} _attributeValueList AttributeValueList - * @returns {AttributeValueList} - */ - 'public withItems' : function(_attributeValueList) { - var list = []; - if (_attributeValueList instanceof Array) { - list = _attributeValueList; - } else if (Class.isA(AttributeValueList, - _attributeValueList)) { - list = _attributeValueList.getItems(); - } - this.items = list; - return this; - }, - - /** - * Add the specified item to this itemList. - * - * @public - * @alias put - * @memberof AttributeValueList# - * @param {AttributeValue} _attributeValue AttributeValue - */ - 'public put' : function(_attributeValue, _multipleInstances) { - if (Class.isA(AttributeValue, _attributeValue)) { - if (_multipleInstances || !(this.containsAttributeType(_attributeValue.getAttributeType()))) { - this.items.push(_attributeValue); - } else { - this.updateValue(_attributeValue); - } - } - }, - - /** - * Adds all items in the specified list to this. - * itemList - * - * @public - * @alias putAll - * @memberof AttributeValueList# - * @param {AttributeValueList} _attributeValueList AttributeValueList - */ - 'public putAll' : function(_attributeValueList) { - var list = []; - if (_attributeValueList instanceof Array) { - list = _attributeValueList; - } else if (Class.isA(AttributeValueList, _attributeValueList)) { - list = _attributeValueList.getItems(); - } - for (var i in list) { - this.put(list[i]); - } - }, - - /** - * Verifies whether the given item is included - * in the list. - * - * @public - * @alias contains - * @memberof AttributeValueList# - * @param {AttributeValue} _attributeValue AttributeValue that should be verified. - * @returns {boolean} - */ - 'public contains' : function(_attributeValue) { - if (Class.isA(AttributeValue, _attributeValue)) { - for (var index in this.items) { - var tmp = this.items[index]; - if (tmp.equals(_attributeValue)) { - return true; - } - } - } - return false; - }, - - 'public containsAttributeType': function(_attributeType) { - if (Class.isA(AttributeType, _attributeType)) { - for (var index in this.items) { - var tmp = this.items[index].getAttributeType(); - if (tmp.equals(_attributeType)) { - return true; - } - } - } - return false; - }, - - /** - * Compare the specified AttributeValueList with - * this instance. - * - * @public - * @alias equals - * @memberof AttributeValueList# - * @param {AttributeValueList} _list AttributeValueList that should be compared. - * @returns {boolean} - */ - 'public equals' : function(_list) { - if (Class.isA(AttributeValueList, _list) && _list.size() == this.size()) { - for (var index in _list.getItems()) { - var theAttributeValue = _list.getItems()[index]; - if (!this.contains(theAttributeValue)) return false; - } - return true; - } - return false; - }, - - /** - * Returns only this values that matches to the - * given type. - * - * @public - * @alias getSubset - * @memberof AttributeValueList# - * @param {(AttributeTypeList|Array)} _attributeTypeList AttributeTypes that should be returned. - * @returns {AttributeValueList} - */ - 'public getSubset' : function(_attributeTypeList) { - var response = new AttributeValueList(); - var list = []; - if (_attributeTypeList instanceof Array) { - list = _attributeTypeList; - } else if (Class.isA(AttributeTypeList, _attributeTypeList)) { - list = _attributeTypeList.getItems(); - } - for ( var i in list) { - var attributeType = list[i]; - if (Class.isA(AttributeType, attributeType)) { - var attribute = this.getValueObjectForAttributeType(attributeType); - if (typeof attribute != "undefined") { - response.put(attribute); - } - } - } - return response; - }, - - /** - * Returns a subset without the given types. - * - * @public - * @alias getSubsetWithoutItems - * @memberof AttributeValueList# - * @param {(AttributeTypeList|Array)} _attributeTypeList AttributeTypes that should not be included - * @returns {AttributeValueList} - */ - 'public getSubsetWithoutItems' : function(_attributeTypeList) { - var response = this; - var list = []; - if (_attributeTypeList instanceof Array) { - list = _attributeTypeList; - } else if (Class.isA(AttributeTypeList, _attributeTypeList)) { - list = _attributeTypeList.getItems(); - } - for (var i in list) { - var attributeType = list[i]; - if (Class.isA(AttributeType, attributeType)) { - response.removeAttributeValuesWithAttributeType(attributeType); - } - } - return response; - }, - - /** - * Returns the attribute value that matches the provided attribute type. - * - * @public - * @alias getValueForAttributeType - * @memberof AttributeValueList# - * @param {AttributeType} _attributeType - * @returns {AttributeValue} - */ - 'public getValueForAttributeType': function(_attributeType) { - return this.getValueObjectForAttributeType(_attributeType).getValue(); - }, - - 'public getValueObjectForAttributeType': function(_attributeType) { - for (var index in this.getItems()) { - var theAttributeValue = this.getItems()[index]; - if (theAttributeValue.getAttributeType().equals(_attributeType)) return theAttributeValue; - } - }, - - 'public removeAttributeValuesWithAttributeType': function(_attributeType) { - for (var index in this.items) { - var theAttributeValue = this.items[index]; - if (theAttributeValue.getAttributeType().equals(_attributeType)) this.items.splice(index, 1); - } - }, - - 'public updateValue': function(_attributeValue) { - for (var index in this.items) { - var theAttributeValue = this.items[index]; - if (theAttributeValue.getAttributeType().equals(_attributeValue.getAttributeType())) this.items[index] = _attributeValue; - } - } - }); - - return AttributeValueList; - }); \ No newline at end of file diff --git a/js/modules/attribute/parameterList.js b/js/modules/attribute/parameterList.js index a78daa1..ba9f5fc 100644 --- a/js/modules/attribute/parameterList.js +++ b/js/modules/attribute/parameterList.js @@ -15,8 +15,7 @@ define([ 'easejs', 'abstractList', 'parameter' ], * @requires AbstractList * @requires Parameter */ - var ParameterList = Class('ParameterList').extend(AbstractList,{ - + var ParameterList = Class('ParameterList').extend(AbstractList, { /** * @alias counter * @protected diff --git a/js/modules/descriptions/interpreterDescription.js b/js/modules/descriptions/interpreterDescription.js index afb433f..1e5b45a 100644 --- a/js/modules/descriptions/interpreterDescription.js +++ b/js/modules/descriptions/interpreterDescription.js @@ -5,8 +5,8 @@ * @module InterpreterDescription * @fileOverview */ -define(['easejs','attributeTypeList','widgetDescription'], - function(easejs,AttributeTypeList,WidgetDescription){ +define(['easejs','attributeList', 'widgetDescription'], + function(easejs,AttributeList, WidgetDescription){ var Class = easejs.Class; var InterpreterDescription = Class('InterpreterDescription'). extend(WidgetDescription, { @@ -27,13 +27,13 @@ define(['easejs','attributeTypeList','widgetDescription'], * @classdesc The description of an interpreter and the communication with it. * @extends WidgetDescription * @requires easejs - * @requires AttributeTypeList + * @requires AttributeList * @requires WidgetDescription * @constructs InterpreterDescription */ 'override public __construct' : function(){ this.__super(); - this.inAttributeTypes = new AttributeTypeList(); + this.inAttributeTypes = new AttributeList(); }, /** @@ -42,7 +42,7 @@ define(['easejs','attributeTypeList','widgetDescription'], * @public * @alias withInAttributeTypes * @memberof InterpreterDescription# - * @param {(AttributeTypeList|Array)} _inAttributeTypes List of AttributeType that are expected + * @param {(AttributeList|Array)} _inAttributeTypes List of AttributeType that are expected * @returns {InterpreterDescription} */ 'public withInAttributeTypes' : function(_inAttributeTypes){ diff --git a/js/modules/descriptions/widgetDescription.js b/js/modules/descriptions/widgetDescription.js index f6db9b3..c930e05 100644 --- a/js/modules/descriptions/widgetDescription.js +++ b/js/modules/descriptions/widgetDescription.js @@ -5,8 +5,8 @@ * @module WidgetDescription * @fileOverview */ -define(['easejs', 'attributeTypeList'], - function(easejs, AttributeTypeList){ +define(['easejs', 'attributeList'], + function(easejs, AttributeList){ var Class = easejs.Class; var WidgetDescription = Class('WidgetDescription',{ @@ -54,7 +54,7 @@ define(['easejs', 'attributeTypeList'], * @constructs WidgetDescription */ 'virtual public __construct' : function(){ - this.outAttributeTypes = new AttributeTypeList(); + this.outAttributeTypes = new AttributeList(); }, /** diff --git a/js/modules/discoverer/discoverer.js b/js/modules/discoverer/discoverer.js index d3bd672..967f314 100644 --- a/js/modules/discoverer/discoverer.js +++ b/js/modules/discoverer/discoverer.js @@ -4,8 +4,8 @@ * @module Discoverer * @fileOverview */ -define([ 'easejs', 'attributeTypeList', 'widget', 'interpreter', 'aggregator' ], function(easejs, - AttributeTypeList, Widget, Interpreter, Aggregator) { +define([ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggregator' ], function(easejs, + AttributeList, Widget, Interpreter, Aggregator) { var Class = easejs.Class; var Discoverer = Class('Discoverer', { @@ -311,7 +311,7 @@ define([ 'easejs', 'attributeTypeList', 'widget', 'interpreter', 'aggregator' ], if (typeof _componentTypes == "undefined") _componentTypes = [Widget, Interpreter, Aggregator]; if (_attributeTypeList instanceof Array) { list = _attributeTypeList; - } else if (Class.isA(AttributeTypeList, _attributeTypeList)) { + } else if (Class.isA(AttributeList, _attributeTypeList)) { list = _attributeTypeList.getItems(); } if (typeof list != "undefined") { diff --git a/js/modules/interpreter/interpreter.js b/js/modules/interpreter/interpreter.js index 1342d95..05a02a4 100644 --- a/js/modules/interpreter/interpreter.js +++ b/js/modules/interpreter/interpreter.js @@ -4,10 +4,10 @@ * @module Interpreter * @fileOverview */ -define([ 'easejs', 'MathUuid', 'attributeType', 'attributeTypeList', - 'attributeValue', 'attributeValueList', 'interpreterDescription', 'interpreterResult' ], - function(easejs, MathUuid, AttributeType, AttributeTypeList, - AttributeValue, AttributeValueList, InterpreterDescription, InterpreterResult) { +define([ 'easejs', 'MathUuid', 'attribute', 'attributeList', + 'interpreterDescription', 'interpreterResult' ], + function(easejs, MathUuid, Attribute, AttributeList, + InterpreterDescription, InterpreterResult) { var Class = easejs.Class; var AbstractClass = easejs.AbstractClass; var Interpreter = AbstractClass('Interpreter', @@ -31,7 +31,7 @@ define([ 'easejs', 'MathUuid', 'attributeType', 'attributeTypeList', /** * @alias inAttributeTypes * @protected - * @type {AttributeTypeList} + * @type {AttributeList} * @memberof Interpreter# * @desc Types of all attributes that can be handled. */ @@ -39,7 +39,7 @@ define([ 'easejs', 'MathUuid', 'attributeType', 'attributeTypeList', /** * @alias outAttributeTypes * @protected - * @type {AttributeTypeList} + * @type {AttributeList} * @memberof Interpreter# * @desc Types of all attributes that will be returned. */ @@ -47,7 +47,7 @@ define([ 'easejs', 'MathUuid', 'attributeType', 'attributeTypeList', /** * @alias inAttributeValues * @protected - * @type {AttributeValueList} + * @type {AttributeList} * @memberof Interpreter# * @desc List of the data that should be interpreted. */ @@ -55,7 +55,7 @@ define([ 'easejs', 'MathUuid', 'attributeType', 'attributeTypeList', /** * @alias outAttributeValues * @protected - * @type {AttributeValueList} + * @type {AttributeList} * @memberof Interpreter# * @desc List of interpreted data. */ @@ -85,10 +85,8 @@ define([ 'easejs', 'MathUuid', 'attributeType', 'attributeTypeList', * @classdesc The Widget handles the access to sensors. * @requires easejs * @requires MathUuid - * @requires AttributeType - * @requires AttributeValue - * @requires AttributeTypeList - * @requires AttributeValueList + * @requires Attribute + * @requires AttributeList * @requires InterpreterDescription * @constructs Interpreter */ @@ -96,10 +94,10 @@ define([ 'easejs', 'MathUuid', 'attributeType', 'attributeTypeList', this.id = Math.uuid(); this.discoverer = _discoverer; this.register(); - this.inAttributeTypes = new AttributeTypeList(); - this.outAttributeTypes = new AttributeTypeList(); - this.inAttributeValues = new AttributeValueList(); - this.outAttributeValues = new AttributeValueList(); + this.inAttributeTypes = new AttributeList(); + this.outAttributeTypes = new AttributeList(); + this.inAttributeValues = new AttributeList(); + this.outAttributeValues = new AttributeList(); this.initInterpreter(); }, @@ -197,7 +195,7 @@ define([ 'easejs', 'MathUuid', 'attributeType', 'attributeTypeList', * @param {ParameterList|Array} _parameter Parameter of the attribute. */ 'protected setInAttribute' : function(_name, _type, _value, _parameters) { - var attributeValue = new AttributeValue().withName(_name) + var attributeValue = new Attribute().withName(_name) .withValue(_value).withType(_type).withParameters(_parameters); if (this.isInAttribute(attributeValue)) { this.inAttributeValues.put(attributeValue); @@ -210,10 +208,10 @@ define([ 'easejs', 'MathUuid', 'attributeType', 'attributeTypeList', * @protected * @alias setInAttributeValues * @memberof Interpreter# - * @param {(AttributeValueList|Array)} _attributeValueList Attributes to set. + * @param {(AttributeList|Array)} _attributeList Attributes to set. */ - 'protected setInAttributeValues' : function(_attributeValueList) { - this.inAttributeValues = new AttributeValueList().withItems(_attributeValueList); + 'protected setInAttributeValues' : function(_attributeList) { + this.inAttributeValues = new AttributeList().withItems(_attributeList); }, /** * Verifies whether the specified attribute is contained in inAttributeList. @@ -225,7 +223,7 @@ define([ 'easejs', 'MathUuid', 'attributeType', 'attributeTypeList', * @return {boolean} */ 'protected isInAttribute' : function(_attribute) { - return !!this.inAttributeTypes.contains(_attribute.getAttributeType()); + return !!this.inAttributeTypes.containsTypeOf(_attribute); }, /** @@ -269,7 +267,7 @@ define([ 'easejs', 'MathUuid', 'attributeType', 'attributeTypeList', * @return {boolean} */ 'protected isOutAttribute' : function(_attribute) { - return !!this.outAttributeTypes.contains(_attribute.getAttributeType()); + return !!this.outAttributeTypes.containsTypeOf(_attribute); }, /** @@ -278,19 +276,20 @@ define([ 'easejs', 'MathUuid', 'attributeType', 'attributeTypeList', * @public * @alias callInterpreter * @memberof Interpreter# - * @param {AttributeValueList} _inAttributeValues Data that should be interpreted. + * @param {AttributeList} _inAttributeValues Data that should be interpreted. + * @param {AttributeList} _outAttributeValues * @param {?function} _function For additional actions, if an asynchronous function is used. */ 'public callInterpreter' : function(_inAttributeValues, _outAttributeValues, _function) { var self = this; - if (!_inAttributeValues || !this.canHandleInAttributeValues(_inAttributeValues)) throw "Empty input attribute list or unhandled input attribute."; - if (!_outAttributeValues || !this.canHandleOutAttributeValues(_outAttributeValues)) throw "Empty output attribute list or unhandled output attribute."; + if (!_inAttributeValues || !this.canHandleInAttributes(_inAttributeValues)) throw "Empty input attribute list or unhandled input attribute."; + if (!_outAttributeValues || !this.canHandleOutAttributes(_outAttributeValues)) throw "Empty output attribute list or unhandled output attribute."; this.interpretData(_inAttributeValues, _outAttributeValues, function(interpretedData) { - var response = new AttributeValueList().withItems(interpretedData); + var response = new AttributeList().withItems(interpretedData); - if (!self.canHandleOutAttributeValues(response)) throw "Unhandled output attribute generated."; + if (!self.canHandleOutAttributes(response)) throw "Unhandled output attribute generated."; self.setInAttributeValues(_inAttributeValues); self.lastInterpretation = new Date(); @@ -309,27 +308,27 @@ define([ 'easejs', 'MathUuid', 'attributeType', 'attributeTypeList', * @public * @alias interpretData * @memberof Interpreter# - * @param {AttributeValueList} _data Data that should be interpreted. + * @param {AttributeList} _data Data that should be interpreted. * @param {?function} _function For additional actions, if an asynchronous function is used. */ - 'abstract protected interpretData' : ['_inAttributeValues', '_outAttributeValues', '_callback'], + 'abstract protected interpretData' : ['_inAttributes', '_outAttributes', '_callback'], /** * Checks whether the specified data match the expected. * * @protected - * @alias canHandleInAttributeValues + * @alias canHandleInAttributes * @memberof Interpreter# - * @param {AttributeValueList|Array.<AttributeValue>} _inAttributeValues Data that should be verified. + * @param {AttributeList|Array.<Attribute>} _inAttributes Data that should be verified. */ - 'protected canHandleInAttributeValues' : function(_inAttributeValues) { + 'protected canHandleInAttributes' : function(_inAttributes) { var list = []; - if (_inAttributeValues instanceof Array) { - list = _inAttributeValues; - } else if (Class.isA(AttributeValueList, _inAttributeValues)) { - list = _inAttributeValues.getItems(); + if (_inAttributes instanceof Array) { + list = _inAttributes; + } else if (Class.isA(AttributeList, _inAttributes)) { + list = _inAttributes.getItems(); } - if (list.length == 0 || _inAttributeValues.size() != this.getInAttributeTypes().size()) { + if (list.length == 0 || _inAttributes.size() != this.getInAttributeTypes().size()) { return false; } for ( var i in list) { @@ -345,18 +344,18 @@ define([ 'easejs', 'MathUuid', 'attributeType', 'attributeTypeList', * Checks whether the specified data match the expected. * * @protected - * @alias canHandle + * @alias canHandleOutAttributes * @memberof Interpreter# - * @param {AttributeValueList|Array.<AttributeValue>} _outAttributeValues Data that should be verified. + * @param {AttributeList|Array.<Attribute>} _outAttributes Data that should be verified. */ - 'protected canHandleOutAttributeValues' : function(_outAttributeValues) { + 'protected canHandleOutAttributes' : function(_outAttributes) { var list = []; - if (_outAttributeValues instanceof Array) { - list = _outAttributeValues; - } else if (Class.isA(AttributeValueList, _outAttributeValues)) { - list = _outAttributeValues.getItems(); + if (_outAttributes instanceof Array) { + list = _outAttributes; + } else if (Class.isA(AttributeList, _outAttributes)) { + list = _outAttributes.getItems(); } - if (list.length == 0 || _outAttributeValues.size() != this.getOutAttributeTypes().size()) { + if (list.length == 0 || _outAttributes.size() != this.getOutAttributeTypes().size()) { return false; } for ( var i in list) { diff --git a/js/modules/interpreter/interpreterResult.js b/js/modules/interpreter/interpreterResult.js index 8c71a09..085873b 100644 --- a/js/modules/interpreter/interpreterResult.js +++ b/js/modules/interpreter/interpreterResult.js @@ -4,8 +4,8 @@ * @module InterpreterResult * @fileOverview */ -define(['easejs', 'attributeValueList'], - function(easejs, AttributeValueList){ +define(['easejs', 'attributeList'], + function(easejs, AttributeList){ var Class = easejs.Class; var InterpreterResult = Class('InterpreterResult',{ diff --git a/js/modules/subscriber/callback.js b/js/modules/subscriber/callback.js index cb3f1e2..b453be4 100644 --- a/js/modules/subscriber/callback.js +++ b/js/modules/subscriber/callback.js @@ -5,8 +5,8 @@ * @module Callback * @fileOverview */ -define(['easejs', 'attributeType', 'attributeTypeList'], - function(easejs, AttributeType, AttributeTypeList){ +define(['easejs', 'attribute', 'attributeList'], + function(easejs, Attribute, AttributeList){ var Class = easejs.Class; var Callback = Class('Callback', @@ -43,7 +43,7 @@ define(['easejs', 'attributeType', 'attributeTypeList'], */ 'public __construct': function() { - this.attributeTypes = new AttributeTypeList(); + this.attributeTypes = new AttributeList(); }, /** @@ -118,19 +118,19 @@ define(['easejs', 'attributeType', 'attributeTypeList'], * @public * @alias setAttributeTypes * @memberof Callback# - * @param {AttributeTypeList} _attributeTypes AttributeTypeList + * @param {AttributeList} _attributes AttributeTypeList */ - 'public setAttributeTypes' : function(_attributeTypes){ + 'public setAttributeTypes' : function(_attributes){ var list = []; - if(_attributeTypes instanceof Array){ - list = _attributeTypes; - } else if (Class.isA( AttributeTypeList, _attributeTypes)) { - list = _attributeTypes.getItems(); + if(_attributes instanceof Array){ + list = _attributes; + } else if (Class.isA( AttributeList, _attributes)) { + list = _attributes.getItems(); } for(var i in list){ - var attributeType = list[i]; - if(Class.isA( AttributeType, attributeType )){ - this.attributeTypes.put(attributeType); + var theAttribute = list[i]; + if(Class.isA(Attribute, theAttribute)){ + this.attributeTypes.put(theAttribute); } } }, @@ -141,14 +141,14 @@ define(['easejs', 'attributeType', 'attributeTypeList'], * @public * @alias addAttributeType * @memberof Callback# - * @param {AttributeType} _attributeType AttributeType + * @param {AttributeType} _attribute AttributeType */ - 'public addAttributeType' : function(_attributeType){ - if(Class.isA( AttributeType, _attributeType )){ - if(!this.attributeTypes.contains(_attributeType)){ - this.attributeTypes.put(_attributeType); + 'public addAttributeType' : function(_attribute){ + if(Class.isA(Attribute, _attribute )){ + if(!this.attributeTypes.containsTypeOf(_attribute)){ + this.attributeTypes.put(_attribute); } - }; + } }, /** @@ -160,9 +160,9 @@ define(['easejs', 'attributeType', 'attributeTypeList'], * @param {AttributeType} _attributeType AttributeType */ 'public removeAttributeType' : function(_attributeType){ - if(Class.isA( AttributeType, _attributeType )){ + if(Class.isA(Attribute, _attributeType )){ this.attributeTypes.removeItem(_attributeType.getName()); - }; + } }, /** diff --git a/js/modules/subscriber/callbackList.js b/js/modules/subscriber/callbackList.js index 8dfbe65..d48a388 100644 --- a/js/modules/subscriber/callbackList.js +++ b/js/modules/subscriber/callbackList.js @@ -16,9 +16,7 @@ define(['easejs', 'abstractList', 'callback'], * @requires AbstractList * @requires Callback */ - var CallbackList = Class('CallbackList'). - extend(AbstractList,{ - + var CallbackList = Class('CallbackList').extend(AbstractList,{ /** * @alias counter * @protected @@ -46,18 +44,10 @@ define(['easejs', 'abstractList', 'callback'], * @returns {CallbackList} */ 'public withItems': function(_callbackList){ - var list = []; - if(_callbackList instanceof Array){ - list = _callbackList; + if (_callbackList instanceof Array) { + this.items = _callbackList; } else if (Class.isA(CallbackList, _callbackList)) { - list = _callbackList.getItems(); - } - for(var i in list){ - var callback = list[i]; - if(Class.isA( Callback, callback )){ - this.items[callback.getName()] = callback; - this.counter++; - } + this.items = _callbackList.getItems(); } return this; }, @@ -71,11 +61,10 @@ define(['easejs', 'abstractList', 'callback'], * @param {Callback} _callback Callback */ 'public put' : function(_callback){ - if(Class.isA(Callback, _callback)){ - if(!(this.containsKey(_callback.getName()))){ - this.counter++; + if (Class.isA(Callback, _callback)) { + if (!(this.contains(_callback))) { + this.items.push(_callback); } - this.items[_callback.getName()] = _callback; } }, @@ -90,19 +79,13 @@ define(['easejs', 'abstractList', 'callback'], */ 'public putAll' : function(_callbackList){ var list = []; - if(_callbackList instanceof Array){ + if (_callbackList instanceof Array) { list = _callbackList; - } else if (Class.isA(CallbackList, _callbackList)) { + } else if (Class.isA(CallbackList, _callbackList)) { list = _callbackList.getItems(); } - for(var i in list){ - var callback = list[i]; - if(Class.isA(Callback, callback)){ - if(!(this.containsKey(callback.getName()))){ - this.counter++; - } - this.items[callback.getName()] = callback; - } + for (var i in list) { + this.put(list[i]); } }, @@ -113,16 +96,18 @@ define(['easejs', 'abstractList', 'callback'], * @public * @alias contains * @memberof CallbackList# - * @param {Callback} _item CallbackType that should be verified. + * @param {Callback} _callback CallbackType that should be verified. * @returns {boolean} */ - 'public contains' : function(_item){ - if(Class.isA(Callback,_item)){ - var tmp = this.getItem(_item.getName()); - if(!(typeof tmp === 'undefined') && tmp.equals(_item)){ - return true; + 'public contains' : function(_callback){ + if (Class.isA(Callback, _callback)) { + for (var index in this.items) { + var tmp = this.items[index]; + if (tmp.equals(_callback)) { + return true; + } } - } + } return false; }, @@ -131,20 +116,17 @@ define(['easejs', 'abstractList', 'callback'], * @public * @alias equals * @memberof CallbackList# - * @param {CallbackList} _list CallbackList that should be compared. + * @param {CallbackList} _callbackList CallbackList that should be compared. * @returns {boolean} */ - 'public equals' : function(_list){ - if(Class.isA(CallbackList,_list) && _list.size() == this.size()){ - var items = _list.getItems(); - for(var i in items){ - var item = items[i]; - if(!this.contains(item)){ - return false; - } + 'public equals' : function(_callbackList){ + if (Class.isA(CallbackList, _callbackList) && _callbackList.size() == this.size()) { + for (var index in _callbackList.getItems()) { + var theCallback = _callbackList.getItems()[index]; + if (!this.contains(theCallback)) return false; } return true; - } + } return false; } diff --git a/js/modules/subscriber/condition/condition.js b/js/modules/subscriber/condition/condition.js index 791a29d..9a45487 100644 --- a/js/modules/subscriber/condition/condition.js +++ b/js/modules/subscriber/condition/condition.js @@ -6,8 +6,8 @@ * @module Condition * @fileOverview */ -define(['easejs','attributeType','attributeValue', 'conditionMethod'], - function(easejs, AttributeType, AttributeValue, ConditionMethod){ +define(['easejs','attribute', 'conditionMethod'], + function(easejs, Attribute, ConditionMethod){ var Class = easejs.Class; /** * @class Condition @@ -126,11 +126,11 @@ define(['easejs','attributeType','attributeValue', 'conditionMethod'], * @public * @alias setAttributeType * @memberof Condition# - * @param {AttributeType} _attributeType AttributeType + * @param {Attribute} _attribute AttributeType */ - 'public setAttributeType' : function(_attributeType){ - if(Class.isA(AttributeType,_attributeType)){ - this.attributeType = _attributeType; + 'public setAttributeType' : function(_attribute){ + if(Class.isA(Attribute, _attribute)){ + this.attributeType = _attribute; } }, @@ -214,21 +214,20 @@ define(['easejs','attributeType','attributeValue', 'conditionMethod'], * @public * @alias compare * @memberof Condition# - * @param {AttributeValue} _newAttributeValue new Attribute that should be compared - * @param {AttributeValue} _oldAttributeValue old Attribute + * @param {Attribute} _newAttributeValue new Attribute that should be compared + * @param {Attribute} _oldAttributeValue old Attribute * @returns {boolean} */ 'public compare' : function(_newAttributeValue, _oldAttributeValue){ - if(!this.attributeType.equals(_newAttributeValue.getAttributeType()) - && !this.attributeType.equals(_oldAttributeValue.getAttributeType())){ + if(!this.attributeType.equalsTypeOf(_newAttributeValue)&& !this.attributeType.equalsTypeOf(_oldAttributeValue)){ return false; - }; + } if(!this.comparisonMethod){ return false; - }; - if(Class.isA(AttributeValue,_newAttributeValue) && Class.isA(AttributeValue,_oldAttributeValue)){ + } + if(Class.isA(Attribute, _newAttributeValue) && Class.isA(Attribute, _oldAttributeValue)){ return this.comparisonMethod.process(this.referenceValue, _newAttributeValue.getValue(), _oldAttributeValue.getValue()); - }; + } return false; }, @@ -245,7 +244,7 @@ define(['easejs','attributeType','attributeValue', 'conditionMethod'], if(Class.isA(Condition, _condition)){ if(_condition.getName() == this.getName() && _condition.getReferenceValue() == this.getReferenceValue() - && _condition.getAttributeType().equals(this.attributeType) + && _condition.getAttributeType().equalsTypeOf(this.attributeType) && _condition.getComparisonMethod() === this.comparisonMethod){ return true; }; diff --git a/js/modules/subscriber/condition/conditionList.js b/js/modules/subscriber/condition/conditionList.js index 2c38a27..54e5a58 100644 --- a/js/modules/subscriber/condition/conditionList.js +++ b/js/modules/subscriber/condition/conditionList.js @@ -45,18 +45,10 @@ define(['easejs','abstractList', 'condition'], * @returns {ConditionList} */ 'public withItems': function(_conditionList){ - var list = new Array(); - if(_conditionList instanceof Array){ - list = _conditionList; + if (_conditionList instanceof Array) { + this.items = _conditionList; } else if (Class.isA(ConditionList, _conditionList)) { - list = _conditionList.getItems(); - } - for(var i in list){ - var condition = list[i]; - if(Class.isA( Condition, condition )){ - this.items[condition.getName()] = condition; - this.counter++; - } + this.items = _conditionList.getItems(); } return this; }, @@ -70,11 +62,9 @@ define(['easejs','abstractList', 'condition'], * @param {Condition} _condition Condition */ 'public put' : function(_condition){ - if(Class.isA(Condition, _condition)){ - if(!(this.containsKey(_condition.getName()))){ - this.counter++; - } - this.items[_condition.getName()] = _condition; + if (Class.isA(Condition, _condition)) { + if (!(this.contains(_condition))) { + this.items.push(_condition);} } }, @@ -88,20 +78,14 @@ define(['easejs','abstractList', 'condition'], * @param {(ConditioneList|Array)} _conditionList ConditionList */ 'public putAll' : function(_conditionList){ - var list = new Array(); - if(_conditionList instanceof Array){ + var list = []; + if (_conditionList instanceof Array) { list = _conditionList; - } else if (Class.isA(ConditionList, _conditionList)) { + } else if (Class.isA(ConditionList, _conditionList)) { list = _conditionList.getItems(); } - for(var i in list){ - var condition = list[i]; - if(Class.isA(Condition, condition)){ - if(!(this.containsKey(condition.getName()))){ - this.counter++; - } - this.items[condition.getName()] = condition; - } + for (var i in list) { + this.put(list[i]); } }, @@ -112,16 +96,18 @@ define(['easejs','abstractList', 'condition'], * @public * @alias contains * @memberof ConditionList# - * @param {Condition} _item Condition that should be verified. + * @param {Condition} _condition Condition that should be verified. * @returns {boolean} */ - 'public contains' : function(_item){ - if(Class.isA(Condition,_item)){ - var tmp = this.getItem(_item.getName()); - if(!(typeof tmp === 'undefined') && tmp.equals(_item)){ - return true; + 'public contains' : function(_condition){ + if (Class.isA(Condition, _condition)) { + for (var index in this.items) { + var theCondition = this.items[index]; + if (theCondition.equals(_condition)) { + return true; + } } - } + } return false; }, @@ -131,24 +117,19 @@ define(['easejs','abstractList', 'condition'], * @public * @alias equals * @memberof ConditionList# - * @param {ConditionList} _list ConditionList that should be compared. + * @param {ConditionList} _conditionList ConditionList that should be compared. * @returns {boolean} */ - 'public equals' : function(_list){ - if(Class.isA(ConditionList,_list) && _list.size() == this.size()){ - var items = _list.getItems(); - for(var i in items){ - var item = items[i]; - if(!this.contains(item)){ - return false; - } + 'public equals' : function(_conditionList){ + if (Class.isA(ConditionList, _conditionList) && _conditionList.size() == this.size()) { + for (var index in _conditionList.getItems()) { + var theCondition = _conditionList.getItems()[index]; + if (!this.contains(theCondition)) return false; } return true; - } + } return false; - }, - - + } }); diff --git a/js/modules/subscriber/subscriber.js b/js/modules/subscriber/subscriber.js index 2f15aca..f2becf4 100644 --- a/js/modules/subscriber/subscriber.js +++ b/js/modules/subscriber/subscriber.js @@ -4,8 +4,8 @@ * @module Subscriber * @fileOverview */ -define(['easejs', 'attributeTypeList', 'callbackList', 'condition', 'conditionList'], - function(easejs, AttributeTypeList, CallbackList, Condition, ConditionList){ +define(['easejs', 'attributeList', 'callbackList', 'condition', 'conditionList'], + function(easejs, AttributeList, CallbackList, Condition, ConditionList){ /* * Callback: name and associated Attributes @@ -73,8 +73,8 @@ define(['easejs', 'attributeTypeList', 'callbackList', 'condition', 'conditionLi 'virtual public __construct': function() { this.subscriptionCallbacks = new CallbackList(); - this.subscriptionCallbacks = new AttributeTypeList(); - this.attributesSubset = new AttributeTypeList(); + this.subscriptionCallbacks = new AttributeList(); + this.attributesSubset = new AttributeList(); this.conditions = new ConditionList(); }, @@ -172,7 +172,7 @@ define(['easejs', 'attributeTypeList', 'callbackList', 'condition', 'conditionLi 'public setSubscriberName' : function(_subscriberName){ if(typeof _subscriberName === 'string'){ this.subscriberName = _subscriberName; - }; + } }, @@ -225,7 +225,7 @@ define(['easejs', 'attributeTypeList', 'callbackList', 'condition', 'conditionLi 'public setSubscriptionCallbacks' : function(_subscriptionCallbacks){ if(Class.isA(CallbackList, _subscriptionCallbacks)){ this.subscriptionCallbacks = _subscriptionCallbacks; - }; + } }, /** @@ -246,12 +246,12 @@ define(['easejs', 'attributeTypeList', 'callbackList', 'condition', 'conditionLi * @public * @alias setAttributesSubset * @memberof Subscriber# - * @param {AttributeTypeList} _attributesSubset attributesSubset + * @param {AttributeList} _attributesSubset attributesSubset */ 'public setAttributesSubset' : function(_attributesSubset){ - if(Class.isA(AttributeTypeList, _attributesSubset)){ + if(Class.isA(AttributeList, _attributesSubset)){ this.attributesSubset = _attributesSubset; - }; + } }, /** diff --git a/js/modules/subscriber/subscriberList.js b/js/modules/subscriber/subscriberList.js index b241e84..2af2efa 100644 --- a/js/modules/subscriber/subscriberList.js +++ b/js/modules/subscriber/subscriberList.js @@ -42,23 +42,14 @@ define(['easejs', 'abstractList', 'subscriber'], * @public * @alias withItems * @memberof SubscriberList# - * @param {(SubscriberList|Array)} - * _subscriberList SubscriberList + * @param {(SubscriberList|Array)} _subscriberList SubscriberList * @returns {SubscriberList} */ 'public withItems': function(_subscriberList){ - var list = new Array(); - if(_subscriberList instanceof Array){ - list = _subscriberList; - } else if (Class.isA( SubscriberList, _subscriberList)) { - list = _subscriberList.getItems(); - } - for(var i in list){ - var subscriber = list[i]; - if(Class.isA( Subscriber, subscriber )){ - this.items[subscriber.getSubscriberId()] = subscriber; - this.counter++; - } + if (_subscriberList instanceof Array) { + this.items = _subscriberList; + } else if (Class.isA(SubscriberList, _subscriberList)) { + this.items = _subscriberList.getItems(); } return this; }, @@ -69,15 +60,12 @@ define(['easejs', 'abstractList', 'subscriber'], * @public * @alias put * @memberof SubscriberList# - * @param {Subscriber} - * _subscriber Subscriber + * @param {Subscriber} _subscriber Subscriber */ 'public put' : function(_subscriber){ - if(Class.isA(Subscriber, _subscriber)){ - if(!(this.containsKey(_subscriber.getSubscriberId()))){ - this.counter++; - } - this.items[_subscriber.getSubscriberId()] = _subscriber; + if (Class.isA(Subscriber, _subscriber)) { + if (!(this.contains(_subscriber))) { + this.items.push(_subscriber);} } }, @@ -90,20 +78,14 @@ define(['easejs', 'abstractList', 'subscriber'], * @param {(SubscriberList|Array)} _subscriberList SubscriberList */ 'public putAll' : function(_subscriberList){ - var list = new Array(); - if(_subscriberList instanceof Array){ + var list = []; + if (_subscriberList instanceof Array) { list = _subscriberList; - } else if (Class.isA(SubscriberList, _subscriberList)) { + } else if (Class.isA(SubscriberList, _subscriberList)) { list = _subscriberList.getItems(); } - for(var i in list){ - var subscriber = list[i]; - if(Class.isA(Subscriber, subscriber)){ - if(!(this.containsKey(subscriber.getSubscriberId()))){ - this.counter++; - } - this.items[subscriber.getSubscriberId()] = subscriber; - } + for (var i in list) { + this.put(list[i]); } }, @@ -113,17 +95,18 @@ define(['easejs', 'abstractList', 'subscriber'], * @public * @alias contains * @memberof SubscriberList# - * @param {Subscriber} - * _item Subscriber that should be verified. + * @param {Subscriber}_subscriber Subscriber that should be verified. * @returns {boolean} */ - 'public contains' : function(_item){ - if(Class.isA(Subscriber,_item)){ - var tmp = this.getItem(_item.getSubscriberId()); - if(!(typeof tmp === 'undefined') && tmp.equals(_item)){ - return true; + 'public contains' : function(_subscriber){ + if (Class.isA(Subscriber, _subscriber)) { + for (var index in this.items) { + var tmp = this.items[index]; + if (tmp.equals(_subscriber)) { + return true; + } } - } + } return false; }, @@ -132,23 +115,26 @@ define(['easejs', 'abstractList', 'subscriber'], * @public * @alias equals * @memberof SubscriberList# - * @param {SubscriberList} _list SubscriberList that should be compared. + * @param {SubscriberList} _subscriberList SubscriberList that should be compared. * @returns {boolean} */ - 'public equals' : function(_list){ - if(Class.isA(SubscriberList,_list) && _list.size() == this.size()){ - var items = _list.getItems(); - for(var i in items){ - var item = items[i]; - if(!this.contains(item)){ - return false; - } + 'public equals' : function(_subscriberList) { + if (Class.isA(SubscriberList, _subscriberList) && _subscriberList.size() == this.size()) { + for (var index in _subscriberList.getItems()) { + var theSubscriber = _subscriberList.getItems()[index]; + if (!this.contains(theSubscriber)) return false; } return true; - } + } return false; }, + 'public removeSubscriberWithId': function(_subscriberId) { + for (var index in this.items) { + var theSubscriber = this.items[index]; + if (theSubscriber.getSubscriberId() == _subscriberId) this.items.splice(index, 1); + } + } }); return SubscriberList; diff --git a/js/modules/widget/widget.js b/js/modules/widget/widget.js index b63b0a6..2bdfe9f 100644 --- a/js/modules/widget/widget.js +++ b/js/modules/widget/widget.js @@ -4,11 +4,11 @@ * @module Widget * @fileOverview */ -define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeType', - 'attributeValue', 'attributeTypeList', 'attributeValueList', 'conditionList', +define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', + 'attributeList', 'conditionList', 'subscriber', 'subscriberList', 'widgetDescription'], - function(easejs, MathUuid, Callback, CallbackList, AttributeType, - AttributeValue, AttributeTypeList, AttributeValueList, ConditionList, + function(easejs, MathUuid, Callback, CallbackList, Attribute, + AttributeList, ConditionList, Subscriber, SubscriberList, WidgetDescription) { var AbstractClass = easejs.AbstractClass; @@ -125,10 +125,10 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeType', this.id = Math.uuid(); this.discoverer = _discoverer; this.register(); - this.attributeTypes = new AttributeTypeList(); - this.constantAttributeTypes = new AttributeTypeList(); - this.attributes = new AttributeValueList(); - this.constantAttributes = new AttributeValueList(); + this.attributeTypes = new AttributeList(); + this.constantAttributeTypes = new AttributeList(); + this.attributes = new AttributeList(); + this.constantAttributes = new AttributeList(); this.subscribers = new SubscriberList(); this.callbacks = new CallbackList(); this.init(_attributeTypes); @@ -191,7 +191,7 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeType', * @public * @alias getWidgetConstantAttributeTypes * @memberof Widget# - * @returns {AttributeTypeList} + * @returns {AttributeList} */ 'public getWidgetConstantAttributeTypes' : function() { return this.constantAttributeTypes; @@ -203,12 +203,12 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeType', * @public * @alias getAttributes * @memberof Widget# - * @param {AttributeTypeList} _attributeTypeList - * @returns {AttributeValueList} + * @param {AttributeList} _attributeList + * @returns {AttributeList} */ - 'public getAttributeValues' : function(_attributeTypeList) { - if (Class.isA(AttributeTypeList, _attributeTypeList)) { - return this.attributes.getSubset(_attributeTypeList); + 'public getAttributeValues' : function(_attributeList) { + if (Class.isA(AttributeList, _attributeList)) { + return this.attributes.getSubset(_attributeList); } else { return this.attributes; } @@ -230,7 +230,7 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeType', * @private * @alias getOldAttributes * @memberof Widget# - * @returns {AttributeValueList} + * @returns {AttributeList} */ 'public getOldAttributes' : function() { return this.oldAttributes; @@ -242,7 +242,7 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeType', * @public * @alias getConstantAttributes * @memberof Widget# - * @returns {AttributeValueList} + * @returns {AttributeList} */ 'public getConstantAttributes' : function() { return this.constantAttributes; @@ -365,14 +365,13 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeType', * @public * @alias addAttribute * @memberof Widget# - * @param {AttributeValue} - * _attribute AttributeValue + * @param {Attribute} _attribute AttributeValue */ 'public addAttribute' : function(_attribute) { - if (Class.isA(AttributeValue, _attribute)) { + if (Class.isA(Attribute, _attribute)) { if (!this.attributes.contains(_attribute)) { - var type = new AttributeType().withName(_attribute.getName()) + var type = new Attribute().withName(_attribute.getName()) .withType(_attribute.getType()) .withParameters(_attribute.getParameters()); this.attributeTypes.put(type); @@ -531,7 +530,7 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeType', * @param {Subscriber} _subscriber Subscriber */ 'public removeSubscriber' : function(_subscriberId) { - this.subscribers.removeItem(_subscriberId); + this.subscribers.removeSubscriberWithId(_subscriberId); }, /** @@ -558,7 +557,7 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeType', * @returns {boolean} */ 'protected isAttribute' : function(_attribute) { - return !!this.attributeTypes.contains(_attribute.getAttributeType()); + return !!this.attributeTypes.containsTypeOf(_attribute); }, /** @@ -683,12 +682,12 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeType', var list = []; if (_data instanceof Array) { list = _data; - } else if (Class.isA(AttributeValueList, _data)) { + } else if (Class.isA(AttributeList, _data)) { list = _data.getItems(); } for ( var i in list) { var x = list[i]; - if (Class.isA(AttributeValue, x) && this.isAttribute(x)) { + if (Class.isA(Attribute, x) && this.isAttribute(x)) { this.addAttribute(x); } } @@ -702,10 +701,10 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeType', * @public * @alias queryWidget * @memberof Widget# - * @returns {AttributeValueList} + * @returns {AttributeList} */ 'public queryWidget' : function() { - var response = new AttributeValueList(); + var response = new AttributeList(); response.putAll(this.getAttributeValues()); response.putAll(this.getConstantAttributes()); return response; @@ -719,14 +718,14 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeType', * @alias updateAndQueryWidget * @memberof Widget# * @param {?function} _function For alternative actions, because an asynchronous function can be used. - * @returns {?AttributeValueList} + * @returns {?AttributeList} */ 'virtual public updateAndQueryWidget' : function(_function) { if(_function && typeof(_function) === 'function'){ this.queryGenerator(_function); } else { this.queryGenerator(); - var response = new AttributeValueList(); + var response = new AttributeList(); response.putAll(this.getAttributeValues()); response.putAll(this.getConstantAttributes()); return response; @@ -746,7 +745,7 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attributeType', var subscriberList = this.subscribers.getItems(); for ( var i in subscriberList) { var subscriber = subscriberList[i]; - if (subscriber.getSubscriptionCallbacks().containsKey( _callback.getName())) { + if (subscriber.getSubscriptionCallbacks().contains(_callback)) { if(this.dataValid(subscriber.getConditions())){ var subscriberInstance = this.discoverer.getComponent(subscriber.getSubscriberId()); var callSubset = _callback.getAttributeTypes(); diff --git a/qunitTest/aggregatorTest.js b/qunitTest/aggregatorTest.js index eed973a..56a8755 100644 --- a/qunitTest/aggregatorTest.js +++ b/qunitTest/aggregatorTest.js @@ -3,38 +3,30 @@ require(['configTest'], function() { function(GeoLocationWidget, contactJS){ QUnit.test( "TestAggregator ", function( assert ) { + var latitudeType = new contactJS.Attribute().withName('latitude').withType('double'); + var longitudeType = new contactJS.Attribute().withName('longitude').withType('double'); + //initializes the infrastructure var discoverer = new contactJS.Discoverer(); var testAggregator = new contactJS.Aggregator(discoverer); - var geoLocationWidget = new GeoLocationWidget(discoverer); + new GeoLocationWidget(discoverer); var aggregatorId = testAggregator.getId(); - assert.ok( aggregatorId && aggregatorId !== "null" && aggregatorId !== "undefined","Passed!: id is not null" ); - assert.equal( testAggregator.getType(), 'Aggregator',"Passed!: type -> Aggregator"); - assert.equal( testAggregator.getName(), 'Aggregator',"Passed!: name -> Aggregator"); + assert.ok(aggregatorId && aggregatorId !== "null" && aggregatorId !== "undefined","Passed!: id is not null" ); + assert.equal(testAggregator.getType(), 'Aggregator',"Passed!: type -> Aggregator"); + assert.equal(testAggregator.getName(), 'Aggregator',"Passed!: name -> Aggregator"); var aggregatorData = testAggregator.getCurrentData(); - assert.equal( aggregatorData.size(), 0, "Passed!: no available attributes" ); + assert.equal(aggregatorData.size(), 0, "Passed!: no available attributes" ); var widgetIds = testAggregator.getWidgets(); - assert.equal( widgetIds.length, 0,"Passed!: no subscribed Widgets" ); + assert.equal(widgetIds.length, 0,"Passed!: no subscribed Widgets" ); //subscription var widgetDescriptions = discoverer.getDescriptions([contactJS.Widget]); - - var latitudeType = new contactJS.AttributeType().withName('latitude') - .withType('double'); - var longitudeType = new contactJS.AttributeType().withName('longitude') - .withType('double'); - var list = new contactJS.AttributeTypeList(); - list.put(latitudeType); - list.put(longitudeType); - - var call = new contactJS.Callback().withName('UPDATE').withAttributeTypes(list); - var callarray = []; - callarray.push(call); - var callList = new contactJS.CallbackList().withItems(callarray); + 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); widgetIds = testAggregator.getWidgets(); @@ -47,13 +39,13 @@ require(['configTest'], function() { var values = testAggregator.getAttributeValues(); assert.equal( values.size(), 2, "Passed!: two available attributes" ); - var latitude = values.getItem('(latitude:double)'); + var latitude = values.getAttributeWithTypeOf(latitudeType); assert.equal(latitude.getName(), 'latitude',"subscribed Attributes Passed!: latitude exists" ); - assert.equal(latitude.getValue(), 'undefined',"subscribed Attributes Passed!: value of latitude is undefined" ); + assert.equal(latitude.getValue(), 'NO_VALUE',"subscribed Attributes Passed!: value of latitude is NO_VALUE" ); - var longitude =values.getItem('(longitude:double)'); + var longitude =values.getAttributeWithTypeOf(longitudeType); assert.equal(longitude.getName(), 'longitude',"subscribed Attributes Passed!: longitude exists" ); - assert.equal(longitude.getValue(), 'undefined',"subscribed Attributes Passed!: value of longitude is undefined" ); + assert.equal(longitude.getValue(), 'NO_VALUE',"subscribed Attributes Passed!: value of longitude is NO_VALUE" ); //unsubscribe testAggregator.unsubscribeFrom(widgetIds[0]); diff --git a/qunitTest/attributeTypeListTest.js b/qunitTest/attributeTypeListTest.js index 14965bc..7cccf20 100644 --- a/qunitTest/attributeTypeListTest.js +++ b/qunitTest/attributeTypeListTest.js @@ -6,20 +6,17 @@ require(['configTest'], function() { var parameter = new contactJS.Parameter().withKey('testKey').withValue('testValue'); - var latitudeType = new contactJS.AttributeType().withName('latitude') - .withType('double').withParameter(parameter); - var longitudeType = new contactJS.AttributeType().withName('longitude') - .withType('double'); - var attributeType = new contactJS.AttributeType().withName('testName') - .withType('integer'); + var latitudeType = new contactJS.Attribute().withName('latitude').withType('double').withParameter(parameter); + var longitudeType = new contactJS.Attribute().withName('longitude').withType('double'); + var attributeType = new contactJS.Attribute().withName('testName').withType('integer'); var array = []; array.push(latitudeType); array.push(longitudeType); - var list = new contactJS.AttributeTypeList().withItems(array); + var list = new contactJS.AttributeList().withItems(array); assert.equal( list.size(), 2, "Passed!: Builder (withItems)" ); - var list2 = new contactJS.AttributeTypeList(); + var list2 = new contactJS.AttributeList(); list2.put(attributeType); assert.equal( list2.size(), 1, "Passed!: Put type to list (put)" ); @@ -35,33 +32,24 @@ require(['configTest'], function() { assert.ok( list2.equals(list2), "Passed!: equals -> true" ); assert.ok( !list.equals(list2), "Passed!: equals -> false" ); - //containsKey - assert.ok( list2.containsKey('(testName:integer)'), "Passed!: containsKey -> true" ); - assert.ok( !list.containsKey('(testName:integer)'), "Passed!: containsKey -> false" ); - //getItem - assert.ok( list2.getItem('(testName:integer)').equals(attributeType), "Passed!: getItem" ); - assert.ok( !list.getItem('(testName:integer)'), "Passed!: getItem -> undefined" ); + assert.ok( list2.getAttributeWithTypeOf(attributeType).equalsTypeOf(attributeType), "Passed!: getItem" ); + assert.ok( !list.getAttributeWithTypeOf(attributeType), "Passed!: getItem -> undefined" ); //removeItem - list2.removeItem('(testName:integer)'); + list2.removeAttributeWithTypeOf(attributeType); assert.equal( list2.size(),2, "Passed!: removeItem" ); assert.ok( !list2.getItem('(testName:integer)'), "Passed!: item removed" ); - list.removeItem('(testName:integer)'); + list.removeAttributeWithTypeOf(attributeType); assert.equal( list.size(), 2, "Passed!: removeItem: key does not exist" ); - //getKeys - assert.equal( list2.getKeys().length, 2, "Passed!: getKeys" ); - assert.equal( list2.getKeys()[0], '(latitude:double)#[testKey:testValue]', "Passed!: getKeys -> latitude" ); - assert.equal( list2.getKeys()[1], '(longitude:double)', "Passed!: getKeys -> longitude" ); - //getItems assert.equal( list2.getItems().length, 2, "Passed!: getItems" ); - assert.ok( list2.getItems()[0].equals(latitudeType), "Passed!: getItems -> latitude" ); - assert.ok( list2.getItems()[1].equals(longitudeType), "Passed!: getItems -> longitude" ); + assert.ok( list2.getItems()[0].equalsTypeOf(latitudeType), "Passed!: getItems -> latitude" ); + assert.ok( list2.getItems()[1].equalsTypeOf(longitudeType), "Passed!: getItems -> longitude" ); //empty - var list3 = new contactJS.AttributeTypeList(); + var list3 = new contactJS.AttributeList(); assert.ok( !list2.isEmpty(), "Passed!: isEmpty ->true" ); assert.ok( list3.isEmpty(), "Passed!: isEmpty ->false" ); diff --git a/qunitTest/attributeTypeTest.js b/qunitTest/attributeTypeTest.js index 5e5c6a5..74d2e30 100644 --- a/qunitTest/attributeTypeTest.js +++ b/qunitTest/attributeTypeTest.js @@ -3,14 +3,15 @@ require(['configTest'], function() { QUnit.test( "AttributeType", function( assert ) { - var attributeType = new contactJS.AttributeType(); + var attributeType = new contactJS.Attribute(); var parameter = new contactJS.Parameter().withKey('testKey').withValue('testValue'); - var attributeType2 = new contactJS.AttributeType().withName('testName'). + var attributeType2 = new contactJS.Attribute().withName('testName'). withType('integer').withParameter(parameter); - assert.ok( attributeType2.equals(attributeType2),"Passed!: equals -> true" ); - assert.ok( !attributeType2.equals(attributeType),"Passed!: equals -> false" ); + + assert.ok( attributeType2.equalsTypeOf(attributeType2),"Passed!: equals -> true" ); + assert.ok( !attributeType2.equalsTypeOf(attributeType),"Passed!: equals -> false" ); }); }); diff --git a/qunitTest/attributeValueListTest.js b/qunitTest/attributeValueListTest.js index e2879a1..b40102c 100644 --- a/qunitTest/attributeValueListTest.js +++ b/qunitTest/attributeValueListTest.js @@ -7,20 +7,20 @@ require(['configTest'], function() { var parameter = new contactJS.Parameter().withKey('testKey').withValue('testValue'); - var latitudeValue = new contactJS.AttributeValue().withName('latitude') + var latitudeValue = new contactJS.Attribute().withName('latitude') .withType('double').withValue('there').withParameter(parameter); - var longitudeValue = new contactJS.AttributeValue().withName('longitude') + var longitudeValue = new contactJS.Attribute().withName('longitude') .withType('double').withValue('here'); - var attributeValue = new contactJS.AttributeValue().withName('testName') + var attributeValue = new contactJS.Attribute().withName('testName') .withType('integer'); - var array = new Array(); + var array = []; array.push(latitudeValue); array.push(longitudeValue); - var list = new contactJS.AttributeValueList().withItems(array); + var list = new contactJS.AttributeList().withItems(array); assert.ok( list.size() == 2, "Passed!: Builder (withItems)" ); - var list2 = new contactJS.AttributeValueList(); + var list2 = new contactJS.AttributeList(); list2.put(attributeValue); assert.equal( list2.size(), 1, "Passed!: Put type to list (put)" ); @@ -37,8 +37,8 @@ require(['configTest'], function() { assert.ok( !list.equals(list2), "Passed!: equals -> false" ); //getSubset - var sublist = new contactJS.AttributeTypeList(); - sublist.put(latitudeValue.getAttributeType()); + var sublist = new contactJS.AttributeList(); + sublist.put(latitudeValue); var subset = list.getSubset(sublist); assert.equal( subset.size(), 1, "Passed!: Subset contains only one value" ); assert.ok( subset.contains(latitudeValue), "Passed!: subset contains latitude" ); diff --git a/qunitTest/attributeValueTest.js b/qunitTest/attributeValueTest.js index bb6c1f7..9083fdc 100644 --- a/qunitTest/attributeValueTest.js +++ b/qunitTest/attributeValueTest.js @@ -4,35 +4,35 @@ require(['configTest'], function() { QUnit.test( "AttributeValue", function( assert ) { - var attributeValue = new contactJS.AttributeValue(); + var attributeValue = new contactJS.Attribute(); var parameter = new contactJS.Parameter().withKey('testKey').withValue('testValue'); var date = new Date(); - var attributeValue2 = new contactJS.AttributeValue().withName('testName'). + var attributeValue2 = new contactJS.Attribute().withName('testName'). withType('integer').withParameter(parameter). withValue('testValue').withTimestamp(date); - var attributeValue3 = new contactJS.AttributeValue().withName('testName').withType('integer') + var attributeValue3 = new contactJS.Attribute().withName('testName').withType('integer') .withParameter(parameter).withValue('testValue') .withTimestamp(date); assert.equal( attributeValue2.getParameters().size(), 1, "Passed!: withParameter() -> size == 1" ); - assert.ok( attributeValue2.equals(attributeValue3),"Passed!: equals -> true" ); - assert.ok( !attributeValue2.equals(attributeValue),"Passed!: equals -> false" ); + assert.ok( attributeValue2.equalsValueOf(attributeValue3),"Passed!: equals -> true" ); + assert.ok( !attributeValue2.equalsValueOf(attributeValue),"Passed!: equals -> false" ); - var attributeValue3 = new contactJS.AttributeValue().withName('testName'). + var attributeValue3 = new contactJS.Attribute().withName('testName'). withType('integer').withParameter(parameter). withValue('testValue').withTimestamp(new Date()); - assert.ok( attributeValue2.equals(attributeValue3),"Passed!: equals -> date is not verified" ); + assert.ok( attributeValue2.equalsValueOf(attributeValue3),"Passed!: equals -> date is not verified" ); /* * getAttributeType */ - var attributeType = new contactJS.AttributeType().withName('testName'). + var attributeType = new contactJS.Attribute().withName('testName'). withType('integer').withParameter(parameter); - assert.ok( attributeValue2.getAttributeType().equals(attributeType),"Passed!: getAttributeType()" ); + assert.ok( attributeValue2.equalsTypeOf(attributeType),"Passed!: getAttributeType()" ); }); diff --git a/qunitTest/callbackListTest.js b/qunitTest/callbackListTest.js index 549fb83..166557f 100644 --- a/qunitTest/callbackListTest.js +++ b/qunitTest/callbackListTest.js @@ -4,21 +4,21 @@ require(['configTest'], function() { QUnit.test( "CallbackList", function( assert ) { - var attributeType = new contactJS.AttributeType(); + var attribute = new contactJS.Attribute(); var parameter = new contactJS.Parameter().withKey('testKey').withValue('testValue'); - var attributeType2 = new contactJS.AttributeType().withName('testName'). - withType('integer').withParameter(parameter); - var array = new Array(); - array.push(attributeType); - var attList = new contactJS.AttributeTypeList().withItems(array); + var attribute2 = new contactJS.Attribute().withName('testName').withType('integer').withParameter(parameter); + + var array = []; + array.push(attribute); + var attList = new contactJS.AttributeList().withItems(array); var call = new contactJS.Callback().withName('test').withAttributeTypes(array); var call2 = new contactJS.Callback().withName('test2').withAttributeTypes(attList); var call3 = new contactJS.Callback().withName('test3').withAttributeTypes(attList); - var array = new Array(); + var array = []; array.push(call2); array.push(call3); var list = new contactJS.CallbackList().withItems(array); diff --git a/qunitTest/callbackTest.js b/qunitTest/callbackTest.js index 5dfef01..b6c9045 100644 --- a/qunitTest/callbackTest.js +++ b/qunitTest/callbackTest.js @@ -3,20 +3,20 @@ require(['configTest'], function() { QUnit.test( "Callback", function( assert ) { - var attributeType = new contactJS.AttributeType(); + var attributeType = new contactJS.Attribute(); var parameter = new contactJS.Parameter().withKey('testKey').withValue('testValue'); - var attributeType2 = new contactJS.AttributeType().withName('testName'). - withType('integer').withParameter(parameter); - var array = new Array(); + var attributeType2 = new contactJS.Attribute().withName('testName').withType('integer').withParameter(parameter); + + var array = []; array.push(attributeType); - var attList = new contactJS.AttributeTypeList().withItems(array); + var attList = new contactJS.AttributeList().withItems(array); var call = new contactJS.Callback().withName('test').withAttributeTypes(array); var call2 = new contactJS.Callback().withName('test').withAttributeTypes(attList); array.push(attributeType2); - var attList2 = new contactJS.AttributeTypeList().withItems(array); + var attList2 = new contactJS.AttributeList().withItems(array); var call3 = new contactJS.Callback().withName('test').withAttributeTypes(attList2); var call4 = new contactJS.Callback().withName('test1').withAttributeTypes(attList2); diff --git a/qunitTest/conditionListTest.js b/qunitTest/conditionListTest.js index 40b003b..179272c 100644 --- a/qunitTest/conditionListTest.js +++ b/qunitTest/conditionListTest.js @@ -3,8 +3,8 @@ require(['configTest'], function() { QUnit.test( "ConditionList", function( assert ) { - var type = new contactJS.AttributeType().withName('test').withType('string'); - var type2 = new contactJS.AttributeType().withName('test').withType('string'); + var type = new contactJS.Attribute().withName('test').withType('string'); + var type2 = new contactJS.Attribute().withName('test').withType('string'); var method = new contactJS.Equals(); var method2 = new contactJS.UnEquals(); @@ -15,19 +15,16 @@ require(['configTest'], function() { .withComparisonMethod(method); var condition3 = new contactJS.Condition().withName('condition3').withAttributeType(type) .withComparisonMethod(method2); - - var array = new Array(); - array.push(condition2); - array.push(condition3); - var list = new contactJS.ConditionList().withItems(array); - assert.equal( list.size(), 2, "Passed!: Builder (withItems)" ); + + var list = new contactJS.ConditionList().withItems([condition2, condition3]); + assert.equal(list.size(), 2, "Passed!: Builder (withItems)" ); var list2 = new contactJS.ConditionList(); list2.put(condition); assert.equal( list2.size(), 1, "Passed!: Put type to list (put)" ); - list2.putAll(array); + list2.putAll([condition2, condition3]); assert.equal( list2.size(), 3, "Passed!: Put another two type to list (putAll)" ); //contains diff --git a/qunitTest/conditionTest.js b/qunitTest/conditionTest.js index dd6fd70..8347572 100644 --- a/qunitTest/conditionTest.js +++ b/qunitTest/conditionTest.js @@ -3,19 +3,15 @@ require(['configTest'], function() { QUnit.test( "Condition", function( assert ) { - var testA = new contactJS.AttributeValue().withName('test').withType('string').withValue('blubb'); - var testA2 = new contactJS.AttributeValue().withName('test').withType('string').withValue('blubb2'); + var testA = new contactJS.Attribute().withName('test').withType('string').withValue('blubb'); + var testA2 = new contactJS.Attribute().withName('test').withType('string').withValue('blubb2'); var method = new contactJS.Equals(); var method2 = new contactJS.UnEquals(); - var conditionTest = new contactJS.Condition().withAttributeType(testA.getAttributeType()) - .withComparisonMethod(method); - var conditionTest2 = new contactJS.Condition().withAttributeType(testA.getAttributeType()) - .withComparisonMethod(method); - var conditionTest3 = new contactJS.Condition().withAttributeType(testA.getAttributeType()) - .withComparisonMethod(method2); - + var conditionTest = new contactJS.Condition().withAttributeType(testA).withComparisonMethod(method); + var conditionTest2 = new contactJS.Condition().withAttributeType(testA).withComparisonMethod(method); + var conditionTest3 = new contactJS.Condition().withAttributeType(testA).withComparisonMethod(method2); assert.ok( conditionTest.equals(conditionTest2),"Passed!: equals -> true" ); assert.ok( !conditionTest.equals(conditionTest3),"Passed!: equals -> false" ); diff --git a/qunitTest/discovererTest.js b/qunitTest/discovererTest.js index ef6be75..23d9293 100644 --- a/qunitTest/discovererTest.js +++ b/qunitTest/discovererTest.js @@ -52,7 +52,7 @@ require(['configTest'], function() { //register Aggregator new contactJS.Aggregator(discoverer, [ - new contactJS.AttributeType().withName('formattedAddress').withType('string') + new contactJS.Attribute().withName('formattedAddress').withType('string') ]); //tested with getWidgetDescriptions var aDescs = discoverer.getDescriptions([contactJS.Aggregator]); @@ -75,10 +75,9 @@ require(['configTest'], function() { //getComponentByAttribute var testParameter = new contactJS.Parameter().withKey('foo').withValue('bar'); - var latitudeType = new contactJS.AttributeType().withName('latitude') - .withType('double').withParameter(testParameter); - var longitudeType = new contactJS.AttributeType().withName('longitude') - .withType('double'); + var latitudeType = new contactJS.Attribute().withName('latitude').withType('double').withParameter(testParameter); + var longitudeType = new contactJS.Attribute().withName('longitude').withType('double'); + var array = []; array.push(longitudeType); diff --git a/qunitTest/interpret_AggregatorInterpreterTest.js b/qunitTest/interpret_AggregatorInterpreterTest.js index bc2c4b7..1f40965 100644 --- a/qunitTest/interpret_AggregatorInterpreterTest.js +++ b/qunitTest/interpret_AggregatorInterpreterTest.js @@ -8,46 +8,41 @@ require(['configTest'], function() { var discoverer = new contactJS.Discoverer(); new GeoLocationWidget(discoverer); new AddressInterpreter(discoverer); + + var formattedAddressType = new contactJS.Attribute().withName('formattedAddress').withType('string'); + var testAggregator = new contactJS.Aggregator(discoverer, [ - new contactJS.AttributeType().withName('formattedAddress').withType('string') + formattedAddressType ]); var interpreter = discoverer.getDescriptions([contactJS.Interpreter]); //put data into aggregator - var latitudeValue = new contactJS.AttributeValue().withName('latitude') - .withType('double').withValue(52.3992404); - var longitudeValue = new contactJS.AttributeValue().withName('longitude') - .withType('double').withValue(13.066132); + var latitudeValue = new contactJS.Attribute().withName('latitude').withType('double').withValue(52.3992404); + var longitudeValue = new contactJS.Attribute().withName('longitude').withType('double').withValue(13.066132); - var list = new contactJS.AttributeValueList(); - list.put(latitudeValue); - list.put(longitudeValue); + var list = new contactJS.AttributeList().withItems([latitudeValue, longitudeValue]); testAggregator.putData(list); //if aggregator provides more attributes - var typeList = new contactJS.AttributeTypeList(); - typeList.put(latitudeValue.getAttributeType()); - typeList.put(longitudeValue.getAttributeType()); + var typeList = new contactJS.AttributeList().withItems([latitudeValue, longitudeValue]); var aggData = testAggregator.getCurrentData(); var data = aggData.getSubset(typeList); assert.equal( data.size(), 2, "Passed!: two available attributes" ); //call Interpreter - var callFunktion = function(){ - var interpret = testAggregator.getInterpretedData(interpreter[0].getId()); - var formattedAddress = interpret.getOutAttributes(); - testAggregator.addAttribute(formattedAddress.getItem('formattedAddress')); + var callFunktion = function(interpret){ + testAggregator.addAttribute(interpret.getAttributeWithTypeOf(formattedAddressType)); var data2 = testAggregator.getCurrentData(); assert.equal( data2.size(), 3,"Passed!: three available attributes" ); - var item = data2.getItem('(formattedAddress:string)'); + var item = data2.getAttributeWithTypeOf(formattedAddressType); assert.ok(item,"Callback passed!: interpreted data exists" ); var add = "Charlottenstraße 70, 14467 Potsdam, Deutschland"; assert.equal(item.getValue(), add ,"Passed!: interpreted data equals expected value" ); }; - testAggregator.interpretData(interpreter[0].getId(), function () {callFunktion(); QUnit.start();}); + testAggregator.interpretData(interpreter[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 d09b6a5..6d6a71f 100644 --- a/qunitTest/interpreterTest.js +++ b/qunitTest/interpreterTest.js @@ -10,24 +10,22 @@ require(['configTest'], function() { assert.equal( testInterpreter.getType(), 'Interpreter',"Passed!: type -> Interpreter" ); //getInAttributeTypes - var latitudeType = new contactJS.AttributeType().withName('latitude') - .withType('double'); - var longitudeType = new contactJS.AttributeType().withName('longitude') - .withType('double'); + var latitudeType = new contactJS.Attribute().withName('latitude').withType('double'); + var longitudeType = new contactJS.Attribute().withName('longitude').withType('double'); var inTypes = testInterpreter.getInAttributeTypes(); assert.ok( inTypes.size() == 2,"Passed!: 2 defined type in addressInterpreter" ); - assert.ok( inTypes.getItem('(latitude:double)'),"Passed!:type latitude exists" ); - assert.ok( inTypes.getItem('(latitude:double)').equals(latitudeType),"Passed!:type latitude equals expected type" ); - assert.ok( inTypes.getItem('(longitude:double)'),"Passed!:type longitude exists" ); - assert.ok( inTypes.getItem('(longitude:double)').equals(longitudeType),"Passed!: longitude equals expected type" ); + assert.ok( inTypes.getAttributeWithTypeOf(latitudeType),"Passed!:type latitude exists" ); + assert.ok( inTypes.getAttributeWithTypeOf(latitudeType).equalsTypeOf(latitudeType),"Passed!:type latitude equals expected type" ); + assert.ok( inTypes.getAttributeWithTypeOf(longitudeType),"Passed!:type longitude exists" ); + assert.ok( inTypes.getAttributeWithTypeOf(longitudeType).equalsTypeOf(longitudeType),"Passed!: longitude equals expected type" ); //getOutAttributeTypes - var formattedAddress = new contactJS.AttributeType().withName('formattedAddress').withType('string'); + var formattedAddress = new contactJS.Attribute().withName('formattedAddress').withType('string'); var outTypes = testInterpreter.getOutAttributeTypes(); assert.ok( outTypes.size() == 1,"Passed!: 1 defined outType in addressInterpreter" ); - assert.ok( outTypes.getItem('(formattedAddress:string)'),"Passed!: formattedAddress exists" ); - assert.ok( outTypes.getItem('(formattedAddress:string)').equals(formattedAddress),"Passed!: formattedAddress equals expected type" ); + assert.ok( outTypes.getAttributeWithTypeOf(formattedAddress),"Passed!: formattedAddress exists" ); + assert.ok( outTypes.getAttributeWithTypeOf(formattedAddress).equalsTypeOf(formattedAddress),"Passed!: formattedAddress equals expected type" ); //interpreterDescription @@ -40,34 +38,25 @@ require(['configTest'], function() { //callInterpreter && getInterpretedData with callback - var latitudeValue = new contactJS.AttributeValue().withName('latitude') - .withType('double').withValue(52.3992404); - var longitudeValue = new contactJS.AttributeValue().withName('longitude') - .withType('double').withValue(13.066132); - - var array = []; - array.push(latitudeValue); - array.push(longitudeValue); - var attributeList = new contactJS.AttributeValueList().withItems(array); + var latitudeValue = new contactJS.Attribute().withName('latitude').withType('double').withValue(52.3992404); + var longitudeValue = new contactJS.Attribute().withName('longitude').withType('double').withValue(13.066132); + + var attributeList = new contactJS.AttributeList().withItems([latitudeValue, longitudeValue]); - var assertData2 = function(){ - var result = testInterpreter.getInterpretedData(); - var data = result.getOutAttributes(); - var data2 = result.getInAttributes(); + var assertData2 = function(result){ assert.ok( testInterpreter.getLastInterpretionTime(),"Callback passed!: getLastInterpretionTime exists" ); - assert.equal(data.size(), 1, "Callback passed!: one outAttribute"); - assert.equal(data2.size(), 2, "Callback passed!: two inAttributes"); - var list = data.getItems(); - for(var i in list){ + assert.equal(result.size(), 1, "Callback passed!: one outAttribute"); + var list = result.getItems(); + for(var i in list){ var att = list[i]; assert.ok(att,"Callback passed!: interpreted data exists" ); - assert.ok(att.getAttributeType().equals(formattedAddress),"Callback passed!: interpreted data equals expected type" ); + assert.ok(att.equalsTypeOf(formattedAddress),"Callback passed!: interpreted data equals expected type" ); var add = "Charlottenstraße 70, 14467 Potsdam, Deutschland"; assert.equal(att.getValue(), add ,"Passed!: interpreted data equals expected value" ); } }; - testInterpreter.callInterpreter(attributeList, function () {assertData2(); QUnit.start();}); + testInterpreter.callInterpreter(attributeList, outTypes, function (result) {assertData2(result); QUnit.start();}); }); diff --git a/qunitTest/notify_AggregatorWidgetTest.js b/qunitTest/notify_AggregatorWidgetTest.js index a4d9e06..082a056 100644 --- a/qunitTest/notify_AggregatorWidgetTest.js +++ b/qunitTest/notify_AggregatorWidgetTest.js @@ -6,10 +6,8 @@ require(['configTest'], function() { var discoverer = new contactJS.Discoverer(); new GeoLocationWidget(discoverer); - var latitudeType = new contactJS.AttributeType().withName('latitude') - .withType('double'); - var longitudeType = new contactJS.AttributeType().withName('longitude') - .withType('double'); + var latitudeType = new contactJS.Attribute().withName('latitude').withType('double'); + var longitudeType = new contactJS.Attribute().withName('longitude').withType('double'); //initializes the Infrastructure var testAggregator = new contactJS.Aggregator(discoverer, [ @@ -21,11 +19,11 @@ require(['configTest'], function() { var checkValues = function(newValues){ assert.equal( newValues.size(), 2,"notify Passed!: two available attributes" ); - var latitude = newValues.getItem('(latitude:double)'); + var latitude = newValues.getAttributeWithTypeOf(latitudeType); assert.equal(latitude.getName(), 'latitude', "notify Passed!: latitude exists" ); assert.notEqual(latitude.getValue(), 'undefined', "notify Passed!: value of latitude is no longer undefined" ); - var longitude = newValues.getItem('(longitude:double)'); + var longitude = newValues.getAttributeWithTypeOf(longitudeType); assert.equal(longitude.getName(), 'longitude',"notify Passed!: longitude exists" ); assert.notEqual(longitude.getValue(), 'undefined',"notify Passed!: value of longitude is no longer undefined" ); }; diff --git a/qunitTest/storageTableContentTest.js b/qunitTest/storageTableContentTest.js index 88d1c7b..321a41c 100644 --- a/qunitTest/storageTableContentTest.js +++ b/qunitTest/storageTableContentTest.js @@ -6,35 +6,29 @@ require(['configTest'], function() { var discoverer = new contactJS.Discoverer(); //initializes the test environment var testAggregator = new contactJS.Aggregator(discoverer, [ - new contactJS.AttributeType().withName('latitude').withType('double'), - new contactJS.AttributeType().withName('longitude').withType('double') + new contactJS.Attribute().withName('latitude').withType('double'), + new contactJS.Attribute().withName('longitude').withType('double') ]); //put data into aggregator - var latitudeValue = new contactJS.AttributeValue().withName('latitude').withType('double').withValue(52.3992404); - var longitudeValue = new contactJS.AttributeValue().withName('longitude').withType('double').withValue(13.066132); + var latitudeValue = new contactJS.Attribute().withName('latitude').withType('double').withValue(52.3992404); + var longitudeValue = new contactJS.Attribute().withName('longitude').withType('double').withValue(13.066132); - var list = new contactJS.AttributeValueList(); - list.put(latitudeValue); - list.put(longitudeValue); - testAggregator.putData(list); + testAggregator.putData(new contactJS.AttributeList().withItems([latitudeValue, longitudeValue])); var data = testAggregator.getCurrentData(); assert.equal(data.size(), 2, "Passed!: two available attributes"); var assertion = function(){ var retrievalResult = testAggregator.retrieveStorage(); - assert.ok(retrievalResult,"Passed!: retrievalResult exists"); - assert.equal(retrievalResult.getName(), 'latitude', "Passed!: name of retrievalResult is latitude"); + assert.ok(retrievalResult ,"Passed!: retrievalResult exists"); + assert.equal(retrievalResult.getName(), '(latitude:double)', "Passed!: name of retrievalResult is latitude"); var data = retrievalResult.getValues(); assert.ok(data,"Passed!: entries exists" ); - assert.equal(data[0].getName(), 'latitude', "Passed!: attributes name is latitude"); + assert.equal(data[0].getName(), '(latitude:double)', "Passed!: attributes name is latitude"); }; - testAggregator.queryAttribute('latitude', function () {assertion(); QUnit.start();}); + testAggregator.queryAttribute('(latitude:double)', function () {assertion(); QUnit.start();}); }); - - - }); }); \ No newline at end of file diff --git a/qunitTest/storageTableTest.js b/qunitTest/storageTableTest.js index b79bbba..b730e1c 100644 --- a/qunitTest/storageTableTest.js +++ b/qunitTest/storageTableTest.js @@ -7,18 +7,15 @@ require(['configTest'], function() { var discoverer = new contactJS.Discoverer(); //initializes the test environment var testAggregator = new contactJS.Aggregator(discoverer, [ - new contactJS.AttributeType().withName('latitude').withType('double'), - new contactJS.AttributeType().withName('longitude').withType('double') + new contactJS.Attribute().withName('latitude').withType('double'), + new contactJS.Attribute().withName('longitude').withType('double') ]); //put data into aggregator - var latitudeValue = new contactJS.AttributeValue().withName('latitude') - .withType('double').withValue(52.3992404); - var longitudeValue = new contactJS.AttributeValue().withName('longitude') - .withType('double').withValue(13.066132); - var list = new contactJS.AttributeValueList(); - list.put(latitudeValue); - list.put(longitudeValue); + var latitudeValue = new contactJS.Attribute().withName('latitude').withType('double').withValue(52.3992404); + var longitudeValue = new contactJS.Attribute().withName('longitude').withType('double').withValue(13.066132); + + var list = new contactJS.AttributeList().withItems([latitudeValue, longitudeValue]); testAggregator.putData(list); var data = testAggregator.getCurrentData(); @@ -30,10 +27,8 @@ require(['configTest'], function() { assert.notEqual(jQuery.inArray('latitude', tables), '-1', "Passed!: table latitude exists" ); assert.notEqual(jQuery.inArray('longitude', tables), '-1', "Passed!: table longitude exists" ); }; + testAggregator.queryTables(function () {assertion(); QUnit.start();}); }); - - - }); }); \ No newline at end of file diff --git a/qunitTest/subscriberListTest.js b/qunitTest/subscriberListTest.js index 41a04e2..d6d7dba 100644 --- a/qunitTest/subscriberListTest.js +++ b/qunitTest/subscriberListTest.js @@ -4,34 +4,27 @@ require(['configTest'], function() { QUnit.test( "SubscriberList", function( assert ) { - var attributeType2 = new contactJS.AttributeType().withName('testName'). - withType('integer'); - var attArray = new Array(); - attArray.push(attributeType2); - var attList = new contactJS.AttributeTypeList().withItems(attArray); - var call = new contactJS.Callback().withName('test').withAttributeTypes(attList); - - var callArray = new Array(); - callArray.push(call); - var callList = new contactJS.CallbackList().withItems(callArray); + var attributeType2 = new contactJS.Attribute().withName('testName').withType('integer'); + + var attList = new contactJS.AttributeList().withItems([attributeType2]); + + var call = new contactJS.Callback().withName('test').withAttributeTypes(attList); + var callList = new contactJS.CallbackList().withItems([call]); - var subscriber = new contactJS.Subscriber().withSubscriberName('test') + var subscriber = new contactJS.Subscriber().withSubscriberName('test') .withSubscriberId('test') .withSubscriptionCallbacks(callList) .withAttributesSubset(attList); - var subscriber2 = new contactJS.Subscriber().withSubscriberName('test1') + var subscriber2 = new contactJS.Subscriber().withSubscriberName('test1') .withSubscriberId('test1') .withSubscriptionCallbacks(callList) .withAttributesSubset(attList); - var subscriber3 = new contactJS.Subscriber().withSubscriberName('test2') + var subscriber3 = new contactJS.Subscriber().withSubscriberName('test2') .withSubscriberId('test2') .withSubscriptionCallbacks(callList); - - var array = new Array(); - array.push(subscriber2); - array.push(subscriber3); - var list = new contactJS.SubscriberList().withItems(array); + + var list = new contactJS.SubscriberList().withItems([subscriber2, subscriber3]); assert.ok( list.size() == 2, "Passed!: Builder (withItems)" ); var list2 = new contactJS.SubscriberList(); @@ -39,7 +32,7 @@ require(['configTest'], function() { assert.ok( list2.size() == 1, "Passed!: Put type to list (put)" ); - list2.putAll(array); + list2.putAll([subscriber2, subscriber3]); assert.ok( list2.size() == 3, "Passed!: Put another two type to list (putAll)" ); //contains diff --git a/qunitTest/subscriberTest.js b/qunitTest/subscriberTest.js index 75abec3..59bf916 100644 --- a/qunitTest/subscriberTest.js +++ b/qunitTest/subscriberTest.js @@ -5,20 +5,15 @@ require(['configTest'], function() { var parameter = new contactJS.Parameter().withKey('testKey').withValue('testValue'); - var attributeType = new contactJS.AttributeType(); - var attributeType2 = new contactJS.AttributeType().withName('testName'). - withType('integer').withParameter(parameter); - var attArray = new Array(); - attArray.push(attributeType); - var attList = new contactJS.AttributeTypeList().withItems(attArray); - - attArray.push(attributeType2); - var attList2 = new contactJS.AttributeTypeList().withItems(attArray); + var attributeType = new contactJS.Attribute(); + var attributeType2 = new contactJS.Attribute().withName('testName').withType('integer').withParameter(parameter); + + var attList = new contactJS.AttributeList().withItems([attributeType]); + var attList2 = new contactJS.AttributeList().withItems([attributeType, attributeType2]); + var call = new contactJS.Callback().withName('test').withAttributeTypes(attList2); - - var callArray = new Array(); - callArray.push(call); - var callList = new contactJS.CallbackList().withItems(callArray); + + var callList = new contactJS.CallbackList().withItems([call]); var subscriber = new contactJS.Subscriber().withSubscriberName('test') .withSubscriberId('test2') @@ -29,13 +24,14 @@ require(['configTest'], function() { .withSubscriberId('test2') .withSubscriptionCallbacks(callList) .withAttributesSubset(attList); + var subscriber3 = new contactJS.Subscriber().withSubscriberName('test') .withSubscriberId('test3') .withSubscriptionCallbacks(callList); + var test = subscriber.getAttributesSubset(); - - - assert.ok(test.size() == 1,"Passed!: AttributeSubset.size() == 1"); + + assert.equal(test.size(), 1, "Passed!: AttributeSubset.size() == 1"); assert.ok( subscriber.equals(subscriber2),"Passed!: equals -> true" ); assert.ok( !subscriber.equals(subscriber3),"Passed!: equals -> false" ); diff --git a/qunitTest/widgetTest.js b/qunitTest/widgetTest.js index d0d3631..c0cab26 100644 --- a/qunitTest/widgetTest.js +++ b/qunitTest/widgetTest.js @@ -5,7 +5,10 @@ require(['configTest'], function() { QUnit.asyncTest( "GeoLocationWidget ", function( assert ) { var discoverer = new contactJS.Discoverer(); var testWidget = new GeoLocationWidget(discoverer); - + + var latitudeType = new contactJS.Attribute().withName('latitude').withType('double'); + var longitudeType = new contactJS.Attribute().withName('longitude').withType('double'); + var id = testWidget.getId(); assert.ok( id && id !== "null" && id !== "undefined", "Passed!: id is not null" ); assert.equal( testWidget.getType(), 'Widget', "Passed!: type -> Widget" ); @@ -28,34 +31,34 @@ require(['configTest'], function() { //attributes var attributes= testWidget.getAttributeValues(); assert.equal(attributes.size(), 2,"queryAttributes Passed!: two attributes were returned" ); - var latitude = attributes.getItem('(latitude:double)'); + var latitude = attributes.getAttributeWithTypeOf(latitudeType); assert.equal(latitude.getName(), 'latitude',"queryAttributes Passed!: latitude exists" ); - assert.equal(latitude.getValue(), 'undefined',"queryAttributes Passed!: value of latitude is undefined" ); + assert.equal(latitude.getValue(), 'NO_VALUE',"queryAttributes Passed!: value of latitude is undefined" ); - var longitude = attributes.getItem('(longitude:double)'); + var longitude = attributes.getAttributeWithTypeOf(longitudeType); assert.equal(longitude.getName(), 'longitude',"queryAttributes Passed!: longitude exists" ); - assert.equal(longitude.getValue(), 'undefined',"queryAttributes Passed!: value of longitude is undefined" ); + assert.equal(longitude.getValue(), 'NO_VALUE',"queryAttributes Passed!: value of longitude is undefined" ); //updateAndQuery without callback var attributes2 = testWidget.updateAndQueryWidget(); assert.equal(attributes2.size(), 2,"updateAndQueryWidget without callback Passed!: two attributes were returned" ); - var latitude2 = attributes2.getItem('(latitude:double)'); + var latitude2 = attributes2.getAttributeWithTypeOf(latitudeType); assert.equal(latitude2.getName(), 'latitude',"updateAndQueryWidget without callbackPassed!: latitude exists" ); - assert.equal(latitude2.getValue(), 'undefined',"value of latitude is not updated yet: " +latitude2.getValue() ); + assert.equal(latitude2.getValue(), 'NO_VALUE',"value of latitude is not updated yet: " +latitude2.getValue() ); - var longitude2 = attributes.getItem('(longitude:double)'); + var longitude2 = attributes.getAttributeWithTypeOf(longitudeType); assert.equal(longitude2.getName(), 'longitude',"updateAndQueryWidget without callbackPassed!: longitude exists" ); - assert.equal(longitude2.getValue(), 'undefined',"value of longitude is not updated yet: " + longitude2.getValue() ); + assert.equal(longitude2.getValue(), 'NO_VALUE',"value of longitude is not updated yet: " + longitude2.getValue() ); //updateAndQuery with callback var testUpdateAndQuery = function(){ var attributes2 = testWidget.queryWidget(); assert.equal(attributes2.size(), 2, "updateAndQueryWidget with callback Passed!: two attributes were returned" ); - var latitude2 = attributes2.getItem('(latitude:double)'); + var latitude2 = attributes2.getAttributeWithTypeOf(latitudeType); assert.equal(latitude2.getName(), 'latitude', "updateAndQueryWidget with callback Passed!: latitude exists" ); assert.notEqual(latitude2.getValue(), 'undefined', "value of latitude is: " +latitude2.getValue() ); - var longitude2 = attributes.getItem('(longitude:double)'); + var longitude2 = attributes.getAttributeWithTypeOf(longitudeType); assert.equal(longitude2.getName(), 'longitude',"updateAndQueryWidget with callback Passed!: longitude exists" ); assert.notEqual(longitude2.getValue(), 'undefined', "value of longitude is: " + longitude2.getValue() ); }; -- GitLab