Update of /cvsroot/sunxacml/sunxacml/com/sun/xacml/attr
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16626/com/sun/xacml/attr
Modified Files:
BaseAttributeFactory.java StandardAttributeFactory.java
Log Message:
re-factored so standard factories are immutable
Index: StandardAttributeFactory.java
===================================================================
RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/attr/StandardAttributeFactory.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** StandardAttributeFactory.java 17 Mar 2004 18:03:38 -0000 1.3
--- StandardAttributeFactory.java 24 May 2004 20:55:07 -0000 1.4
***************
*** 52,55 ****
--- 52,60 ----
import com.sun.xacml.attr.proxy.X500NameAttributeProxy;
+ import java.util.Collections;
+ import java.util.HashMap;
+ import java.util.Iterator;
+ import java.util.Map;
+
import org.w3c.dom.Node;
***************
*** 57,61 ****
/**
* 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.
*
* @since 1.2
--- 62,76 ----
/**
* 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, 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 datatypes, this
! * factory does not allow the addition of any other datatypes. If you call
! * <code>addDatatype</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>BaseAttributeFactory</code> (or some other
! * <code>AttributeFactory</code>) and then configure it with the standard
! * datatypes using <code>addStandardDatatypes</code>.
*
* @since 1.2
***************
*** 68,74 ****
private static StandardAttributeFactory factoryInstance = null;
! // dummy object used as a lock for the getFactory routine
! // FIXME: this needs a better mechanism
! private static Object factoryLock = new Object();
/**
--- 83,88 ----
private static StandardAttributeFactory factoryInstance = null;
! // the datatypes supported by this factory
! private static Map supportedDatatypes = null;
/**
***************
*** 77,101 ****
*/
private StandardAttributeFactory() {
! addDatatype(BooleanAttribute.identifier, new BooleanAttributeProxy());
! addDatatype(StringAttribute.identifier, new StringAttributeProxy());
! addDatatype(DateAttribute.identifier, new DateAttributeProxy());
! addDatatype(TimeAttribute.identifier, new TimeAttributeProxy());
! addDatatype(DateTimeAttribute.identifier,
! new DateTimeAttributeProxy());
! addDatatype(DayTimeDurationAttribute.identifier,
! new DayTimeDurationAttributeProxy());
! addDatatype(YearMonthDurationAttribute.identifier,
! new YearMonthDurationAttributeProxy());
! addDatatype(DoubleAttribute.identifier, new DoubleAttributeProxy());
! addDatatype(IntegerAttribute.identifier, new IntegerAttributeProxy());
! addDatatype(AnyURIAttribute.identifier, new AnyURIAttributeProxy());
! addDatatype(HexBinaryAttribute.identifier,
! new HexBinaryAttributeProxy());
! addDatatype(Base64BinaryAttribute.identifier,
! new Base64BinaryAttributeProxy());
! addDatatype(X500NameAttribute.identifier,
! new X500NameAttributeProxy());
! addDatatype(RFC822NameAttribute.identifier,
! new RFC822NameAttributeProxy());
}
--- 91,132 ----
*/
private StandardAttributeFactory() {
! super(supportedDatatypes);
! }
!
! /**
! * Private initializer for the supported datatypes. This isn't called
! * until something needs these values, and is only called once.
! */
! private static void initDatatypes() {
! supportedDatatypes = new HashMap();
!
! supportedDatatypes.put(BooleanAttribute.identifier,
! new BooleanAttributeProxy());
! supportedDatatypes.put(StringAttribute.identifier,
! new StringAttributeProxy());
! supportedDatatypes.put(DateAttribute.identifier,
! new DateAttributeProxy());
! supportedDatatypes.put(TimeAttribute.identifier,
! new TimeAttributeProxy());
! supportedDatatypes.put(DateTimeAttribute.identifier,
! new DateTimeAttributeProxy());
! supportedDatatypes.put(DayTimeDurationAttribute.identifier,
! new DayTimeDurationAttributeProxy());
! supportedDatatypes.put(YearMonthDurationAttribute.identifier,
! new YearMonthDurationAttributeProxy());
! supportedDatatypes.put(DoubleAttribute.identifier,
! new DoubleAttributeProxy());
! supportedDatatypes.put(IntegerAttribute.identifier,
! new IntegerAttributeProxy());
! supportedDatatypes.put(AnyURIAttribute.identifier,
! new AnyURIAttributeProxy());
! supportedDatatypes.put(HexBinaryAttribute.identifier,
! new HexBinaryAttributeProxy());
! supportedDatatypes.put(Base64BinaryAttribute.identifier,
! new Base64BinaryAttributeProxy());
! supportedDatatypes.put(X500NameAttribute.identifier,
! new X500NameAttributeProxy());
! supportedDatatypes.put(RFC822NameAttribute.identifier,
! new RFC822NameAttributeProxy());
}
***************
*** 110,118 ****
* @return the factory instance
*/
! public static AttributeFactory getFactory() {
if (factoryInstance == null) {
! synchronized (factoryLock) {
! if (factoryInstance == null)
factoryInstance = new StandardAttributeFactory();
}
}
--- 141,151 ----
* @return the factory instance
*/
! public static StandardAttributeFactory getFactory() {
if (factoryInstance == null) {
! synchronized (StandardAttributeFactory.class) {
! if (factoryInstance == null) {
! initDatatypes();
factoryInstance = new StandardAttributeFactory();
+ }
}
}
***************
*** 122,132 ****
/**
! * Returns a new instance of <code>AttributeFactory</code> that
! * supports all the standard datatypes.
*
! * @return a new <code>StandardAttributeFactory</code>
*/
! public static AttributeFactory getNewFactory() {
! return new StandardAttributeFactory();
}
--- 155,179 ----
/**
! * Returns the set of datatypes that this standard factory supports.
*
! * @return a <code>Map</code> of <code>String</code> to
! * <code>AttributeProxy</code>s
*/
! public Map getStandardDatatypes() {
! return Collections.unmodifiableMap(supportedDatatypes);
! }
!
! /**
! * Throws an <code>UnsupportedOperationException</code> since you are not
! * allowed to modify what a standard factory supports.
! *
! * @param id the name of the attribute type
! * @param proxy the proxy used to create new attributes of the given type
! *
! * @throws UnsupportedOperationException always
! */
! public void addDatatype(String id, AttributeProxy proxy) {
! throw new UnsupportedOperationException("a standard factory cannot " +
! "support new datatypes");
}
Index: BaseAttributeFactory.java
===================================================================
RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/attr/BaseAttributeFactory.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** BaseAttributeFactory.java 17 May 2004 20:33:45 -0000 1.3
--- BaseAttributeFactory.java 24 May 2004 20:55:07 -0000 1.4
***************
*** 44,47 ****
--- 44,49 ----
import java.util.Collections;
import java.util.HashMap;
+ import java.util.Iterator;
+ import java.util.Map;
import java.util.Set;
***************
*** 53,56 ****
--- 55,66 ----
* implements the insertion and retrieval methods, but doesn't actually
* setup the factory with any datatypes.
+ * <p>
+ * Note that while this class is thread-safe on all creation methods, it
+ * is not safe to add support for a new datatype while creating an instance
+ * of a value. 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
***************
*** 71,74 ****
--- 81,111 ----
/**
+ * Constructor that configures this factory with an initial set of
+ * supported datatypes.
+ *
+ * @param attributes a <code>Map</code> of <code>String</code>s to
+ * </code>AttributeProxy</code>s
+ *
+ * @throws IllegalArgumentException if any elements of the Map are not
+ * </code>AttributeProxy</code>s
+ */
+ public BaseAttributeFactory(Map attributes) {
+ attributeMap = new HashMap();
+
+ Iterator it = attributes.keySet().iterator();
+ while (it.hasNext()) {
+ try {
+ String id = (it.next()).toString();
+ AttributeProxy proxy = (AttributeProxy)(attributes.get(id));
+ attributeMap.put(id, proxy);
+ } catch (ClassCastException cce) {
+ throw new IllegalArgumentException("an element of the map " +
+ "was not an instance of " +
+ "AttributeProxy");
+ }
+ }
+ }
+
+ /**
* Adds a proxy to the factory, which in turn will allow new attribute
* types to be created using the factory. Typically the proxy is
|