UNPKG

@sap/odata-v4

Version:

OData V4.0 server library

118 lines (99 loc) 3.14 kB
'use strict'; const AnnotationFactory = require('./AnnotationExpressionFactory'); const CsdlAnnotationExpression = require('../../csdl/annotationExpression/CsdlAnnotationExpression'); const EdmAnnotationExpression = require('./EdmAnnotationExpression'); const IllegalArgumentError = require('../../errors/IllegalArgumentError'); /** * * <a href="./../ODataSpecification/odata-v4.0-errata03-os/complete/part3-csdl/odata-v4.0-errata03-os-part3-csdl-complete.html#_Toc453752652"> * OData CSDL # 14.5.6 Expression edm:If * </a> * * @extends EdmAnnotationExpression * @hideconstructor */ class EdmIfExpression extends EdmAnnotationExpression { /** * @param {Edm} edm The edm itself * @param {CsdlIfExpression} ifExpression */ constructor(edm, ifExpression) { if (!edm) { throw IllegalArgumentError.createForIllegalInstance('edm', 'Edm'); } if (!ifExpression) { throw IllegalArgumentError.createForIllegalInstance('ifExpression', 'CsdlIfExpression'); } super(CsdlAnnotationExpression.kinds.If); /** * @type {Edm} * @private */ this._edm = edm; /** * @type {CsdlIfExpression} * @private */ this._ifExpression = ifExpression; /** * @type {EdmAnnotationExpression} * @private */ this._condition = AnnotationFactory.createEdmExpressionFromCsdlExpression(edm, ifExpression.condition); /** * @type {EdmAnnotationExpression} * @private */ this._ifTrue = AnnotationFactory.createEdmExpressionFromCsdlExpression(edm, ifExpression.ifTrue); /** * @type {EdmAnnotationExpression} * @private */ this._ifFalse = AnnotationFactory.createEdmExpressionFromCsdlExpression(edm, ifExpression.ifFalse); /** * @type {EdmAnnotation[]} * @private */ this._annotations = null; } /** * Return the condition expression * * @returns {EdmAnnotationExpression} Condition expression which must evaluate to a boolean value */ getCondition() { return this._condition; } /** * Returns the true-expression * * @returns {EdmAnnotationExpression} Expression used if the condition evaluates to true */ getIfTrue() { return this._ifTrue; } /** * Returns the false-expression * * @returns {EdmAnnotationExpression} Expression used if the condition evaluates to true */ getIfFalse() { return this._ifFalse; } /** * Returns the annotations for this object * * @returns {EdmAnnotation[]} */ getAnnotations() { if (this._annotations) { return this._annotations; } this._annotations = []; for (let item of this._ifExpression.annotations) { this._annotations.push(AnnotationFactory.createAnnotation(this._edm, item)); } return this._annotations; } } module.exports = EdmIfExpression;