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

📄 functionbase.java

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

/*
 * @(#)FunctionBase.java
 *
 * Copyright 2003-2005 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.Indenter;

import com.sun.xacml.attr.AttributeValue;

import com.sun.xacml.ctx.Status;

import java.net.URI;
import java.net.URISyntaxException;

import java.io.OutputStream;
import java.io.PrintStream;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;


/**
 * An abstract utility superclass for functions. Supplies several useful
 * methods, making it easier to implement a <code>Function</code>. You can
 * extend this class or implement <code>Function</code> directly, depending
 * on your needs.
 *
 * @since 1.0
 * @author Steve Hanna
 * @author Seth Proctor
 */
public abstract class FunctionBase implements Function
{
    
    /**
     * The standard namespace where all XACML 1.0 spec-defined functions live
     */
    public static final String FUNCTION_NS =
        "urn:oasis:names:tc:xacml:1.0:function:";

    /**
     * The standard namespace where all XACML 2.0 spec-defined functions live
     */
    public static final String FUNCTION_NS_2 =
        "urn:oasis:names:tc:xacml:2.0:function:";

    // A List used by makeProcessingError() to save some steps.
    private static List processingErrList = null;

    // the name of this function
    private String functionName;

    // the id used by this function
    private int functionId;

    // the return type of this function, and whether it's a bag
    private String returnType;
    private boolean returnsBag;

    // flag that tells us which of the two constructors was used
    private boolean singleType;
    
    // parameter data if we're only using a single type
    private String paramType;
    private boolean paramIsBag;
    private int numParams;
    private int minParams;
    
    // paramater data if we're using different types
    private String [] paramTypes;
    private boolean [] paramsAreBags;

    /**
     * Constructor that sets up the function as having some number of
     * parameters all of the same given type. If <code>numParams</code> is
     * -1, then the length is variable
     *
     * @param functionName the name of this function as used by the factory
     *                     and any XACML policies
     * @param functionId an optional identifier that can be used by your
     *                   code for convenience
     * @param paramType the type of all parameters to this function, as used
     *                  by the factory and any XACML documents
     * @param paramIsBag whether or not every parameter is actually a bag
     *                   of values
     * @param numParams the number of parameters required by this function,
     *                  or -1 if any number are allowed
     * @param returnType the type returned by this function, as used by
     *                   the factory and any XACML documents
     * @param returnsBag whether or not this function returns a bag of values
     */
    public FunctionBase(String functionName, int functionId, String paramType,
                        boolean paramIsBag, int numParams,
                        String returnType, boolean returnsBag) {
        this(functionName, functionId, returnType, returnsBag);

        singleType = true;

        this.paramType = paramType;
        this.paramIsBag = paramIsBag;
        this.numParams = numParams;
        this.minParams = 0;
    }

    /**
     * Constructor that sets up the function as having some number of
     * parameters all of the same given type. If <code>numParams</code> is
     * -1, then the length is variable, and then <code>minParams</code> may
     * be used to specify a minimum number of parameters. If
     * <code>numParams</code> is not -1, then <code>minParams</code> is
     * ignored.
     *
     * @param functionName the name of this function as used by the factory
     *                     and any XACML policies
     * @param functionId an optional identifier that can be used by your
     *                   code for convenience
     * @param paramType the type of all parameters to this function, as used
     *                  by the factory and any XACML documents
     * @param paramIsBag whether or not every parameter is actually a bag
     *                   of values
     * @param numParams the number of parameters required by this function,
     *                  or -1 if any number are allowed
     * @param minParams the minimum number of parameters required if 
     *                  <code>numParams</code> is -1
     * @param returnType the type returned by this function, as used by
     *                   the factory and any XACML documents
     * @param returnsBag whether or not this function returns a bag of values
     */
    public FunctionBase(String functionName, int functionId, String paramType,
                        boolean paramIsBag, int numParams, int minParams,
                        String returnType, boolean returnsBag) {
        this(functionName, functionId, returnType, returnsBag);

        singleType = true;

        this.paramType = paramType;
        this.paramIsBag = paramIsBag;
        this.numParams = numParams;
        this.minParams = minParams;
    }


    /**
     * Constructor that sets up the function as having different types for
     * each given parameter.
     *
     * @param functionName the name of this function as used by the factory
     *                     and any XACML policies
     * @param functionId an optional identifier that can be used by your
     *                   code for convenience
     * @param paramTypes the type of each parameter, in order, required by
     *                   this function, as used by the factory and any XACML
     *                    documents
     * @param paramIsBag whether or not each parameter is actually a bag
     *                   of values
     * @param returnType the type returned by this function, as used by
     *                   the factory and any XACML documents
     * @param returnsBag whether or not this function returns a bag of values
     */
    public FunctionBase(String functionName, int functionId,
                        String [] paramTypes, boolean [] paramIsBag,
                        String returnType, boolean returnsBag) {
        this(functionName, functionId, returnType, returnsBag);

        singleType = false;

        this.paramTypes = paramTypes;
        this.paramsAreBags = paramIsBag;
    }

    /**
     * Constructor that sets up some basic values for functions that will
     * take care of parameter checking on their own. If you use this
     * constructor for your function class, then you must override the
     * two check methods to make sure that parameters are correct.
     *
     * @param functionName the name of this function as used by the factory
     *                     and any XACML policies
     * @param functionId an optional identifier that can be used by your
     *                   code for convenience
     * @param returnType the type returned by this function, as used by
     *                   the factory and any XACML documents
     * @param returnsBag whether or not this function returns a bag of values
     */
    public FunctionBase(String functionName, int functionId,
                        String returnType, boolean returnsBag) {
        this.functionName = functionName;
        this.functionId = functionId;
        this.returnType = returnType;
        this.returnsBag = returnsBag;
    }

    /**
     * Returns the full identifier of this function, as known by the factories.
     *
     * @return the function's identifier
     *
     * @throws IllegalArgumentException if the identifier isn't a valid URI
     */
    public URI getIdentifier() {
        // this is to get around the exception handling problems, but may
        // change if this code changes to include exceptions from the
        // constructors
        try {
            return new URI(functionName);
        } catch (URISyntaxException use) {
            throw new IllegalArgumentException("invalid URI");
        }
    }

    /**
     * Returns the name of the function to be handled by this particular
     * object.
     *
     * @return the function name

⌨️ 快捷键说明

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