2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.translator.services.heattotosca;
24 import org.openecomp.config.api.Configuration;
25 import org.openecomp.config.api.ConfigurationManager;
26 import org.openecomp.core.utilities.CommonMethods;
27 import org.openecomp.sdc.datatypes.configuration.ImplementationConfiguration;
28 import org.openecomp.sdc.heat.datatypes.model.Resource;
29 import org.openecomp.sdc.translator.services.heattotosca.impl.resourcetranslation.ResourceTranslationBase;
34 public class ResourceTranslationFactory {
35 private static Map<String, ImplementationConfiguration> resourceTranslationImplMap;
38 Configuration config = ConfigurationManager.lookup();
39 resourceTranslationImplMap = config.populateMap(ConfigConstants.TRANSLATOR_NAMESPACE,
40 ConfigConstants.RESOURCE_TRANSLATION_IMPL_KEY, ImplementationConfiguration.class);
41 resourceTranslationImplMap.putAll(config.populateMap(ConfigConstants.MANDATORY_TRANSLATOR_NAMESPACE,
42 ConfigConstants.RESOURCE_TRANSLATION_IMPL_KEY, ImplementationConfiguration.class));
46 * Gets resource translation instance.
48 * @param resource the resource
49 * @return the instance
51 public static ResourceTranslationBase getInstance(Resource resource) {
52 if (isSupportedResource(resource.getType())) {
53 return getResourceTranslationImpl(resource.getType());
54 } else if (HeatToToscaUtil.isYmlFileType(resource.getType())) {
55 return getResourceTranslationImpl(ConfigConstants.NESTED_RESOURCE_TRANSLATION_IMPL_KEY);
57 return getResourceTranslationImpl(ConfigConstants.DEFAULT_RESOURCE_TRANSLATION_IMPL_KEY);
60 private static ResourceTranslationBase getResourceTranslationImpl(String resourceImplKey) {
61 String resourceTranslationImplClassName = resourceTranslationImplMap
62 .get(resourceImplKey).getImplementationClass();
64 .newInstance(resourceTranslationImplClassName, ResourceTranslationBase.class);
67 private static boolean isSupportedResource(String resourceType) {
68 if (resourceTranslationImplMap.containsKey(resourceType)
69 && resourceTranslationImplMap.get(resourceType).isEnable()) {