d2658bcd2330d5d43f5d176222dd73f31cbaca4d
[so.git] / adapters / mso-adapter-utils / src / main / java / org / openecomp / mso / cloud / IdentityServerTypeAbstract.java
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * OPENECOMP - MSO\r
4  * ================================================================================\r
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
6  * ================================================================================\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  *\r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  *\r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  * ============LICENSE_END=========================================================\r
19  */\r
20 package org.openecomp.mso.cloud;\r
21 \r
22 import java.util.Map;\r
23 import java.util.concurrent.ConcurrentHashMap;\r
24 \r
25 import org.openecomp.mso.openstack.utils.MsoTenantUtils;\r
26 \r
27 \r
28 public abstract class IdentityServerTypeAbstract {\r
29 \r
30         // This map will prevent duplicates (as if it was an Enum).\r
31         // Without this, using an instance specific field for the class could allow\r
32         // different classes bound to the same entry name.\r
33         private static final Map<String, IdentityServerTypeAbstract> entries = new ConcurrentHashMap<>();\r
34 \r
35         private String serverType;\r
36 \r
37         private Class<? extends MsoTenantUtils> utilsClass;\r
38 \r
39         protected IdentityServerTypeAbstract(String serverType, Class<? extends MsoTenantUtils> utilsClass) {\r
40                 if ((serverType == null) || (serverType.isEmpty())) {\r
41                         throw new IllegalArgumentException("Server Type name cannot be null or empty, provided value was " + serverType);\r
42                 }\r
43                 if (entries.containsKey(serverType)) {\r
44                         throw new IllegalArgumentException("Duplicate Server Type entry for registration: " + serverType);\r
45                 }\r
46                 this.serverType = serverType;\r
47                 this.utilsClass = utilsClass;\r
48                 entries.put(serverType, this);\r
49         }\r
50 \r
51         public static final IdentityServerTypeAbstract valueOf(String serverType) {\r
52                 return entries.get(serverType);\r
53         }\r
54 \r
55         @Override\r
56         public final String toString() {\r
57                 return this.serverType;\r
58         }\r
59 \r
60         public final String name() {\r
61                 return this.serverType;\r
62         }\r
63 \r
64         public static final IdentityServerTypeAbstract[] values() {\r
65                 return (IdentityServerTypeAbstract[]) entries.values().stream().toArray(IdentityServerTypeAbstract[]::new);\r
66         }\r
67 \r
68         public final Class<? extends MsoTenantUtils> getMsoTenantUtilsClass() {\r
69                 return this.utilsClass;\r
70         }\r
71 \r
72         @Override\r
73         public final boolean equals(Object other) {\r
74                 return ((this.serverType != null) && (other != null) && (other instanceof IdentityServerTypeAbstract) && (this.serverType.equals(other.toString())));\r
75         }\r
76 \r
77 }\r