• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import Log from '../../default/Log';
17import SourceLoader, { LoaderChannel } from './SourceLoader';
18import DataAbilitySourceLoader from './DataAbilitySourceLoader';
19import MetaSourceLoader from './MetaSourceLoader';
20import PluginSourceLoader from './PluginSourceLoader';
21import { LoaderConfigInfo } from '../common/Constants';
22
23const TAG = 'SourceLoaderFactory';
24
25const classMap: { [key: string]: any } = {
26  MetaSource: MetaSourceLoader,
27  PluginSourceLoader: PluginSourceLoader,
28  DataAbilitySourceLoader: DataAbilitySourceLoader,
29};
30
31export default class SourceLoaderFactory {
32  mChannel: LoaderChannel;
33
34  constructor(channel: LoaderChannel) {
35    Log.showDebug(TAG, `constructor, channel: ${channel}`);
36    this.mChannel = channel;
37  }
38
39  getSourceLoader(pluginType: string, config: LoaderConfigInfo): null | SourceLoader {
40    let clz = classMap[pluginType];
41    if (!clz) {
42      Log.showError(TAG, `Can't find pluginType: ${pluginType}`);
43      return null;
44    }
45    let loader: SourceLoader = new clz(config);
46    loader.setChannel(this.mChannel);
47    return loader;
48  }
49}