001/* 002 * CDDL HEADER START 003 * 004 * The contents of this file are subject to the terms of the 005 * Common Development and Distribution License, Version 1.0 only 006 * (the "License"). You may not use this file except in compliance 007 * with the License. 008 * 009 * You can obtain a copy of the license at 010 * docs/licenses/cddl.txt 011 * or http://www.opensource.org/licenses/cddl1.php. 012 * See the License for the specific language governing permissions 013 * and limitations under the License. 014 * 015 * When distributing Covered Code, include this CDDL HEADER in each 016 * file and include the License file at 017 * docs/licenses/cddl.txt. If applicable, 018 * add the following below this CDDL HEADER, with the fields enclosed 019 * by brackets "[]" replaced with your own identifying information: 020 * Portions Copyright [yyyy] [name of copyright owner] 021 * 022 * CDDL HEADER END 023 * 024 * 025 * Copyright 2010-2021 Ping Identity Corporation 026 */ 027package com.unboundid.directory.sdk.common.types; 028 029 030 031import com.unboundid.util.StaticUtils; 032 033 034 035/** 036 * This enumeration defines the severities that may be used for alert types. 037 */ 038public enum AlertSeverity 039{ 040 /** 041 * Indicates that the associated alert type is used for informational 042 * messages. 043 */ 044 INFO("info"), 045 046 047 048 /** 049 * Indicates that the associated alert type is used for warning messages. 050 */ 051 WARNING("warning"), 052 053 054 055 /** 056 * Indicates that the associated alert type is used for error messages. 057 */ 058 ERROR("error"), 059 060 061 062 /** 063 * Indicates that the associated alert type is used for fatal alerts that 064 * cause the server to shut down or lose significant functionality. 065 */ 066 FATAL("fatal"); 067 068 069 070 // The name for this alert severity. 071 private final String name; 072 073 074 075 /** 076 * Creates a new alert severity with the specified name. 077 * 078 * @param name The name for this alert severity. 079 */ 080 AlertSeverity(final String name) 081 { 082 this.name = name; 083 } 084 085 086 087 /** 088 * Retrieves the name of this alert severity. 089 * 090 * @return The name of this alert severity. 091 */ 092 public String getName() 093 { 094 return name; 095 } 096 097 098 099 /** 100 * Retrieves the alert severity with the specified name. 101 * 102 * @param name The name of the alert severity to retrieve. 103 * 104 * @return The requested alert severity, or {@code null} if there is no such 105 * severity. 106 */ 107 public static AlertSeverity forName(final String name) 108 { 109 final String lowerName = StaticUtils.toLowerCase(name); 110 111 if (lowerName.equals("info")) 112 { 113 return INFO; 114 } 115 else if (lowerName.equals("warning")) 116 { 117 return WARNING; 118 } 119 else if (lowerName.equals("error")) 120 { 121 return ERROR; 122 } 123 else if (lowerName.equals("fatal")) 124 { 125 return FATAL; 126 } 127 128 return null; 129 } 130}