Update of /cvsroot/sunxacml/sunxacml/com/sun/xacml/combine
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31308/com/sun/xacml/combine
Added Files:
StandardCombiningAlgFactory.java
Log Message:
introduced new, still unstable, factories for standard 1.0/1.1 behavior
--- NEW FILE: StandardCombiningAlgFactory.java ---
/*
* @(#)StandardCombiningAlgFactory.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.combine;
import com.sun.xacml.ProcessingException;
import com.sun.xacml.UnknownIdentifierException;
import java.net.URI;
import java.util.HashMap;
/**
* This factory supports the standard set of datatypes specified in XACML
* 1.0 and 1.1. It is the default factory used by the system.
*
* @author Seth Proctor
*/
public class StandardCombiningAlgFactory extends CombiningAlgFactory
{
// the single factory instance
private static StandardCombiningAlgFactory factoryInstance = null;
// the map of available combining algorithms
private HashMap algMap;
// dummy object used as a lock for the getFactory routine
// FIXME: this needs a better mechanism
private static Object factoryLock = new Object();
/**
* Default constructor.
*/
private StandardCombiningAlgFactory() {
algMap = new HashMap();
addAlgorithm(new DenyOverridesRuleAlg());
addAlgorithm(new DenyOverridesPolicyAlg());
addAlgorithm(new OrderedDenyOverridesRuleAlg());
addAlgorithm(new OrderedDenyOverridesPolicyAlg());
addAlgorithm(new PermitOverridesRuleAlg());
addAlgorithm(new PermitOverridesPolicyAlg());
addAlgorithm(new OrderedPermitOverridesRuleAlg());
addAlgorithm(new OrderedPermitOverridesPolicyAlg());
addAlgorithm(new FirstApplicableRuleAlg());
addAlgorithm(new FirstApplicablePolicyAlg());
addAlgorithm(new OnlyOneApplicablePolicyAlg());
}
/**
* Returns the single instance of this factory, creating it if it doesn't
* exist yet.
*
* @return the factory instance
*/
public static CombiningAlgFactory getFactory() {
if (factoryInstance == null) {
synchronized (factoryLock) {
if (factoryInstance == null)
factoryInstance = new StandardCombiningAlgFactory();
}
}
return factoryInstance;
}
/**
* Adds a combining algorithm to the factory. This single instance will
* be returned to anyone who asks the factory for an algorithm with the
* id given here.
*
* @param alg the combining algorithm to add
*
* @throws ProcessingException if the algId is already registered
*/
public void addAlgorithm(CombiningAlgorithm alg)
throws ProcessingException
{
String algId = alg.getIdentifier().toString();
// check that the id doesn't already exist in the factory
if (algMap.containsKey(algId))
throw new ProcessingException("algorithm already registered");
// add the algorithm
algMap.put(algId, alg);
}
/**
* Tries to return the correct combinging algorithm based on the
* given algorithm ID.
*
* @param algId the identifier by which the algorithm is known
*
* @return a combining algorithm
*
* @throws UnknownIdentifierException algId is unknown
*/
public CombiningAlgorithm createAlgorithm(URI algId)
throws UnknownIdentifierException
{
String id = algId.toString();
if (algMap.containsKey(id)) {
return (CombiningAlgorithm)(algMap.get(algId.toString()));
} else {
throw new UnknownIdentifierException("unknown combining algId: "
+ id);
}
}
}
|