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 2008 Sun Microsystems, Inc.
015 * Portions Copyright 2015 ForgeRock AS.
016 */
017package org.opends.server.authorization.dseecompat;
018
019/**
020 * This class provides an enumeration of the allowed bind rule boolean types.
021 */
022public enum EnumBooleanTypes {
023
024    /**
025     * The enumeration type when the bind rule has specified boolean type of
026     * "AND".
027     */
028    AND_BOOLEAN_TYPE               ("and"),
029    /**
030     * The enumeration type when the bind rule has specified boolean type of
031     * "OR".
032     */
033    OR_BOOLEAN_TYPE                ("or"),
034    /**
035     * The enumeration type when the bind rule has specified boolean type of
036     * "NOT".
037     */
038    NOT_BOOLEAN_TYPE                ("not");
039
040    /** The bind rule boolean type name. */
041    private final String booleanType;
042
043    /**
044     * Creates a new enumeration type for the specified bind rule boolean type.
045     * @param booleanType  The boolean type name.
046     */
047    EnumBooleanTypes(String booleanType){
048        this.booleanType = booleanType;
049    }
050
051    /**
052     * Checks to see if the boolean type string is equal to the enumeration type
053     * name.
054     * @param booleanType  The type name to check equality for.
055     * @return  True if the keyword is equal to the specified name.
056     */
057    public boolean isBindRuleBooleanOperand(String booleanType){
058        return booleanType.equalsIgnoreCase(this.booleanType);
059    }
060
061    /**
062     * Create a new enumeration type for the specified boolean type name.
063     * @param booleanType  The name of the enumeration to create.
064     * @return A new enumeration type for the name or null if the name is
065     * not valid.
066     */
067    public static
068    EnumBooleanTypes createBindruleOperand(String booleanType) {
069        if (booleanType != null){
070          for (EnumBooleanTypes t : EnumBooleanTypes.values()) {
071                if (t.isBindRuleBooleanOperand(booleanType)) {
072                    return t;
073                }
074            }
075        }
076        return null;
077    }
078}