2 * Copyright © 2016-2018 European Support Limited
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.openecomp.sdc.translator.services.heattotosca;
19 import org.onap.config.api.Configuration;
20 import org.onap.config.api.ConfigurationManager;
21 import org.openecomp.core.utilities.CommonMethods;
22 import org.openecomp.sdc.datatypes.configuration.ImplementationConfiguration;
25 import java.util.Optional;
27 public class FunctionTranslationFactory {
28 private static final Map<String, ImplementationConfiguration> functionTranslationImplMap;
31 Configuration config = ConfigurationManager.lookup();
32 functionTranslationImplMap = config.populateMap(ConfigConstants.TRANSLATOR_NAMESPACE,
33 ConfigConstants.FUNCTION_TRANSLATION_IMPL_KEY, ImplementationConfiguration.class);
34 functionTranslationImplMap.putAll(config.populateMap(ConfigConstants.MANDATORY_TRANSLATOR_NAMESPACE,
35 ConfigConstants.FUNCTION_TRANSLATION_IMPL_KEY, ImplementationConfiguration.class));
40 * Gets function translation instance.
42 * @param heatFunctionKey heat function key
43 * @return the instance
45 public static Optional<FunctionTranslation> getInstance(String heatFunctionKey) {
46 if (isSupportedFunction(heatFunctionKey)) {
47 String functionTranslationImplClassName =
48 functionTranslationImplMap.get(heatFunctionKey).getImplementationClass();
49 return Optional.of(CommonMethods
50 .newInstance(functionTranslationImplClassName, FunctionTranslation.class));
52 return Optional.empty();
55 private static boolean isSupportedFunction(String heatFunctionKey) {
56 return functionTranslationImplMap.containsKey(heatFunctionKey);