Skip to content
Snippets Groups Projects
Commit 242846bd authored by Helena Jank's avatar Helena Jank
Browse files

# adjusted attribute's method equalsTypeOf including synonyms

# corrected discoverer: constructor and buildAttribute
parent b65c1953
No related branches found
No related tags found
No related merge requests found
...@@ -240,6 +240,7 @@ define(['easejs', ...@@ -240,6 +240,7 @@ define(['easejs',
* @public * @public
* @alias getSynonyms * @alias getSynonyms
* @memberof Attribute# * @memberof Attribute#
* @returns {Array}
*/ */
'public getSynonyms' : function(){ 'public getSynonyms' : function(){
return this.synonymList; return this.synonymList;
...@@ -409,7 +410,10 @@ define(['easejs', ...@@ -409,7 +410,10 @@ define(['easejs',
*/ */
'public equalsTypeOf' : function(_attribute) { 'public equalsTypeOf' : function(_attribute) {
if (Class.isA(Attribute, _attribute)) { if (Class.isA(Attribute, _attribute)) {
if (this.getName() == _attribute.getName() && this.getType() == _attribute.getType() && this.getParameters().equals(_attribute.getParameters())) { var name = _attribute.getName();
if ((this.getName() == name || this.getSynonyms().indexOf(name) != -1) &&
this.getType() == _attribute.getType() &&
this.getParameters().equals(_attribute.getParameters())) {
return true; return true;
} }
} }
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
* @module Discoverer * @module Discoverer
* @fileOverview * @fileOverview
*/ */
define([ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggregator' ], function(easejs, define([ 'easejs', 'attribute', 'attributeList', 'parameter', 'translation', 'widget', 'interpreter', 'aggregator' ], function(easejs,
AttributeList, Widget, Interpreter, Aggregator) { Attribute, AttributeList, Parameter, Translation, Widget, Interpreter, Aggregator) {
var Class = easejs.Class; var Class = easejs.Class;
var Discoverer = Class('Discoverer', { var Discoverer = Class('Discoverer', {
...@@ -52,10 +52,12 @@ define([ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggregator' ], fun ...@@ -52,10 +52,12 @@ define([ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggregator' ], fun
* @class Discoverer * @class Discoverer
* @classdesc The Discoverer handles requests for components and attributes. * @classdesc The Discoverer handles requests for components and attributes.
* @requires easejs * @requires easejs
* @requires AttributeList * @param _widgets
* @param _interpreters
* @param _translations
* @constructs Discoverer * @constructs Discoverer
*/ */
'public __construct' : function(_translations) { 'public __construct' : function(_widgets, _interpreters, _translations) {
this.translations = _translations; this.translations = _translations;
}, },
...@@ -252,9 +254,20 @@ define([ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggregator' ], fun ...@@ -252,9 +254,20 @@ define([ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggregator' ], fun
return this.translations; return this.translations;
}, },
/**
* Returns a newly built attribute.
*
* @public
* @alias buildAttribute
* @memberof Discoverer#
* @param {string} name the proposed name of the will-be attribute
* @param {string} type its type
* @param {Array} parameterList an array of arrays with two elements each: key and value
* @returns {Attribute}
*/
'public buildAttribute' : function(name, type, parameterList) { 'public buildAttribute' : function(name, type, parameterList) {
var newAttribute = new Attribute().withName(name).withType(type); var newAttribute = new Attribute().withName(name).withType(type);
while (typeof parameterList != 'undefined' && parameterList.length > 0) while (typeof parameterList != 'undefined' && parameterList.length > 0)
{ {
var param = parameterList.pop(); var param = parameterList.pop();
...@@ -263,7 +276,8 @@ define([ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggregator' ], fun ...@@ -263,7 +276,8 @@ define([ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggregator' ], fun
if (typeof key != 'undefined' && typeof value != 'undefined') if (typeof key != 'undefined' && typeof value != 'undefined')
newAttribute = newAttribute.withParameter(new Parameter().withKey(key).withValue(value)); newAttribute = newAttribute.withParameter(new Parameter().withKey(key).withValue(value));
} }
for (translation in this.translations) { for (index in this.translations) {
var translation = this.translations[index];
if (translation.translates(newAttribute)) if (translation.translates(newAttribute))
newAttribute = newAttribute.withSynonym(translation.getSynonym()); newAttribute = newAttribute.withSynonym(translation.getSynonym());
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment