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 2006-2008 Sun Microsystems, Inc.
025 *      Portions Copyright 2014-2015 ForgeRock AS
026 */
027package org.opends.server.types;
028
029import static org.opends.server.util.StaticUtils.*;
030
031
032
033/**
034 * This class implements an enumeration that may be used to control
035 * the writability mode for the entire server or for a specific
036 * backend.  The writability mode may be "enabled", "disabled", or
037 * "internal-only".
038 */
039@org.opends.server.types.PublicAPI(
040     stability=org.opends.server.types.StabilityLevel.UNCOMMITTED,
041     mayInstantiate=false,
042     mayExtend=false,
043     mayInvoke=true)
044public enum WritabilityMode
045{
046  /**
047   * Indicates that all write operations should be allowed.
048   */
049  ENABLED("enabled"),
050
051
052
053  /**
054   * Indicates that all write operations should be rejected.
055   */
056  DISABLED("disabled"),
057
058
059
060  /**
061   * Indicates that write operations from clients will be rejected,
062   * but internal operations and updates through synchronization will
063   * be allowed.
064   */
065  INTERNAL_ONLY("internal-only");
066
067
068
069  /** The human-readable name for this writability mode. */
070  private String modeName;
071
072
073
074  /**
075   * Creates a new writability mode with the provided name.
076   *
077   * @param  modeName  The human-readable name for this writability
078   *                   mode.
079   */
080  private WritabilityMode(String modeName)
081  {
082    this.modeName = modeName;
083  }
084
085
086
087  /**
088   * Retrieves the writability mode for the specified name.
089   *
090   * @param  modeName  The name of the writability mode to retrieve.
091   *
092   * @return  The requested writability mode, or <CODE>null</CODE> if
093   *          the provided value is not the name of a valid mode.
094   */
095  public static WritabilityMode modeForName(String modeName)
096  {
097    String lowerName = toLowerCase(modeName);
098    if (lowerName.equals("enabled"))
099    {
100      return WritabilityMode.ENABLED;
101    }
102    else if (lowerName.equals("disabled"))
103    {
104      return WritabilityMode.DISABLED;
105    }
106    else if (lowerName.equals("internal-only"))
107    {
108      return WritabilityMode.INTERNAL_ONLY;
109    }
110    else
111    {
112      return null;
113    }
114  }
115
116
117
118  /**
119   * Retrieves a string representation of this writability mode.
120   *
121   * @return  A string representation of this writability mode.
122   */
123  public String toString()
124  {
125    return modeName;
126  }
127}
128