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 2015 ForgeRock AS.
016 */
017package org.opends.server.types;
018
019
020
021/**
022 * This class implements an enumeration that may be used for
023 * configuration items that may have three possible values:  accept,
024 * reject, or warn.
025 */
026@org.opends.server.types.PublicAPI(
027     stability=org.opends.server.types.StabilityLevel.UNCOMMITTED,
028     mayInstantiate=false,
029     mayExtend=false,
030     mayInvoke=true)
031public enum AcceptRejectWarn
032{
033  /**
034   * Indicates that elements meeting the associated criteria should be
035   * accepted.
036   */
037  ACCEPT("accept"),
038
039
040
041  /**
042   * Indicates that elements meeting the associated criteria should be
043   * rejected.
044   */
045  REJECT("reject"),
046
047
048
049  /**
050   * Indicates that a warning should be logged if an element meets the
051   * associated criteria.  Whether it will be accepted or rejected
052   * after the log warning is dependent on the scenario in which this
053   * enumeration is used.
054   */
055  WARN("warn");
056
057
058
059  /** The human-readable name for this policy. */
060  private String policyName;
061
062
063
064  /**
065   * Creates a new accept/reject/warn policy with the provided name.
066   *
067   * @param  policyName  The human-readable name for this policy.
068   */
069  private AcceptRejectWarn(String policyName)
070  {
071    this.policyName = policyName;
072  }
073
074
075
076  /**
077   * Retrieves the accept/reject/warn policy for the specified name.
078   *
079   * @param  policyName  The name of the policy to retrieve.
080   *
081   * @return  The requested accept/reject/warn policy, or
082   *          <CODE>null</CODE> if the provided value is not the name
083   *          of a valid policy.
084   */
085  public static AcceptRejectWarn policyForName(String policyName)
086  {
087    String lowerName = policyName.toLowerCase();
088    if (lowerName.equals("accept") || lowerName.equals("allow"))
089    {
090      return AcceptRejectWarn.ACCEPT;
091    }
092    else if (lowerName.equals("reject") || lowerName.equals("deny"))
093    {
094      return AcceptRejectWarn.REJECT;
095    }
096    else if (lowerName.equals("warn"))
097    {
098      return AcceptRejectWarn.WARN;
099    }
100    else
101    {
102      return null;
103    }
104  }
105
106
107
108  /**
109   * Retrieves the human-readable name for this accept/reject/warn
110   * policy.
111   *
112   * @return  The human-readable name for this accept/reject/warn
113   *          policy.
114   */
115  public String toString()
116  {
117    return policyName;
118  }
119}
120