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