diff --git a/dist/contactJS.js b/dist/contactJS.js index f680ef6d66e59757189316aefbb0c4f0d755a09a..8683d1a0b30484f172c7baef59a2ca9f632cd297 100644 --- a/dist/contactJS.js +++ b/dist/contactJS.js @@ -5418,17 +5418,23 @@ define('interpreter',[ 'easejs', 'MathUuid', 'attributeType', 'attributeTypeList * @param {?function} _function For additional actions, if an asynchronous function is used. */ 'public callInterpreter' : function(_inAttributeValues, _outAttributeValues, _function) { - if (_inAttributeValues && this.canHandle(_inAttributeValues)) { - this.interpretData(_inAttributeValues, _outAttributeValues, _function); - this.setInAttributeValues(_inAttributeValues); - this.lastInterpretation = new Date(); - } else { - var list = this.outAttributeTypes.getItems(); - for ( var i in list) { - this.setOutAttribute(list[i].getName(), list[i].getType(), 'unavailable'); + var self = this; + + if (!_inAttributeValues || !this.canHandleInAttributeValues(_inAttributeValues)) throw "Empty input attribute list or unhandled input attribute."; + if (!_outAttributeValues || !this.canHandleOutAttributeValues(_outAttributeValues)) throw "Empty output attribute list or unhandled output attribute."; + + this.interpretData(_inAttributeValues, _outAttributeValues, function(interpretedData) { + var response = new AttributeValueList().withItems(interpretedData); + + if (!self.canHandleOutAttributeValues(response)) throw "Unhandled output attribute generated."; + + self.setInAttributeValues(_inAttributeValues); + self.lastInterpretation = new Date(); + + if (_function && typeof(_function) == 'function'){ + _function(response); } - _function(); - } + }); }, /** @@ -5442,24 +5448,24 @@ define('interpreter',[ 'easejs', 'MathUuid', 'attributeType', 'attributeTypeList * @param {AttributeValueList} _data Data that should be interpreted. * @param {?function} _function For additional actions, if an asynchronous function is used. */ - 'abstract protected interpretData' : [ '_data', '_function' ], + 'abstract protected interpretData' : ['_inAttributeValues', '_outAttributeValues', '_callback'], /** * Checks whether the specified data match the expected. * * @protected - * @alias canHandle + * @alias canHandleInAttributeValues * @memberof Interpreter# - * @param {AttributeValueList} _inAtts Data that should be verified. + * @param {AttributeValueList|Array.<AttributeValue>} _inAttributeValues Data that should be verified. */ - 'protected canHandle' : function(_inAtts) { + 'protected canHandleInAttributeValues' : function(_inAttributeValues) { var list = []; - if (_inAtts instanceof Array) { - list = _inAtts; - } else if (Class.isA(AttributeValueList, _inAtts)) { - list = _inAtts.getItems(); + if (_inAttributeValues instanceof Array) { + list = _inAttributeValues; + } else if (Class.isA(AttributeValueList, _inAttributeValues)) { + list = _inAttributeValues.getItems(); } - if (list.length == 0 || _inAtts.size() != this.getInAttributeTypes().size()) { + if (list.length == 0 || _inAttributeValues.size() != this.getInAttributeTypes().size()) { return false; } for ( var i in list) { @@ -5471,6 +5477,33 @@ define('interpreter',[ 'easejs', 'MathUuid', 'attributeType', 'attributeTypeList return true; }, + /** + * Checks whether the specified data match the expected. + * + * @protected + * @alias canHandle + * @memberof Interpreter# + * @param {AttributeValueList|Array.<AttributeValue>} _outAttributeValues Data that should be verified. + */ + 'protected canHandleOutAttributeValues' : function(_outAttributeValues) { + var list = []; + if (_outAttributeValues instanceof Array) { + list = _outAttributeValues; + } else if (Class.isA(AttributeValueList, _outAttributeValues)) { + list = _outAttributeValues.getItems(); + } + if (list.length == 0 || _outAttributeValues.size() != this.getOutAttributeTypes().size()) { + return false; + } + for ( var i in list) { + var inAtt = list[i]; + if (!this.isOutAttribute(inAtt)) { + return false; + } + } + return true; + }, + /** * Returns the time of the last interpretation. * diff --git a/js/modules/interpreter/interpreter.js b/js/modules/interpreter/interpreter.js index d0aa7e0e0947ab744a1e79bf8fdcf74044c348b4..1342d95d318f14229d633836f395363868099a2e 100644 --- a/js/modules/interpreter/interpreter.js +++ b/js/modules/interpreter/interpreter.js @@ -282,17 +282,23 @@ define([ 'easejs', 'MathUuid', 'attributeType', 'attributeTypeList', * @param {?function} _function For additional actions, if an asynchronous function is used. */ 'public callInterpreter' : function(_inAttributeValues, _outAttributeValues, _function) { - if (_inAttributeValues && this.canHandle(_inAttributeValues)) { - this.interpretData(_inAttributeValues, _outAttributeValues, _function); - this.setInAttributeValues(_inAttributeValues); - this.lastInterpretation = new Date(); - } else { - var list = this.outAttributeTypes.getItems(); - for ( var i in list) { - this.setOutAttribute(list[i].getName(), list[i].getType(), 'unavailable'); + var self = this; + + if (!_inAttributeValues || !this.canHandleInAttributeValues(_inAttributeValues)) throw "Empty input attribute list or unhandled input attribute."; + if (!_outAttributeValues || !this.canHandleOutAttributeValues(_outAttributeValues)) throw "Empty output attribute list or unhandled output attribute."; + + this.interpretData(_inAttributeValues, _outAttributeValues, function(interpretedData) { + var response = new AttributeValueList().withItems(interpretedData); + + if (!self.canHandleOutAttributeValues(response)) throw "Unhandled output attribute generated."; + + self.setInAttributeValues(_inAttributeValues); + self.lastInterpretation = new Date(); + + if (_function && typeof(_function) == 'function'){ + _function(response); } - _function(); - } + }); }, /** @@ -306,24 +312,24 @@ define([ 'easejs', 'MathUuid', 'attributeType', 'attributeTypeList', * @param {AttributeValueList} _data Data that should be interpreted. * @param {?function} _function For additional actions, if an asynchronous function is used. */ - 'abstract protected interpretData' : [ '_data', '_function' ], + 'abstract protected interpretData' : ['_inAttributeValues', '_outAttributeValues', '_callback'], /** * Checks whether the specified data match the expected. * * @protected - * @alias canHandle + * @alias canHandleInAttributeValues * @memberof Interpreter# - * @param {AttributeValueList} _inAtts Data that should be verified. + * @param {AttributeValueList|Array.<AttributeValue>} _inAttributeValues Data that should be verified. */ - 'protected canHandle' : function(_inAtts) { + 'protected canHandleInAttributeValues' : function(_inAttributeValues) { var list = []; - if (_inAtts instanceof Array) { - list = _inAtts; - } else if (Class.isA(AttributeValueList, _inAtts)) { - list = _inAtts.getItems(); + if (_inAttributeValues instanceof Array) { + list = _inAttributeValues; + } else if (Class.isA(AttributeValueList, _inAttributeValues)) { + list = _inAttributeValues.getItems(); } - if (list.length == 0 || _inAtts.size() != this.getInAttributeTypes().size()) { + if (list.length == 0 || _inAttributeValues.size() != this.getInAttributeTypes().size()) { return false; } for ( var i in list) { @@ -335,6 +341,33 @@ define([ 'easejs', 'MathUuid', 'attributeType', 'attributeTypeList', return true; }, + /** + * Checks whether the specified data match the expected. + * + * @protected + * @alias canHandle + * @memberof Interpreter# + * @param {AttributeValueList|Array.<AttributeValue>} _outAttributeValues Data that should be verified. + */ + 'protected canHandleOutAttributeValues' : function(_outAttributeValues) { + var list = []; + if (_outAttributeValues instanceof Array) { + list = _outAttributeValues; + } else if (Class.isA(AttributeValueList, _outAttributeValues)) { + list = _outAttributeValues.getItems(); + } + if (list.length == 0 || _outAttributeValues.size() != this.getOutAttributeTypes().size()) { + return false; + } + for ( var i in list) { + var inAtt = list[i]; + if (!this.isOutAttribute(inAtt)) { + return false; + } + } + return true; + }, + /** * Returns the time of the last interpretation. *