@sap/odata-v4
Version:
OData V4.0 server library
120 lines (102 loc) • 2.97 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#_Toc453752660">
* OData CSDL # 14.5.14 Expression edm:Record
* </a>
*
* @extends EdmAnnotationExpression
* @hideconstructor
*/
class EdmRecordExpression extends EdmAnnotationExpression {
/**
* @param {Edm} edm
* @param {CsdlRecordExpression} record
*/
constructor(edm, record) {
if (!edm) {
throw IllegalArgumentError.createForIllegalInstance('edm', 'Edm');
}
if (!record) {
throw IllegalArgumentError.createForIllegalInstance('record', 'CsdlRecordExpression');
}
super(CsdlAnnotationExpression.kinds.Record);
/**
* @type {Edm}
* @private
*/
this._edm = edm;
/**
* @type {CsdlRecordExpression}
* @private
*/
this._record = record;
/**
* @type {EdmAnnotationExpression[]}
* @private
*/
this._propertyValues = [];
for (let item of record.propertyValues) {
const element = AnnotationFactory.createEdmExpressionFromCsdlExpression(edm, item);
this._propertyValues.push(element);
}
/**
* @type {EdmType}
* @private
*/
this._type = null;
/**
* @type {EdmAnnotation[]}
* @private
*/
this._annotations = null;
}
/**
* Return the type used for check
*
* @returns {EdmType} Type
*/
getType() {
if (this._type) {
return this._type;
}
if (this._record.type) {
this._type = EdmTypeFactory.createTypeFromFQN(this._edm, this._record.type);
}
return this._type;
}
/**
* Returns the Full Qualified Name of the type
* @returns {FullQualifiedName}
*/
getTypeFQN() {
return this._record.type;
}
/**
* Returns the the records properties
*
* @returns {Array}
*/
getPropertyValues() {
return this._propertyValues;
}
/**
* @returns {EdmAnnotation[]}
*/
getAnnotations() {
if (this._annotations) {
return this._annotations;
}
this._annotations = [];
for (let item of this._record.annotations) {
this._annotations.push(AnnotationFactory.createAnnotation(this._edm, item));
}
return this._annotations;
}
}
module.exports = EdmRecordExpression;