@sap/odata-v4
Version:
OData V4.0 server library
152 lines (130 loc) • 3.51 kB
JavaScript
'use strict';
const AnnotationFactory = require('./AnnotationExpressionFactory');
const CsdlAnnotationExpression = require('../../csdl/annotationExpression/CsdlAnnotationExpression');
const EdmAnnotationExpression = require('./EdmAnnotationExpression');
const EdmTypeFactory = require('../EdmTypeFactory');
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#_Toc453752650">
* OData CSDL # 14.5.4 Expression edm:Cast
* </a>
*
* @extends EdmAnnotationExpression
* @hideconstructor
*/
class EdmCastExpression extends EdmAnnotationExpression {
/**
* @param {Edm} edm The edm itself
* @param {CsdlCastExpression} cast The csdl cast expression
*/
constructor(edm, cast) {
if (!edm) {
throw IllegalArgumentError.createForIllegalInstance('edm', 'Edm');
}
if (!cast) {
throw IllegalArgumentError.createForIllegalInstance('cast', 'CsdlCastExpression');
}
super(CsdlAnnotationExpression.kinds.Cast);
/**
* @type {Edm}
* @private
*/
this._edm = edm;
/**
* @type {CsdlCastExpression}
* @private
*/
this._cast = cast;
/**
* @type {EdmAnnotationExpression}
* @private
*/
this._expression = AnnotationFactory.createEdmExpressionFromCsdlExpression(edm, cast.expression);
/**
* @type {EdmType}
* @private
*/
this._type = null;
/**
* @type {EdmAnnotation[]}
* @private
*/
this._annotations = null;
}
/**
* Return the target type
*
* @returns {EdmType}
*/
getType() {
if (this._type) {
return this._type;
}
this._type = EdmTypeFactory.createTypeFromFQN(this._edm, this._cast.type);
return this._type;
}
/**
* Returns the Full Qualified Name of the type
* @returns {FullQualifiedName}
*/
getTypeFQN() {
return this._cast.type;
}
/**
* Return the expression to be casted
*
* @returns {EdmAnnotationExpression}
*/
getExpression() {
return this._expression;
}
/**
* Returns the max length
*
* @returns {number|string}
*/
getMaxLength() {
return this._cast.maxLength;
}
/**
* Returns the precision
*
* @returns {number|string}
*/
getPrecision() {
return this._cast.precision;
}
/**
* Returns the scale
*
* @returns {number}
*/
getScale() {
return this._cast.scale;
}
/**
* Return true if this type is a collection, else false.
*
* @returns {boolean} True if this type is a collection, else false
*/
isCollection() {
return this._cast.isCollection;
}
/**
* Returns the annotations for this cast expression
*
* @returns {EdmAnnotation[]}
*/
getAnnotations() {
if (this._annotations) {
return this._annotations;
}
this._annotations = [];
for (let item of this._cast.annotations) {
this._annotations.push(AnnotationFactory.createAnnotation(this._edm, item));
}
return this._annotations;
}
}
module.exports = EdmCastExpression;