2cab6aebd95c8281ef2d7f8e3a73ad2f32eaac3e
[aai/babel.git] / src / main / java / org / onap / aai / babel / xml / generator / model / WidgetType.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved.
6  * Copyright (c) 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
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  */
21
22 package org.onap.aai.babel.xml.generator.model;
23
24 import java.util.Arrays;
25 import java.util.LinkedHashMap;
26 import java.util.List;
27 import java.util.Map;
28
29 /**
30  * Widget Type Enumeration.
31  *
32  */
33 public class WidgetType {
34
35     /**
36      * Dynamically created set of Widget Types.
37      */
38     private static Map<String, WidgetType> elements = new LinkedHashMap<>();
39
40     /**
41      * Types that must be present for Model generation to function correctly.
42      */
43     private static final List<String> mandatoryElements = Arrays.asList( //
44             "SERVICE", "VF", "VFC", "VSERVER", "VOLUME", "FLAVOR", "TENANT", "VOLUME_GROUP", "LINT", "L3_NET",
45             "VFMODULE", "IMAGE", "OAM_NETWORK", "ALLOTTED_RESOURCE", "TUNNEL_XCONNECT", "CONFIGURATION", "CR",
46             "INSTANCE_GROUP");
47
48     private final String name;
49
50     public WidgetType(String name) {
51         this.name = name;
52         elements.put(name, this);
53     }
54
55     public static void validateElements() {
56         mandatoryElements.forEach(WidgetType::valueOf);
57     }
58
59     public static WidgetType valueOf(String typeName) {
60         WidgetType type = elements.get(typeName);
61         if (type == null) {
62             throw new IllegalArgumentException("Unknown type " + typeName);
63         }
64         return type;
65     }
66
67     @Override
68     public String toString() {
69         return name;
70     }
71
72 }
73