Warning, /firebird/firebird-ng/src/app/model/entry-component.ts is written in an unsupported language. File is not indexed.
0001 /**
0002 * The EntryComponent class is an abstract base class for all entry components.
0003 */
0004 export abstract class EntryComponent {
0005
0006 /**
0007 * The name of the component, intended to be a unique identifier in UI menus and such.
0008 */
0009 name: string;
0010
0011 /**
0012 * The type of the component, used to identify the component class
0013 * and facilitate deserialization and factory lookup.
0014 */
0015 type: string;
0016
0017 /**
0018 * An optional string indicating the origin type of the component,
0019 * such as the original EDM4EIC/EDM4HEP/C++ data type from which it was derived.
0020 */
0021 originType?: string;
0022
0023 /**
0024 * The constructor is protected to prevent direct instantiation of the abstract class.
0025 * Only derived classes can call this constructor when they implement their own constructors.
0026 *
0027 * @param name - The name of the component.
0028 * @param type - The type of the component.
0029 * @param originType - Optional origin type of the component.
0030 */
0031 protected constructor(name: string, type: string, originType?: string) {
0032 this.name = name;
0033 this.type = type;
0034 this.originType = originType;
0035 }
0036
0037 /**
0038 * Abstract method that must be implemented by derived classes.
0039 * This method should serialize the component instance into a JSON-compatible object
0040 * following the Data Exchange format (DexObject).
0041 *
0042 * @returns A JSON-compatible object representing the serialized component.
0043 */
0044 abstract toDexObject(): any;
0045 }
0046
0047 /**
0048 * The EntryComponentFactory interface defines the structure for factory classes
0049 * that are responsible for creating instances of EntryComponent subclasses.
0050 */
0051 export interface EntryComponentFactory {
0052
0053 /**
0054 * The type of the component that this factory creates.
0055 * This should match the `type` property of the components it creates.
0056 */
0057 type: string;
0058
0059 /**
0060 * Method to create an instance of an EntryComponent subclass from a deserialized object.
0061 * The method takes a generic object (typically parsed from JSON) and returns an instance
0062 * of the corresponding EntryComponent subclass.
0063 *
0064 * @param obj - The deserialized object from which to create the component.
0065 * @returns An instance of an EntryComponent subclass.
0066 */
0067 fromDexObject(obj: any): EntryComponent;
0068 }
0069
0070 /**
0071 * The componentRegistry is a mapping from component type strings to their corresponding factories.
0072 * It is used to look up the appropriate factory when deserializing components from JSON data.
0073 * This registry enables the system to support multiple component types dynamically.
0074 */
0075 const componentRegistry: { [type: string]: EntryComponentFactory } = {};
0076
0077 /**
0078 * Registers a new component factory in the registry.
0079 * This allows the factory to be used during deserialization to create instances
0080 * of the component it represents.
0081 *
0082 * @param factory - The factory to register.
0083 */
0084 export function registerComponentFactory(factory: EntryComponentFactory): void {
0085 componentRegistry[factory.type] = factory;
0086 }
0087
0088 /**
0089 * Retrieves a component factory from the registry based on the component type.
0090 *
0091 * @param type - The type of the component.
0092 * @returns The corresponding EntryComponentFactory, or undefined if not found.
0093 */
0094 export function getComponentFactory(type: string): EntryComponentFactory | undefined {
0095 return componentRegistry[type];
0096 }
0097
0098 /**
0099 * Resets the component registry.
0100 * This function is intended for internal use during testing.
0101 *
0102 * @internal
0103 */
0104 export function _resetComponentRegistry(): void {
0105 for (const key in componentRegistry) {
0106 delete componentRegistry[key];
0107 }
0108 }