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

📄 basefunctionfactory.java

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

/*
 * @(#)BaseCombiningAlgFactory.java
 *
 * Copyright 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.ParsingException;
import com.sun.xacml.UnknownIdentifierException;

import java.net.URI;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import org.w3c.dom.Node;


/**
 * This is a basic implementation of <code>FunctionFactory</code>. It
 * implements the insertion and retrieval methods, but it doesn't actually
 * setup the factory with any functions. It also assumes a certain model
 * with regard to the different kinds of functions (Target, Condition, and
 * General). For this reason, you may want to re-use this class, or you 
 * may want to extend FunctionFactory directly, if you're writing a new
 * factory implementation.
 * <p>
 * Note that while this class is thread-safe on all creation methods, it
 * is not safe to add support for a new function while creating an instance
 * of a function. This follows from the assumption that most people will
 * initialize these factories up-front, and then start processing without
 * ever modifying the factories. If you need these mutual operations to
 * be thread-safe, then you should write a wrapper class that implements
 * the right synchronization.
 *
 * @since 1.2
 * @author Seth Proctor
 */
public class BaseFunctionFactory extends FunctionFactory
{

    // the backing maps for the Function objects
    private HashMap functionMap = null;

    // the superset factory chained to this factory
    private FunctionFactory superset = null;

    /**
     * Default constructor. No superset factory is used.
     */
    public BaseFunctionFactory() {
        this(null);
    }

    /**
     * Constructor that sets a "superset factory". This is useful since
     * the different function factories (Target, Condition, and General)
     * have a superset relationship (Condition functions are a superset
     * of Target functions, etc.). Adding a function to this factory will
     * automatically add the same function to the superset factory.
     *
     * @param superset the superset factory or null
     */
    public BaseFunctionFactory(FunctionFactory superset) {
        functionMap = new HashMap();

        this.superset = superset;
    }

    /**
     * Constructor that defines the initial functions supported by this
     * factory but doesn't use a superset factory.
     *
     * @param supportedFunctions a <code>Set</code> of <code>Function</code>s
     * @param supportedAbstractFunctions a mapping from <code>URI</code> to
     *                                   <code>FunctionProxy</code>
     */
    public BaseFunctionFactory(Set supportedFunctions,
                               Map supportedAbstractFunctions) {
        this(null, supportedFunctions, supportedAbstractFunctions);
    }

    /**
     * Constructor that defines the initial functions supported by this
     * factory and uses a superset factory. Note that the functions
     * supplied here are not propagated up to the superset factory, so
     * you must either make sure the superst factory is correctly
     * initialized or use <code>BaseFunctionFactory(FunctionFactory)</code>
     * and then manually add each function.
     *
     * @param superset the superset factory or null
     * @param supportedFunctions a <code>Set</code> of <code>Function</code>s
     * @param supportedAbstractFunctions a mapping from <code>URI</code> to
     *                                   <code>FunctionProxy</code>
     */
    public BaseFunctionFactory(FunctionFactory superset,
                               Set supportedFunctions,
                               Map supportedAbstractFunctions) {
        this(superset);

        Iterator it = supportedFunctions.iterator();
        while (it.hasNext()) {
            Function function = (Function)(it.next());
            functionMap.put(function.getIdentifier().toString(), function);
        }

        it = supportedAbstractFunctions.keySet().iterator();
        while (it.hasNext()) {
            URI id = (URI)(it.next());
            FunctionProxy proxy =
                (FunctionProxy)(supportedAbstractFunctions.get(id));
            functionMap.put(id.toString(), proxy);
        }
    }

    /**
     * Adds the function to the factory. Most functions have no state, so
     * the singleton model used here is typically desireable. The factory will
     * not enforce the requirement that a Target or Condition matching function
     * must be boolean.
     *
     * @param function the <code>Function</code> to add to the factory
     *
     * @throws IllegalArgumentException if the function's identifier is already
     *                                  used or if the function is non-boolean
     *                                  (when this is a Target or Condition
     *                                  factory)
     */
    public void addFunction(Function function)
        throws IllegalArgumentException
    {
        String id = function.getIdentifier().toString();

        // make sure this doesn't already exist
        if (functionMap.containsKey(id))
            throw new IllegalArgumentException("function already exists");

        // add to the superset factory
        if (superset != null)
            superset.addFunction(function);

        // finally, add to this factory
        functionMap.put(id, function);
    }

    /**
     * Adds the abstract function proxy to the factory. This is used for
     * those functions which have state, or change behavior (for instance
     * the standard map function, which changes its return type based on
     * how it is used). 
     *
     * @param proxy the <code>FunctionProxy</code> to add to the factory
     * @param identity the function's identifier
     *
     * @throws IllegalArgumentException if the function's identifier is already
     *                                  used

⌨️ 快捷键说明

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