import { AttributeType, AttributeValueType } from './attributeType'; import { IDerivedOCLAttributeTypeJSON } from './iDerivedOCLAttributeTypeJSON'; import { IDerivedOCLAttributeTypeModelFormat } from './iDerivedOCLAttributeTypeModelFormat'; import { IAttributeTypeModelFormat } from '.'; /** * A `DerivedOCLAttributeType` is an [[AttributeType]] whose value is determined by an OCL rule. * * DerivedOCLAttributeTypes are **mutable** * * @specfield oclRule (string): OCL rule determining the value of the attributeType. */ export class DerivedOCLAttributeType extends AttributeType { //================================ Representation ================================ private oclRule: string; //================================= Constructor ================================== /** * Returns a new DerivedOCLAttributeType doat so that: * * doat.name = name * * doat.valueType = valueType * * doat.oclRule = oclRule * * doat.optional = optional * @param name Name of the attribute type * @param valueType Type of value held in the attribute * @param oclRule OCL Rule determining the value of the attribute * @param optional Defines whether or not the attribute is optional */ public constructor(name: string, valueType: AttributeValueType, oclRule: string, optional: boolean = false) { super(name, valueType, optional); this.oclRule = oclRule; } //=================================== Getters ==================================== /** * @willreturn this.oclRule */ public getOCLRule(): string { return this.oclRule; } //================================== Overriding ================================== public isValid(): boolean { if(this.oclRule == '') return false; return super.isValid(); } public toJSON(): IDerivedOCLAttributeTypeJSON { return { id : super.getId(), name : super.getName(), valueType: super.getValueType(), optional : super.isOptional(), oclRule : this.getOCLRule() }; } public toModelFormat(): IDerivedOCLAttributeTypeModelFormat { return { type : 'DERIVED_OCL', id : super.getId(), name : super.getName(), valueType: super.getValueType(), optional : super.isOptional(), oclRule : this.getOCLRule() }; } };