Skip to content
Snippets Groups Projects
widget.js 18.7 KiB
Newer Older
Stefanie Lemcke's avatar
Stefanie Lemcke committed
/**
 * This module representing a Context Widget.
 * 
 * @module Widget
 */
define(['MathUuid', 'callback', 'callbackList', 'attribute', 'attributeList', 'conditionList', 'subscriber', 'subscriberList'],
	function(MathUuid, Callback, CallbackList, Attribute, AttributeList, ConditionList, Subscriber, SubscriberList) {
		return (function() {

			/**
			 * Defines all outAttributes and constOutAttributes as an object.
			 * @type {object}
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 * @public
			 */
			Widget.inOut = {
				out: [
					{
						"name":"",
						"type":"",
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			/**
			 * Constructor: Generates the ID and initializes the
			 * Widget with attributes, callbacks and subscriber
			 * that are specified in the provided functions.
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 * @abstract
			 * @classdesc The Widget handles the access to sensors.
			 * @constructs Widget
			 */
			function Widget(discoverer, attributes) {
				var self = this;

				/**
				 * Name of the Widget.
				 *
				 * @type {string}
				 */
				this.name = 'Widget';

				/**
				 * ID of the Widget. Will be generated.
				 *
				 * @type {string}
				 */
Stefanie Lemcke's avatar
Stefanie Lemcke committed
				this.id = Math.uuid();

				/**
				 *
				 * @protected
				 * @type {AttributeList}
				 * @memberof Widget#
				 * @desc All available Attributes and their values.
				 */
				this._outAttributes = new AttributeList();

				/**
				 * @alias oldAttributes
				 * @protected
				 * @type {AttributeList}
				 * @memberof Widget#
				 * @desc This temporary variable is used for storing the old attribute values.
				 * 			So these can be used to check conditions.
				 */
				this._oldOutAttributes = new AttributeList();

				/**
				 * @alias constantAttributes
				 * @protected
				 * @type {AttributeList}
				 * @memberof Widget#
				 * @desc All available constant Attributes and their values.
				 */
				this._constantOutAttributes = new AttributeList();

				/**
				 * @alias callbacks
				 * @protected
				 * @type {CallbackList}
				 * @memberof Widget#
				 * @desc List of Callbacks.
				 */
				this._callbacks = new CallbackList();

				/**
				 * @alias subscribers
				 * @protected
				 * @type {SubscriberList}
				 * @memberof Widget#
				 * @desc List of Subscriber.
				 */
				this._subscribers = new SubscriberList();

				/**
				 * Associated discoverer.
				 *
				 * @type {Discoverer}
				 * @private
				 */
				this._discoverer = discoverer;

				this._register();
				this._init(attributes);

				return this;
			}
Stefanie Lemcke's avatar
Stefanie Lemcke committed

			/**
			 * Initializes the provided Attributes.
			 *
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 */
			Widget.prototype._initOutAttributes = function() {
				for(var outAttributeIndex in this.constructor.inOut.out) {
					var out = this.constructor.inOut.out[outAttributeIndex];
					this._outAttributes.put(this._discoverer.buildAttribute(
						out.name,
						out.type,
						out.parameterList,
						true
					));
				}
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			/**
			 * Initializes the provided ConstantAttributes.
			 *
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 */
			Widget.prototype._initConstantOutAttributes = function() {
				for(var constAttributeIndex in this.constructor.inOut.const) {
					var constants = this.constructor.inOut.const[constAttributeIndex];
					this._outAttributes.put(this._discoverer.buildAttribute(
						constants.name,
						constants.type,
						constants.parameterList,
						true
					));
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			/**
			 * Initializes the provided Callbacks.
			 *
			 * @abstract
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 * @protected
			 */
			Widget.prototype._initCallbacks = function() {
				throw new Error("Abstract function!");
			};
Stefanie Lemcke's avatar
Stefanie Lemcke committed

			/**
			 * Function for initializing. Calls all initFunctions
			 * and will be called by the constructor.
			 *
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 * @protected
			 */
			Widget.prototype._init = function(attributes) {
				this._initConstantOutAttributes();
				this._initCallbacks();

				this.didFinishInitialization(attributes);
			};
Stefanie Lemcke's avatar
Stefanie Lemcke committed

			/**
			 * Method will be invoked after the initialization of the widget finished.
			 * Can be overridden by inheriting classes to take action after initialization.
			 *
			 * @public
			 * @virtual
			 * @param attributes
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 */
			Widget.prototype.didFinishInitialization = function(attributes) {

			};
Stefanie Lemcke's avatar
Stefanie Lemcke committed

			/**
			 * Returns the name of the widget.
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 * @public
			 * @alias getName
			 * @memberof Widget#
			 * @returns {string}
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 */
			Widget.prototype.getName = function() {
Stefanie Lemcke's avatar
Stefanie Lemcke committed
				return this.name;
Stefanie Lemcke's avatar
Stefanie Lemcke committed

			/**
			 * Returns the id of the widget.
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 * @public
			 * @alias getId
			 * @memberof Widget#
			 * @returns {string}
			 */
			Widget.prototype.getId = function() {
Stefanie Lemcke's avatar
Stefanie Lemcke committed
				return this.id;
Stefanie Lemcke's avatar
Stefanie Lemcke committed

			/**
			 * Returns the available AttributeTypes.
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 * @public
			 * @param {?AttributeList} [attributes]
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 */
			Widget.prototype.getOutAttributes = function(attributes) {
				// test if attributeList is a list
				if (attributes && attributes instanceof AttributeList) {
					return this._outAttributes.getSubset(attributes);
					return this._outAttributes;
Stefanie Lemcke's avatar
Stefanie Lemcke committed

			/**
			 * Returns the available ConstantAttributeTypes
			 * (attributes that do not change).
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 * @public
			 * @param {?AttributeList} attributes
			 * @returns {AttributeList}
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 */
			Widget.prototype.getConstantOutAttributes = function(attributes) {
				if (attributes && attributes instanceof AttributeList) {
					return this._constantOutAttributes.getSubset(attributes);
					return this._constantOutAttributes;
			};

			/**
			 * Returns the last acquired attribute value with the given attribute type.
			 *
			 * @param {AttributeType} attributeType The attribute type to return the last value for.
			 * @returns {*}
			 */
			Widget.prototype.getValueForAttributeWithTypeOf = function(attributeType) {
				return this.getOutAttributes().getAttributeWithTypeOf(attributeType).getValue();
			};

Stefanie Lemcke's avatar
Stefanie Lemcke committed
			/**
			 * Returns the old Attributes.
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 * @private
			 * @alias getOldAttributes
			 * @memberof Widget#
			 * @returns {AttributeList}
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 */
			Widget.prototype.getOldAttributes = function() {
				return this._oldOutAttributes;
			};
Stefanie Lemcke's avatar
Stefanie Lemcke committed

			/**
			 * Returns a list of callbacks that can be
			 * subscribed to.
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 * @public
			 * @alias getCallbacks
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 * @memberof Widget#
			 * @returns {CallbackList}
			 */
			Widget.prototype.getCallbackList = function() {
				return this._callbacks;
			};

			/**
			 * Returns the specified callbacks that can be
			 * subscribed to.
			 *
			 * @public
			 * @alias getCallbacks
			 * @memberof Widget#
			 * @returns {Array}
			 */
			Widget.prototype.getCallbacks = function() {
				return this._callbacks.getItems();
			};

			Widget.prototype.queryServices = function() {
Stefanie Lemcke's avatar
Stefanie Lemcke committed
				return this.services;
Stefanie Lemcke's avatar
Stefanie Lemcke committed

			/**
			 * Returns the Subscriber.
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 * @public
			 * @alias getSubscriber
			 * @memberof Widget#
			 * @returns {SubscriberList}
			 */
			Widget.prototype.getSubscriber = function() {
				return this._subscribers;
			};
Stefanie Lemcke's avatar
Stefanie Lemcke committed

			/**
			 * Sets the name of the Widget.
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 * @protected
			 * @alias setName
			 * @memberof Widget#
			 * @param {string} name Name of the Widget.
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 */
			Widget.prototype.setName = function(name) {
				if (typeof name === 'string') {
					this.name = name;
Stefanie Lemcke's avatar
Stefanie Lemcke committed
				}
Stefanie Lemcke's avatar
Stefanie Lemcke committed

			/**
			 * Sets the id of the Widget.
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 * @protected
			 * @alias setId
			 * @memberof Widget#
			 * @param {string} id Id of the Widget.
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 */
			Widget._setId = function(id) {
				if (typeof id === 'string') {
					this.id = id;
Stefanie Lemcke's avatar
Stefanie Lemcke committed
				}
Stefanie Lemcke's avatar
Stefanie Lemcke committed

			/**
			 * Sets the AttributeValueList and also the associated
			 * AttributeTypes.
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 * @protected
			 * @param {(AttributeList|Array)} attributesOrArray List or Array of AttributeValues
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 */
			Widget.prototype._setOutAttributes = function(attributesOrArray) {
				this._outAttributes = new AttributeList().withItems(attributesOrArray);
Stefanie Lemcke's avatar
Stefanie Lemcke committed

			/**
			 * Adds a new AttributeValue. If the given value is
			 * not included in the list, the associated type will
			 * be also added. Otherwise, only the value will be
			 * updated.
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 * @public
			 * @param {Attribute} attribute
			 * @param {Boolean} multipleInstances
			 */
			Widget.prototype.addOutAttribute = function(attribute, multipleInstances) {
				multipleInstances = typeof multipleInstances == "undefined" ? false : multipleInstances;
				if (attribute instanceof Attribute) {
					if (!this._outAttributes.containsTypeOf(attribute)) {
						this._oldOutAttributes = this._outAttributes;
						attribute.setTimestamp(this.getCurrentTime());
						this._outAttributes.put(attribute, multipleInstances);
Stefanie Lemcke's avatar
Stefanie Lemcke committed
					}
				}
Stefanie Lemcke's avatar
Stefanie Lemcke committed

			/**
			 * Sets the ConstantAttributeValueList and also the
			 * associated AttributeTypes.
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 * @protected
			 * @alias setConstantOutAttributes
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 * @memberof Widget#
			 * @param {(AttributeList|Array)} constantAttributes List or Array of AttributeValues
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 */
			Widget.prototype._setConstantOutAttributes = function(constantAttributes) {
				this._constantOutAttributes = new AttributeList().withItems(constantAttributes);
Stefanie Lemcke's avatar
Stefanie Lemcke committed

			/**
			 * Adds a new constantAttributeValue. If the given value is
			 * not included in the list, the associated type will
			 * be also added. Otherwise, only the value will be
			 * updated.
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 * @protected
			 * @param {Attribute} constantAttribute AttributeValue
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 */
			Widget.prototype._addConstantOutAttribute = function(constantAttribute) {
				if (Class.isA(AttributeValue, constantAttribute)) {
Stefanie Lemcke's avatar
Stefanie Lemcke committed
					if (!this.constantAttributes
							.contains(constantAttribute)) {
Stefanie Lemcke's avatar
Stefanie Lemcke committed

						var type = new AttributeType().withName(constantAttribute.getName())
							.withType(constantAttribute.getType())
							.withParameters(constantAttribute.getParameters());
Stefanie Lemcke's avatar
Stefanie Lemcke committed
						this.constantAttributeTypes.put(type);
					}
					_attribute.setTimestamp(this.getCurrentTime());
					this.constantAttributes.put(constantAttribute);
Stefanie Lemcke's avatar
Stefanie Lemcke committed
				}
Stefanie Lemcke's avatar
Stefanie Lemcke committed

			/**
			 * Sets Callbacks.
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 * @protected
			 * @alias setCallbacks
			 * @memberof Widget#
			 * @param {(CallbackList|Array)} callbacks List or Array of Callbacks.
			 */
			Widget.prototype._setCallbacks = function(callbacks) {
				var list = [];
				if (callbacks instanceof Array) {
					list = callbacks;
				} else if (callbacks instanceof CallbackList) {
					list = callbacks.getItems();
Stefanie Lemcke's avatar
Stefanie Lemcke committed
				}
				for ( var i in list) {
					var callback = list[i];
					if (callback instanceof Callback) {
Stefanie Lemcke's avatar
Stefanie Lemcke committed
						this.callbacks.put(callback);
					}
				}
Stefanie Lemcke's avatar
Stefanie Lemcke committed

			/**
			 * Adds a new Callback.
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 * @protected
			 * @alias addCallback
			 * @memberof Widget#
			 * @param {Callback} callback List or Array of AttributeValues.
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 */
			Widget.prototype._addCallback = function(callback) {
				if (callback instanceof Callback) {
					this._callbacks.put(callback);
Stefanie Lemcke's avatar
Stefanie Lemcke committed

			Widget.prototype._setServices = function(services) {
				this.services = services;
			};
Stefanie Lemcke's avatar
Stefanie Lemcke committed

			/**
			 * Sets SubscriberList.
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 * @protected
			 * @alias setSubscriber
			 * @memberof Widget#
			 * @param {(SubscriberList|Array)}  subscribers List or Array of Subscriber.
			 */
			Widget.prototype._setSubscriber = function(subscribers) {
				var list = [];
				if (subscribers instanceof Array) {
					list = subscribers;
				} else if (subscribers instanceof SubscriberList) {
					list = subscribers.getItems();
Stefanie Lemcke's avatar
Stefanie Lemcke committed
				}
				for ( var i in list) {
Stefanie Lemcke's avatar
Stefanie Lemcke committed
					var singleSubscriber = list[i];
					if (singleSubscriber instanceof Subscriber) {
						this._subscribers.put(singleSubscriber);
Stefanie Lemcke's avatar
Stefanie Lemcke committed
					}
				}
Stefanie Lemcke's avatar
Stefanie Lemcke committed

			/**
			 * Adds a new Subscriber.
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 * @public
			 * @param {?Subscriber} subscriber Subscriber
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 */
			Widget.prototype.addSubscriber = function(subscriber) {
				if (subscriber && subscriber instanceof Subscriber) {
					this._subscribers.put(subscriber);
Stefanie Lemcke's avatar
Stefanie Lemcke committed
				}
Stefanie Lemcke's avatar
Stefanie Lemcke committed

			/**
			 * Removes the specified Subscriber.
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 * @public
			 * @param {Subscriber} subscriberId Subscriber
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 */
			Widget.prototype.removeSubscriber = function(subscriberId) {
				this._subscribers.removeSubscriberWithId(subscriberId);
			};
Stefanie Lemcke's avatar
Stefanie Lemcke committed

			/**
			 * Returns the current time.
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 * @private
			 * @returns {Date}
			 */
			Widget.prototype.getCurrentTime = function() {
Stefanie Lemcke's avatar
Stefanie Lemcke committed
				return new Date();
Stefanie Lemcke's avatar
Stefanie Lemcke committed

			/**
			 * Verifies whether the specified attributes is a
			 * provided Attribute.
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 * @protected
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 * @memberof Widget#
			 * @param {Attribute} attribute
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 * @returns {boolean}
			 */
			Widget.prototype._isOutAttribute = function(attribute) {
				return !!this._outAttributes.containsTypeOf(attribute);
			};
Stefanie Lemcke's avatar
Stefanie Lemcke committed

			/**
			 * Notifies other components and sends the attributes.
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 * @virtual
			 * @public
			 */
			Widget.prototype.notify = function() {
				var callbacks = this.getCallbacks();
				for (var i in callbacks) {
					this.sendToSubscriber(callbacks[i]);
				}
			};
Stefanie Lemcke's avatar
Stefanie Lemcke committed

			/**
			 * Queries the associated sensor and updates the attributes with new values.
			 * Must be overridden by the subclasses. Overriding subclasses can call
			 * this.__super(_function) to invoke the provided callback function.
			 *
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 * @virtual
			 * @public
			 * @param {?function} callback For alternative actions, because an asynchronous function can be used.
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 */
			Widget.prototype.sendToSubscriber = function(callback) {
				if (callback && typeof(callback) == 'function') {
					callback();
				}
			};
Stefanie Lemcke's avatar
Stefanie Lemcke committed

			/**
			 *
			 * @abstract
			 * @param callback
			 */
			Widget.prototype.queryGenerator = function (callback) {
				throw "Call to abstract method 'queryGenerator'.";
			};

			/**
			 *
			 * @param response
			 * @param callback
			 * @protected
			 */
			Widget.prototype._sendResponse = function(response, callback) {
				this.putData(response);
				this.notify();

				if (callback && typeof(callback) == 'function') {
					callback();
				}
			};

Stefanie Lemcke's avatar
Stefanie Lemcke committed
			/**
			 * Updates the attributes by calling queryGenerator.
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 * @public
			 * @alias updateWidgetInformation
			 * @memberof Widget#
			 * @param {?function} callback For alternative  actions, because an asynchronous function can be used.
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 *
			 */
			Widget.prototype.updateWidgetInformation = function(callback) {
				this.queryGenerator(callback);
			};
Stefanie Lemcke's avatar
Stefanie Lemcke committed

			/**
			 * Updates the Attributes by external components.
			 *
			 * @param {(AttributeList|Array)} attributes Data that should be entered.
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 */
			Widget.prototype.putData = function(attributes) {
				var list = [];
				if (attributes instanceof Array) {
					list = attributes;
				} else if (attributes instanceof AttributeList) {
					list = attributes.getItems();
Stefanie Lemcke's avatar
Stefanie Lemcke committed
				}
				for ( var i in list) {
					var theAttribute = list[i];
					if (theAttribute.type === Attribute && this.isOutAttribute(theAttribute)) {
						this.addOutAttribute(theAttribute);
Stefanie Lemcke's avatar
Stefanie Lemcke committed
					}
				}
Stefanie Lemcke's avatar
Stefanie Lemcke committed

			/**
			 * Returns all available AttributeValues, Attributes and ConstantAttributes.
			 *
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 * @public
			 * @returns {AttributeList}
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 */
			Widget.prototype.queryWidget = function() {
				var response = new AttributeList();
				response.putAll(this.getOutAttributes());
				response.putAll(this.getConstantOutAttributes());
Stefanie Lemcke's avatar
Stefanie Lemcke committed
				return response;
Stefanie Lemcke's avatar
Stefanie Lemcke committed

			/**
			 * Updates and returns all available AttributeValues,
			 * Attributes and ConstantAtrributes.
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 * @public
			 * @alias updateAndQueryWidget
			 * @memberof Widget#
			 * @param {?function} callback For alternative  actions, because an asynchronous function can be used.
			 * @returns {?AttributeList}
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 */
			Widget.prototype.updateAndQueryWidget = function(callback) {
				if(callback && typeof(callback) === 'function'){
					this.queryGenerator(callback);
Stefanie Lemcke's avatar
Stefanie Lemcke committed
				} else {
					this.queryGenerator();
					return this.queryWidget();
Stefanie Lemcke's avatar
Stefanie Lemcke committed
				}
Stefanie Lemcke's avatar
Stefanie Lemcke committed

			/**
			 * Sends all Attributes, specified in the given callback,
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 * to components which are subscribed to this Callback.
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 * @protected
			 * @param {string} callback Name of the searched Callback.
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 */
			Widget.prototype._sendToSubscriber = function(callback) {
				if (callback && callback instanceof Callback) {
					var subscriberList = this._subscribers.getItems();
					for (var i in subscriberList) {
Stefanie Lemcke's avatar
Stefanie Lemcke committed
						var subscriber = subscriberList[i];
						if (subscriber.getSubscriptionCallbacks().contains(callback)) {
Stefanie Lemcke's avatar
Stefanie Lemcke committed
							if(this.dataValid(subscriber.getConditions())){
								var subscriberInstance = this._discoverer.getComponent(subscriber.getSubscriberId());
								var callSubset =  callback.getAttributeTypes();
Stefanie Lemcke's avatar
Stefanie Lemcke committed
								var subscriberSubset = subscriber.getAttributesSubset();
								var data = this.outAttributes.getSubset(callSubset);
Stefanie Lemcke's avatar
Stefanie Lemcke committed
								if (subscriberSubset && subscriberSubset.size() > 0) {
									data = data.getSubset(subscriberSubset);
								}
							}
							if (data) {
								subscriberInstance.putData(data);
							}
						}
					}
				}
Stefanie Lemcke's avatar
Stefanie Lemcke committed

			/**
			 * Verifies if the attributes match to the specified conditions in case any exists.
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 * @private
			 * @alias dataValid
			 * @memberof Widget#
			 * @param {string} conditions List of Conditions that will be verified.
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 * @returns {boolean}
			 */
			Widget.prototype._dataValid = function(conditions) {
				if (conditions instanceof ConditionList) {
Stefanie Lemcke's avatar
Stefanie Lemcke committed
					return true;
				}
				if (!conditions.isEmpty()) {
Stefanie Lemcke's avatar
Stefanie Lemcke committed
					var items = _condition.getItems();
Stefanie Lemcke's avatar
Stefanie Lemcke committed
						var condition = items[i];
						var conditionAttributeType = condition.getAttributeType();
						var conditionAttributeTypeList = new AttributeTypeList()
							.withItems(new Array(conditionAttributeType));
						var newValue = this.getAttributes().getSubset(conditionAttributeTypeList);
Stefanie Lemcke's avatar
Stefanie Lemcke committed
						var oldValue = this.getOldAttributes.getSubset(conditionAttributeTypeList);
						return condition.compare(newValue, oldValue);
					}
				}
				return false;
Stefanie Lemcke's avatar
Stefanie Lemcke committed

			/**
			 * Runs the context acquisition constantly in an interval.
			 * Can be called by init.
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 * @virtual
			 * @protected
			 * @param {Number} interval Interval in ms
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 */
			Widget.prototype._intervalRunning = function(interval) {
Stefanie Lemcke's avatar
Stefanie Lemcke committed
				var self = this;
				if (interval === parseInt(interval)) {
					setInterval(function() {self.queryGenerator();}, interval);
Stefanie Lemcke's avatar
Stefanie Lemcke committed
				}
Stefanie Lemcke's avatar
Stefanie Lemcke committed

			/**
			 * Sets the associated Discoverer and registers to that.
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 * @public
			 * @param {Discoverer} _discoverer Discoverer
			 */
			Widget.prototype.setDiscoverer = function(_discoverer) {
				if (!this._discoverer) {
					this._discoverer = _discoverer;
Stefanie Lemcke's avatar
Stefanie Lemcke committed
				}
Stefanie Lemcke's avatar
Stefanie Lemcke committed

			/**
			 * Registers the component to the associated Discoverer.
			 *
			 * @protected
Stefanie Lemcke's avatar
Stefanie Lemcke committed
			 */
			Widget.prototype._register = function() {
				if (this._discoverer) {
					this._discoverer.registerNewComponent(this);
Stefanie Lemcke's avatar
Stefanie Lemcke committed
				}
Stefanie Lemcke's avatar
Stefanie Lemcke committed

			/**
			 * Returns true if the widget can satisfy the requested attribute type.
			 *
			 * @public
			 * @param {AttributeType} attribute
			Widget.prototype.doesSatisfyTypeOf = function(attribute) {
				return this._outAttributes.containsTypeOf(attribute);
			};
Stefanie Lemcke's avatar
Stefanie Lemcke committed

			return Widget;
		})();
	}
);