⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 criteria.java

📁 OPIAM stands for Open Identity and Access Management. This Suite will provide modules for user & rig
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * OPIAM Suite
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

package opiam.admin.faare.service.javabeans;

import opiam.admin.faare.MessageUtil;
import opiam.admin.faare.config.javabeans.JBRessource;
import opiam.admin.faare.exception.ConfigurationException;
import opiam.admin.faare.exception.PersistenceException;
import opiam.admin.faare.persistence.LdapObjectFilter;
import opiam.admin.faare.service.UserContext;

import org.apache.log4j.Logger;

import java.io.Serializable;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;


/**
 * This object allows to specify a search criterion, relative to a requested object type.<br>
 * It fits to a LDAP filter (combination of simple filters by AND / OR operators).<br>
 * This object is mainly used in the search argument constructor.<br>
 * Do notice that the first agument of the methods refer to an attribute of the business object
 * given to the corresponding SearchArgument.<br>
 * BEWARE : The case of the attribute name must be respected as given in the business object JavaBean.
 *
 */
public final class Criteria implements Serializable
{
    /** Instance of logger. */
    private static Logger _logger = Logger.getLogger(Criteria.class);

    /** Begins with operator. */
    public static final int BEGINS_WITH = 11;
    /** Ends with operator. */
    public static final int ENDS_WITH = 12;
    /** Contains operator. */
    public static final int CONTAINS = 13;
    /** Equals operator. */
    public static final int EQUALS = 14;
    /** Does not contain operator. */
    public static final int NOTCONTAINS = 15;
    /** Is not equal to operator. */
    public static final int NOTEQUALS = 16;
    /** Approximately equals operator. */
    public static final int APPROX_EQUALS = 17;
    /** Is greater than operator. */
    public static final int GREATERTHAN = 18;
    /** Is less than operator. */
    public static final int LESSTHAN = 19;
    /** Exists operator. */
    public static final int EXISTS = 20;
    /** Does not exist operator. */
    public static final int NOTEXISTS = 21;
    /** Is less than or equal to operator. */
    public static final int LESSOREQUALTHAN = 22;
    /** Is greater than or equal to operator. */
    public static final int GREATEROREQUALTHAN = 23;

    /*DW/2648/BeginPatch*/
    /** Does not begin with operator. */
    public static final int NOTBEGINS_WITH = 24;
    /*DW/2648/EndPatch*/

    /*DW/2650/BeginPatch*/
    /** Does not end with operator. */
    public static final int NOTENDS_WITH = 25;
    /*DW/2650/BeginPatch*/

    /** Or operator. */
    public static final int OR = 0;
    /** And operator. */
    public static final int AND = 1;

    /** Criteria list. */
    private List criteriaList = new ArrayList();

    /** Default operator type. */
    private int type = AND;

    /**
     * Creates a new Criteria object.
     */
    private Criteria()
    {
        // forbid Criteria creation by new constructor
    }

    /**
     * This method allows to initialize a conjunctive filter.
     *
     * @return The filter.
     */
    public static Criteria getAndInstance()
    {
        Criteria result = new Criteria();
        result.setType(AND);

        return result;
    }

    /**
     * This method allows to initialize a disjunctive filter.
     *
     * @return The filter.
     */
    public static Criteria getOrInstance()
    {
        Criteria result = new Criteria();
        result.setType(OR);

        return result;
    }

    /**
     * Adds a leaf criterion with the operator code directly.
     * It should not be used unless we have the operator code directly.
     *
     * @param attribute  The attribute name to be used.
     * @param op         Type of operator.
     * @param value      A String representing the value of the attribute.
     */
    public void addLeafCriteria(String attribute, int op, String value)
    {
        /*DW/2650/BeginPatch*/
        if ((op < BEGINS_WITH) || (op > NOTENDS_WITH))
        /*DW/2650/EndPatch*/
        {
            throw new ConfigurationException(op +
                " is not a correct leafCriteria operator");
        }

        LeafCriteria leaf = new LeafCriteria();
        leaf.setAttribute(attribute);
        leaf.setOperator(op);
        leaf.setValue(value);
        criteriaList.add(leaf);
    }

    /**
     * Add a criterion to the criteria list.
     *
     * @param pc  Search criterion to add.
     */
    public void addCriteria(Criteria pc)
    {
        criteriaList.add(pc);
    }

    /**
     * Adds BeginsWith criterion (xxx*).<br>
     * Example : customer_id = 100*.
     *
     * @param attribute   The attribute name to be used.
     * @param value       A String representing the value of the attribute.
     *
     */
    public void addBeginsWith(String attribute, String value)
    {
        LeafCriteria leaf = new LeafCriteria();
        leaf.setAttribute(attribute);
        leaf.setOperator(BEGINS_WITH);
        leaf.setValue(value);
        criteriaList.add(leaf);
    }

    /**
     * Adds EndsWith criterion (*xxx).
     * Example : customer_id = *100.
     *
     * @param attribute   The attribute name to be used.
     * @param value       A String representing the value of the attribute.
     *
     */
    public void addEndsWith(String attribute, String value)
    {
        LeafCriteria leaf = new LeafCriteria();
        leaf.setAttribute(attribute);
        leaf.setOperator(ENDS_WITH);
        leaf.setValue(value);
        criteriaList.add(leaf);
    }

    /**
     * Adds Contains criterion : (*xxx*).
     * Example : customer_id = *100*.
     *
     * @param attribute   The attribute name to be used.
     * @param value       A String representing the value of the attribute.
     *
     */
    public void addContains(String attribute, String value)
    {
        LeafCriteria leaf = new LeafCriteria();
        leaf.setAttribute(attribute);
        leaf.setOperator(CONTAINS);
        leaf.setValue(value);
        criteriaList.add(leaf);
    }

    /**
     * Adds an equals criterion (=).
     * Example : customer_id = 10034.
     *
     * @param attribute   The attribute name to be used.
     * @param value       A String representing the value of the attribute.
     *
     */
    public void addEqualsTo(String attribute, String value)
    {
        LeafCriteria leaf = new LeafCriteria();
        leaf.setAttribute(attribute);
        leaf.setOperator(EQUALS);
        leaf.setValue(value);
        criteriaList.add(leaf);
    }

    /*DW/2648/BeginPatch*/
    /**
     * Adds Not BeginsWith criterion (xxx*).<br>
     * Example : !(customer_id = 100*).
     *
     * @param  attribute   The attribute name to be used.
     * @param  value       A String representing the value of the attribute.
     *
     */
    public void addNotBeginsWith(String attribute, String value)
    {
        LeafCriteria leaf = new LeafCriteria();
        leaf.setAttribute(attribute);
        leaf.setOperator(NOTBEGINS_WITH);
        leaf.setValue(value);
        criteriaList.add(leaf);
    }
    /*DW/2648/EndPatch*/

    /*DW/2650/BeginPatch*/
    /**
     * Adds Not EndsWith criterion (*xxx).
     * Example : !(customer_id = *100).
     *
     * @param attribute   The attribute name to be used.
     * @param value       A String representing the value of the attribute.
     *
     */
    public void addNotEndsWith(String attribute, String value)
    {
        LeafCriteria leaf = new LeafCriteria();
        leaf.setAttribute(attribute);
        /*DW/2669/BeginPatch*/
        //leaf.setOperator(ENDS_WITH);
        leaf.setOperator(NOTENDS_WITH);
        /*DW/2669/EndPatch*/
        leaf.setValue(value);
        criteriaList.add(leaf);
    }
    /*DW/2650/EndPatch*/

    /**
     * Adds Not Contains criterion (*xxx*).
     * Example : !(customer_id = *100*).
     *

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -