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

📄 criteria.java

📁 OPIAM stands for Open Identity and Access Management. This Suite will provide modules for user & rig
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * @param attribute   The attribute name to be used.
     * @param value       A String representing the value of the attribute.
     *

     */
    public void addNotContains(String attribute, String value)
    {
        LeafCriteria leaf = new LeafCriteria();
        leaf.setAttribute(attribute);
        leaf.setOperator(NOTCONTAINS);
        leaf.setValue(value);
        criteriaList.add(leaf);
    }

    /**
     * Adds an not 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 addNotEqualsTo(String attribute, String value)
    {
        LeafCriteria leaf = new LeafCriteria();
        leaf.setAttribute(attribute);
        leaf.setOperator(NOTEQUALS);
        leaf.setValue(value);
        criteriaList.add(leaf);
    }

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

    /**
     * Adds Greater Than criterion (>).
     * Exmaple : customer_id > 10034.
     *
     * @param attribute   The attribute name to be used.
     * @param value       A String representing the value of the attribute.
     */
    public void addGreaterThan(String attribute, String value)
    {
        LeafCriteria leaf = new LeafCriteria();
        leaf.setAttribute(attribute);
        leaf.setOperator(GREATERTHAN);
        leaf.setValue(value);
        criteriaList.add(leaf);
    }

    /**
     * Adds Less Than 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 addLessThan(String attribute, String value)
    {
        LeafCriteria leaf = new LeafCriteria();
        leaf.setAttribute(attribute);
        leaf.setOperator(LESSTHAN);
        leaf.setValue(value);
        criteriaList.add(leaf);
    }

    /**
     * Adds an exists criterion (attr).
     *
     * @param attr  The attribute name to be used.
     *
     */
    public void addExists(String attr)
    {
        LeafCriteria leaf = new LeafCriteria();
        leaf.setAttribute(attr);
        leaf.setOperator(EXISTS);
        criteriaList.add(leaf);
    }

    /**
     * Adds an NOT exists criterion (attr).
     *
     * @param attr  The attribute name to be used.
     *
     */
    public void addNotExists(String attr)
    {
        LeafCriteria leaf = new LeafCriteria();
        leaf.setAttribute(attr);
        leaf.setOperator(NOTEXISTS);
        criteriaList.add(leaf);
    }

    /**
     * Adds LessOrEqual Than 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 addLessOrEqualThan(String attribute, String value)
    {
        LeafCriteria leaf = new LeafCriteria();
        leaf.setAttribute(attribute);
        leaf.setOperator(LESSOREQUALTHAN);
        leaf.setValue(value);
        criteriaList.add(leaf);
    }

    /**
     * Adds GreaterOrEqual Than 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 addGreaterOrEqualThan(String attribute, String value)
    {
        LeafCriteria leaf = new LeafCriteria();
        leaf.setAttribute(attribute);
        leaf.setOperator(GREATEROREQUALTHAN);
        leaf.setValue(value);
        criteriaList.add(leaf);
    }

    /**
     * Returns the criteriaList.
     *
     * @return List of criteria.
     */
    public List getCriteriaList()
    {
        return criteriaList;
    }

    /**
     * Returns the type.
     *
     * @return Type of search filter.
     */
    public int getType()
    {
        return type;
    }

    /**
     * Sets the criteriaList.
     *
     * @param acriteriaList  The criteriaList to set.
     */
    public void setCriteriaList(List acriteriaList)
    {
        this.criteriaList = acriteriaList;
    }

    /**
     * Sets the type.
     *
     * @param atype  The type to set
     */
    public void setType(int atype)
    {
        this.type = atype;
    }

    /**
     * Indicates if the current operator type is "AND".
     *
     * @return True if it is, false otherwise.
     */
    public boolean isTypeAnd()
    {
        return (type == AND);
    }

    /**
     * Indicates if the current operator type is "OR".
     *
     * @return True if it is, false otherwise.
     */
    public boolean isTypeOr()
    {
        return (type == OR);
    }

    /**
     * Builds and returns the ldap filter.
     *
     * @param jbRessource  A resource such as defined in the profiles configuration file.
     * @param userContext  Context of the user.
     *
     * @return A String representing the ldap filter.
     * @throws Exception in case the criteria contains attributes which do not exist in
     *                    the requested resource.
     */
    public String getLdapFilter(JBRessource jbRessource, UserContext userContext)
        throws Exception
    {
        _logger.debug("getLdapFilter criteriaList.size() : " +
            criteriaList.size());

        StringBuffer buf = new StringBuffer();
        Iterator it = criteriaList.iterator();
        LeafCriteria leaf = null;
        Criteria node = null;
        Object obj = null;

        if (criteriaList.size() > 1)
        {
            // only for multiple argument search
            if (isTypeOr())
            {
                buf.append("(|");
            }

            if (isTypeAnd())
            {
                buf.append("(&");
            }
        }

        try
        {
            while (it.hasNext())
            {
                obj = it.next();

                if (obj instanceof LeafCriteria)
                {
                    leaf = (LeafCriteria) obj;
                    addLeafLdapFilter(buf, leaf, jbRessource, userContext);
                }

                if (obj instanceof Criteria)
                {
                    node = (Criteria) obj;
                    buf.append(node.getLdapFilter(jbRessource, userContext));
                }
            }

            if (criteriaList.size() > 1)
            {
                buf.append(")");
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();

            //DW/2578/BeginPatch
            // cas o

⌨️ 快捷键说明

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