Update of /cvsroot/sunxacml/sunxacml/com/sun/xacml/combine
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30760/com/sun/xacml/combine
Modified Files:
CombiningAlgFactory.java
Added Files:
CombiningAlgFactoryProxy.java
Log Message:
introducing new, pluggable, still unstable factory interfaces
--- NEW FILE: CombiningAlgFactoryProxy.java ---
/*
* @(#)CombiningAlgFactoryProxy.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;
/**
* A simple proxy interface used to install new
* <code>CombiningAlgFactory</code>s.
*
* @author Seth Proctor
*/
public interface CombiningAlgFactoryProxy
{
/**
* Returns an instance of the <code>CombiningAlgFactory</code> for which
* this is a proxy.
*
* @return a <code>CombiningAlgFactory</code> instance
*/
public CombiningAlgFactory getFactory();
}
Index: CombiningAlgFactory.java
===================================================================
RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/combine/CombiningAlgFactory.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** CombiningAlgFactory.java 25 Oct 2003 21:35:55 -0000 1.5
--- CombiningAlgFactory.java 13 Feb 2004 17:52:11 -0000 1.6
***************
*** 3,7 ****
* @(#)CombiningAlgFactory.java
*
! * Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
--- 3,7 ----
* @(#)CombiningAlgFactory.java
*
! * Copyright 2003-2004 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
***************
*** 42,97 ****
import java.net.URI;
- import java.util.HashMap;
-
/**
* Provides a factory mechanism for installing and retrieving combining
! * algorithms. By default this supports all the standard combining
! * algorithms listed in the XACML specification.
*
* @author Seth Proctor
*/
! public class CombiningAlgFactory
{
! // the single map of available combining algorithms
! private static HashMap algMap;
/**
! * Static initializer that sets up all the default algs
*/
static {
! algMap = new HashMap();
!
! /**
! * NOTE: there only needs to be one instance of each Alg, so for now
! * this doesn't use the proxy mechanism, and is instead a simple
! * mapping to a single instance.
! */
!
! addCombiningAlg(new DenyOverridesRuleAlg());
! addCombiningAlg(new DenyOverridesPolicyAlg());
!
! addCombiningAlg(new OrderedDenyOverridesRuleAlg());
! addCombiningAlg(new OrderedDenyOverridesPolicyAlg());
!
! addCombiningAlg(new PermitOverridesRuleAlg());
! addCombiningAlg(new PermitOverridesPolicyAlg());
!
! addCombiningAlg(new OrderedPermitOverridesRuleAlg());
! addCombiningAlg(new OrderedPermitOverridesPolicyAlg());
!
! addCombiningAlg(new FirstApplicableRuleAlg());
! addCombiningAlg(new FirstApplicablePolicyAlg());
! addCombiningAlg(new OnlyOneApplicablePolicyAlg());
}
/**
! * Default constructor. There is only one instance of this factory,
! * so there is never any need to construct this class.
*/
! protected CombiningAlgFactory() {
}
--- 42,95 ----
import java.net.URI;
/**
* Provides a factory mechanism for installing and retrieving combining
! * algorithms.
*
* @author Seth Proctor
*/
! public abstract class CombiningAlgFactory
{
! // the proxy used to get the default factory
! private static CombiningAlgFactoryProxy defaultFactoryProxy;
/**
! * static intialiazer that sets up the default factory proxy
! * NOTE: this will change when the right setup mechanism is in place
*/
static {
! defaultFactoryProxy = new CombiningAlgFactoryProxy() {
! public CombiningAlgFactory getFactory() {
! return StandardCombiningAlgFactory.getFactory();
! }
! };
! };
! /**
! * Default constructor. Used only by subclasses.
! */
! protected CombiningAlgFactory() {
!
}
/**
! * Returns the default factory. Depending on the default factory's
! * implementation, this may return a singleton instance or new instances
! * with each invokation.
! *
! * @return the default <code>CombiningAlgFactory</code>
*/
! public static final CombiningAlgFactory getInstance() {
! return defaultFactoryProxy.getFactory();
! }
+ /**
+ * Sets the default factory. Note that this is just a placeholder for
+ * now, and will be replaced with a more useful mechanism soon.
+ */
+ public static final void setDefaultFactory(CombiningAlgFactoryProxy proxy)
+ {
+ defaultFactoryProxy = proxy;
}
***************
*** 105,119 ****
* @throws ProcessingException if the algId is already registered
*/
public static void addCombiningAlg(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);
}
--- 103,130 ----
* @throws ProcessingException if the algId is already registered
*/
+ public abstract void addAlgorithm(CombiningAlgorithm alg)
+ throws ProcessingException;
+
+ /**
+ * 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.
+ *
+ * @deprecated As of version 1.2, replaced by
+ * {@link #addAlgorithm(CombiningAlgorithm)}.
+ * The new factory system requires you to get a factory
+ * instance and then call the non-static methods on that
+ * factory. The static versions of these methods have been
+ * left in for now, but are slower and will be removed in
+ * a future version.
+ *
+ * @param alg the combining algorithm to add
+ *
+ * @throws ProcessingException if the algId is already registered
+ */
public static void addCombiningAlg(CombiningAlgorithm alg)
throws ProcessingException
{
! getInstance().addAlgorithm(alg);
}
***************
*** 128,142 ****
* @throws UnknownIdentifierException algId is unknown
*/
public static CombiningAlgorithm createCombiningAlg(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);
! }
}
--- 139,167 ----
* @throws UnknownIdentifierException algId is unknown
*/
+ public abstract CombiningAlgorithm createAlgorithm(URI algId)
+ throws UnknownIdentifierException;
+
+ /**
+ * Tries to return the correct combinging algorithm based on the
+ * given algorithm ID.
+ *
+ * @deprecated As of version 1.2, replaced by
+ * {@link #createAlgorithm(URI)}.
+ * The new factory system requires you to get a factory
+ * instance and then call the non-static methods on that
+ * factory. The static versions of these methods have been
+ * left in for now, but are slower and will be removed in
+ * a future version.
+ *
+ * @param algId the identifier by which the algorithm is known
+ *
+ * @return a combining algorithm
+ *
+ * @throws UnknownIdentifierException algId is unknown
+ */
public static CombiningAlgorithm createCombiningAlg(URI algId)
throws UnknownIdentifierException
{
! return getInstance().createAlgorithm(algId);
}
|