Update of /cvsroot/sunxacml/sunxacml/com/sun/xacml/combine
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16626/com/sun/xacml/combine
Modified Files:
BaseCombiningAlgFactory.java StandardCombiningAlgFactory.java
Log Message:
re-factored so standard factories are immutable
Index: StandardCombiningAlgFactory.java
===================================================================
RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/combine/StandardCombiningAlgFactory.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** StandardCombiningAlgFactory.java 17 Mar 2004 18:03:38 -0000 1.3
--- StandardCombiningAlgFactory.java 24 May 2004 20:55:07 -0000 1.4
***************
*** 37,44 ****
package com.sun.xacml.combine;
/**
* This factory supports the standard set of algorithms specified in XACML
! * 1.0 and 1.1. It is the default factory used by the system.
*
* @since 1.2
--- 37,59 ----
package com.sun.xacml.combine;
+ import java.util.Collections;
+ import java.util.HashSet;
+ import java.util.Iterator;
+ import java.util.Set;
+
/**
* This factory supports the standard set of algorithms specified in XACML
! * 1.0 and 1.1. 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 algorithms, this
! * factory does not allow the addition of any other algorithms. If you call
! * <code>addAlgorithm</code> on an instance of this class, an exception
! * will be thrown. If you need a standard factory that is modifiable, you
! * should create a new <code>BaseCombiningAlgFactory</code> (or some other
! * <code>CombiningAlgFactory</code>) and then configure it with the standard
! * algorithms using <code>getStandardAlgorithms</code>.
*
* @since 1.2
***************
*** 51,78 ****
private static StandardCombiningAlgFactory factoryInstance = null;
! // 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() {
! 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());
}
--- 66,102 ----
private static StandardCombiningAlgFactory factoryInstance = null;
! // the algorithms supported by this factory
! private static Set supportedAlgorithms = null;
!
/**
* Default constructor.
*/
private StandardCombiningAlgFactory() {
! super(supportedAlgorithms);
! }
! /**
! * Private initializer for the supported algorithms. This isn't called
! * until something needs these values, and is only called once.
! */
! private static void initAlgorithms() {
! supportedAlgorithms = new HashSet();
!
! supportedAlgorithms.add(new DenyOverridesRuleAlg());
! supportedAlgorithms.add(new DenyOverridesPolicyAlg());
!
! supportedAlgorithms.add(new OrderedDenyOverridesRuleAlg());
! supportedAlgorithms.add(new OrderedDenyOverridesPolicyAlg());
!
! supportedAlgorithms.add(new PermitOverridesRuleAlg());
! supportedAlgorithms.add(new PermitOverridesPolicyAlg());
!
! supportedAlgorithms.add(new OrderedPermitOverridesRuleAlg());
! supportedAlgorithms.add(new OrderedPermitOverridesPolicyAlg());
!
! supportedAlgorithms.add(new FirstApplicableRuleAlg());
! supportedAlgorithms.add(new FirstApplicablePolicyAlg());
!
! supportedAlgorithms.add(new OnlyOneApplicablePolicyAlg());
}
***************
*** 82,109 ****
* the factory if it hasn't been requested before. This is the default
* model used by the <code>CombiningAlgFactory</code>, ensuring quick
! * access to this factory. If you need a new instance of this factory
! * you should use the <code>getNewFactory</code> method.
*
* @return the factory instance
*/
! public static CombiningAlgFactory getFactory() {
if (factoryInstance == null) {
! synchronized (factoryLock) {
! if (factoryInstance == null)
factoryInstance = new StandardCombiningAlgFactory();
}
}
!
return factoryInstance;
}
/**
! * Returns a new instance of <code>CombiningAlgFactory</code> that
! * supports all the standard algorithms.
*
! * @return a new <code>StandardCombiningAlgFactory</code>
*/
! public static CombiningAlgFactory getNewFactory() {
! return new StandardCombiningAlgFactory();
}
--- 106,146 ----
* the factory if it hasn't been requested before. This is the default
* model used by the <code>CombiningAlgFactory</code>, ensuring quick
! * access to this factory.
*
* @return the factory instance
*/
! public static StandardCombiningAlgFactory getFactory() {
if (factoryInstance == null) {
! synchronized (StandardCombiningAlgFactory.class) {
! if (factoryInstance == null) {
! initAlgorithms();
factoryInstance = new StandardCombiningAlgFactory();
+ }
}
}
!
return factoryInstance;
}
/**
! * Returns the set of algorithms that this standard factory supports.
*
! * @return a <code>Set</code> of <code>CombiningAlgorithm</code>s
*/
! public Set getStandardAlgorithms() {
! return Collections.unmodifiableSet(supportedAlgorithms);
! }
!
! /**
! * Throws an <code>UnsupportedOperationException</code> since you are not
! * allowed to modify what a standard factory supports.
! *
! * @param alg the combining algorithm to add
! *
! * @throws UnsupportedOperationException always
! */
! public void addAlgorithm(CombiningAlgorithm alg) {
! throw new UnsupportedOperationException("a standard factory cannot " +
! "support new algorithms");
}
Index: BaseCombiningAlgFactory.java
===================================================================
RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/combine/BaseCombiningAlgFactory.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** BaseCombiningAlgFactory.java 17 May 2004 20:33:45 -0000 1.3
--- BaseCombiningAlgFactory.java 24 May 2004 20:55:07 -0000 1.4
***************
*** 43,46 ****
--- 43,47 ----
import java.util.Collections;
import java.util.HashMap;
+ import java.util.Iterator;
import java.util.Set;
***************
*** 50,53 ****
--- 51,62 ----
* implements the insertion and retrieval methods, but doesn't actually
* setup the factory with any algorithms.
+ * <p>
+ * Note that while this class is thread-safe on all creation methods, it
+ * is not safe to add support for a new algorithm while creating an instance
+ * of an algorithm. 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
***************
*** 68,71 ****
--- 77,106 ----
/**
+ * Constructor that configures this factory with an initial set of
+ * supported algorithms.
+ *
+ * @param algorithms a <code>Set</code> of
+ * </code>CombiningAlgorithm</code>s
+ *
+ * @throws IllegalArgumentException if any elements of the set are not
+ * </code>CombiningAlgorithm</code>s
+ */
+ public BaseCombiningAlgFactory(Set algorithms) {
+ algMap = new HashMap();
+
+ Iterator it = algorithms.iterator();
+ while (it.hasNext()) {
+ try {
+ CombiningAlgorithm alg = (CombiningAlgorithm)(it.next());
+ algMap.put(alg.getIdentifier().toString(), alg);
+ } catch (ClassCastException cce) {
+ throw new IllegalArgumentException("an element of the set " +
+ "was not an instance of " +
+ "CombiningAlgorithm");
+ }
+ }
+ }
+
+ /**
* Adds a combining algorithm to the factory. This single instance will
* be returned to anyone who asks the factory for an algorithm with the
***************
*** 74,78 ****
* @param alg the combining algorithm to add
*
! * @throws ProcessingException if the algId is already registered
*/
public void addAlgorithm(CombiningAlgorithm alg) {
--- 109,113 ----
* @param alg the combining algorithm to add
*
! * @throws IllegalArgumentException if the algId is already registered
*/
public void addAlgorithm(CombiningAlgorithm alg) {
***************
*** 81,85 ****
// check that the id doesn't already exist in the factory
if (algMap.containsKey(algId))
! throw new IllegalArgumentException("algorithm already registered");
// add the algorithm
--- 116,121 ----
// check that the id doesn't already exist in the factory
if (algMap.containsKey(algId))
! throw new IllegalArgumentException("algorithm already registered: "
! + algId);
// add the algorithm
|