From 91c95186897fc35497ad5d5a005639dc1de4c3bb Mon Sep 17 00:00:00 2001
From: Helena Jank <jank@uni-potsdam.de>
Date: Mon, 27 Apr 2015 17:48:11 +0200
Subject: [PATCH] + added module Translation (as part of discoverer)

---
 js/config.js                         |  1 +
 js/modules/discoverer/discoverer.js  | 24 ++++++++++-
 js/modules/discoverer/translation.js | 63 ++++++++++++++++++++++++++++
 3 files changed, 87 insertions(+), 1 deletion(-)
 create mode 100644 js/modules/discoverer/translation.js

diff --git a/js/config.js b/js/config.js
index 398dda8..d791169 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 d3bd672..557a792 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 0000000..bc4f92e
--- /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
-- 
GitLab