• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2  * Copyright (c) 2023-2025 Huawei Device Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7    *
8  * http://www.apache.org/licenses/LICENSE-2.0
9    *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17export class GlobalContext {
18  private constructor() {
19  }
20
21  private static instance: GlobalContext;
22  private _objects = new Map<string, Object>();
23
24  public static getContext(): GlobalContext {
25    if (!GlobalContext.instance) {
26      GlobalContext.instance = new GlobalContext();
27    }
28    return GlobalContext.instance;
29  }
30
31  getValue(value: string): Object {
32    let result = this._objects.get(value);
33    if (!result) {
34      throw new Error("this value undefined");
35    }
36    return result;
37  }
38
39  setValue(key: string, objectClass: Object): void {
40    this._objects.set(key, objectClass);
41  }
42}