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 2013 ForgeRock AS.
016 */
017package org.opends.server.authorization.dseecompat;
018
019/**
020 * This class provides an enumeration of the allowed bind rule types.
021 */
022public enum EnumBindRuleType {
023
024    /**
025     * The enumeration type when the bind rule has specified type of
026     * "=".
027     */
028    EQUAL_BINDRULE_TYPE             ("="),
029    /**
030     * The enumeration type when the bind rule has specified type of
031     * "!=".
032     */
033    NOT_EQUAL_BINDRULE_TYPE         ("!="),
034    /**
035     * The enumeration type when the bind rule has specified type of
036     * "<".
037     */
038    LESS_BINDRULE_TYPE              ("<"),
039    /**
040     * The enumeration type when the bind rule has specified type of
041     * "<=".
042     */
043    LESS_OR_EQUAL_BINDRULE_TYPE     ("<="),
044    /**
045     * The enumeration type when the bind rule has specified type of
046     * >".
047     */
048    GREATER_BINDRULE_TYPE           (">"),
049    /**
050     * The enumeration type when the bind rule has specified type of
051     * ">=".
052     */
053    GREATER_OR_EQUAL_BINDRULE_TYPE  (">=");
054
055    /** The bind rule type name. */
056    private final String type;
057
058    /**
059     * Creates a new enumeration type for the specified bind rule type.
060     * @param type The bind rule type name.
061     */
062    EnumBindRuleType(String type){
063        this.type = type;
064    }
065
066    /**
067     * Returns the comparison operator corresponding to this EnumBindRuleType.
068     *
069     * @return the string representing the comparison operator
070     */
071    public String getType()
072    {
073      return type;
074    }
075
076    /**
077     * Checks to see if the type string is equal to the enumeration type
078     * name.
079     * @param type  The type name to check equality for.
080     * @return  True if the keyword is equal to the specified name.
081     */
082    public boolean isBindRuleType(String type){
083        return type.equals(this.type);
084    }
085
086    /**
087     * Create a new enumeration type for the specified type name.
088     * @param type  The name of the enumeration to create.
089     * @return A new enumeration type for the name or null if the name is
090     * not valid.
091     */
092    public static EnumBindRuleType createBindruleOperand(String type){
093        if (type != null){
094            for (EnumBindRuleType t : EnumBindRuleType.values()){
095                if (t.isBindRuleType(type)){
096                    return t;
097                }
098            }
099        }
100        return null;
101    }
102}