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 2008 Sun Microsystems, Inc.
026     */
027    
028    package org.opends.server.authorization.dseecompat;
029    
030    /**
031     * This class provides an enumeration of the two access
032     * types (allow, deny).
033     */
034    public enum EnumAccessType {
035    
036        /**
037         * Allow access type.
038         */
039        ALLOW   ("allow"),
040        /**
041         *  Deny access type.
042         */
043        DENY    ("deny");
044    
045        /*
046         * The access type string.
047         */
048        private final String accessType;
049    
050        /**
051         * Constructor that sets the accessType string.
052         * @param accessType The access type string to set.
053         */
054        EnumAccessType (String accessType){
055            this.accessType = accessType ;
056        }
057    
058        /**
059         * Checks if the access type is equal to the string
060         * representation passed in.
061         * @param type The string representation of the access type.
062         * @return True if the access types are equal.
063         */
064        public boolean isAccessType(String type){
065            return type.equalsIgnoreCase(accessType);
066        }
067    
068        /*
069         * TODO Make this method and all other Enum decode methods more efficient.
070         *
071         * Using the Enum.values() method is documented to be potentially slow.
072         * If we ever expect to use the decode() method in a performance-critical
073         * manner, then we should make it more efficient.  The same thing applies
074         * to all of the other enumeration types defined in the package.
075         */
076        /**
077         * Decodes an access type enumeration from a string passed into the method.
078         * @param type The string representation of the access type.
079         * @return   Return an EnumAccessType matching the string representation,
080         * or null if the string is not valid.
081         */
082        public static EnumAccessType decode(String type){
083            if (type != null){
084                for (EnumAccessType t : EnumAccessType.values()) {
085                    if (t.isAccessType(type)){
086                        return t;
087                    }
088                }
089            }
090            return null;
091        }
092    }