import { AttributeType, AttributeValueType } from './attributeType'; import { IDerivedComplexAttributeTypeJSON } from './iDerivedComplexAttributeTypeJSON'; import { IDerivedComplexAttributeTypeModelFormat } from './iDerivedComplexAttributeTypeModelFormat'; /** * A `DerivedComplexAttributeType` is an [[AttributeType]] whose value is determined by an manually-provided implementation * * DerivedComplexAttributeTypes are **mutable** * * @specfield implementation (string): Implementation defining the value of the attribute */ export class DerivedComplexAttributeType extends AttributeType { //================================ Representation ================================ private implementation: string; //================================= Constructor ================================== /** * Returns a new DerivedComplexAttributeType doat so that: * * doat.name = name * * doat.valueType = valueType * * doat.implementation = implementation * * doat.optional = optional * @param name Name of the attribute type * @param valueType Type of value held in the attribute * @param implementation Implementation defining the value of the attribute * @param optional Defines whether or not the attribute is optional */ public constructor(name: string, valueType: AttributeValueType, implementation: string, optional: boolean = false) { super(name, valueType, optional); this.implementation = implementation; } //=================================== Getters ==================================== /** * @willreturn this.implementation */ public getImplementation(): string { return this.implementation; } //================================== Overriding ================================== public isValid(): boolean { if(this.implementation == '') return false; return super.isValid(); } public toJSON(): IDerivedComplexAttributeTypeJSON { return { id : super.getId(), name : super.getName(), valueType : super.getValueType(), optional : super.isOptional(), implementation: this.getImplementation() }; } public toModelFormat(): IDerivedComplexAttributeTypeModelFormat { return { type : 'DERIVED_COMPLEX', id : super.getId(), name : super.getName(), valueType : super.getValueType(), optional : super.isOptional(), implementation: this.getImplementation() } } };