📄 standardfunctionfactory.java
字号:
/*
* @(#)StandardFunctionFactory.java
*
* Copyright 2004-2006 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.PolicyMetaData;
import com.sun.xacml.UnknownIdentifierException;
import com.sun.xacml.cond.cluster.AbsFunctionCluster;
import com.sun.xacml.cond.cluster.AddFunctionCluster;
import com.sun.xacml.cond.cluster.ComparisonFunctionCluster;
import com.sun.xacml.cond.cluster.ConditionBagFunctionCluster;
import com.sun.xacml.cond.cluster.ConditionSetFunctionCluster;
import com.sun.xacml.cond.cluster.DateMathFunctionCluster;
import com.sun.xacml.cond.cluster.DivideFunctionCluster;
import com.sun.xacml.cond.cluster.EqualFunctionCluster;
import com.sun.xacml.cond.cluster.FloorFunctionCluster;
import com.sun.xacml.cond.cluster.GeneralBagFunctionCluster;
import com.sun.xacml.cond.cluster.GeneralSetFunctionCluster;
import com.sun.xacml.cond.cluster.HigherOrderFunctionCluster;
import com.sun.xacml.cond.cluster.LogicalFunctionCluster;
import com.sun.xacml.cond.cluster.MatchFunctionCluster;
import com.sun.xacml.cond.cluster.ModFunctionCluster;
import com.sun.xacml.cond.cluster.MultiplyFunctionCluster;
import com.sun.xacml.cond.cluster.NOfFunctionCluster;
import com.sun.xacml.cond.cluster.NotFunctionCluster;
import com.sun.xacml.cond.cluster.NumericConvertFunctionCluster;
import com.sun.xacml.cond.cluster.RoundFunctionCluster;
import com.sun.xacml.cond.cluster.StringFunctionCluster;
import com.sun.xacml.cond.cluster.StringNormalizeFunctionCluster;
import com.sun.xacml.cond.cluster.SubtractFunctionCluster;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Collections;
import java.util.HashSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.logging.Logger;
/**
* This factory supports the standard set of functions specified in XACML
* 1.x and 2.0. It is the default factory used by the system, and imposes
* a singleton pattern insuring that there is only ever one instance of
* this class.
* <p>
* Note that because this supports only the standard functions, this
* factory does not allow the addition of any other functions. If you call
* <code>addFunction</code> on an instance of this class, an exception
* will be thrown. If you need a standard factory that is modifiable,
* you can either create a new <code>BaseFunctionFactory</code> (or some
* other implementation of <code>FunctionFactory</code>) populated with
* the standard functions from <code>getStandardFunctions</code> or
* you can use <code>getNewFactoryProxy</code> to get a proxy containing
* a new, modifiable set of factories.
*
* @since 1.2
* @author Seth Proctor
*/
public class StandardFunctionFactory extends BaseFunctionFactory
{
// the three singleton instances
private static StandardFunctionFactory targetFactory = null;
private static StandardFunctionFactory conditionFactory = null;
private static StandardFunctionFactory generalFactory = null;
// the three function sets/maps that we use internally
private static Set targetFunctions = null;
private static Set conditionFunctions = null;
private static Set generalFunctions = null;
private static Map targetAbstractFunctions = null;
private static Map conditionAbstractFunctions = null;
private static Map generalAbstractFunctions = null;
// the static sets of supported identifiers for each XACML version
private static Set supportedV1Functions;
private static Set supportedV2Functions;
// the set/map used by each singleton factory instance
private Set supportedFunctions = null;
private Map supportedAbstractFunctions = null;
// the logger we'll use for all messages
private static final Logger logger =
Logger.getLogger(StandardFunctionFactory.class.getName());
/**
* Creates a new StandardFunctionFactory, making sure that the default
* maps are initialized correctly. Standard factories can't be modified,
* so there is no notion of supersetting since that's only used for
* correctly propagating new functions.
*/
private StandardFunctionFactory(Set supportedFunctions,
Map supportedAbstractFunctions) {
super(supportedFunctions, supportedAbstractFunctions);
this.supportedFunctions = supportedFunctions;
this.supportedAbstractFunctions = supportedAbstractFunctions;
}
/**
* Private initializer for the target functions. This is only ever
* called once.
*/
private static void initTargetFunctions() {
logger.config("Initializing standard Target functions");
targetFunctions = new HashSet();
// add EqualFunction
targetFunctions.addAll((new EqualFunctionCluster()).
getSupportedFunctions());
// add LogicalFunction
targetFunctions.addAll((new LogicalFunctionCluster()).
getSupportedFunctions());
// add NOfFunction
targetFunctions.addAll((new NOfFunctionCluster()).
getSupportedFunctions());
// add NotFunction
targetFunctions.addAll((new NotFunctionCluster()).
getSupportedFunctions());
// add ComparisonFunction
targetFunctions.addAll((new ComparisonFunctionCluster()).
getSupportedFunctions());
// add MatchFunction
targetFunctions.addAll((new MatchFunctionCluster()).
getSupportedFunctions());
targetAbstractFunctions = new HashMap();
}
/**
* Private initializer for the condition functions. This is only ever
* called once.
*/
private static void initConditionFunctions() {
logger.config("Initializing standard Condition functions");
if (targetFunctions == null)
initTargetFunctions();
conditionFunctions = new HashSet(targetFunctions);
// add condition function TimeInRange
conditionFunctions.add(new TimeInRangeFunction());
// add condition functions from BagFunction
conditionFunctions.addAll((new ConditionBagFunctionCluster()).
getSupportedFunctions());
// add condition functions from SetFunction
conditionFunctions.addAll((new ConditionSetFunctionCluster()).
getSupportedFunctions());
// add condition functions from HigherOrderFunction
conditionFunctions.addAll((new HigherOrderFunctionCluster()).
getSupportedFunctions());
conditionAbstractFunctions = new HashMap(targetAbstractFunctions);
}
/**
* Private initializer for the general functions. This is only ever
* called once.
*/
private static void initGeneralFunctions() {
logger.config("Initializing standard General functions");
if (conditionFunctions == null)
initConditionFunctions();
generalFunctions = new HashSet(conditionFunctions);
// add AddFunction
generalFunctions.addAll((new AddFunctionCluster()).
getSupportedFunctions());
// add SubtractFunction
generalFunctions.addAll((new SubtractFunctionCluster()).
getSupportedFunctions());
// add MultiplyFunction
generalFunctions.addAll((new MultiplyFunctionCluster()).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -