UNPKG

@p2olab/pimad-core

Version:

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

89 lines (88 loc) 3.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ServiceVendor = exports.Services = exports.BaseServiceFactory = void 0; const Utils_1 = require("../Utils"); const ProcedureModel_1 = require("./ProcedureModel"); class AService extends ProcedureModel_1.AProcedure { constructor() { super(); this.procedures = []; } /** * @inheritDoc {@link ServiceModel.getAllProcedures} */ getAllProcedures(callback) { this.genericPiMAdGetter(this.procedures, callback); } /** * @inheritDoc {@link ServiceModel.getProcedure} */ getProcedure(name, callback) { const localProcedure = this.procedures.find(procedure => { let testCondition = false; procedure.getName((response, procedureName) => { testCondition = name === procedureName; }); return testCondition; }); if (localProcedure === undefined) { this.genericPiMAdGetter({}, callback); } else { this.genericPiMAdGetter(localProcedure, callback); } } /** * @inheritDoc {@link ServiceModel.initialize} */ initialize(instructions) { if (!this.initialized) { this.attributes = instructions.attributes; this.dataAssembly = instructions.dataAssembly; this.parameters = instructions.parameter; this.procedures = instructions.procedure; this.initialized = (JSON.stringify(this.attributes) === JSON.stringify(instructions.attributes) && JSON.stringify(this.dataAssembly) === JSON.stringify(instructions.dataAssembly) && JSON.stringify(this.parameters) === JSON.stringify(instructions.parameter) && JSON.stringify(this.procedures) === JSON.stringify(instructions.procedure) && this.moduleAutomationObjectInitialize({ dataSourceIdentifier: instructions.dataSourceIdentifier, metaModelRef: instructions.metaModelRef, name: instructions.name, pimadIdentifier: instructions.pimadIdentifier })); return this.initialized; } else { return false; } } } class BaseService extends AService { } class AServiceFactory { } class BaseServiceFactory extends AServiceFactory { create() { const service = new BaseService(); Utils_1.logger.debug(this.constructor.name + ' creates a ' + service.constructor.name); return service; } } exports.BaseServiceFactory = BaseServiceFactory; var Services; (function (Services) { Services[Services["BaseService"] = 0] = "BaseService"; })(Services = exports.Services || (exports.Services = {})); class ServiceVendor { constructor() { this.baseServiceFactory = new BaseServiceFactory(); } buy(serviceType) { switch (serviceType) { case Services.BaseService: return this.baseServiceFactory.create(); } } } exports.ServiceVendor = ServiceVendor;