Update of /cvsroot/sunxacml/sunxacml/com/sun/xacml/attr
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30760/com/sun/xacml/attr
Modified Files:
AttributeFactory.java
Added Files:
AttributeFactoryProxy.java
Log Message:
introducing new, pluggable, still unstable factory interfaces
--- NEW FILE: AttributeFactoryProxy.java ---
/*
* @(#)AttributeFactoryProxy.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.attr;
/**
* A simple proxy interface used to install new
* <code>AttributeFactory</code>s.
*
* @author Seth Proctor
*/
public interface AttributeFactoryProxy
{
/**
* Returns an instance of the <code>AttributeFactory</code> for which
* this is a proxy.
*
* @return an <code>AttributeFactory</code> instance
*/
public AttributeFactory getFactory();
}
Index: AttributeFactory.java
===================================================================
RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/attr/AttributeFactory.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** AttributeFactory.java 29 Aug 2003 18:56:48 -0000 1.3
--- AttributeFactory.java 13 Feb 2004 17:52:10 -0000 1.4
***************
*** 1,7 ****
/*
! * @(#)AttributeFactory.java 1.21 01/31/03
*
! * Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
--- 1,7 ----
/*
! * @(#)AttributeFactory.java
*
! * Copyright 2003-2004 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
***************
*** 42,47 ****
import java.net.URI;
- import java.util.HashMap;
-
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
--- 42,45 ----
***************
*** 49,221 ****
/**
! * This factory can create <code>AttributeValue/code>s for all of the
! * standard attributes in XACML, and allows programmers to add new attribute
! * types.
*
* @author Seth Proctor
* @author Marco Barreno
*/
! public class AttributeFactory
{
! // the map of proxies
! private static HashMap attributeMap;
/**
! * The default types must always be available
*/
static {
! attributeMap = new HashMap();
!
! // boolean
! attributeMap.put(BooleanAttribute.identifier, new AttributeProxy() {
! public AttributeValue getInstance(Node root) throws Exception {
! return BooleanAttribute.getInstance(root);
! }
! public AttributeValue getInstance(String value) throws Exception {
! return BooleanAttribute.getInstance(value);
! }
! });
!
! // date
! attributeMap.put(DateAttribute.identifier, new AttributeProxy() {
! public AttributeValue getInstance(Node root) throws Exception {
! return DateAttribute.getInstance(root);
! }
! public AttributeValue getInstance(String value) throws Exception {
! return DateAttribute.getInstance(value);
! }
! });
!
! // time
! attributeMap.put(TimeAttribute.identifier, new AttributeProxy() {
! public AttributeValue getInstance(Node root) throws Exception {
! return TimeAttribute.getInstance(root);
! }
! public AttributeValue getInstance(String value) throws Exception {
! return TimeAttribute.getInstance(value);
! }
! });
!
! // dateTime
! attributeMap.put(DateTimeAttribute.identifier, new AttributeProxy() {
! public AttributeValue getInstance(Node root) throws Exception {
! return DateTimeAttribute.getInstance(root);
! }
! public AttributeValue getInstance(String value) throws Exception {
! return DateTimeAttribute.getInstance(value);
! }
! });
!
! // dayTimeDuration
! attributeMap.put(DayTimeDurationAttribute.identifier,
! new AttributeProxy() {
! public AttributeValue getInstance(Node root) throws Exception {
! return DayTimeDurationAttribute.getInstance(root);
! }
! public AttributeValue getInstance(String value) throws Exception {
! return DayTimeDurationAttribute.getInstance(value);
! }
! });
!
! // yearMonthDuration
! attributeMap.put(YearMonthDurationAttribute.identifier,
! new AttributeProxy() {
! public AttributeValue getInstance(Node root) throws Exception {
! return YearMonthDurationAttribute.getInstance(root);
! }
! public AttributeValue getInstance(String value) throws Exception {
! return YearMonthDurationAttribute.getInstance(value);
! }
! });
!
! // double
! attributeMap.put(DoubleAttribute.identifier, new AttributeProxy() {
! public AttributeValue getInstance(Node root) throws Exception {
! return DoubleAttribute.getInstance(root);
! }
! public AttributeValue getInstance(String value) throws Exception {
! return DoubleAttribute.getInstance(value);
! }
! });
!
! // integer
! attributeMap.put(IntegerAttribute.identifier, new AttributeProxy() {
! public AttributeValue getInstance(Node root) throws Exception {
! return IntegerAttribute.getInstance(root);
! }
! public AttributeValue getInstance(String value) throws Exception {
! return IntegerAttribute.getInstance(value);
! }
! });
!
! // string
! attributeMap.put(StringAttribute.identifier, new AttributeProxy() {
! public AttributeValue getInstance(Node root) {
! return StringAttribute.getInstance(root);
! }
! public AttributeValue getInstance(String value) {
! return StringAttribute.getInstance(value);
! }
! });
!
! // anyURI
! attributeMap.put(AnyURIAttribute.identifier, new AttributeProxy() {
! public AttributeValue getInstance(Node root) throws Exception {
! return AnyURIAttribute.getInstance(root);
! }
! public AttributeValue getInstance(String value) throws Exception {
! return AnyURIAttribute.getInstance(value);
! }
! });
!
! // hexBinary
! attributeMap.put(HexBinaryAttribute.identifier, new AttributeProxy() {
! public AttributeValue getInstance(Node root) throws Exception {
! return HexBinaryAttribute.getInstance(root);
! }
! public AttributeValue getInstance(String value) throws Exception {
! return HexBinaryAttribute.getInstance(value);
! }
! });
!
! // base64Binary
! attributeMap.put(Base64BinaryAttribute.identifier,
! new AttributeProxy() {
! public AttributeValue getInstance(Node root) throws Exception {
! return Base64BinaryAttribute.getInstance(root);
! }
! public AttributeValue getInstance(String value) throws Exception {
! return Base64BinaryAttribute.getInstance(value);
! }
! });
!
! // x500Name
! attributeMap.put(X500NameAttribute.identifier, new AttributeProxy() {
! public AttributeValue getInstance(Node root) throws Exception {
! return X500NameAttribute.getInstance(root);
! }
! public AttributeValue getInstance(String value) throws Exception {
! return X500NameAttribute.getInstance(value);
! }
! });
! // rfc822Name
! attributeMap.put(RFC822NameAttribute.identifier, new AttributeProxy() {
! public AttributeValue getInstance(Node root) {
! return RFC822NameAttribute.getInstance(root);
! }
! public AttributeValue getInstance(String value) {
! return RFC822NameAttribute.getInstance(value);
! }
! });
}
/**
! * In this simple factory model we only have one instance of the factory,
! * and we don't need to expose this interface.
*/
! private AttributeFactory() {
}
--- 47,99 ----
/**
! * This is an abstract factory class for creating XACML attribute values.
! * There may be any number of factories available in the system, though
! * there is always one default factory used by the core code.
*
* @author Seth Proctor
* @author Marco Barreno
*/
! public abstract class AttributeFactory
{
! // the proxy used to get the default factory
! private static AttributeFactoryProxy 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 AttributeFactoryProxy() {
! public AttributeFactory getFactory() {
! return StandardAttributeFactory.getFactory();
! }
! };
! };
! /**
! * Default constructor. Used only by subclasses.
! */
! protected AttributeFactory() {
!
}
/**
! * 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>AttributeFactory</code>
*/
! public static final AttributeFactory 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(AttributeFactoryProxy proxy) {
+ defaultFactoryProxy = proxy;
}
***************
*** 230,235 ****
* @param proxy the proxy used to create new attributes of the given type
*/
public static void addAttributeProxy(String id, AttributeProxy proxy) {
! attributeMap.put(id, proxy);
}
--- 108,135 ----
* @param proxy the proxy used to create new attributes of the given type
*/
+ public abstract void addDatatype(String id, AttributeProxy proxy);
+
+ /**
+ * Adds a proxy to the default factory, which in turn will allow new
+ * attribute types to be created using the factory. Typically the proxy
+ * is provided as an anonymous class that simply calls the getInstance
+ * methods (or something similar) of some <code>AttributeValue</code>
+ * class.
+ *
+ * @deprecated As of version 1.2, replaced by
+ * {@link #addDatatype(String,AttributeProxy)}.
+ * 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 id the name of the attribute type
+ * @param proxy the proxy used to create new attributes of the given type
+ */
public static void addAttributeProxy(String id, AttributeProxy proxy) {
! // FIXME: this may have to change when the final mechanism is in
! // place for the default factory...
! getInstance().addDatatype(id, proxy);
}
***************
*** 250,259 ****
* by the appropriate proxy
*/
public static AttributeValue createAttribute(Node root)
throws UnknownIdentifierException, ParsingException
{
! Node node = root.getAttributes().getNamedItem("DataType");
!
! return createAttribute(root, node.getNodeValue());
}
--- 150,184 ----
* by the appropriate proxy
*/
+ public abstract AttributeValue createValue(Node root)
+ throws UnknownIdentifierException, ParsingException;
+
+ /**
+ * Creates a value based on the given DOM root node. The type of the
+ * attribute is assumed to be present in the node as an XAML attribute
+ * named <code>DataType</code>, as is the case with the
+ * AttributeValueType in the policy schema. The value is assumed to be
+ * the first child of this node. This uses the default factory.
+ *
+ * @deprecated As of version 1.2, replaced by
+ * {@link #createValue(Node)}.
+ * 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 root the DOM root of an attribute value
+ *
+ * @return a new <code>AttributeValue</code>
+ *
+ * @throws UnknownIdentifierException if the type in the node isn't
+ * known to the factory
+ * @throws ParsingException if the node is invalid or can't be parsed
+ * by the appropriate proxy
+ */
public static AttributeValue createAttribute(Node root)
throws UnknownIdentifierException, ParsingException
{
! return getInstance().createValue(root);
}
***************
*** 271,278 ****
* by the appropriate proxy
*/
public static AttributeValue createAttribute(Node root, URI dataType)
throws UnknownIdentifierException, ParsingException
{
! return createAttribute(root, dataType.toString());
}
--- 196,228 ----
* by the appropriate proxy
*/
+ public abstract AttributeValue createValue(Node root, URI dataType)
+ throws UnknownIdentifierException, ParsingException;
+
+ /**
+ * Creates a value based on the given DOM root node and data type. This
+ * uses the default factory.
+ *
+ * @deprecated As of version 1.2, replaced by
+ * {@link #createValue(Node,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 root the DOM root of an attribute value
+ * @param dataType the type of the attribute
+ *
+ * @return a new <code>AttributeValue</code>
+ *
+ * @throws UnknownIdentifierException if the data type isn't known to
+ * the factory
+ * @throws ParsingException if the node is invalid or can't be parsed
+ * by the appropriate proxy
+ */
public static AttributeValue createAttribute(Node root, URI dataType)
throws UnknownIdentifierException, ParsingException
{
! return getInstance().createValue(root, dataType);
}
***************
*** 290,309 ****
* by the appropriate proxy
*/
public static AttributeValue createAttribute(Node root, String type)
throws UnknownIdentifierException, ParsingException
{
! AttributeProxy proxy = (AttributeProxy)(attributeMap.get(type));
!
! if (proxy != null) {
! try {
! return proxy.getInstance(root);
! } catch (Exception e) {
! throw new ParsingException("couldn't create " + type +
! " attribute based on DOM node");
! }
! } else {
! throw new UnknownIdentifierException("Attributes of type " + type +
! " aren't supported.");
! }
}
--- 240,272 ----
* by the appropriate proxy
*/
+ public abstract AttributeValue createValue(Node root, String type)
+ throws UnknownIdentifierException, ParsingException;
+
+ /**
+ * Creates a value based on the given DOM root node and data type. This
+ * uses the default factory.
+ *
+ * @deprecated As of version 1.2, replaced by
+ * {@link #createValue(Node,String)}.
+ * 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 root the DOM root of an attribute value
+ * @param type the type of the attribute
+ *
+ * @return a new <code>AttributeValue</code>
+ *
+ * @throws UnknownIdentifierException if the type isn't known to
+ * the factory
+ * @throws ParsingException if the node is invalid or can't be parsed
+ * by the appropriate proxy
+ */
public static AttributeValue createAttribute(Node root, String type)
throws UnknownIdentifierException, ParsingException
{
! return getInstance().createValue(root, type);
}
***************
*** 324,344 ****
* by the appropriate proxy
*/
public static AttributeValue createAttribute(URI dataType, String value)
throws UnknownIdentifierException, ParsingException
{
! String type = dataType.toString();
! AttributeProxy proxy = (AttributeProxy)(attributeMap.get(type));
!
! if (proxy != null) {
! try {
! return proxy.getInstance(value);
! } catch (Exception e) {
! throw new ParsingException("couldn't create " + type +
! " attribute from input: " + value);
! }
! } else {
! throw new UnknownIdentifierException("Attributes of type " + type +
! " aren't supported.");
! }
}
--- 287,321 ----
* by the appropriate proxy
*/
+ public abstract AttributeValue createValue(URI dataType, String value)
+ throws UnknownIdentifierException, ParsingException;
+
+ /**
+ * Creates a value based on the given data type and text-encoded value.
+ * Used primarily by code that does an XPath query to get an
+ * attribute value, and then needs to turn the resulting value into
+ * an Attribute class. This uses the default factory.
+ *
+ * @deprecated As of version 1.2, replaced by
+ * {@link #createValue(URI,String)}.
+ * 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 dataType the type of the attribute
+ * @param value the text-encoded representation of an attribute's value
+ *
+ * @return a new <code>AttributeValue</code>
+ *
+ * @throws UnknownIdentifierException if the data type isn't known to
+ * the factory
+ * @throws ParsingException if the text is invalid or can't be parsed
+ * by the appropriate proxy
+ */
public static AttributeValue createAttribute(URI dataType, String value)
throws UnknownIdentifierException, ParsingException
{
! return getInstance().createValue(dataType, value);
}
|