import { MetaElement } from '../../metaElement'; import { State } from '../state'; import { Method } from '../../method'; import { ITransitionJSON } from './iTransitionJSON'; import { ITransitionModelFormat } from './iTransitionModelFormat'; /** * A `Transition` is a [[MetaElement]] representing a transition in a [[FSM]]. * * Transitions are **mutable** * * @specfield origin ([[State]]) : origin state for the transition * @specfield destination ([[State]]): destination state for the transition * @specfield method ([[Method]]) : method that triggers the transition * @specfield guard (string) : OCL rule specifying a guard for the transition (i.e. condition to be met for the transition to successfully execute) */ export class Transition extends MetaElement { //================================ Representation ================================ private originState : State; private destinationState: State; private triggeringMethod: Method; private oclGuard : string; //================================= Constructor ================================== /** * Creates a new Transition t so that: * * t.name = triggeringMethod.name && * * t.origin = origin && * * t.destination = destination && * * t.guard = oclGuard * @param origin [[State]] of origin * @param destination [[State]] of destination * @param triggeringMethod [[Method]] triggering the transition * @param oclGuard Guard to be checked before executing the transition */ public constructor(origin: State, destination: State, triggeringMethod: Method, oclGuard: string = "") { super(triggeringMethod.getName()); this.originState = origin; this.destinationState = destination; this.triggeringMethod = triggeringMethod; this.oclGuard = oclGuard; } //=================================== Getters ==================================== /** * @willreturn this.origin */ public getOrigin(): State { return this.originState; } /** * @willreturn this.destination */ public getDestination(): State { return this.destinationState; } /** * @willreturn this.method */ public getMethod(): Method { return this.triggeringMethod; } /** * @willreturn this.guard */ public getOCLGuard(): string { return this.oclGuard; } //================================== Overriding ================================== public toJSON(): ITransitionJSON { return { id : this.getId(), name : this.getName(), origin : this.originState.toJSON(), destination: this.destinationState.toJSON(), method : this.triggeringMethod.toJSON(), guard : this.oclGuard }; } public toModelFormat(): ITransitionModelFormat { return { id : this.getId(), name : this.getName(), origin : this.getOrigin().getId(), destination: this.getDestination().getId(), method : this.getMethod().getId(), guard : this.oclGuard }; } }