Update of /cvsroot/sunxacml/sunxacml/com/sun/xacml/combine
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10845/com/sun/xacml/combine
Modified Files:
CombiningAlgFactory.java StandardCombiningAlgFactory.java
Added Files:
BaseCombiningAlgFactory.java
Log Message:
setup new, more flexible factory scheme
Index: CombiningAlgFactory.java
===================================================================
RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/combine/CombiningAlgFactory.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** CombiningAlgFactory.java 13 Feb 2004 17:52:11 -0000 1.6
--- CombiningAlgFactory.java 15 Mar 2004 21:34:50 -0000 1.7
***************
*** 37,41 ****
package com.sun.xacml.combine;
- import com.sun.xacml.ProcessingException;
import com.sun.xacml.UnknownIdentifierException;
--- 37,40 ----
***************
*** 101,108 ****
* @param alg the combining algorithm to add
*
! * @throws ProcessingException if the algId is already registered
*/
! public abstract void addAlgorithm(CombiningAlgorithm alg)
! throws ProcessingException;
/**
--- 100,106 ----
* @param alg the combining algorithm to add
*
! * @throws IllegalArgumentException if the algorithm is already registered
*/
! public abstract void addAlgorithm(CombiningAlgorithm alg);
/**
***************
*** 121,129 ****
* @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);
}
--- 119,125 ----
* @param alg the combining algorithm to add
*
! * @throws IllegalArgumentException if the algorithm is already registered
*/
! public static void addCombiningAlg(CombiningAlgorithm alg) {
getInstance().addAlgorithm(alg);
}
Index: StandardCombiningAlgFactory.java
===================================================================
RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/combine/StandardCombiningAlgFactory.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** StandardCombiningAlgFactory.java 13 Feb 2004 17:54:33 -0000 1.1
--- StandardCombiningAlgFactory.java 15 Mar 2004 21:34:51 -0000 1.2
***************
*** 37,55 ****
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
{
--- 37,48 ----
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.
*
* @author Seth Proctor
*/
! public class StandardCombiningAlgFactory extends BaseCombiningAlgFactory
{
***************
*** 57,63 ****
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
--- 50,53 ----
***************
*** 68,73 ****
*/
private StandardCombiningAlgFactory() {
- algMap = new HashMap();
-
addAlgorithm(new DenyOverridesRuleAlg());
addAlgorithm(new DenyOverridesPolicyAlg());
--- 58,61 ----
***************
*** 89,94 ****
/**
! * Returns the single instance of this factory, creating it if it doesn't
! * exist yet.
*
* @return the factory instance
--- 77,86 ----
/**
! * Returns an instance of this factory. This method enforces a singleton
! * model, meaning that this always returns the same instance, creating
! * 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
***************
*** 106,151 ****
/**
! * 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);
! }
}
--- 98,108 ----
/**
! * 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();
}
--- NEW FILE: BaseCombiningAlgFactory.java ---
/*
* @(#)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.combine;
import com.sun.xacml.UnknownIdentifierException;
import java.net.URI;
import java.util.HashMap;
/**
* This is a basic implementation of <code>CombiningAlgFactory</code>. It
* implements the insertion and retrieval methods, but doesn't actually
* setup the factory with any algorithms.
*
* @author Seth Proctor
*/
public class BaseCombiningAlgFactory extends CombiningAlgFactory
{
// the map of available combining algorithms
private HashMap algMap;
/**
* Default constructor.
*/
public BaseCombiningAlgFactory() {
algMap = new HashMap();
}
/**
* 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) {
String algId = alg.getIdentifier().toString();
// check that the id doesn't already exist in the factory
if (algMap.containsKey(algId))
throw new IllegalArgumentException("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);
}
}
}
|