diff --git a/build/contactJS.js b/build/contactJS.js index 8a0ee3398b4472a57ce7d5210ae24b1a5252ad77..5eee3bebf24c6f7dfabf63e59330ece77da0a97c 100644 --- a/build/contactJS.js +++ b/build/contactJS.js @@ -70,7 +70,7 @@ contactJS.InterpreterResult = InterpreterResult; contactJS.Callback = Callback; contactJS.CallbackList = CallbackList; - contactJS.Subscriber =Subscriber; + contactJS.Subscriber = Subscriber; contactJS.SubscriberList = SubscriberList; contactJS.Widget = Widget; contactJS.AbstractList = AbstractList; diff --git a/dist/contactJS.js b/dist/contactJS.js index c5f48fd1d65c6570314a8b80905289eeb8bf6006..9639fe6b52245b91831f144e6de7905a94a41f14 100644 --- a/dist/contactJS.js +++ b/dist/contactJS.js @@ -1523,19 +1523,19 @@ define('attributeList',['easejs', 'abstractList', 'attribute', 'parameterList' ] 'public equals': function(_attributeList, _typeOnly) { _typeOnly = typeof _typeOnly == "undefined" ? false : _typeOnly; - return _typeOnly ? this.equalsAllTypesOf(_attributeList) : this.equalsAllValuesOf(_attributeList); + return _typeOnly ? this.equalsTypesIn(_attributeList) : this.equalsValuesIn(_attributeList); }, /** * Compare the specified AttributeList with this instance. * * @public - * @alias equals + * @alias equalsTypesIn * @memberof AttributeList# * @param {AttributeList} _attributeList AttributeList that should be compared. * @returns {boolean} */ - 'public equalsAllTypesOf' : function(_attributeList) { + 'public equalsTypesIn' : function(_attributeList) { if (Class.isA(AttributeList, _attributeList) && _attributeList.size() == this.size()) { for (var index in _attributeList.getItems()) { var theAttributeType = _attributeList.getItems()[index]; @@ -1551,12 +1551,12 @@ define('attributeList',['easejs', 'abstractList', 'attribute', 'parameterList' ] * this instance. * * @public - * @alias equals + * @alias equalsValuesIn * @memberof AttributeList# * @param {AttributeList} _attributeList AttributeList that should be compared. * @returns {boolean} */ - 'public equalsAllValuesOf' : function(_attributeList) { + 'public equalsValuesIn' : function(_attributeList) { if (Class.isA(AttributeList, _attributeList) && _attributeList.size() == this.size()) { for (var index in _attributeList.getItems()) { var theAttribute = _attributeList.getItems()[index]; @@ -1589,7 +1589,7 @@ define('attributeList',['easejs', 'abstractList', 'attribute', 'parameterList' ] var attribute = list[i]; if (Class.isA(Attribute, attribute)) { var attribute = this.getAttributeWithTypeOf(attribute); - if (typeof attribute != "undefined") { + if (typeof attribute != "NO_VALUE") { response.put(attribute); } } @@ -3733,7 +3733,7 @@ define('widgetDescription',['easejs', 'attributeList'], * @public * @alias addOutAttributeTypes * @memberof WidgetDescription# - * @param {(AttributeTypeList|Array)} _outAttributeTypes List of AttributeType that are provided + * @param {(AttributeList|Array)} _outAttributeTypes List of AttributeType that are provided */ 'public addOutAttributeTypes' : function(_outAttributeTypes){ this.outAttributeTypes.putAll(_outAttributeTypes); @@ -3753,11 +3753,12 @@ define('widgetDescription',['easejs', 'attributeList'], * @public * @alias doesSatisfyAttributeType * @memberof WidgetDescription# - * @param {AttributeType} _attributeType + * @param {AttributeType} _attribute * @returns {boolean} */ - 'public doesSatisfyAttributeType': function(_attributeType) { - return this.getOutAttributeTypes().contains(_attributeType); + + 'public doesSatisfyAttributeType': function(_attribute) { + return this.getOutAttributeTypes().containsTypeOf(_attribute); } }); @@ -3796,27 +3797,11 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * @desc ID of the Widget. Will be generated. */ 'public id' : '', - /** - * @alias attributeTypes - * @protected - * @type {AttributeTypeList} - * @memberof Widget# - * @desc Types of all available attributes. - */ - 'protected attributeTypes' : [], - /** - * @alias constantAttributeTypes - * @protected - * @type {AttributeTypeList} - * @memberof Widget# - * @desc Types of all available ConstantAttributes. - */ - 'protected constantAttributeTypes' : [], /** * @alias attributes * @protected - * @type {AttributeValueList} + * @type {AttributeList} * @memberof Widget# * @desc All available Attributes and their values. */ @@ -3824,7 +3809,7 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', /** * @alias oldAttributes * @protected - * @type {AttributeValueList} + * @type {AttributeList} * @memberof Widget# * @desc This temporary variable is used for storing the old attribute values. * So these can be used to check conditions. @@ -3833,7 +3818,7 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', /** * @alias constantAttributes * @protected - * @type {AttributeValueList} + * @type {AttributeList} * @memberof Widget# * @desc All available constant Attributes and their values. */ @@ -3876,10 +3861,8 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * @requires MathUuid * @requires Callback * @requires CallbackList - * @requires AttributeType - * @requires AttributeValue - * @requires AttributeTypeList - * @requires AttributeValueList + * @requires Attribute + * @requires AttributeList * @requires ConditionList * @requires Subscriber * @requires SubscriberList @@ -3891,8 +3874,6 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', this.id = Math.uuid(); this.discoverer = _discoverer; this.register(); - this.attributeTypes = new AttributeList(); - this.constantAttributeTypes = new AttributeList(); this.attributes = new AttributeList(); this.constantAttributes = new AttributeList(); this.subscribers = new SubscriberList(); @@ -3942,12 +3923,16 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * Returns the available AttributeTypes. * * @public - * @alias getAttributeTypes + * @alias getAttributes * @memberof Widget# - * @returns {AttributeTypeList} + * @returns {AttributeList} */ - 'public getAttributeTypes' : function() { - return this.attributeTypes; + 'public getAttributes' : function(_attributeList) { + if (Class.isA(AttributeList, _attributeList)) { + return this.attributes.getSubset(_attributeList); + } else { + return this.attributes; + } }, /** @@ -3959,25 +3944,12 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * @memberof Widget# * @returns {AttributeList} */ - 'public getWidgetConstantAttributeTypes' : function() { - return this.constantAttributeTypes; - }, - - /** - * Returns the last acquired attribute values. - * - * @public - * @alias getAttributes - * @memberof Widget# - * @param {AttributeList} _attributeList - * @returns {AttributeList} - */ - 'public getAttributeValues' : function(_attributeList) { - if (Class.isA(AttributeList, _attributeList)) { - return this.attributes.getSubset(_attributeList); - } else { - return this.attributes; - } + 'public getConstantAttributes' : function(_attributeList) { + if (Class.isA(AttributeList, _attributeList)) { + return this.constantAttributes.getSubset(_attributeList); + } else { + return this.constantAttributes; + } }, /** @@ -3986,8 +3958,8 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * @param {AttributeType} _attributeType The attribute type to return the last value for. * @returns {*} */ - 'public getAttributeValue': function(_attributeType) { - return this.getAttributeValues().getItemForAttributeType(_attributeType).getValue(); + 'public getValueForAttributeWithTypeOf': function(_attributeType) { + return this.getAttributes().getAttributeWithTypeOf(_attributeType).getValue(); }, /** @@ -4002,18 +3974,6 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', return this.oldAttributes; }, - /** - * Returns the ConstantAttributes. - * - * @public - * @alias getConstantAttributes - * @memberof Widget# - * @returns {AttributeList} - */ - 'public getConstantAttributes' : function() { - return this.constantAttributes; - }, - /** * Returns a list of callbacks that can be * subscribed to. @@ -4133,20 +4093,14 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * @memberof Widget# * @param {Attribute} _attribute AttributeValue */ - 'public addAttribute' : function(_attribute) { + 'public addAttribute' : function(_attribute, _multipleInstances) { + _multipleInstances = typeof _multipleInstances == "undefined" ? false : _multipleInstances; if (Class.isA(Attribute, _attribute)) { - if (!this.attributes.contains(_attribute)) { - - var type = new Attribute().withName(_attribute.getName()) - .withType(_attribute.getType()) - .withParameters(_attribute.getParameters()); - this.attributeTypes.put(type); - + if (!this.attributes.containsTypeOf(_attribute)) { + this.oldAttributes = this.attributes; + _attribute.setTimestamp(this.getCurrentTime()); + this.attributes.put(_attribute, _multipleInstances); } - this.oldAttributes = this.attributes; - - _attribute.setTimestamp(this.getCurrentTime()); - this.attributes.put(_attribute); } }, @@ -4323,7 +4277,7 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * @returns {boolean} */ 'protected isAttribute' : function(_attribute) { - return !!this.attributeTypes.containsTypeOf(_attribute); + return !!this.attributes.containsTypeOf(_attribute); }, /** @@ -4471,7 +4425,7 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', */ 'public queryWidget' : function() { var response = new AttributeList(); - response.putAll(this.getAttributeValues()); + response.putAll(this.getAttributes()); response.putAll(this.getConstantAttributes()); return response; }, @@ -4492,7 +4446,7 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', } else { this.queryGenerator(); var response = new AttributeList(); - response.putAll(this.getAttributeValues()); + response.putAll(this.getAttributes()); response.putAll(this.getConstantAttributes()); return response; } @@ -4567,8 +4521,8 @@ define('widget',[ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', */ 'virtual public getDescription' : function() { var description = new WidgetDescription().withId(this.id).withName(this.name); - description.addOutAttributeTypes(this.attributeTypes); - description.addOutAttributeTypes(this.constantAttributeTypes); + description.addOutAttributeTypes(this.attributes); + description.addOutAttributeTypes(this.constantAttributes); var widgetCallbacks = this.callbacks.getItems(); for(var i in widgetCallbacks) { description.addCallbackName(widgetCallbacks[i].getName()); @@ -4961,37 +4915,21 @@ define('interpreter',[ 'easejs', 'MathUuid', 'attribute', 'attributeList', */ 'public id' : '', /** - * @alias inAttributeTypes + * @alias inAttributes * @protected * @type {AttributeList} * @memberof Interpreter# * @desc Types of all attributes that can be handled. */ - 'protected inAttributeTypes' : [], + 'protected inAttributes' : [], /** - * @alias outAttributeTypes + * @alias outAttributes * @protected * @type {AttributeList} * @memberof Interpreter# * @desc Types of all attributes that will be returned. */ - 'protected outAttributeTypes' : [], - /** - * @alias inAttributeValues - * @protected - * @type {AttributeList} - * @memberof Interpreter# - * @desc List of the data that should be interpreted. - */ - 'protected inAttributeValues' : [], - /** - * @alias outAttributeValues - * @protected - * @type {AttributeList} - * @memberof Interpreter# - * @desc List of interpreted data. - */ - 'protected outAttributeValues' : [], + 'protected outAttributes' : [], /** * @alias lastInterpretation * @protected @@ -5026,10 +4964,8 @@ define('interpreter',[ 'easejs', 'MathUuid', 'attribute', 'attributeList', this.id = Math.uuid(); this.discoverer = _discoverer; this.register(); - this.inAttributeTypes = new AttributeList(); - this.outAttributeTypes = new AttributeList(); - this.inAttributeValues = new AttributeList(); - this.outAttributeValues = new AttributeList(); + this.inAttributes = new AttributeList(); + this.outAttributes = new AttributeList(); this.initInterpreter(); }, @@ -5109,10 +5045,10 @@ define('interpreter',[ 'easejs', 'MathUuid', 'attribute', 'attributeList', * @public * @alias getInAttributeTypes * @memberof Interpreter# - * @returns {AttributeTypeList} + * @returns {AttributeList} */ - 'public getInAttributeTypes' : function() { - return this.inAttributeTypes; + 'public getInAttributes' : function() { + return this.inAttributes; }, /** @@ -5121,53 +5057,46 @@ define('interpreter',[ 'easejs', 'MathUuid', 'attribute', 'attributeList', * @protected * @alias setInAttribute * @memberof Interpreter# - * @param {string} _name name of the attribute - * @param {string} _type type of the attribute - * @param {string} _value value of the attribute - * @param {ParameterList|Array} _parameter Parameter of the attribute. */ - 'protected setInAttribute' : function(_name, _type, _value, _parameters) { - var attributeValue = new Attribute().withName(_name) - .withValue(_value).withType(_type).withParameters(_parameters); - if (this.isInAttribute(attributeValue)) { - this.inAttributeValues.put(attributeValue); - } + 'protected setInAttribute' : function(_attribute) { + this.inAttributes.put(_attribute); }, /** * Sets an inAttributes. * * @protected - * @alias setInAttributeValues + * @alias setInAttributes * @memberof Interpreter# * @param {(AttributeList|Array)} _attributeList Attributes to set. */ - 'protected setInAttributeValues' : function(_attributeList) { - this.inAttributeValues = new AttributeList().withItems(_attributeList); + 'protected setInAttributes' : function(_attributeList) { + this.inAttributes = new AttributeList().withItems(_attributeList); }, + /** * Verifies whether the specified attribute is contained in inAttributeList. * * @protected * @alias isInAttribute * @memberof Interpreter# - * @param {AttributeValue} _attribute Attribute that should be verified. + * @param {Attribute} _attribute Attribute that should be verified. * @return {boolean} */ 'protected isInAttribute' : function(_attribute) { - return !!this.inAttributeTypes.containsTypeOf(_attribute); + return !!this.inAttributes.containsTypeOf(_attribute); }, /** * Returns the provided outAttributeTypes. * * @public - * @alias getOutAttributeTypes + * @alias getOutAttributes * @memberof Interpreter# - * @returns {AttributeTypeList} + * @returns {AttributeList} */ - 'public getOutAttributeTypes' : function() { - return this.outAttributeTypes; + 'public getOutAttributes' : function() { + return this.outAttributes; }, /** @@ -5176,17 +5105,21 @@ define('interpreter',[ 'easejs', 'MathUuid', 'attribute', 'attributeList', * @protected * @alias setOutAttribute * @memberof Interpreter# - * @param {string} _name name of the attribute - * @param {string} _type type of the attribute - * @param {string} _value value of the attribute - * @param {ParameterList|Array} _parameters Parameter of the attribute. */ - 'protected setOutAttribute' : function(_name, _type, _value,_parameters) { - var attributeValue = new AttributeValue().withName(_name) - .withValue(_value).withType(_type).withParameters(_parameters); - if (this.isOutAttribute(attributeValue)) { - this.outAttributeValues.put(attributeValue); - } + 'protected setOutAttribute' : function(_attribute) { + this.outAttributes.put(_attribute); + }, + + /** + * Sets an outAttributes. + * + * @protected + * @alias setOutAttributes + * @memberof Interpreter# + * @param {(AttributeList|Array)} _attributeList Attributes to set. + */ + 'protected setOutAttributes' : function(_attributeList) { + this.outAttributes = new AttributeList().withItems(_attributeList); }, /** @@ -5195,11 +5128,11 @@ define('interpreter',[ 'easejs', 'MathUuid', 'attribute', 'attributeList', * @protected * @alias isOutAttribute * @memberof Interpreter# - * @param {AttributeValue} _attribute Attribute that should be verified. + * @param {Attribute} _attribute Attribute that should be verified. * @return {boolean} */ 'protected isOutAttribute' : function(_attribute) { - return !!this.outAttributeTypes.containsTypeOf(_attribute); + return !!this.outAttributes.containsTypeOf(_attribute); }, /** @@ -5223,7 +5156,7 @@ define('interpreter',[ 'easejs', 'MathUuid', 'attribute', 'attributeList', if (!self.canHandleOutAttributes(response)) throw "Unhandled output attribute generated."; - self.setInAttributeValues(_inAttributeValues); + self.setInAttributes(_inAttributeValues); self.lastInterpretation = new Date(); if (_function && typeof(_function) == 'function'){ @@ -5260,7 +5193,7 @@ define('interpreter',[ 'easejs', 'MathUuid', 'attribute', 'attributeList', } else if (Class.isA(AttributeList, _inAttributes)) { list = _inAttributes.getItems(); } - if (list.length == 0 || _inAttributes.size() != this.getInAttributeTypes().size()) { + if (list.length == 0 || _inAttributes.size() != this.getInAttributes().size()) { return false; } for ( var i in list) { @@ -5287,7 +5220,7 @@ define('interpreter',[ 'easejs', 'MathUuid', 'attribute', 'attributeList', } else if (Class.isA(AttributeList, _outAttributes)) { list = _outAttributes.getItems(); } - if (list.length == 0 || _outAttributes.size() != this.getOutAttributeTypes().size()) { + if (list.length == 0 || _outAttributes.size() != this.getOutAttributes().size()) { return false; } for ( var i in list) { @@ -5320,10 +5253,9 @@ define('interpreter',[ 'easejs', 'MathUuid', 'attribute', 'attributeList', * @returns {InterpreterDescription} */ 'virtual public getDescription' : function() { - var description = new InterpreterDescription().withId( - this.id).withName(this.name); - description.addOutAttributeTypes(this.outAttributeTypes); - description.setInAttributeTypes(this.inAttributeTypes); + var description = new InterpreterDescription().withId(this.id).withName(this.name); + description.addOutAttributeTypes(this.outAttributes); + description.setInAttributeTypes(this.inAttributes); return description; }, @@ -5352,7 +5284,6 @@ define('interpreter',[ 'easejs', 'MathUuid', 'attribute', 'attributeList', if (this.discoverer) { this.discoverer.registerNewComponent(this); } - }, /** @@ -5360,28 +5291,12 @@ define('interpreter',[ 'easejs', 'MathUuid', 'attribute', 'attributeList', * @returns {boolean} */ 'public hasOutAttributesWithInputParameters': function() { - return this.outAttributeTypes.hasAttributesWithInputParameters(); + return this.outAttributes.hasAttributesWithInputParameters(); }, 'public getOutAttributesWithInputParameters': function() { - return this.outAttributeTypes.getAttributesWithInputParameters(); + return this.outAttributes.getAttributesWithInputParameters(); } - -// /** -// * Unregisters the component to the associated discoverer -// * and deletes the reference. -// * -// * @public -// * @alias register -// * @memberof Widget# -// */ -// 'protected unregister' : function() { -// if (this.discoverer) { -// this.discoverer.unregisterComponent(this.getId()); -// this.discoverer = null; -// } -// }, - }); return Interpreter; @@ -5478,7 +5393,6 @@ define('aggregator',['easejs', 'MathUuid','widget', * @requires easejs * @requires MathUuid * @requires CallbackList - * @requires AttributeType * @requires Attribute * @requires AttributeList * @requires Subscriber @@ -5487,12 +5401,12 @@ define('aggregator',['easejs', 'MathUuid','widget', * @requires Widget * @constructs Aggregator */ - 'override virtual public __construct': function(_discoverer, _attributeTypes) + 'override virtual public __construct': function(_discoverer, _attributes) { this.id = Math.uuid(); this.widgets = []; this.interpretations = []; - this.__super(_discoverer, _attributeTypes); + this.__super(_discoverer, _attributes); }, /** @@ -5508,22 +5422,6 @@ define('aggregator',['easejs', 'MathUuid','widget', 'override public getType' : function(){ return 'Aggregator'; }, - - /** - * Adds new AttributeTypes, useful when a new Widget is subscribed. - * - * @protected - * @alias addAttributeType - * @memberof Aggregator# - * @param {AttributeType} _attribute attributeType - * @param {boolean} _multipleInstances - */ - 'protected addAttributeType' : function(_attribute, _multipleInstances){ - if(Class.isA(Attribute, _attribute )){ - this.attributeTypes.put(_attribute, _multipleInstances); - this.attributes.put(_attribute, _multipleInstances); - } - }, /** * Sets Widget IDs. @@ -5643,10 +5541,10 @@ define('aggregator',['easejs', 'MathUuid','widget', * @public * @alias didFinishInitialization * @memberof Aggregator# - * @param _attributeTypes + * @param _attributes */ - 'override public didFinishInitialization': function(_attributeTypes) { - this.aggregatorSetup(_attributeTypes); + 'override public didFinishInitialization': function(_attributes) { + this.aggregatorSetup(_attributes); }, /** @@ -5657,9 +5555,9 @@ define('aggregator',['easejs', 'MathUuid','widget', * @alias aggregatorSetup * @memberof Aggregator# */ - 'protected aggregatorSetup' : function(_attributeTypes){ + 'protected aggregatorSetup' : function(_attributes){ this.initStorage('DB_'+this.name); - this.setAggregatorAttributeValues(_attributeTypes); + this.setAggregatorAttributeValues(_attributes); this.setAggregatorConstantAttributeValues(); this.setAggregatorCallbacks(); @@ -5717,12 +5615,10 @@ define('aggregator',['easejs', 'MathUuid','widget', * @public * @alias getCurrentData * @memberof Aggregator# - * @returns {AttributeValueList} + * @returns {AttributeList} */ 'public getCurrentData' : function(){ - var response = new AttributeList(); - response.putAll(this.attributes); - return response; + return this.attributes; }, /** @@ -5795,7 +5691,7 @@ define('aggregator',['easejs', 'MathUuid','widget', var typeList = singleCallback.getAttributeTypes().getItems(); for(var y in typeList){ var singleType = typeList[y]; - this.addAttributeType(singleType); + this.addAttribute(singleType); } } this.addWidget(_widgetIdOrWidget); @@ -5813,7 +5709,7 @@ define('aggregator',['easejs', 'MathUuid','widget', * @param {String} _widgetId Widget that should be removed. */ 'public unsubscribeFrom' : function(_widgetId){ - if(typeof _widgetId == "string"){ + if(typeof _widgetId == "string") { var widget = this.discoverer.getComponent(_widgetId); if (widget) { console.log('aggregator unsubscribeFrom: ' + widget.getName()); @@ -5937,8 +5833,8 @@ define('aggregator',['easejs', 'MathUuid','widget', }, /** - * Only actualizes the attributeType cache in th database. - * For an alternativ action can be used a callback. + * Only updates the attribute cache in the database. + * For an alternative action a callback can be used. * * @public * @alias queryTables @@ -5999,16 +5895,16 @@ define('aggregator',['easejs', 'MathUuid','widget', * * @private * @alias doesSatisfyAttributeType - * @param _attributeType + * @param _attribute * @returns {boolean} */ - 'private doesSatisfyAttributeType': function(_attributeType) { + 'private doesSatisfyAttributeType': function(_attribute) { var componentUUIDs = this.getComponentUUIDs(); var doesSatisfy = false; for (var index in componentUUIDs) { var theComponent = this.discoverer.getComponent(componentUUIDs[index]); - if (theComponent.getDescription().doesSatisfyAttributeType(_attributeType)) { + if (theComponent.getDescription().doesSatisfyAttributeType(_attribute)) { doesSatisfy = true; } } @@ -6051,14 +5947,14 @@ define('aggregator',['easejs', 'MathUuid','widget', for (var widgetOutAttributeIndex in outAttributes) { var widgetOutAttribute = outAttributes[widgetOutAttributeIndex]; // add the attribute type to the aggregators list of handled attribute types - if (!this.getAttributeTypes().contains(widgetOutAttribute)) this.addAttributeType(widgetOutAttribute); + if (!this.getAttributes().containsTypeOf(widgetOutAttribute)) this.addAttribute(widgetOutAttribute); console.log("I can now satisfy attribute "+widgetOutAttribute+" with the help of "+theComponent.getName()+"! That was easy :)"); _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."); - var inAttributes = theComponent.getInAttributeTypes().getItems(); + var inAttributes = theComponent.getInAttributes().getItems(); var canSatisfyInAttributes = true; // iterate over the attributes needed to satisfy the interpreter @@ -6092,9 +5988,9 @@ define('aggregator',['easejs', 'MathUuid','widget', for (var unsatisfiedAttributeIndex in _unsatisfiedAttributes.getItems()) { var theUnsatisfiedAttribute = _unsatisfiedAttributes.getItems()[unsatisfiedAttributeIndex]; if (theUnsatisfiedAttribute.equalsTypeOf(interpreterOutAttribute)) { - this.addAttributeType(theUnsatisfiedAttribute); + this.addAttribute(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 AttributeList().withItems([theUnsatisfiedAttribute]))); + this.interpretations.push(new Interpretation(theComponent.getId(), theComponent.getInAttributes(), new AttributeList().withItems([theUnsatisfiedAttribute]))); } } _unsatisfiedAttributes.removeAttributeWithTypeOf(interpreterOutAttribute, true); @@ -6121,7 +6017,7 @@ define('aggregator',['easejs', 'MathUuid','widget', * @memberof Aggregator# */ 'virtual public didFinishSetup': function() { - unsatisfiedAttributes = this.getAttributeTypes().clone(); + unsatisfiedAttributes = this.getAttributes().clone(); // get all widgets that satisfy attribute types this.getComponentsForUnsatisfiedAttributeTypes(unsatisfiedAttributes, false, [Widget]); @@ -6129,7 +6025,7 @@ define('aggregator',['easejs', 'MathUuid','widget', this.getComponentsForUnsatisfiedAttributeTypes(unsatisfiedAttributes, false, [Interpreter]); console.log("Unsatisfied attributes: "+unsatisfiedAttributes.size()); - console.log("Satisfied attributes: "+this.getAttributeTypes().size()); + console.log("Satisfied attributes: "+this.getAttributes().size()); console.log("Interpretations "+this.interpretations.length); }, @@ -6153,14 +6049,14 @@ define('aggregator',['easejs', 'MathUuid','widget', completedQueriesCounter++; if (completedQueriesCounter == self.widgets.length) { if (_callback && typeof(_callback) == 'function') { - _callback(self.getAttributeValues()); + _callback(self.getAttributes()); } } }); } } else { if (_callback && typeof(_callback) == 'function') { - _callback(self.getAttributeValues()); + _callback(self.getAttributes()); } } }, @@ -6181,15 +6077,15 @@ define('aggregator',['easejs', 'MathUuid','widget', for (var index in this.interpretations) { var theInterpretation = this.interpretations[index]; var theInterpreterId = theInterpretation.interpreterId; - var interpretationInAttributeValues = this.getAttributeValues(theInterpretation.inAttributeTypes); - var interpretationOutAttributeValues = this.getAttributeValues(theInterpretation.outAttributeTypes); + var interpretationInAttributeValues = this.getAttributes(theInterpretation.inAttributeTypes); + var interpretationOutAttributeValues = this.getAttributes(theInterpretation.outAttributeTypes); self.interpretData(theInterpreterId, interpretationInAttributeValues, interpretationOutAttributeValues, function(_interpretedData) { for (var j in _interpretedData.getItems()) { var theInterpretedData = _interpretedData.getItems()[j]; self.addAttribute(theInterpretedData); - if(self.db){ + if (self.db){ self.store(theInterpretedData); } } @@ -6197,14 +6093,14 @@ define('aggregator',['easejs', 'MathUuid','widget', completedQueriesCounter++; if (completedQueriesCounter == self.interpretations.length) { if (_callback && typeof(_callback) == 'function') { - _callback(self.getAttributeValues()); + _callback(self.getAttributes()); } } }); } } else { if (_callback && typeof(_callback) == 'function') { - _callback(self.getAttributeValues()); + _callback(self.getAttributes()); } } }, @@ -6359,7 +6255,7 @@ define('discoverer',[ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggre * @class Discoverer * @classdesc The Discoverer handles requests for components and attributes. * @requires easejs - * @requires AttributeTypeList + * @requires AttributeList * @constructs Discoverer */ 'public __construct' : function() { @@ -6616,27 +6512,27 @@ define('discoverer',[ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggre * @public * @alias getComponentsByAttributes * @memberof Discoverer# - * @param {AttributeTypeList} _attributeTypeList list of searched attributes + * @param {AttributeList} _attributeList list of searched attributes * @param {boolean} _all choise of the verification mode * @param {Array} _componentTypes Components types to search for * @returns {Array} */ - 'public getComponentsByAttributes' : function(_attributeTypeList, _all, _componentTypes) { + 'public getComponentsByAttributes' : function(_attributeList, _all, _componentTypes) { var componentList = []; var list = {}; if (typeof _componentTypes == "undefined") _componentTypes = [Widget, Interpreter, Aggregator]; - if (_attributeTypeList instanceof Array) { - list = _attributeTypeList; - } else if (Class.isA(AttributeList, _attributeTypeList)) { - list = _attributeTypeList.getItems(); + if (_attributeList instanceof Array) { + list = _attributeList; + } else if (Class.isA(AttributeList, _attributeList)) { + list = _attributeList.getItems(); } if (typeof list != "undefined") { var descriptions = this.getDescriptions(_componentTypes); for (var i in descriptions) { var description = descriptions[i]; - if(_all && this.containsAllAttributes(description, list)){ + if(_all && this.containsAllAttributes(description, list)) { componentList.push(this.getComponent(description.getId())); - } else if(!_all && this.containsAtLeastOneAttribute(description, list)){ + } else if(!_all && this.containsAtLeastOneAttribute(description, list)) { componentList.push(this.getComponent(description.getId())); } } diff --git a/examples/GeoLocationWidget.js b/examples/GeoLocationWidget.js index 136872c7d5e2c0cb0c8df0bfcab5cfb193c1a83d..c8fd8515b90f41e55f693c2374419bb30dd3c37f 100644 --- a/examples/GeoLocationWidget.js +++ b/examples/GeoLocationWidget.js @@ -25,7 +25,7 @@ define(['easejs', 'contactJS'], function (easejs, contactJS) { }, 'protected initCallbacks': function () { - this.addCallback(new contactJS.Callback().withName('UPDATE').withAttributeTypes(this.getAttributeTypes())); + this.addCallback(new contactJS.Callback().withName('UPDATE').withAttributeTypes(this.getAttributes())); }, 'override protected queryGenerator': function (_function) { @@ -34,8 +34,8 @@ define(['easejs', 'contactJS'], function (easejs, contactJS) { if(navigator.geolocation){ navigator.geolocation.getCurrentPosition(function(_position) { - response.put(self.getAttributeValues().getItems()[0].setValue(_position.coords.latitude)); - response.put(self.getAttributeValues().getItems()[1].setValue(_position.coords.longitude)); + response.put(self.getAttributes().getItems()[0].setValue(_position.coords.latitude)); + response.put(self.getAttributes().getItems()[1].setValue(_position.coords.longitude)); self.sendResponse(response, _function); }, function(error) { diff --git a/examples/addressInterpreter.js b/examples/addressInterpreter.js index 35978786defdc97b90fdc31c66c19f269a541315..def370a4aa0024d316d7bdfb578f2110f6171748 100644 --- a/examples/addressInterpreter.js +++ b/examples/addressInterpreter.js @@ -9,21 +9,18 @@ define(['easejs', 'contactJS'], 'public name' : 'AddressInterpreter', 'protected initInAttributes' : function() { - this.inAttributeTypes.put( + this.setInAttributes([ new contactJS.Attribute() .withName('latitude') - .withType('double') - ); - - this.inAttributeTypes.put( + .withType('double'), new contactJS.Attribute() .withName('longitude') .withType('double') - ); + ]); }, 'protected initOutAttributes' : function() { - this.outAttributeTypes.put( + this.setOutAttribute( new contactJS.Attribute() .withName('formattedAddress') .withType('string') @@ -33,8 +30,8 @@ define(['easejs', 'contactJS'], 'protected interpretData' : function(_inAttributeValues, _outAttributeValues, _callback) { var addressValue = _outAttributeValues.getItems()[0]; - var latitude = _inAttributeValues.getValueForAttributeWithTypeOf(this.inAttributeTypes.getItems()[0]); - var longitude = _inAttributeValues.getValueForAttributeWithTypeOf(this.inAttributeTypes.getItems()[1]); + var latitude = _inAttributeValues.getValueForAttributeWithTypeOf(this.inAttributes.getItems()[0]); + var longitude = _inAttributeValues.getValueForAttributeWithTypeOf(this.inAttributes.getItems()[1]); if(navigator.onLine){ if (latitude && longitude) { diff --git a/js/modules/aggregator/aggregator.js b/js/modules/aggregator/aggregator.js index cf4ea5a6f8e0b82e0c2e7740069393133bf92789..73df5ba140cdde781b3fef5aaa65a558d3d107fa 100644 --- a/js/modules/aggregator/aggregator.js +++ b/js/modules/aggregator/aggregator.js @@ -68,7 +68,6 @@ define(['easejs', 'MathUuid','widget', * @requires easejs * @requires MathUuid * @requires CallbackList - * @requires AttributeType * @requires Attribute * @requires AttributeList * @requires Subscriber @@ -77,12 +76,12 @@ define(['easejs', 'MathUuid','widget', * @requires Widget * @constructs Aggregator */ - 'override virtual public __construct': function(_discoverer, _attributeTypes) + 'override virtual public __construct': function(_discoverer, _attributes) { this.id = Math.uuid(); this.widgets = []; this.interpretations = []; - this.__super(_discoverer, _attributeTypes); + this.__super(_discoverer, _attributes); }, /** @@ -98,22 +97,6 @@ define(['easejs', 'MathUuid','widget', 'override public getType' : function(){ return 'Aggregator'; }, - - /** - * Adds new AttributeTypes, useful when a new Widget is subscribed. - * - * @protected - * @alias addAttributeType - * @memberof Aggregator# - * @param {AttributeType} _attribute attributeType - * @param {boolean} _multipleInstances - */ - 'protected addAttributeType' : function(_attribute, _multipleInstances){ - if(Class.isA(Attribute, _attribute )){ - this.attributeTypes.put(_attribute, _multipleInstances); - this.attributes.put(_attribute, _multipleInstances); - } - }, /** * Sets Widget IDs. @@ -233,10 +216,10 @@ define(['easejs', 'MathUuid','widget', * @public * @alias didFinishInitialization * @memberof Aggregator# - * @param _attributeTypes + * @param _attributes */ - 'override public didFinishInitialization': function(_attributeTypes) { - this.aggregatorSetup(_attributeTypes); + 'override public didFinishInitialization': function(_attributes) { + this.aggregatorSetup(_attributes); }, /** @@ -247,9 +230,9 @@ define(['easejs', 'MathUuid','widget', * @alias aggregatorSetup * @memberof Aggregator# */ - 'protected aggregatorSetup' : function(_attributeTypes){ + 'protected aggregatorSetup' : function(_attributes){ this.initStorage('DB_'+this.name); - this.setAggregatorAttributeValues(_attributeTypes); + this.setAggregatorAttributeValues(_attributes); this.setAggregatorConstantAttributeValues(); this.setAggregatorCallbacks(); @@ -307,12 +290,10 @@ define(['easejs', 'MathUuid','widget', * @public * @alias getCurrentData * @memberof Aggregator# - * @returns {AttributeValueList} + * @returns {AttributeList} */ 'public getCurrentData' : function(){ - var response = new AttributeList(); - response.putAll(this.attributes); - return response; + return this.attributes; }, /** @@ -385,7 +366,7 @@ define(['easejs', 'MathUuid','widget', var typeList = singleCallback.getAttributeTypes().getItems(); for(var y in typeList){ var singleType = typeList[y]; - this.addAttributeType(singleType); + this.addAttribute(singleType); } } this.addWidget(_widgetIdOrWidget); @@ -403,7 +384,7 @@ define(['easejs', 'MathUuid','widget', * @param {String} _widgetId Widget that should be removed. */ 'public unsubscribeFrom' : function(_widgetId){ - if(typeof _widgetId == "string"){ + if(typeof _widgetId == "string") { var widget = this.discoverer.getComponent(_widgetId); if (widget) { console.log('aggregator unsubscribeFrom: ' + widget.getName()); @@ -527,8 +508,8 @@ define(['easejs', 'MathUuid','widget', }, /** - * Only actualizes the attributeType cache in th database. - * For an alternativ action can be used a callback. + * Only updates the attribute cache in the database. + * For an alternative action a callback can be used. * * @public * @alias queryTables @@ -589,16 +570,16 @@ define(['easejs', 'MathUuid','widget', * * @private * @alias doesSatisfyAttributeType - * @param _attributeType + * @param _attribute * @returns {boolean} */ - 'private doesSatisfyAttributeType': function(_attributeType) { + 'private doesSatisfyAttributeType': function(_attribute) { var componentUUIDs = this.getComponentUUIDs(); var doesSatisfy = false; for (var index in componentUUIDs) { var theComponent = this.discoverer.getComponent(componentUUIDs[index]); - if (theComponent.getDescription().doesSatisfyAttributeType(_attributeType)) { + if (theComponent.getDescription().doesSatisfyAttributeType(_attribute)) { doesSatisfy = true; } } @@ -641,14 +622,14 @@ define(['easejs', 'MathUuid','widget', for (var widgetOutAttributeIndex in outAttributes) { var widgetOutAttribute = outAttributes[widgetOutAttributeIndex]; // add the attribute type to the aggregators list of handled attribute types - if (!this.getAttributeTypes().contains(widgetOutAttribute)) this.addAttributeType(widgetOutAttribute); + if (!this.getAttributes().containsTypeOf(widgetOutAttribute)) this.addAttribute(widgetOutAttribute); console.log("I can now satisfy attribute "+widgetOutAttribute+" with the help of "+theComponent.getName()+"! That was easy :)"); _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."); - var inAttributes = theComponent.getInAttributeTypes().getItems(); + var inAttributes = theComponent.getInAttributes().getItems(); var canSatisfyInAttributes = true; // iterate over the attributes needed to satisfy the interpreter @@ -682,9 +663,9 @@ define(['easejs', 'MathUuid','widget', for (var unsatisfiedAttributeIndex in _unsatisfiedAttributes.getItems()) { var theUnsatisfiedAttribute = _unsatisfiedAttributes.getItems()[unsatisfiedAttributeIndex]; if (theUnsatisfiedAttribute.equalsTypeOf(interpreterOutAttribute)) { - this.addAttributeType(theUnsatisfiedAttribute); + this.addAttribute(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 AttributeList().withItems([theUnsatisfiedAttribute]))); + this.interpretations.push(new Interpretation(theComponent.getId(), theComponent.getInAttributes(), new AttributeList().withItems([theUnsatisfiedAttribute]))); } } _unsatisfiedAttributes.removeAttributeWithTypeOf(interpreterOutAttribute, true); @@ -711,7 +692,7 @@ define(['easejs', 'MathUuid','widget', * @memberof Aggregator# */ 'virtual public didFinishSetup': function() { - unsatisfiedAttributes = this.getAttributeTypes().clone(); + unsatisfiedAttributes = this.getAttributes().clone(); // get all widgets that satisfy attribute types this.getComponentsForUnsatisfiedAttributeTypes(unsatisfiedAttributes, false, [Widget]); @@ -719,7 +700,7 @@ define(['easejs', 'MathUuid','widget', this.getComponentsForUnsatisfiedAttributeTypes(unsatisfiedAttributes, false, [Interpreter]); console.log("Unsatisfied attributes: "+unsatisfiedAttributes.size()); - console.log("Satisfied attributes: "+this.getAttributeTypes().size()); + console.log("Satisfied attributes: "+this.getAttributes().size()); console.log("Interpretations "+this.interpretations.length); }, @@ -743,14 +724,14 @@ define(['easejs', 'MathUuid','widget', completedQueriesCounter++; if (completedQueriesCounter == self.widgets.length) { if (_callback && typeof(_callback) == 'function') { - _callback(self.getAttributeValues()); + _callback(self.getAttributes()); } } }); } } else { if (_callback && typeof(_callback) == 'function') { - _callback(self.getAttributeValues()); + _callback(self.getAttributes()); } } }, @@ -771,15 +752,15 @@ define(['easejs', 'MathUuid','widget', for (var index in this.interpretations) { var theInterpretation = this.interpretations[index]; var theInterpreterId = theInterpretation.interpreterId; - var interpretationInAttributeValues = this.getAttributeValues(theInterpretation.inAttributeTypes); - var interpretationOutAttributeValues = this.getAttributeValues(theInterpretation.outAttributeTypes); + var interpretationInAttributeValues = this.getAttributes(theInterpretation.inAttributeTypes); + var interpretationOutAttributeValues = this.getAttributes(theInterpretation.outAttributeTypes); self.interpretData(theInterpreterId, interpretationInAttributeValues, interpretationOutAttributeValues, function(_interpretedData) { for (var j in _interpretedData.getItems()) { var theInterpretedData = _interpretedData.getItems()[j]; self.addAttribute(theInterpretedData); - if(self.db){ + if (self.db){ self.store(theInterpretedData); } } @@ -787,14 +768,14 @@ define(['easejs', 'MathUuid','widget', completedQueriesCounter++; if (completedQueriesCounter == self.interpretations.length) { if (_callback && typeof(_callback) == 'function') { - _callback(self.getAttributeValues()); + _callback(self.getAttributes()); } } }); } } else { if (_callback && typeof(_callback) == 'function') { - _callback(self.getAttributeValues()); + _callback(self.getAttributes()); } } }, diff --git a/js/modules/attribute/attributeList.js b/js/modules/attribute/attributeList.js index 8fbf58357816426b270393eec3dda6a0c01b7581..b7058347de7f242be71a25dacecacb83efbc2198 100644 --- a/js/modules/attribute/attributeList.js +++ b/js/modules/attribute/attributeList.js @@ -144,19 +144,19 @@ define(['easejs', 'abstractList', 'attribute', 'parameterList' ], 'public equals': function(_attributeList, _typeOnly) { _typeOnly = typeof _typeOnly == "undefined" ? false : _typeOnly; - return _typeOnly ? this.equalsAllTypesOf(_attributeList) : this.equalsAllValuesOf(_attributeList); + return _typeOnly ? this.equalsTypesIn(_attributeList) : this.equalsValuesIn(_attributeList); }, /** * Compare the specified AttributeList with this instance. * * @public - * @alias equals + * @alias equalsTypesIn * @memberof AttributeList# * @param {AttributeList} _attributeList AttributeList that should be compared. * @returns {boolean} */ - 'public equalsAllTypesOf' : function(_attributeList) { + 'public equalsTypesIn' : function(_attributeList) { if (Class.isA(AttributeList, _attributeList) && _attributeList.size() == this.size()) { for (var index in _attributeList.getItems()) { var theAttributeType = _attributeList.getItems()[index]; @@ -172,12 +172,12 @@ define(['easejs', 'abstractList', 'attribute', 'parameterList' ], * this instance. * * @public - * @alias equals + * @alias equalsValuesIn * @memberof AttributeList# * @param {AttributeList} _attributeList AttributeList that should be compared. * @returns {boolean} */ - 'public equalsAllValuesOf' : function(_attributeList) { + 'public equalsValuesIn' : function(_attributeList) { if (Class.isA(AttributeList, _attributeList) && _attributeList.size() == this.size()) { for (var index in _attributeList.getItems()) { var theAttribute = _attributeList.getItems()[index]; @@ -210,7 +210,7 @@ define(['easejs', 'abstractList', 'attribute', 'parameterList' ], var attribute = list[i]; if (Class.isA(Attribute, attribute)) { var attribute = this.getAttributeWithTypeOf(attribute); - if (typeof attribute != "undefined") { + if (typeof attribute != "NO_VALUE") { response.put(attribute); } } diff --git a/js/modules/descriptions/widgetDescription.js b/js/modules/descriptions/widgetDescription.js index c930e050688c852dae6806d87aff854b6c464e6b..6bd148c23addb07432e6a3aebd48c6097b981832 100644 --- a/js/modules/descriptions/widgetDescription.js +++ b/js/modules/descriptions/widgetDescription.js @@ -195,7 +195,7 @@ define(['easejs', 'attributeList'], * @public * @alias addOutAttributeTypes * @memberof WidgetDescription# - * @param {(AttributeTypeList|Array)} _outAttributeTypes List of AttributeType that are provided + * @param {(AttributeList|Array)} _outAttributeTypes List of AttributeType that are provided */ 'public addOutAttributeTypes' : function(_outAttributeTypes){ this.outAttributeTypes.putAll(_outAttributeTypes); @@ -215,11 +215,12 @@ define(['easejs', 'attributeList'], * @public * @alias doesSatisfyAttributeType * @memberof WidgetDescription# - * @param {AttributeType} _attributeType + * @param {AttributeType} _attribute * @returns {boolean} */ - 'public doesSatisfyAttributeType': function(_attributeType) { - return this.getOutAttributeTypes().contains(_attributeType); + + 'public doesSatisfyAttributeType': function(_attribute) { + return this.getOutAttributeTypes().containsTypeOf(_attribute); } }); diff --git a/js/modules/discoverer/discoverer.js b/js/modules/discoverer/discoverer.js index 967f314d16c73b2dfc0f537bd3c338bfa7c4f13c..ffb69ddd3d4d3c5851050543d8ea2a163af257fe 100644 --- a/js/modules/discoverer/discoverer.js +++ b/js/modules/discoverer/discoverer.js @@ -43,7 +43,7 @@ define([ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggregator' ], fun * @class Discoverer * @classdesc The Discoverer handles requests for components and attributes. * @requires easejs - * @requires AttributeTypeList + * @requires AttributeList * @constructs Discoverer */ 'public __construct' : function() { @@ -300,27 +300,27 @@ define([ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggregator' ], fun * @public * @alias getComponentsByAttributes * @memberof Discoverer# - * @param {AttributeTypeList} _attributeTypeList list of searched attributes + * @param {AttributeList} _attributeList list of searched attributes * @param {boolean} _all choise of the verification mode * @param {Array} _componentTypes Components types to search for * @returns {Array} */ - 'public getComponentsByAttributes' : function(_attributeTypeList, _all, _componentTypes) { + 'public getComponentsByAttributes' : function(_attributeList, _all, _componentTypes) { var componentList = []; var list = {}; if (typeof _componentTypes == "undefined") _componentTypes = [Widget, Interpreter, Aggregator]; - if (_attributeTypeList instanceof Array) { - list = _attributeTypeList; - } else if (Class.isA(AttributeList, _attributeTypeList)) { - list = _attributeTypeList.getItems(); + if (_attributeList instanceof Array) { + list = _attributeList; + } else if (Class.isA(AttributeList, _attributeList)) { + list = _attributeList.getItems(); } if (typeof list != "undefined") { var descriptions = this.getDescriptions(_componentTypes); for (var i in descriptions) { var description = descriptions[i]; - if(_all && this.containsAllAttributes(description, list)){ + if(_all && this.containsAllAttributes(description, list)) { componentList.push(this.getComponent(description.getId())); - } else if(!_all && this.containsAtLeastOneAttribute(description, list)){ + } else if(!_all && this.containsAtLeastOneAttribute(description, list)) { componentList.push(this.getComponent(description.getId())); } } diff --git a/js/modules/interpreter/interpreter.js b/js/modules/interpreter/interpreter.js index 05a02a47856238e8e1f4fbca61224506c57b9ac6..e3aabf602a5db2331001223273f3eaef3adafd63 100644 --- a/js/modules/interpreter/interpreter.js +++ b/js/modules/interpreter/interpreter.js @@ -29,37 +29,21 @@ define([ 'easejs', 'MathUuid', 'attribute', 'attributeList', */ 'public id' : '', /** - * @alias inAttributeTypes + * @alias inAttributes * @protected * @type {AttributeList} * @memberof Interpreter# * @desc Types of all attributes that can be handled. */ - 'protected inAttributeTypes' : [], + 'protected inAttributes' : [], /** - * @alias outAttributeTypes + * @alias outAttributes * @protected * @type {AttributeList} * @memberof Interpreter# * @desc Types of all attributes that will be returned. */ - 'protected outAttributeTypes' : [], - /** - * @alias inAttributeValues - * @protected - * @type {AttributeList} - * @memberof Interpreter# - * @desc List of the data that should be interpreted. - */ - 'protected inAttributeValues' : [], - /** - * @alias outAttributeValues - * @protected - * @type {AttributeList} - * @memberof Interpreter# - * @desc List of interpreted data. - */ - 'protected outAttributeValues' : [], + 'protected outAttributes' : [], /** * @alias lastInterpretation * @protected @@ -94,10 +78,8 @@ define([ 'easejs', 'MathUuid', 'attribute', 'attributeList', this.id = Math.uuid(); this.discoverer = _discoverer; this.register(); - this.inAttributeTypes = new AttributeList(); - this.outAttributeTypes = new AttributeList(); - this.inAttributeValues = new AttributeList(); - this.outAttributeValues = new AttributeList(); + this.inAttributes = new AttributeList(); + this.outAttributes = new AttributeList(); this.initInterpreter(); }, @@ -177,10 +159,10 @@ define([ 'easejs', 'MathUuid', 'attribute', 'attributeList', * @public * @alias getInAttributeTypes * @memberof Interpreter# - * @returns {AttributeTypeList} + * @returns {AttributeList} */ - 'public getInAttributeTypes' : function() { - return this.inAttributeTypes; + 'public getInAttributes' : function() { + return this.inAttributes; }, /** @@ -189,53 +171,46 @@ define([ 'easejs', 'MathUuid', 'attribute', 'attributeList', * @protected * @alias setInAttribute * @memberof Interpreter# - * @param {string} _name name of the attribute - * @param {string} _type type of the attribute - * @param {string} _value value of the attribute - * @param {ParameterList|Array} _parameter Parameter of the attribute. */ - 'protected setInAttribute' : function(_name, _type, _value, _parameters) { - var attributeValue = new Attribute().withName(_name) - .withValue(_value).withType(_type).withParameters(_parameters); - if (this.isInAttribute(attributeValue)) { - this.inAttributeValues.put(attributeValue); - } + 'protected setInAttribute' : function(_attribute) { + this.inAttributes.put(_attribute); }, /** * Sets an inAttributes. * * @protected - * @alias setInAttributeValues + * @alias setInAttributes * @memberof Interpreter# * @param {(AttributeList|Array)} _attributeList Attributes to set. */ - 'protected setInAttributeValues' : function(_attributeList) { - this.inAttributeValues = new AttributeList().withItems(_attributeList); + 'protected setInAttributes' : function(_attributeList) { + this.inAttributes = new AttributeList().withItems(_attributeList); }, + /** * Verifies whether the specified attribute is contained in inAttributeList. * * @protected * @alias isInAttribute * @memberof Interpreter# - * @param {AttributeValue} _attribute Attribute that should be verified. + * @param {Attribute} _attribute Attribute that should be verified. * @return {boolean} */ 'protected isInAttribute' : function(_attribute) { - return !!this.inAttributeTypes.containsTypeOf(_attribute); + return !!this.inAttributes.containsTypeOf(_attribute); }, /** * Returns the provided outAttributeTypes. * * @public - * @alias getOutAttributeTypes + * @alias getOutAttributes * @memberof Interpreter# - * @returns {AttributeTypeList} + * @returns {AttributeList} */ - 'public getOutAttributeTypes' : function() { - return this.outAttributeTypes; + 'public getOutAttributes' : function() { + return this.outAttributes; }, /** @@ -244,17 +219,21 @@ define([ 'easejs', 'MathUuid', 'attribute', 'attributeList', * @protected * @alias setOutAttribute * @memberof Interpreter# - * @param {string} _name name of the attribute - * @param {string} _type type of the attribute - * @param {string} _value value of the attribute - * @param {ParameterList|Array} _parameters Parameter of the attribute. */ - 'protected setOutAttribute' : function(_name, _type, _value,_parameters) { - var attributeValue = new AttributeValue().withName(_name) - .withValue(_value).withType(_type).withParameters(_parameters); - if (this.isOutAttribute(attributeValue)) { - this.outAttributeValues.put(attributeValue); - } + 'protected setOutAttribute' : function(_attribute) { + this.outAttributes.put(_attribute); + }, + + /** + * Sets an outAttributes. + * + * @protected + * @alias setOutAttributes + * @memberof Interpreter# + * @param {(AttributeList|Array)} _attributeList Attributes to set. + */ + 'protected setOutAttributes' : function(_attributeList) { + this.outAttributes = new AttributeList().withItems(_attributeList); }, /** @@ -263,11 +242,11 @@ define([ 'easejs', 'MathUuid', 'attribute', 'attributeList', * @protected * @alias isOutAttribute * @memberof Interpreter# - * @param {AttributeValue} _attribute Attribute that should be verified. + * @param {Attribute} _attribute Attribute that should be verified. * @return {boolean} */ 'protected isOutAttribute' : function(_attribute) { - return !!this.outAttributeTypes.containsTypeOf(_attribute); + return !!this.outAttributes.containsTypeOf(_attribute); }, /** @@ -291,7 +270,7 @@ define([ 'easejs', 'MathUuid', 'attribute', 'attributeList', if (!self.canHandleOutAttributes(response)) throw "Unhandled output attribute generated."; - self.setInAttributeValues(_inAttributeValues); + self.setInAttributes(_inAttributeValues); self.lastInterpretation = new Date(); if (_function && typeof(_function) == 'function'){ @@ -328,7 +307,7 @@ define([ 'easejs', 'MathUuid', 'attribute', 'attributeList', } else if (Class.isA(AttributeList, _inAttributes)) { list = _inAttributes.getItems(); } - if (list.length == 0 || _inAttributes.size() != this.getInAttributeTypes().size()) { + if (list.length == 0 || _inAttributes.size() != this.getInAttributes().size()) { return false; } for ( var i in list) { @@ -355,7 +334,7 @@ define([ 'easejs', 'MathUuid', 'attribute', 'attributeList', } else if (Class.isA(AttributeList, _outAttributes)) { list = _outAttributes.getItems(); } - if (list.length == 0 || _outAttributes.size() != this.getOutAttributeTypes().size()) { + if (list.length == 0 || _outAttributes.size() != this.getOutAttributes().size()) { return false; } for ( var i in list) { @@ -388,10 +367,9 @@ define([ 'easejs', 'MathUuid', 'attribute', 'attributeList', * @returns {InterpreterDescription} */ 'virtual public getDescription' : function() { - var description = new InterpreterDescription().withId( - this.id).withName(this.name); - description.addOutAttributeTypes(this.outAttributeTypes); - description.setInAttributeTypes(this.inAttributeTypes); + var description = new InterpreterDescription().withId(this.id).withName(this.name); + description.addOutAttributeTypes(this.outAttributes); + description.setInAttributeTypes(this.inAttributes); return description; }, @@ -420,7 +398,6 @@ define([ 'easejs', 'MathUuid', 'attribute', 'attributeList', if (this.discoverer) { this.discoverer.registerNewComponent(this); } - }, /** @@ -428,28 +405,12 @@ define([ 'easejs', 'MathUuid', 'attribute', 'attributeList', * @returns {boolean} */ 'public hasOutAttributesWithInputParameters': function() { - return this.outAttributeTypes.hasAttributesWithInputParameters(); + return this.outAttributes.hasAttributesWithInputParameters(); }, 'public getOutAttributesWithInputParameters': function() { - return this.outAttributeTypes.getAttributesWithInputParameters(); + return this.outAttributes.getAttributesWithInputParameters(); } - -// /** -// * Unregisters the component to the associated discoverer -// * and deletes the reference. -// * -// * @public -// * @alias register -// * @memberof Widget# -// */ -// 'protected unregister' : function() { -// if (this.discoverer) { -// this.discoverer.unregisterComponent(this.getId()); -// this.discoverer = null; -// } -// }, - }); return Interpreter; diff --git a/js/modules/widget/widget.js b/js/modules/widget/widget.js index 2bdfe9f0c4d00ef0e5b60d90ad94c7a59f00b387..cab418964be6fbddd8e51d86edd459fff8291117 100644 --- a/js/modules/widget/widget.js +++ b/js/modules/widget/widget.js @@ -30,27 +30,11 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * @desc ID of the Widget. Will be generated. */ 'public id' : '', - /** - * @alias attributeTypes - * @protected - * @type {AttributeTypeList} - * @memberof Widget# - * @desc Types of all available attributes. - */ - 'protected attributeTypes' : [], - /** - * @alias constantAttributeTypes - * @protected - * @type {AttributeTypeList} - * @memberof Widget# - * @desc Types of all available ConstantAttributes. - */ - 'protected constantAttributeTypes' : [], /** * @alias attributes * @protected - * @type {AttributeValueList} + * @type {AttributeList} * @memberof Widget# * @desc All available Attributes and their values. */ @@ -58,7 +42,7 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', /** * @alias oldAttributes * @protected - * @type {AttributeValueList} + * @type {AttributeList} * @memberof Widget# * @desc This temporary variable is used for storing the old attribute values. * So these can be used to check conditions. @@ -67,7 +51,7 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', /** * @alias constantAttributes * @protected - * @type {AttributeValueList} + * @type {AttributeList} * @memberof Widget# * @desc All available constant Attributes and their values. */ @@ -110,10 +94,8 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * @requires MathUuid * @requires Callback * @requires CallbackList - * @requires AttributeType - * @requires AttributeValue - * @requires AttributeTypeList - * @requires AttributeValueList + * @requires Attribute + * @requires AttributeList * @requires ConditionList * @requires Subscriber * @requires SubscriberList @@ -125,8 +107,6 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', this.id = Math.uuid(); this.discoverer = _discoverer; this.register(); - this.attributeTypes = new AttributeList(); - this.constantAttributeTypes = new AttributeList(); this.attributes = new AttributeList(); this.constantAttributes = new AttributeList(); this.subscribers = new SubscriberList(); @@ -176,12 +156,16 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * Returns the available AttributeTypes. * * @public - * @alias getAttributeTypes + * @alias getAttributes * @memberof Widget# - * @returns {AttributeTypeList} + * @returns {AttributeList} */ - 'public getAttributeTypes' : function() { - return this.attributeTypes; + 'public getAttributes' : function(_attributeList) { + if (Class.isA(AttributeList, _attributeList)) { + return this.attributes.getSubset(_attributeList); + } else { + return this.attributes; + } }, /** @@ -193,25 +177,12 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * @memberof Widget# * @returns {AttributeList} */ - 'public getWidgetConstantAttributeTypes' : function() { - return this.constantAttributeTypes; - }, - - /** - * Returns the last acquired attribute values. - * - * @public - * @alias getAttributes - * @memberof Widget# - * @param {AttributeList} _attributeList - * @returns {AttributeList} - */ - 'public getAttributeValues' : function(_attributeList) { - if (Class.isA(AttributeList, _attributeList)) { - return this.attributes.getSubset(_attributeList); - } else { - return this.attributes; - } + 'public getConstantAttributes' : function(_attributeList) { + if (Class.isA(AttributeList, _attributeList)) { + return this.constantAttributes.getSubset(_attributeList); + } else { + return this.constantAttributes; + } }, /** @@ -220,8 +191,8 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * @param {AttributeType} _attributeType The attribute type to return the last value for. * @returns {*} */ - 'public getAttributeValue': function(_attributeType) { - return this.getAttributeValues().getItemForAttributeType(_attributeType).getValue(); + 'public getValueForAttributeWithTypeOf': function(_attributeType) { + return this.getAttributes().getAttributeWithTypeOf(_attributeType).getValue(); }, /** @@ -236,18 +207,6 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', return this.oldAttributes; }, - /** - * Returns the ConstantAttributes. - * - * @public - * @alias getConstantAttributes - * @memberof Widget# - * @returns {AttributeList} - */ - 'public getConstantAttributes' : function() { - return this.constantAttributes; - }, - /** * Returns a list of callbacks that can be * subscribed to. @@ -367,20 +326,14 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * @memberof Widget# * @param {Attribute} _attribute AttributeValue */ - 'public addAttribute' : function(_attribute) { + 'public addAttribute' : function(_attribute, _multipleInstances) { + _multipleInstances = typeof _multipleInstances == "undefined" ? false : _multipleInstances; if (Class.isA(Attribute, _attribute)) { - if (!this.attributes.contains(_attribute)) { - - var type = new Attribute().withName(_attribute.getName()) - .withType(_attribute.getType()) - .withParameters(_attribute.getParameters()); - this.attributeTypes.put(type); - + if (!this.attributes.containsTypeOf(_attribute)) { + this.oldAttributes = this.attributes; + _attribute.setTimestamp(this.getCurrentTime()); + this.attributes.put(_attribute, _multipleInstances); } - this.oldAttributes = this.attributes; - - _attribute.setTimestamp(this.getCurrentTime()); - this.attributes.put(_attribute); } }, @@ -557,7 +510,7 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', * @returns {boolean} */ 'protected isAttribute' : function(_attribute) { - return !!this.attributeTypes.containsTypeOf(_attribute); + return !!this.attributes.containsTypeOf(_attribute); }, /** @@ -705,7 +658,7 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', */ 'public queryWidget' : function() { var response = new AttributeList(); - response.putAll(this.getAttributeValues()); + response.putAll(this.getAttributes()); response.putAll(this.getConstantAttributes()); return response; }, @@ -726,7 +679,7 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', } else { this.queryGenerator(); var response = new AttributeList(); - response.putAll(this.getAttributeValues()); + response.putAll(this.getAttributes()); response.putAll(this.getConstantAttributes()); return response; } @@ -801,8 +754,8 @@ define([ 'easejs', 'MathUuid', 'callback', 'callbackList', 'attribute', */ 'virtual public getDescription' : function() { var description = new WidgetDescription().withId(this.id).withName(this.name); - description.addOutAttributeTypes(this.attributeTypes); - description.addOutAttributeTypes(this.constantAttributeTypes); + description.addOutAttributeTypes(this.attributes); + description.addOutAttributeTypes(this.constantAttributes); var widgetCallbacks = this.callbacks.getItems(); for(var i in widgetCallbacks) { description.addCallbackName(widgetCallbacks[i].getName()); diff --git a/qunitTest/aggregatorTest.js b/qunitTest/aggregatorTest.js index 56a8755f4feb18c4dff6f513ee421233c369cdbb..ce072d6ca72e047bacf50a55ab11e23befc80064 100644 --- a/qunitTest/aggregatorTest.js +++ b/qunitTest/aggregatorTest.js @@ -37,7 +37,7 @@ require(['configTest'], function() { assert.equal(subscriber.size(), 1,"subscribe Passed!: one subscribed Widget in geolocationWidget too"); - var values = testAggregator.getAttributeValues(); + var values = testAggregator.getAttributes(); assert.equal( values.size(), 2, "Passed!: two available attributes" ); var latitude = values.getAttributeWithTypeOf(latitudeType); assert.equal(latitude.getName(), 'latitude',"subscribed Attributes Passed!: latitude exists" ); diff --git a/qunitTest/discovererTest.js b/qunitTest/discovererTest.js index 23d929341553b574f00e9c59a64d4a4af24b9784..dcbd9984a1d3de9c5c481449e0bca2e15302ddb1 100644 --- a/qunitTest/discovererTest.js +++ b/qunitTest/discovererTest.js @@ -2,13 +2,13 @@ require(['configTest'], function() { require(['contactJS', '../examples/AddressInterpreter', '../examples/GeoLocationWidget'], function(contactJS, AddressInterpreter, GeoLocationWidget){ - QUnit.test( "Discoverer", function( assert ) { + QUnit.test("Discoverer", function(assert) { var discoverer = new contactJS.Discoverer(); //type - assert.equal( discoverer.getType(), 'Discoverer',"Passed!: type -> Discoverer" ); + assert.equal(discoverer.getType(), 'Discoverer', "Passed!: type -> Discoverer" ); //register Widget - var geo = new GeoLocationWidget(discoverer); + new GeoLocationWidget(discoverer); //initWidgets ->geoLocationWidget expected //tested with getWidgetDescriptions @@ -31,7 +31,8 @@ require(['configTest'], function() { assert.equal( widget2.getName(), 'GeoLocationWidget',"getComponent passed!: name of the instance is te expected one" ); //register Interpreter - var testInterpreter = new AddressInterpreter(discoverer); + new AddressInterpreter(discoverer); + //tested with getWidgetDescriptions var iDescs = discoverer.getDescriptions([contactJS.Interpreter]); assert.equal( iDescs.length, 1,"getInterpreterDescriptions passed!: One Interpreter is registered" ); @@ -78,8 +79,7 @@ require(['configTest'], function() { 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); + var array = [longitudeType]; //one searched attribute var list = discoverer.getComponentsByAttributes(array, false); diff --git a/qunitTest/interpret_AggregatorInterpreterTest.js b/qunitTest/interpret_AggregatorInterpreterTest.js index 1f4096520dd85a51145aa097ad49637bf8e3f058..6c96a4d2835f2ec83b2fb5e74c238c93c0207cc7 100644 --- a/qunitTest/interpret_AggregatorInterpreterTest.js +++ b/qunitTest/interpret_AggregatorInterpreterTest.js @@ -26,7 +26,7 @@ require(['configTest'], function() { //if aggregator provides more attributes 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" ); diff --git a/qunitTest/interpreterTest.js b/qunitTest/interpreterTest.js index 6d6a71fae1d1cac8c1eb4733a502ddff057dfb41..ad95cfeb35b31028145f3dcf4239e7eae6560a02 100644 --- a/qunitTest/interpreterTest.js +++ b/qunitTest/interpreterTest.js @@ -3,7 +3,8 @@ require(['configTest'], function() { function(AddressInterpreter, contactJS){ QUnit.asyncTest( "AddressInterpreter", function( assert ) { - var testInterpreter = new AddressInterpreter(); + var discoverer = new contactJS.Discoverer(); + var testInterpreter = new AddressInterpreter(discoverer); var id = testInterpreter.getId(); assert.ok( id && id !== "null" && id !== "undefined","Passed!: id is not null" ); @@ -12,7 +13,7 @@ require(['configTest'], function() { //getInAttributeTypes var latitudeType = new contactJS.Attribute().withName('latitude').withType('double'); var longitudeType = new contactJS.Attribute().withName('longitude').withType('double'); - var inTypes = testInterpreter.getInAttributeTypes(); + var inTypes = testInterpreter.getInAttributes(); assert.ok( inTypes.size() == 2,"Passed!: 2 defined type in addressInterpreter" ); assert.ok( inTypes.getAttributeWithTypeOf(latitudeType),"Passed!:type latitude exists" ); @@ -22,12 +23,11 @@ require(['configTest'], function() { //getOutAttributeTypes var formattedAddress = new contactJS.Attribute().withName('formattedAddress').withType('string'); - var outTypes = testInterpreter.getOutAttributeTypes(); + var outTypes = testInterpreter.getOutAttributes(); assert.ok( outTypes.size() == 1,"Passed!: 1 defined outType in addressInterpreter" ); assert.ok( outTypes.getAttributeWithTypeOf(formattedAddress),"Passed!: formattedAddress exists" ); assert.ok( outTypes.getAttributeWithTypeOf(formattedAddress).equalsTypeOf(formattedAddress),"Passed!: formattedAddress equals expected type" ); - - + //interpreterDescription var desc = testInterpreter.getDescription(); assert.ok( desc,"Passed!: InterpreterDescription exists" ); @@ -44,7 +44,7 @@ require(['configTest'], function() { var attributeList = new contactJS.AttributeList().withItems([latitudeValue, longitudeValue]); var assertData2 = function(result){ - assert.ok( testInterpreter.getLastInterpretionTime(),"Callback passed!: getLastInterpretionTime exists" ); + assert.ok(testInterpreter.getLastInterpretionTime(),"Callback passed!: getLastInterpretionTime exists" ); assert.equal(result.size(), 1, "Callback passed!: one outAttribute"); var list = result.getItems(); for(var i in list){ diff --git a/qunitTest/widgetTest.js b/qunitTest/widgetTest.js index c0cab269ae2427d91de2c420ac1968129ed107fe..b042e5895d4650b4b658ab02c0ea2b661814700d 100644 --- a/qunitTest/widgetTest.js +++ b/qunitTest/widgetTest.js @@ -15,9 +15,9 @@ require(['configTest'], function() { assert.equal( testWidget.getName(), 'GeoLocationWidget', "Passed!: name -> GeoLocationWidget" ); //attributeTypes - var types = testWidget.getAttributeTypes(); + var types = testWidget.getAttributes(); assert.equal(types.size(), 2,"getWidgetAttributeTypes Passed!: two types were returned" ); - var constantTypes = testWidget.getWidgetConstantAttributeTypes(); + var constantTypes = testWidget.getConstantAttributes(); assert.equal(constantTypes.size(), 0,"getWidgetConstantAttributeTypes Passed!: zero constantTypes was returned" ); //callbacks @@ -29,7 +29,7 @@ require(['configTest'], function() { assert.equal(subscriber.size(), 0,"getSubscriber Passed!: zero subscriber was returned" ); //attributes - var attributes= testWidget.getAttributeValues(); + var attributes = testWidget.getAttributes(); assert.equal(attributes.size(), 2,"queryAttributes Passed!: two attributes were returned" ); var latitude = attributes.getAttributeWithTypeOf(latitudeType); assert.equal(latitude.getName(), 'latitude',"queryAttributes Passed!: latitude exists" );