UNPKG

@p2olab/pimad-core

Version:

PiMAd (Process-industry-Modular-Automation-description) High level access to automation of modular plants.

160 lines (159 loc) 5.59 kB
/** * The namespace Backbone provides the classes in PiMAd-core with various elementary functionalities. The * {@link PiMAdResponse} interface serves as an exchange format between individual classes or even between PiMAd and * docking software. * <uml> abstract class AResponse { #content: object #msg: string -initialized: boolean = false } abstract class AResponseFactory class PiMAdResponseVendor { -dummyResponseFactory: PiMAdResponseFactory -errorResponseFactory: PiMAdResponseFactory -successResponseFactory: PiMAdResponseFactory -warningResponseFactory: PiMAdResponseFactory +buyDummyResponse(): PiMAdResponse +buyErrorResponse(): PiMAdResponse +buySuccessResponse(): PiMAdResponse +buyWarningResponse(): PiMAdResponse } class PiMAdResponseHandler { -responseVendor: ResponseVendor +handleCallbackWithResponse(type: ResponseTypes, message: string, content: object, callback: (response: PiMAdResponse) => void): void } enum PiMAdResponseTypes { DUMMY ERROR SUCCESS WARNING } interface PiMAdResponse { +getMessage(): string +getContent(): object +initialize(message: string, content: object): boolean } interface PiMAdResponseFactory { +create(): PiMAdResponse } PiMAdResponse <|.. AResponse PiMAdResponse <-- PiMAdResponseFactory PiMAdResponse <-- PiMAdResponseVendor PiMAdResponseFactory <|.. AResponseFactory AResponse <|-- DummyResponse AResponse <|-- ErrorResponse AResponse <|-- SuccessResponse AResponse <|-- WarningResponse AResponseFactory <|-- DummyResponseFactory AResponseFactory <|-- ErrorResponseFactory AResponseFactory <|-- SuccessResponseFactory AResponseFactory <|-- WarningResponseFactory PiMAdResponseHandler "1" o-- "1" PiMAdResponseVendor PiMAdResponseVendor "1" o-- "1..*" PiMAdResponseFactory </uml> */ export declare namespace Backbone { /** * In PiMAd, PiMAdResponses serve the standardized exchange of responses between different classes. The executing * class reports the status of the response directly to the calling class using different response types. */ interface PiMAdResponse { /** * Get the message of the response. */ getMessage(): string; /** * Get the content of the response. */ getContent(): object; /** * Initialize the new response object. * @param message - The message serves as a further explanation of the response. * @param content - Data or information to be exchanged using the response. */ initialize(message: string, content: object): boolean; } /** * This Factory creates Instances of {@link PiMAdResponse}. */ interface PiMAdResponseFactory { /** * Create an Instances of {@link PiMAdResponse}. */ create(): PiMAdResponse; } /** * This vendor sells various {@link PiMAdResponse}-Instances. */ class PiMAdResponseVendor { private dummyResponseFactory; private errorResponseFactory; private successResponseFactory; private warningResponseFactory; constructor(); /** * Buy a {@link DummyResponse} as {@link PiMAdResponse}. */ buyDummyResponse(): PiMAdResponse; /** * Buy an {@link ErrorResponse} as {@link PiMAdResponse}. */ buyErrorResponse(): PiMAdResponse; /** * Buy a {@link SuccessResponse} as {@link PiMAdResponse}. */ buySuccessResponse(): PiMAdResponse; /** * Buy a {@link WarningResponse} as {@link PiMAdResponse}. */ buyWarningResponse(): PiMAdResponse; } /** * This enum referencing to all implementations of {@link PiMAdResponse}. */ enum PiMAdResponseTypes { /** * Referencing a {@link DummyResponse}. */ DUMMY = 0, /** * Referencing an {@link ErrorResponse}. */ ERROR = 1, /** * Referencing a {@link SuccessResponse}. */ SUCCESS = 2, /** * Referencing a {@link WarningResponse}. */ WARNING = 3 } /** * This class generalizes the handling of objects of the response interface and thus reduces the repeated * occurrence of certain code fragments. */ class PiMAdResponseHandler { private responseVendor; constructor(); /** * This method creates the desired {@link PiMAdResponse}-Instance, initializes it with the given data and finally calls the * callback function. * @param type - The type of the response. * @param message - The message of the response. * @param content - The content of the response. * @param callback - The callback function that expects a {@link PiMAdResponse}-Instance as input. */ handleCallbackWithResponse(type: PiMAdResponseTypes, message: string, content: object, callback: (response: PiMAdResponse) => void): void; /** * This method creates the desired {@link PiMAdResponse}-Instance, initializes it with the given data and * returns the instance. * @param type - The type of the response. * @param message - The message of the response. * @param content - The content of the response. */ handleResponse(type: PiMAdResponseTypes, message: string, content: object): PiMAdResponse; } }