issrg.ac
Class Attribute

java.lang.Object
  extended by issrg.ac.Attribute
All Implemented Interfaces:
java.lang.Cloneable

public class Attribute
extends java.lang.Object
implements java.lang.Cloneable

This class represents an Attribute ASN.1 construct. It contains a vector of values, each of them being a subclass of AttributeValue.

This class maintains a register of AttributeValue subclasses, one per attribute object identifier (OID). This way it can construct the specific AttributeValue subclasses when an Attribute with a specific OID is encountered By default, it creates just AttributeValue elements when parsing an ASN1Object, but you can register your own AttributeValue subclasses using registerAttribute method. The subclasses must have a constructor with ASN1Object as a parameter.

See Also:
registerAttribute(java.lang.String, java.lang.Class)

Field Summary
protected static java.util.Map registry
           
protected  java.lang.String type
           
protected  java.util.Vector values
           
 
Constructor Summary
protected Attribute()
           
  Attribute(ASN1Object ao)
          This constructor builds an Attribute from ASN1Object.
  Attribute(java.lang.String type, AttributeValue value)
          This constructor builds an Attribute given its type and a single value.
  Attribute(java.lang.String type, java.util.Vector values)
          This constructor creates an Attribute of the given type and a set of values.
 
Method Summary
 java.lang.Object clone()
           
 void decode(ASN1Object ao)
          This method decodes the given ASN1Object and sets this attribute type and value, as in ASN1Object.
 java.lang.String getType()
          Returns the OID of the Attribute.
 java.util.Vector getValues()
          Returns the vector of values of the attribute.
static void registerAttribute(java.lang.String oid, java.lang.Class attribute)
          This method lets you register custom AttributeValue subclasses that will be used to decode values of specific attributes.
 void setType(java.lang.String type)
          Sets the OID of the Attribute type.
 void setValues(java.util.Vector values)
          Sets the vector of values of the attribute.
 ASN1Object toASN1Object()
          This method returns the ASN1Object of this Attribute.
 java.lang.String toString()
           
 java.lang.String toString(java.lang.String ident)
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

type

protected java.lang.String type

values

protected java.util.Vector values

registry

protected static java.util.Map registry
Constructor Detail

Attribute

protected Attribute()

Attribute

public Attribute(ASN1Object ao)
          throws CodingException
This constructor builds an Attribute from ASN1Object.

Parameters:
ao - - the ASN1Object containing the Attribute
Throws:
CodingException

Attribute

public Attribute(java.lang.String type,
                 java.util.Vector values)
This constructor creates an Attribute of the given type and a set of values.

Parameters:
type - - the OID of the Attribute in dotted form
values - - the Vector of attribute values; each element must be of AttributeValue class or its subclass; should not be null; in fact, the standard requires that at least one element were present

Attribute

public Attribute(java.lang.String type,
                 AttributeValue value)
This constructor builds an Attribute given its type and a single value.

Parameters:
type - - the OID of the Attribute in the dotted form
value - - the AttributeValue of the Attribute
Method Detail

getType

public java.lang.String getType()
Returns the OID of the Attribute.


setType

public void setType(java.lang.String type)
Sets the OID of the Attribute type. It should be in the dotted notation.


getValues

public java.util.Vector getValues()
Returns the vector of values of the attribute. Each element is a AttributeValue or its subclass.


setValues

public void setValues(java.util.Vector values)
Sets the vector of values of the attribute. The sequence of them does not matter, since they are encoded as a SET.

Parameters:
values - - the Vector of attribute values; each element must be of AttributeValue class or a subclass of it.

toASN1Object

public ASN1Object toASN1Object()
                        throws CodingException
This method returns the ASN1Object of this Attribute.

Returns:
SEQUENCE of ObjectID and a SET of attribute values
Throws:
CodingException

decode

public void decode(ASN1Object ao)
            throws CodingException
This method decodes the given ASN1Object and sets this attribute type and value, as in ASN1Object. This method looks for AttributeValue subclasses in the registry to find the appropriate subclass to decode individual values. If no appropriate subclass is found, AttributeValue is used.

You can register custom AttributeValue subclasses for decoding values of specific attribute types using registerAttribute method.

Parameters:
ao - - the ASN1Object to decode; it must be a SEQUENCE of ObjectID and a SET of AttributeValues
Throws:
CodingException
See Also:
registerAttribute(java.lang.String, java.lang.Class)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toString

public java.lang.String toString(java.lang.String ident)

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object

registerAttribute

public static void registerAttribute(java.lang.String oid,
                                     java.lang.Class attribute)
This method lets you register custom AttributeValue subclasses that will be used to decode values of specific attributes.

...
Attribute.registerAttribute("1.2.3.4.5", MyCuteAttribute.class);

Now the constructor of your class will be invoked automatically whenever the OID is encountered in the attributes of an encoded AC.

Parameters:
oid - is the dotted form of the OID
attribute - is the class that will decode single attribute values; must be a subclass of AttributeValue and must have a constructor with ASN1Object as an argument