codec.asn1
Class ASN1AbstractCollection

java.lang.Object
  |
  +--java.util.AbstractCollection
        |
        +--java.util.AbstractList
              |
              +--java.util.ArrayList
                    |
                    +--codec.asn1.ASN1AbstractCollection
All Implemented Interfaces:
ASN1Collection, ASN1Type, Cloneable, Collection, Externalizable, List, Serializable
Direct Known Subclasses:
ASN1AbstractCollectionOf, ASN1Sequence, ASN1Set

public abstract class ASN1AbstractCollection
extends ArrayList
implements ASN1Collection, Cloneable, Externalizable

Represents an abstract collection of ASN.1 types such as a SEQUENCE or a SET. Since this class inherits from the Collection framework class ArrayList, ASN.1 types may be added conveniently just as object instances are added to a list.

Please note that constraints of collections are validated before encoding and after decoding. Invalid modification of a collection type can be detected on importing and exporting abstract collections. On DER encoding a collection its constraint is validated twice since the DER encoding is a two-pass process.

Version:
"$Id: ASN1AbstractCollection.java,v 1.5 2005/03/22 16:12:45 flautens Exp $"
Author:
Volker Roth
See Also:
Serialized Form

Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
ASN1AbstractCollection()
          Method declarations with default implementation.
ASN1AbstractCollection(int capacity)
          Creates an instance with the given capacity.
 
Method Summary
 void checkConstraints()
          Checks the constraint on this type if it is set.
 void decode(Decoder dec)
          Reads this collection from the given Decoder.
 void encode(Encoder enc)
          Writes this collection to the given encoder.
 Collection getCollection()
          Returns the Java type that corresponds to this ASN.1 type.
 Constraint getConstraint()
          Returns the Constraint of this type or null if there is none.
abstract  int getTag()
          Abstract method declarations.
 int getTagClass()
          This default implementation returns UNIVERSAL.
 Object getValue()
          Returns the Java type that corresponds to this ASN.1 type.
 boolean isExplicit()
           
 boolean isOptional()
           
 boolean isType(int tag, int tagclass)
          Returns true if the given tag and tag class matches the tag and tag class of this instance.
 void readExternal(ObjectInput in)
          The writeExternal and readExternal methods of the Externalizable interface are implemented by a class to give the serializable class complete control over the format and contents of the stream for an object and its supertypes.
 void setConstraint(Constraint constraint)
          Sets the Constraint of this type.
 void setExplicit(boolean explicit)
          Sets the tagging of this type as either EXPLICIT or IMPLICIT.
 void setOptional(boolean optional)
          Optional types may be present in an encoding but they need not be.
 String toString()
          Prints this collection.
 void writeExternal(ObjectOutput out)
          The writeExternal and readExternal methods of the Externalizable interface are implemented by a class to give the serializable class complete control over the format and contents of the stream for an object and its supertypes.
 
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, removeRange, set, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
equals, hashCode, iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, remove, removeAll, retainAll
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Collection
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, iterator, listIterator, listIterator, remove, removeAll, retainAll, subList
 

Constructor Detail

ASN1AbstractCollection

public ASN1AbstractCollection()
Method declarations with default implementation.

ASN1AbstractCollection

public ASN1AbstractCollection(int capacity)
Creates an instance with the given capacity.
Parameters:
capacity - The capacity.
Method Detail

getTag

public abstract int getTag()
Abstract method declarations.
Specified by:
getTag in interface ASN1Type
Returns:
corresponding ASN1 tag

getValue

public Object getValue()
Returns the Java type that corresponds to this ASN.1 type.
Specified by:
getValue in interface ASN1Type
Returns:
The collection used internally for storing the elements in this constructed ASN.1 type.

getCollection

public Collection getCollection()
Returns the Java type that corresponds to this ASN.1 type.
Specified by:
getCollection in interface ASN1Collection
Returns:
The collection used internally for storing the elements in this constructed ASN.1 type.

setOptional

public void setOptional(boolean optional)
Optional types may be present in an encoding but they need not be.
Specified by:
setOptional in interface ASN1Type
Parameters:
optional - true iff this type is optional.

isOptional

public boolean isOptional()
Specified by:
isOptional in interface ASN1Type
Returns:
true iff this type is optional.

getTagClass

public int getTagClass()
This default implementation returns UNIVERSAL.
Specified by:
getTagClass in interface ASN1Type
Returns:
The class of the ASN.1 tag.

setExplicit

public void setExplicit(boolean explicit)
Sets the tagging of this type as either EXPLICIT or IMPLICIT. The default is EXPLICIT. Encoders skip the encoding of identifier octets for types that are declared as IMPLICIT.
Specified by:
setExplicit in interface ASN1Type
Parameters:
explicit - true if this type shall be tagged EXPLICIT and false if it shall be encoded IMPLICIT.

isExplicit

public boolean isExplicit()
Specified by:
isExplicit in interface ASN1Type
Returns:
true if this type is tagged EXPLICIT and false if it is tagged IMPLICIT.

setConstraint

public void setConstraint(Constraint constraint)
Sets the Constraint of this type. For instance an ASN.1 INTEGER might be constrained to a certain range such as INTEGER (0..99). null can be passed as a constraint which disables constraint checking.
Specified by:
setConstraint in interface ASN1Type
Parameters:
constraint - The Constraint of this type.

getConstraint

public Constraint getConstraint()
Returns the Constraint of this type or null if there is none.
Specified by:
getConstraint in interface ASN1Type
Returns:
The Constraint or null.

checkConstraints

public void checkConstraints()
                      throws ConstraintException
Checks the constraint on this type if it is set. Otherwise this method returns silently.
Specified by:
checkConstraints in interface ASN1Type
Throws:
ConstraintException - if this type is not in the appropriate range of values.

isType

public boolean isType(int tag,
                      int tagclass)
Returns true if the given tag and tag class matches the tag and tag class of this instance. This method is used primarily by decoders and variable types such as ASN1Choice and ASN1OpenType. It enables decoders to query a variable type whether a decoded type is accepted.

This method provides a default implementation that matches the given tag and tag class against the values returned by getTag and getTagClass respectively.

Specified by:
isType in interface ASN1Type
Parameters:
tag - The tag to compare with.
tagclass - The tag class to compare with.
Returns:
true if the given tag and tag class matches this type and false otherwise.

encode

public void encode(Encoder enc)
            throws ASN1Exception,
                   IOException
Writes this collection to the given encoder.
Specified by:
encode in interface ASN1Type
Parameters:
enc - The encoder to write this type to.

decode

public void decode(Decoder dec)
            throws ASN1Exception,
                   IOException
Reads this collection from the given Decoder. This type is initialized with the decoded data. The components of the decoded collection must match the components of this collection. If they do then the components are also initialized with the decoded values. Otherwise an exception is thrown.
Specified by:
decode in interface ASN1Type
Parameters:
dec - The decoder to read from.

toString

public String toString()
Prints this collection. This default implementation derives a descriptive name from the name of the fully qualified name of this class (or that of the respective subclass). The last component of the class name is extracted and a prefix of "ASN1" is removed from it. Then the elements contained in this collection are printed.
Overrides:
toString in class AbstractCollection
Returns:
The string representation of this ASN.1 collection.

writeExternal

public void writeExternal(ObjectOutput out)
                   throws IOException
The writeExternal and readExternal methods of the Externalizable interface are implemented by a class to give the serializable class complete control over the format and contents of the stream for an object and its supertypes.
Specified by:
writeExternal in interface Externalizable
Parameters:
out - - the stream to write the object to
See Also:
Externalizable

readExternal

public void readExternal(ObjectInput in)
                  throws IOException
The writeExternal and readExternal methods of the Externalizable interface are implemented by a class to give the serializable class complete control over the format and contents of the stream for an object and its supertypes.
Specified by:
readExternal in interface Externalizable
Parameters:
in - - the stream to read data from in order to restore the object
See Also:
Externalizable


Copyright © Fraunhofer Gesellschaft. All Rights Reserved.