import { MetaElement } from '../metaElement'; import { IAttributeTypeJSON } from './iAttributeTypeJSON'; import { IAttributeTypeModelFormat } from './iAttributeTypeModelFormat'; /** * Defines the different types of values that can be held in an attribute */ export enum AttributeValueType { String = 'string', Boolean = 'boolean', Number = 'number' } /** * An `AttributeType` represents a type of attribute. They can be added to [[BusinessObjectType]]s and be used as parameters for [[Method]]s. * Every AttributeType is a [[MetaElement]]. * * AttributeTypes are **mutable** * * @specfield valueType ([[AttributeValueType]]): type of value held in the attribute * @specfield optional (boolean) : determines whether or not the attribute is optional */ export class AttributeType extends MetaElement { //================================ Representation ================================ private optional : boolean; private valueType: AttributeValueType; //================================= Constructor ================================== /** * Creates a new `AttributeType` at so that: * * at.name = attributeName * * at.valueType = valueType * * at.optional = optional * * @param attributeName Name of the type of attribute * @param valueType Type of value held in the attribute * @param optional Defines whether or not a value must be provided for the attribute */ public constructor(attributeName: string, valueType: AttributeValueType, optional: boolean = false) { super(attributeName); this.valueType = valueType; this.optional = optional; } //=================================== Getters ==================================== /** * @willreturn this.valueType */ public getValueType(): AttributeValueType { return this.valueType; } /** * @willreturn this.optional */ public isOptional(): boolean { return this.optional; } //================================== Overriding ================================== public isValid(): boolean { if(this.getName() == '') return false; return true; } public toJSON(): IAttributeTypeJSON { return { id : super.getId(), name : super.getName(), valueType: this.getValueType(), optional : this.isOptional() }; } public toModelFormat(): IAttributeTypeModelFormat { return { type : 'BASE', id : super.getId(), name : super.getName(), valueType: this.getValueType(), optional : this.isOptional() } } };