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=========================================================
20 package org.openecomp.mso.cloud;
23 import java.util.concurrent.ConcurrentHashMap;
25 import org.openecomp.mso.openstack.utils.MsoTenantUtils;
28 public abstract class IdentityServerTypeAbstract {
30 // This map will prevent duplicates (as if it was an Enum).
31 // Without this, using an instance specific field for the class could allow
32 // different classes bound to the same entry name.
33 private static final Map<String, IdentityServerTypeAbstract> entries = new ConcurrentHashMap<>();
35 private String serverType;
37 private Class<? extends MsoTenantUtils> utilsClass;
39 protected IdentityServerTypeAbstract(String serverType, Class<? extends MsoTenantUtils> utilsClass) {
40 if ((serverType == null) || (serverType.isEmpty())) {
41 throw new IllegalArgumentException("Server Type name cannot be null or empty, provided value was " + serverType);
43 if (entries.containsKey(serverType)) {
44 throw new IllegalArgumentException("Duplicate Server Type entry for registration: " + serverType);
46 this.serverType = serverType;
47 this.utilsClass = utilsClass;
48 entries.put(serverType, this);
51 public static final IdentityServerTypeAbstract valueOf(String serverType) {
52 return entries.get(serverType);
56 public final String toString() {
57 return this.serverType;
60 public final String name() {
61 return this.serverType;
64 public static final IdentityServerTypeAbstract[] values() {
65 return (IdentityServerTypeAbstract[]) entries.values().stream().toArray(IdentityServerTypeAbstract[]::new);
68 public final Class<? extends MsoTenantUtils> getMsoTenantUtilsClass() {
69 return this.utilsClass;
73 public final boolean equals(Object other) {
74 return ((this.serverType != null) && (other != null) && (other instanceof IdentityServerTypeAbstract) && (this.serverType.equals(other.toString())));