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 legal-notices/CDDLv1_0.txt 010 * or http://forgerock.org/license/CDDLv1.0.html. 011 * See the License for the specific language governing permissions 012 * and limitations under the License. 013 * 014 * When distributing Covered Code, include this CDDL HEADER in each 015 * file and include the License file at legal-notices/CDDLv1_0.txt. 016 * If applicable, add the following below this CDDL HEADER, with the 017 * fields enclosed by brackets "[]" replaced with your own identifying 018 * information: 019 * Portions Copyright [yyyy] [name of copyright owner] 020 * 021 * CDDL HEADER END 022 * 023 * 024 * Copyright 2008 Sun Microsystems, Inc. 025 * Portions Copyright 2014-2015 ForgeRock AS 026 */ 027 028package org.opends.messages; 029 030import java.util.HashMap; 031import java.util.Map; 032import java.util.EnumSet; 033import java.util.Set; 034import java.util.HashSet; 035import java.util.Collections; 036 037/** 038 * Defines values for message severity. Severities contain an 039 * integer value that can be used for bitwise operations as well 040 * as a short abbreviated string form of each value. 041 */ 042@org.opends.server.types.PublicAPI( 043 stability=org.opends.server.types.StabilityLevel.UNCOMMITTED, 044 mayInstantiate=false, 045 mayExtend=false, 046 mayInvoke=true) 047public enum Severity { 048 049 /** 050 * The severity that will be used for informational messages. 051 */ 052 INFORMATION("INFO"), 053 054 /** 055 * The severity that will be used for warning messages. 056 */ 057 WARNING("WARN"), 058 059 /** 060 * The severity that will be used for warning messages. 061 */ 062 ERROR("ERR"), 063 064 /** 065 * The severity that will be used for debug messages. 066 */ 067 DEBUG("DEBUG"), 068 069 /** 070 * The severity that will be used for important informational 071 * messages. 072 */ 073 NOTICE("NOTE"); 074 075 private static Set<String> PROPERTY_KEY_FORM_VALUES_SET; 076 077 private static Map<String,Severity> PROPERTY_KEY_FORM_MAP; 078 079 static { 080 PROPERTY_KEY_FORM_MAP = new HashMap<>(); 081 PROPERTY_KEY_FORM_VALUES_SET = new HashSet<>(); 082 for (Severity s : EnumSet.allOf(Severity.class)) { 083 PROPERTY_KEY_FORM_MAP.put(s.propertyKeyFormName(), s); 084 PROPERTY_KEY_FORM_VALUES_SET.add(s.propertyKeyFormName()); 085 } 086 } 087 088 /** 089 * Returns a set of string representing all <code>Severitys'</code> 090 * abbreviated representations. 091 * @return set of messageDescriptorForm strings 092 */ 093 public static Set<String> getPropertyKeyFormSet() { 094 return Collections.unmodifiableSet(PROPERTY_KEY_FORM_VALUES_SET); 095 } 096 097 /** 098 * Returns the <code>Severity</code> associated with the input 099 * string <code>s</code> which can either be a severity's name 100 * or messageDescriptorForm. 101 * @param s Severity name or messageDescriptorForm 102 * @return Severity associated with <code>s</code> 103 */ 104 public static Severity parseString(String s) { 105 Severity sev = PROPERTY_KEY_FORM_MAP.get(s); 106 if (sev == null) { 107 sev = valueOf(s); 108 } 109 return sev; 110 } 111 112 private final String name; 113 114 /** 115 * Gets the abbreviated form of this <code>Severity</code>. 116 * @return String abbreviated form 117 */ 118 public String messageDesciptorName() { 119 return name; 120 } 121 122 /** 123 * Gets the name of this severity as it must appear in the 124 * property key name in a messages file. 125 * 126 * @return name of this severity 127 */ 128 public String propertyKeyFormName() { 129 return name; 130 } 131 132 private Severity(String propertyKeyForm) { 133 this.name = propertyKeyForm; 134 } 135 136}