diff --git a/js/config.js b/js/config.js index 398dda8a99ad8f2ee5d640eacbda4695f661ba2e..d79116981d60980e891abb2668d352c0a4bf169f 100644 --- a/js/config.js +++ b/js/config.js @@ -26,6 +26,7 @@ requirejs.config({ interpreterDescription: 'modules/descriptions/interpreterDescription', widgetDescription: 'modules/descriptions/widgetDescription', discoverer: 'modules/discoverer/discoverer', + translation: 'modules/discoverer/translation', interpreter: 'modules/interpreter/interpreter', interpreterResult: 'modules/interpreter/interpreterResult', callback: 'modules/subscriber/callback', diff --git a/js/modules/discoverer/discoverer.js b/js/modules/discoverer/discoverer.js index d3bd67263a8ba56fea5c77ad5d5f904de3c84fac..557a7921ac77f2c8b7d2574460d49967ca84ed61 100644 --- a/js/modules/discoverer/discoverer.js +++ b/js/modules/discoverer/discoverer.js @@ -37,6 +37,15 @@ define([ 'easejs', 'attributeTypeList', 'widget', 'interpreter', 'aggregator' ], */ 'private interpreter' : {}, + /** + * @alias translations + * @private + * @type {Array} + * @memberof Discoverer# + * @desc List of available attributeType translations (or synonyms). + */ + 'private translations' : {}, + /** * Constructor: All known components given in the associated functions will be registered as startup. * @@ -46,7 +55,8 @@ define([ 'easejs', 'attributeTypeList', 'widget', 'interpreter', 'aggregator' ], * @requires AttributeTypeList * @constructs Discoverer */ - 'public __construct' : function() { + 'public __construct' : function(_translations) { + this.translations = _translations; this.register(); }, @@ -327,6 +337,18 @@ define([ 'easejs', 'attributeTypeList', 'widget', 'interpreter', 'aggregator' ], } return componentList; }, + + /** + * Returns the (associative array of) this discoverer's translations. + * + * @public + * @alias getTranslations + * @memberof Discoverer# + * @returns {Object} + */ + 'public getTranslations' : function() { + return this.translations; + }, /*********************************************************************** * Helper * diff --git a/js/modules/discoverer/translation.js b/js/modules/discoverer/translation.js new file mode 100644 index 0000000000000000000000000000000000000000..bc4f92e1b8d8a85dcef60ca03a669ca96ec2d2f3 --- /dev/null +++ b/js/modules/discoverer/translation.js @@ -0,0 +1,63 @@ +/** + * This module represents the helper class Translation. + * + * @module Translation + * @fileOverview + */ +define('translation', ['easejs', 'attributeType'], function(easejs, AttributeType) { + var Class = easejs.Class; + + var Translation = Class('Translation', { + + 'private fromAttributeType' : {}, + + 'private toAttributeType' : {}, + + /** + * Constructor: Constructs a translation tuple. + * + * @class Translation + * @classdesc This class represents a translation tuple. + * It holds two synonymous attribute types. + * @requires easejs + * @requires attributeType + * @constructs Translation + */ + 'public __construct' : function(_fromAttributeType, _toAttributeType) { + + this.fromAttributeType = _fromAttributeType; + this.toAttributeType = _toAttributeType; + }, + + /** + * Look for a translation and return the found synonym. + * + * @public + * @alias getSynonym + * @memberof Translation# + * @param {AttributeType} attributeType AttributeType whose synonym is queried + * @returns {AttributeType} The synonym if one exists, otherwise the given attributeType + */ + 'public getSynonym': function(_attributeType) { + + return this.hasSynonym(_attributeType) ? this.toAttributeType : _attributeType; + }, + + /** + * Look for a translation and return true if one exists. + * + * @public + * @alias hasSynonym + * @memberof Translation# + * @param {AttributeType} attributeType AttributeType whose synonym is queried + * @returns {boolean} + */ + 'public hasSynonym': function(_attributeType) { + + return this.fromAttributeType.equals(_attributeType); + } + + }); + + return Translation; +}); \ No newline at end of file