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
010     * docs/licenses/cddl.txt
011     * or http://www.opensource.org/licenses/cddl1.php.
012     * See the License for the specific language governing permissions
013     * and limitations under the License.
014     *
015     * When distributing Covered Code, include this CDDL HEADER in each
016     * file and include the License file at
017     * docs/licenses/cddl.txt.  If applicable,
018     * add the following below this CDDL HEADER, with the fields enclosed
019     * by brackets "[]" replaced with your own identifying information:
020     *      Portions Copyright [yyyy] [name of copyright owner]
021     *
022     * CDDL HEADER END
023     *
024     *
025     *      Copyright 2011-2013 UnboundID Corp.
026     */
027    package com.unboundid.directory.sdk.ds.types;
028    
029    
030    import com.unboundid.util.ThreadSafety;
031    import com.unboundid.util.ThreadSafetyLevel;
032    
033    
034    /**
035     * This class implements an enumeration that may be used to control
036     * the writability mode for the entire server or for a specific
037     * backend. The writability mode may be "enabled", "disabled", or
038     * "internal-only".
039     */
040    @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
041    public enum WritabilityMode
042    {
043      /**
044       * Indicates that all write operations should be allowed.
045       */
046      ENABLED("enabled"),
047    
048    
049    
050      /**
051       * Indicates that all write operations should be rejected.
052       */
053      DISABLED("disabled"),
054    
055    
056    
057      /**
058       * Indicates that write operations from clients will be rejected,
059       * but internal operations and updates through replication will
060       * be allowed.
061       */
062      INTERNAL_ONLY("internal-only");
063    
064    
065    
066      // The human-readable name for this writability mode.
067      private String modeName;
068    
069    
070    
071      /**
072       * Creates a new {@code WritabilityMode} with the provided name.
073       *
074       * @param  modeName  The human-readable name for this {@code WritabilityMode}.
075       */
076      private WritabilityMode(final String modeName)
077      {
078        this.modeName = modeName;
079      }
080    
081    
082    
083      /**
084       * Retrieves the {@code WritabilityMode} for the specified name.
085       *
086       * @param  modeName  The name of the {@code WritabilityMode} to retrieve.
087       *
088       * @return  The requested {@code WritabilityMode}, or <CODE>null</CODE> if
089       *          the provided value is not the name of a valid mode.
090       */
091      public static WritabilityMode forName(final String modeName)
092      {
093        String lowerName = modeName.toLowerCase();
094        if (lowerName.equals("enabled"))
095        {
096          return WritabilityMode.ENABLED;
097        }
098        else if (lowerName.equals("disabled"))
099        {
100          return WritabilityMode.DISABLED;
101        }
102        else if (lowerName.equals("internal-only") ||
103                 lowerName.equals("internal_only"))
104        {
105          return WritabilityMode.INTERNAL_ONLY;
106        }
107        else
108        {
109          return null;
110        }
111      }
112    
113    
114    
115      /**
116       * Retrieves a string representation of this {@code WritabilityMode}.
117       *
118       * @return  A string representation of this {@code WritabilityMode}.
119       */
120      @Override
121      public String toString()
122      {
123        return modeName;
124      }
125    }