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