2 * ============LICENSE_START=======================================================
\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
11 * http://www.apache.org/licenses/LICENSE-2.0
\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
20 package org.openecomp.mso.cloud;
\r
22 import java.util.Map;
\r
23 import java.util.concurrent.ConcurrentHashMap;
\r
25 import org.openecomp.mso.openstack.utils.MsoTenantUtils;
\r
28 public abstract class IdentityServerTypeAbstract {
\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
35 private String serverType;
\r
37 private Class<? extends MsoTenantUtils> utilsClass;
\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
43 if (entries.containsKey(serverType)) {
\r
44 throw new IllegalArgumentException("Duplicate Server Type entry for registration: " + serverType);
\r
46 this.serverType = serverType;
\r
47 this.utilsClass = utilsClass;
\r
48 entries.put(serverType, this);
\r
51 public static final IdentityServerTypeAbstract valueOf(String serverType) {
\r
52 return entries.get(serverType);
\r
56 public final String toString() {
\r
57 return this.serverType;
\r
60 public final String name() {
\r
61 return this.serverType;
\r
64 public static final IdentityServerTypeAbstract[] values() {
\r
65 return (IdentityServerTypeAbstract[]) entries.values().stream().toArray(IdentityServerTypeAbstract[]::new);
\r
68 public final Class<? extends MsoTenantUtils> getMsoTenantUtilsClass() {
\r
69 return this.utilsClass;
\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