2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2019 European Software Marketing Ltd.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 package org.onap.aai.babel.xml.generator.data;
23 import java.util.Collections;
24 import java.util.HashMap;
25 import java.util.List;
27 import java.util.Map.Entry;
28 import java.util.Properties;
29 import org.onap.aai.babel.xml.generator.model.Model;
31 public class WidgetConfigurationUtil {
33 private static Properties config;
34 private static List<String> instanceGroups = Collections.emptyList();
35 private static Map<String, Class<? extends Model>> typeToModel = new HashMap<>();
38 * Private constructor to prevent instantiation
40 private WidgetConfigurationUtil() {
41 throw new UnsupportedOperationException("This static class should not be instantiated!");
44 public static Properties getConfig() {
48 public static void setConfig(Properties config) {
49 WidgetConfigurationUtil.config = config;
52 public static void setSupportedInstanceGroups(List<String> supportedInstanceGroups) {
53 instanceGroups = supportedInstanceGroups;
56 public static boolean isSupportedInstanceGroup(String groupType) {
57 return instanceGroups.contains(groupType);
61 * Create the mappings from TOSCA type to Widget type. The Properties store a set of TOSCA type prefix Strings.
62 * These keys take a single class name (String), which is used to map to a Widget Class in the Model.
65 * the key/value pairs of TOSCA type and Class name
67 @SuppressWarnings("unchecked")
68 public static void setTypeMappings(Map<String, String> map) {
69 for (Entry<String, String> entry : map.entrySet()) {
70 final String toscaType = entry.getKey();
71 final String javaBean = entry.getValue();
72 final String modelClassName = Model.class.getPackage().getName() + "." + javaBean;
74 typeToModel.put(toscaType, (Class<? extends Model>) Class.forName(modelClassName));
75 } catch (ClassNotFoundException e) {
76 throw new IllegalArgumentException(
77 String.format("Unsupported type \"%s\" for TOSCA mapping %s: no class found for %s", //
78 javaBean, toscaType, modelClassName));
83 public static Class<? extends Model> getModelFromType(String typePrefix) {
84 return typeToModel.get(typePrefix);