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