push addional code
[sdc.git] / openecomp-be / lib / openecomp-core-lib / openecomp-facade-lib / openecomp-facade-core / src / main / java / org / openecomp / core / factory / FactoriesConfigImpl.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.core.factory;
22
23
24 import org.openecomp.core.factory.api.FactoriesConfiguration;
25 import org.openecomp.core.utilities.file.FileUtils;
26 import org.openecomp.core.utilities.json.JsonUtil;
27
28 import java.io.InputStream;
29 import java.util.HashMap;
30 import java.util.List;
31 import java.util.Map;
32
33 public final class FactoriesConfigImpl implements FactoriesConfiguration {
34
35
36   private static final String FACTORY_CONFIG_FILE_NAME = "factoryConfiguration.json";
37   private static Map factoryMap = new HashMap();
38   private static boolean initialized = false;
39
40   @SuppressWarnings("unchecked")
41   @Override
42   public Map<String, String> getFactoriesMap() {
43     synchronized (this) {
44       if (!initialized) {
45         init();
46         initialized = true;
47       }
48     }
49     return factoryMap;
50   }
51
52   private void init() {
53     List<InputStream> factoryConfigIsList = FileUtils.getFileInputStreams(FACTORY_CONFIG_FILE_NAME);
54     for (InputStream factoryConfigIs : factoryConfigIsList) {
55       factoryMap.putAll(JsonUtil.json2Object(factoryConfigIs, Map.class));
56     }
57   }
58
59
60 }
61