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