org.opensaml
Class SAMLAttribute

java.lang.Object
  extended by org.opensaml.SAMLObject
      extended by org.opensaml.SAMLAttribute
All Implemented Interfaces:
Cloneable

public class SAMLAttribute
extends SAMLObject
implements Cloneable

Basic SAML Attribute implementation that handles rudimentary attribute value types

Author:
Scott Cantor

Field Summary
protected  long lifetime
          Effective lifetime of attribute's value(s) in seconds (0 means infinite)
protected  String name
          Name of attribute
protected  String namespace
          Namespace/qualifier of attribute
protected  javax.xml.namespace.QName type
          The schema type of attribute value(s)
protected  ArrayList values
          An array of attribute values
 
Fields inherited from class org.opensaml.SAMLObject
config, dirty, log, parentObject, root
 
Constructor Summary
SAMLAttribute()
          Default constructor
SAMLAttribute(Element e)
          Reconstructs an attribute from a DOM tree
SAMLAttribute(InputStream in)
          Reconstructs an attribute from a stream
SAMLAttribute(String name, String namespace, javax.xml.namespace.QName type, long lifetime, Collection values)
          Builds an Attribute out of its component parts
 
Method Summary
 void addValue(Object value)
          Adds a value to the attribute
protected  Element buildRoot(Document doc, boolean xmlns)
          Delegates the process of building the root element of an object and inserting appropriate namespaces.
 void checkValidity()
          Evaluates the object's content to see if it is currently valid if serialized.
 Object clone()
          Copies a SAML object such that no dependencies exist between the original and the copy.
protected  String computeTypeDecl(Element e)
          Computes the xsi:type attribute on each AttributeValue element with any supporting declarations created.
 void fromDOM(Element e)
          Initialization of attribute from a DOM element.
static String getFactory()
          Obtains a class name to handle SAML attribute construction from XML
static SAMLAttribute getInstance(Element e)
          Locates an implementation class for an attribute and constructs it based on the DOM provided.
static SAMLAttribute getInstance(InputStream in)
          Locates an implementation class for an attribute and constructs it based on the stream provided.
 long getLifetime()
          Gets the value's lifetime, in seconds
 String getName()
          Gets the AttributeName attribute of the SAML Attribute
 String getNamespace()
          Gets the AttributeNamespace attribute of the SAML Attribute
 javax.xml.namespace.QName getType()
          Gets the value of the xsi:type attribute, if any, of the SAML Attribute
 NodeList getValueElements()
          Gets the set of existing AttributeValue elements, if the DOM exists.
 Iterator getValues()
          Gets the values of the SAML Attribute
 void removeValue(int index)
          Removes a value by position (zero-based)
static String setFactory(String className)
          Registers a class name to handle SAML attribute construction from XML
 void setLifetime(long lifetime)
          Sets the value's lifetime, in seconds
 void setName(String name)
          Sets the AttributeName attribute of the SAML Attribute
 void setNamespace(String namespace)
          Sets the AttributeNamespace attribute of the SAML Attribute
 void setType(javax.xml.namespace.QName type)
          Sets the value of the xsi:type attribute, if any, of the SAML Attribute
 void setValues(Collection values)
          Sets the values of the attribute
 Node toDOM(Document doc, boolean xmlns)
          Transforms the object into a DOM tree using an existing document context
protected  void valueFromDOM(Element e)
          Creates the internal representation of an attribute value from the specified element.
protected  void valueToDOM(int index, Element e)
          Creates the DOM representation of an attribute value in the specified element.
 
Methods inherited from class org.opensaml.SAMLObject
fromStream, fromStream, getParent, plantRoot, setDirty, setParent, toBase64, toDOM, toDOM, toDOM, toStream, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

name

protected String name
Name of attribute


namespace

protected String namespace
Namespace/qualifier of attribute


type

protected javax.xml.namespace.QName type
The schema type of attribute value(s)


lifetime

protected long lifetime
Effective lifetime of attribute's value(s) in seconds (0 means infinite)


values

protected ArrayList values
An array of attribute values

Constructor Detail

SAMLAttribute

public SAMLAttribute()
Default constructor


SAMLAttribute

public SAMLAttribute(String name,
                     String namespace,
                     javax.xml.namespace.QName type,
                     long lifetime,
                     Collection values)
              throws SAMLException
Builds an Attribute out of its component parts

Parameters:
name - Name of attribute
namespace - Namespace/qualifier of attribute
type - The schema type of attribute value(s)
lifetime - Effective lifetime of attribute's value(s) in seconds (0 means infinite)
values - An array of attribute values
Throws:
SAMLException - Thrown if attribute cannot be built from the supplied information

SAMLAttribute

public SAMLAttribute(Element e)
              throws SAMLException
Reconstructs an attribute from a DOM tree

Parameters:
e - The root of a DOM tree
Throws:
SAMLException - Thrown if the object cannot be constructed

SAMLAttribute

public SAMLAttribute(InputStream in)
              throws SAMLException
Reconstructs an attribute from a stream

Parameters:
in - A stream containing XML
Throws:
SAMLException - Raised if an exception occurs while constructing the object.
Method Detail

setFactory

public static String setFactory(String className)
Registers a class name to handle SAML attribute construction from XML

Parameters:
className - The Java class to register

getFactory

public static String getFactory()
Obtains a class name to handle SAML attribute construction from XML

Parameters:
className - The registered Java class

getInstance

public static SAMLAttribute getInstance(Element e)
                                 throws SAMLException
Locates an implementation class for an attribute and constructs it based on the DOM provided.

Parameters:
e - The root of a DOM containing the SAML attribute
Returns:
SAMLAttribute A constructed attribute object
Throws:
SAMLException - Thrown if an error occurs while constructing the object

getInstance

public static SAMLAttribute getInstance(InputStream in)
                                 throws SAMLException
Locates an implementation class for an attribute and constructs it based on the stream provided.

Parameters:
in - The stream to deserialize from
Returns:
SAMLAttribute A constructed attribute object
Throws:
SAMLException - Thrown if an error occurs while constructing the object

fromDOM

public void fromDOM(Element e)
             throws SAMLException
Initialization of attribute from a DOM element.

Checks the attribute's syntactic validity. An exception is thrown if any problems are detected. The exception will contain a message describing the problem, and may wrap another exception.

Because attributes are generalized, this base method only handles attributes whose values are of uniform schema type. The attribute's schema type is set by the first xsi:type attribute found in the value list, if any.

The addValue method is used to actually process the values, and can be overridden to handle more complex values

Overrides:
fromDOM in class SAMLObject
Parameters:
e - Root element of a DOM tree
Throws:
SAMLException - Raised if an exception occurs while constructing the object.

valueFromDOM

protected void valueFromDOM(Element e)
                     throws SAMLException
Creates the internal representation of an attribute value from the specified element.

The base implementation handles simple string values by extracting a single Text node. Override this method in your subclass to perform more advanced processing.

Parameters:
e - The AttributeValue element to read from
Throws:
SAMLException - Raised if an error occurs while parsing the DOM

getName

public String getName()
Gets the AttributeName attribute of the SAML Attribute

Returns:
The name value

setName

public void setName(String name)
Sets the AttributeName attribute of the SAML Attribute

Parameters:
name - The name value

getNamespace

public String getNamespace()
Gets the AttributeNamespace attribute of the SAML Attribute

Returns:
The namespace value

setNamespace

public void setNamespace(String namespace)
Sets the AttributeNamespace attribute of the SAML Attribute

Parameters:
namespace - The name value

getType

public javax.xml.namespace.QName getType()
Gets the value of the xsi:type attribute, if any, of the SAML Attribute

Returns:
The schema type value

setType

public void setType(javax.xml.namespace.QName type)
Sets the value of the xsi:type attribute, if any, of the SAML Attribute

Parameters:
type - The schema type value

getLifetime

public long getLifetime()
Gets the value's lifetime, in seconds

Returns:
The effective lifetime of the attribute value, in seconds (0 means infinite)

setLifetime

public void setLifetime(long lifetime)
Sets the value's lifetime, in seconds

Parameters:
lifetime - The effective lifetime of the attribute value, in seconds (0 means infinite)

getValues

public Iterator getValues()
Gets the values of the SAML Attribute

Returns:
An iterator over the values

getValueElements

public NodeList getValueElements()
Gets the set of existing AttributeValue elements, if the DOM exists.

Returns:
A NodeList containing the elements, or null

setValues

public void setValues(Collection values)
               throws SAMLException
Sets the values of the attribute

Parameters:
values - The values to use
Throws:
SAMLException - Raised if the value cannot be added to the attribute

addValue

public void addValue(Object value)
              throws SAMLException
Adds a value to the attribute

Parameters:
value - The value to add
Throws:
SAMLException - Raised if the value cannot be properly added

removeValue

public void removeValue(int index)
                 throws IndexOutOfBoundsException
Removes a value by position (zero-based)

Parameters:
index - The position of the value to remove
Throws:
IndexOutOfBoundsException

computeTypeDecl

protected String computeTypeDecl(Element e)
Computes the xsi:type attribute on each AttributeValue element with any supporting declarations created.

Parameters:
e - The root element of the attribute
Returns:
The xsi:type value to use

buildRoot

protected Element buildRoot(Document doc,
                            boolean xmlns)
Description copied from class: SAMLObject
Delegates the process of building the root element of an object and inserting appropriate namespaces.

Specified by:
buildRoot in class SAMLObject
Parameters:
doc - The document context to use
xmlns - Include namespace(s) on root element?
Returns:
A new root element for the object
See Also:
SAMLObject.buildRoot(org.w3c.dom.Document,boolean)

valueToDOM

protected void valueToDOM(int index,
                          Element e)
                   throws SAMLException
Creates the DOM representation of an attribute value in the specified element.

The base implementation handles string values by creating a single Text node. Override this method in your subclass to perform more advanced processing.

Parameters:
index - The position of the attribute value to DOM-ify
e - The AttributeValue element to write into
Throws:
SAMLException - Raised if an error occurs while creating the DOM

toDOM

public Node toDOM(Document doc,
                  boolean xmlns)
           throws SAMLException
Description copied from class: SAMLObject
Transforms the object into a DOM tree using an existing document context

Overrides:
toDOM in class SAMLObject
Parameters:
doc - A Document object to use in manufacturing the tree
xmlns - Include namespace(s) on root element?
Returns:
Root element node of the DOM tree capturing the object
Throws:
SAMLException - Raised if the object is incompletely defined
See Also:
SAMLObject.toDOM(org.w3c.dom.Document,boolean)

checkValidity

public void checkValidity()
                   throws SAMLException
Description copied from class: SAMLObject
Evaluates the object's content to see if it is currently valid if serialized. Does not evaluate embedded objects except on the basis of whether they exist. For example, an Assertion must have a Statement, but if an invalid statement is added, SAMLAssertion.checkValidity() would succeed, while SAMLStatement.checkValidity would raise an exception.

Specified by:
checkValidity in class SAMLObject
Throws:
SAMLException - Raised if the serialized object would be invalid SAML, excluding any embedded objects
See Also:
SAMLObject.checkValidity()

clone

public Object clone()
             throws CloneNotSupportedException
Copies a SAML object such that no dependencies exist between the original and the copy. Does not clone values.

Overrides:
clone in class SAMLObject
Returns:
The new object
Throws:
CloneNotSupportedException
See Also:
Object.clone()


Copyright ? 2005 UCAID. All Rights Reserved.