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

📄 comparisonfunction.java

📁 sunxacml源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

/*
 * @(#)ComparisonFunction.java
 *
 * Copyright 2003-2004 Sun Microsystems, Inc. All Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *   1. Redistribution of source code must retain the above copyright notice,
 *      this list of conditions and the following disclaimer.
 * 
 *   2. Redistribution in binary form must reproduce the above copyright
 *      notice, this list of conditions and the following disclaimer in the
 *      documentation and/or other materials provided with the distribution.
 *
 * Neither the name of Sun Microsystems, Inc. or the names of contributors may
 * be used to endorse or promote products derived from this software without
 * specific prior written permission.
 * 
 * This software is provided "AS IS," without a warranty of any kind. ALL
 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
 * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
 * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN")
 * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
 * AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
 * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
 * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
 * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY
 * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
 * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
 *
 * You acknowledge that this software is not designed or intended for use in
 * the design, construction, operation or maintenance of any nuclear facility.
 */

package com.sun.xacml.cond;

import com.sun.xacml.EvaluationCtx;

import com.sun.xacml.attr.AttributeValue;
import com.sun.xacml.attr.BooleanAttribute;
import com.sun.xacml.attr.DateAttribute;
import com.sun.xacml.attr.DateTimeAttribute;
import com.sun.xacml.attr.DoubleAttribute;
import com.sun.xacml.attr.IntegerAttribute;
import com.sun.xacml.attr.StringAttribute;
import com.sun.xacml.attr.TimeAttribute;

import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;


/**
 * A class that implements all of the standard comparison functions.
 *
 * @since 1.0
 * @author Steve Hanna
 * @author Seth Proctor
 */
public class ComparisonFunction extends FunctionBase
{

    /**
     * Standard identifier for the integer-greater-than function.
     */
    public static final String NAME_INTEGER_GREATER_THAN =
        FUNCTION_NS + "integer-greater-than";

    /**
     * Standard identifier for the integer-greater-than-or-equal function.
     */
    public static final String NAME_INTEGER_GREATER_THAN_OR_EQUAL =
        FUNCTION_NS + "integer-greater-than-or-equal";

    /**
     * Standard identifier for the integer-less-than function.
     */
    public static final String NAME_INTEGER_LESS_THAN =
        FUNCTION_NS + "integer-less-than";

    /**
     * Standard identifier for the integer-less-than-or-equal function.
     */
    public static final String NAME_INTEGER_LESS_THAN_OR_EQUAL =
        FUNCTION_NS + "integer-less-than-or-equal";


    /**
     * Standard identifier for the double-greater-than function.
     */
    public static final String NAME_DOUBLE_GREATER_THAN =
        FUNCTION_NS + "double-greater-than";

    /**
     * Standard identifier for the double-greater-than-or-equal function.
     */
    public static final String NAME_DOUBLE_GREATER_THAN_OR_EQUAL =
        FUNCTION_NS + "double-greater-than-or-equal";

    /**
     * Standard identifier for the double-less-than function.
     */
    public static final String NAME_DOUBLE_LESS_THAN =
        FUNCTION_NS + "double-less-than";

    /**
     * Standard identifier for the double-less-than-or-equal function.
     */
    public static final String NAME_DOUBLE_LESS_THAN_OR_EQUAL =
        FUNCTION_NS + "double-less-than-or-equal";


    /**
     * Standard identifier for the string-greater-than function.
     */
    public static final String NAME_STRING_GREATER_THAN =
        FUNCTION_NS + "string-greater-than";

    /**
     * Standard identifier for the string-greater-than-or-equal function.
     */
    public static final String NAME_STRING_GREATER_THAN_OR_EQUAL =
        FUNCTION_NS + "string-greater-than-or-equal";

    /**
     * Standard identifier for the string-less-than function.
     */
    public static final String NAME_STRING_LESS_THAN =
        FUNCTION_NS + "string-less-than";

    /**
     * Standard identifier for the string-less-than-or-equal function.
     */
    public static final String NAME_STRING_LESS_THAN_OR_EQUAL =
        FUNCTION_NS + "string-less-than-or-equal";


    /**
     * Standard identifier for the time-greater-than function.
     */
    public static final String NAME_TIME_GREATER_THAN =
        FUNCTION_NS + "time-greater-than";

    /**
     * Standard identifier for the time-greater-than-or-equal function.
     */
    public static final String NAME_TIME_GREATER_THAN_OR_EQUAL =
        FUNCTION_NS + "time-greater-than-or-equal";

    /**
     * Standard identifier for the time-less-than function.
     */
    public static final String NAME_TIME_LESS_THAN =
        FUNCTION_NS + "time-less-than";

    /**
     * Standard identifier for the time-less-than-or-equal function.
     */
    public static final String NAME_TIME_LESS_THAN_OR_EQUAL =
        FUNCTION_NS + "time-less-than-or-equal";


    /**
     * Standard identifier for the dateTime-greater-than function.
     */
    public static final String NAME_DATETIME_GREATER_THAN =
        FUNCTION_NS + "dateTime-greater-than";

    /**
     * Standard identifier for the dateTime-greater-than-or-equal function.
     */
    public static final String NAME_DATETIME_GREATER_THAN_OR_EQUAL =
        FUNCTION_NS + "dateTime-greater-than-or-equal";

    /**
     * Standard identifier for the dateTime-less-than function.
     */
    public static final String NAME_DATETIME_LESS_THAN =
        FUNCTION_NS + "dateTime-less-than";

    /**
     * Standard identifier for the dateTime-less-than-or-equal function.
     */
    public static final String NAME_DATETIME_LESS_THAN_OR_EQUAL =
        FUNCTION_NS + "dateTime-less-than-or-equal";


    /**
     * Standard identifier for the date-greater-than function.
     */
    public static final String NAME_DATE_GREATER_THAN =
        FUNCTION_NS + "date-greater-than";

    /**
     * Standard identifier for the date-greater-than-or-equal function.
     */
    public static final String NAME_DATE_GREATER_THAN_OR_EQUAL =
        FUNCTION_NS + "date-greater-than-or-equal";

    /**
     * Standard identifier for the date-less-than function.
     */
    public static final String NAME_DATE_LESS_THAN =
        FUNCTION_NS + "date-less-than";

    /**
     * Standard identifier for the date-less-than-or-equal function.
     */
    public static final String NAME_DATE_LESS_THAN_OR_EQUAL =
        FUNCTION_NS + "date-less-than-or-equal";

    // private identifiers for the supported functions
    private static final int ID_INTEGER_GREATER_THAN = 0;
    private static final int ID_INTEGER_GREATER_THAN_OR_EQUAL = 1;
    private static final int ID_INTEGER_LESS_THAN = 2;
    private static final int ID_INTEGER_LESS_THAN_OR_EQUAL = 3;
    private static final int ID_DOUBLE_GREATER_THAN = 4;
    private static final int ID_DOUBLE_GREATER_THAN_OR_EQUAL = 5;
    private static final int ID_DOUBLE_LESS_THAN = 6;
    private static final int ID_DOUBLE_LESS_THAN_OR_EQUAL = 7;
    private static final int ID_STRING_GREATER_THAN = 8;
    private static final int ID_STRING_GREATER_THAN_OR_EQUAL = 9;
    private static final int ID_STRING_LESS_THAN = 10;
    private static final int ID_STRING_LESS_THAN_OR_EQUAL = 11;
    private static final int ID_TIME_GREATER_THAN = 12;
    private static final int ID_TIME_GREATER_THAN_OR_EQUAL = 13;
    private static final int ID_TIME_LESS_THAN = 14;
    private static final int ID_TIME_LESS_THAN_OR_EQUAL = 15;
    private static final int ID_DATE_GREATER_THAN = 16;
    private static final int ID_DATE_GREATER_THAN_OR_EQUAL = 17;
    private static final int ID_DATE_LESS_THAN = 18;
    private static final int ID_DATE_LESS_THAN_OR_EQUAL = 19;
    private static final int ID_DATETIME_GREATER_THAN = 20;
    private static final int ID_DATETIME_GREATER_THAN_OR_EQUAL = 21;
    private static final int ID_DATETIME_LESS_THAN = 22;
    private static final int ID_DATETIME_LESS_THAN_OR_EQUAL = 23;

    // mappings from name to private identifier and argument datatype
    private static HashMap idMap;
    private static HashMap typeMap;

    /**
     * Static initializer to setup the two maps.
     */
    static {
        idMap = new HashMap();

        idMap.put(NAME_INTEGER_GREATER_THAN,
                  new Integer(ID_INTEGER_GREATER_THAN));
        idMap.put(NAME_INTEGER_GREATER_THAN_OR_EQUAL,
                  new Integer(ID_INTEGER_GREATER_THAN_OR_EQUAL));
        idMap.put(NAME_INTEGER_LESS_THAN,
                  new Integer(ID_INTEGER_LESS_THAN));
        idMap.put(NAME_INTEGER_LESS_THAN_OR_EQUAL,
                  new Integer(ID_INTEGER_LESS_THAN_OR_EQUAL));
        idMap.put(NAME_DOUBLE_GREATER_THAN,
                  new Integer(ID_DOUBLE_GREATER_THAN));
        idMap.put(NAME_DOUBLE_GREATER_THAN_OR_EQUAL,
                  new Integer(ID_DOUBLE_GREATER_THAN_OR_EQUAL));
        idMap.put(NAME_DOUBLE_LESS_THAN,
                  new Integer(ID_DOUBLE_LESS_THAN));
        idMap.put(NAME_DOUBLE_LESS_THAN_OR_EQUAL,
                  new Integer(ID_DOUBLE_LESS_THAN_OR_EQUAL));
        idMap.put(NAME_STRING_GREATER_THAN,
                  new Integer(ID_STRING_GREATER_THAN));
        idMap.put(NAME_STRING_GREATER_THAN_OR_EQUAL,
                  new Integer(ID_STRING_GREATER_THAN_OR_EQUAL));
        idMap.put(NAME_STRING_LESS_THAN,
                  new Integer(ID_STRING_LESS_THAN));
        idMap.put(NAME_STRING_LESS_THAN_OR_EQUAL,
                  new Integer(ID_STRING_LESS_THAN_OR_EQUAL));
        idMap.put(NAME_TIME_GREATER_THAN,
                  new Integer(ID_TIME_GREATER_THAN));
        idMap.put(NAME_TIME_GREATER_THAN_OR_EQUAL,
                  new Integer(ID_TIME_GREATER_THAN_OR_EQUAL));
        idMap.put(NAME_TIME_LESS_THAN,
                  new Integer(ID_TIME_LESS_THAN));
        idMap.put(NAME_TIME_LESS_THAN_OR_EQUAL,
                  new Integer(ID_TIME_LESS_THAN_OR_EQUAL));
        idMap.put(NAME_DATE_GREATER_THAN,
                  new Integer(ID_DATE_GREATER_THAN));
        idMap.put(NAME_DATE_GREATER_THAN_OR_EQUAL,
                  new Integer(ID_DATE_GREATER_THAN_OR_EQUAL));
        idMap.put(NAME_DATE_LESS_THAN,
                  new Integer(ID_DATE_LESS_THAN));
        idMap.put(NAME_DATE_LESS_THAN_OR_EQUAL,
                  new Integer(ID_DATE_LESS_THAN_OR_EQUAL));
        idMap.put(NAME_DATETIME_GREATER_THAN,
                  new Integer(ID_DATETIME_GREATER_THAN));
        idMap.put(NAME_DATETIME_GREATER_THAN_OR_EQUAL,
                  new Integer(ID_DATETIME_GREATER_THAN_OR_EQUAL));
        idMap.put(NAME_DATETIME_LESS_THAN,
                  new Integer(ID_DATETIME_LESS_THAN));
        idMap.put(NAME_DATETIME_LESS_THAN_OR_EQUAL,
                  new Integer(ID_DATETIME_LESS_THAN_OR_EQUAL));

        typeMap = new HashMap();

        typeMap.put(NAME_INTEGER_GREATER_THAN, IntegerAttribute.identifier);
        typeMap.put(NAME_INTEGER_GREATER_THAN_OR_EQUAL,
                    IntegerAttribute.identifier);
        typeMap.put(NAME_INTEGER_LESS_THAN, IntegerAttribute.identifier);
        typeMap.put(NAME_INTEGER_LESS_THAN_OR_EQUAL,
                    IntegerAttribute.identifier);
        typeMap.put(NAME_DOUBLE_GREATER_THAN, DoubleAttribute.identifier);
        typeMap.put(NAME_DOUBLE_GREATER_THAN_OR_EQUAL,
                    DoubleAttribute.identifier);
        typeMap.put(NAME_DOUBLE_LESS_THAN, DoubleAttribute.identifier);
        typeMap.put(NAME_DOUBLE_LESS_THAN_OR_EQUAL,
                    DoubleAttribute.identifier);
        typeMap.put(NAME_STRING_GREATER_THAN, StringAttribute.identifier);
        typeMap.put(NAME_STRING_GREATER_THAN_OR_EQUAL,
                    StringAttribute.identifier);
        typeMap.put(NAME_STRING_LESS_THAN, StringAttribute.identifier);
        typeMap.put(NAME_STRING_LESS_THAN_OR_EQUAL,
                    StringAttribute.identifier);
        typeMap.put(NAME_TIME_GREATER_THAN, TimeAttribute.identifier);
        typeMap.put(NAME_TIME_GREATER_THAN_OR_EQUAL, TimeAttribute.identifier);
        typeMap.put(NAME_TIME_LESS_THAN, TimeAttribute.identifier);
        typeMap.put(NAME_TIME_LESS_THAN_OR_EQUAL, TimeAttribute.identifier);
        typeMap.put(NAME_DATETIME_GREATER_THAN, DateTimeAttribute.identifier);
        typeMap.put(NAME_DATETIME_GREATER_THAN_OR_EQUAL,
                    DateTimeAttribute.identifier);
        typeMap.put(NAME_DATETIME_LESS_THAN, DateTimeAttribute.identifier);
        typeMap.put(NAME_DATETIME_LESS_THAN_OR_EQUAL,
                    DateTimeAttribute.identifier);
        typeMap.put(NAME_DATE_GREATER_THAN, DateAttribute.identifier);
        typeMap.put(NAME_DATE_GREATER_THAN_OR_EQUAL, DateAttribute.identifier);
        typeMap.put(NAME_DATE_LESS_THAN, DateAttribute.identifier);
        typeMap.put(NAME_DATE_LESS_THAN_OR_EQUAL, DateAttribute.identifier);
    };

    /**
     * Creates a new <code>ComparisonFunction</code> object.
     *
     * @param functionName the standard XACML name of the function to be
     *                     handled by this object, including the full namespace
     *
     * @throws IllegalArgumentException if the function isn't known
     */
    public ComparisonFunction(String functionName) {
        super(functionName, getId(functionName), getArgumentType(functionName),
              false, 2, BooleanAttribute.identifier, false);
    }

    /**
     * Private helper that returns the internal identifier used for the
     * given standard function.
     */
    private static int getId(String functionName) {
        Integer i = (Integer)(idMap.get(functionName));

⌨️ 快捷键说明

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