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 2007-2009 Sun Microsystems, Inc.
015 * Portions Copyright 2011-2015 ForgeRock AS.
016 */
017
018package org.opends.messages;
019
020import java.util.Map;
021import java.util.HashMap;
022import java.util.EnumSet;
023
024/**
025 * Defines values for message categories which are loosly based on
026 * server components.  Categories contain an in value that can be
027 * used as a mask for bitwise operations.
028 */
029@org.opends.server.types.PublicAPI(
030    stability=org.opends.server.types.StabilityLevel.UNCOMMITTED,
031    mayInstantiate=false,
032    mayExtend=false,
033    mayInvoke=true)
034public enum Category {
035
036  /**
037   * The category that will be used for messages associated with the
038   * core server.
039   */
040  CORE(0x00000000),
041
042  /**
043   * The category that will be used for messages associated with server
044   * extensions (e.g., extended operations, SASL mechanisms, password storage
045   * schemes, password validators, etc.).
046   */
047  EXTENSIONS(0x00100000),
048
049  /**
050   * The category that will be used for messages associated with
051   * connection and protocol handling (e.g., ASN.1 and LDAP).
052   */
053  PROTOCOL(0x00200000),
054
055  /**
056   * The category that will be used for messages associated with
057   * configuration handling.
058   */
059  CONFIG(0x00300000),
060
061  /**
062   * The category that will be used for messages associated with the
063   * server loggers.
064   */
065  LOG(0x00400000),
066
067  /**
068   * The category that will be used for messages associated with the
069   * general server utilities.
070   */
071  UTIL(0x00500000),
072
073  /**
074   * The category that will be used for messages associated with the
075   * server schema elements.
076   */
077  SCHEMA(0x00600000),
078
079  /**
080   * The category that will be used for messages associated with plugin
081   * processing.
082   */
083  PLUGIN(0x00700000),
084
085  /**
086   * The category used for messages associated with the JE backend.
087   */
088  JEB(0x00800000),
089
090  /**
091   * The category used for messages associated with generic backends.
092   */
093  BACKEND(0x00900000),
094
095  /**
096   * The category used for messages associated with tools.
097   */
098  TOOLS(0x00A00000),
099
100  /**
101   * The category used for messages associated with tasks.
102   */
103  TASK(0x00B00000),
104
105  /**
106   * The category used for messages associated with Access Control.
107   */
108  ACCESS_CONTROL(0x00C00000),
109
110  /**
111   * The category used for messages associated with the
112   * administration framework.
113   */
114  ADMIN(0x00D00000),
115
116  /**
117   * The category used for messages associated with the Synchronization.
118   */
119  SYNC(0x00E00000),
120
121  /**
122   * The category used for messages associated with version information.
123   */
124  VERSION(0x00F00000),
125
126  /**
127   * The category used for messages associated with quicksetup tools.
128   */
129  QUICKSETUP(0x01000000),
130
131  /**
132   * The category used for messages associated with the tool like the
133   * offline installer and unintaller.
134   */
135  ADMIN_TOOL(0x01100000),
136
137  /**
138   * The category used for messages associated with the dsconfig
139   * administration tool.
140   */
141  DSCONFIG(0x01200000),
142
143  /**
144   * The category used for messages associated with the runtime information.
145   */
146
147  RUNTIME_INFORMATION(0x01300000),
148
149  /**
150   * The category used for messages associated with the Servicetag registration.
151   * No longer used.
152   * SERVICETAG(0x01400000),
153   */
154
155  /**
156   * The category that will be used for messages associated with
157   * third-party (including user-defined) modules.
158   */
159  THIRD_PARTY(0x40000000),
160
161  /**
162   * The category that will be used for messages associated with
163   * user-defined modules.
164   */
165  USER_DEFINED(0x7FF00000);
166
167  private static Map<Integer,Category> MASK_VALUE_MAP;
168
169  static {
170    MASK_VALUE_MAP = new HashMap<>();
171    for (Category c : EnumSet.allOf(Category.class)) {
172      MASK_VALUE_MAP.put(c.mask, c);
173    }
174  }
175
176  /**
177   * Obtains the <code>Severity</code> associated with the the input
178   * message ID <code>msgId</code>.
179   * @param msgId int message ID
180   * @return Severity associated with the ID
181   */
182  public static Category parseMessageId(int msgId) {
183    return Category.parseMask(msgId & 0xFFF00000);
184  }
185
186  /**
187   * Obtains the <code>Severity</code> associated with a given mask
188   * value.
189   * @param mask for which a <code>Severity</code> is obtained.
190   * @return Severity associated with <code>mask</code>
191   */
192  public static Category parseMask(int mask) {
193    return MASK_VALUE_MAP.get(mask);
194  }
195
196  private final int mask;
197
198  /**
199   * Gets the mask value associated with this category.
200   * @return int mask value
201   */
202  public int getMask() {
203    return this.mask;
204  }
205
206  private Category(int intValue) {
207    this.mask = intValue;
208  }
209
210}