codec.asn1
Class ASN1AbstractType

java.lang.Object
  |
  +--codec.asn1.ASN1AbstractType
All Implemented Interfaces:
ASN1Type, Cloneable, Externalizable, Serializable
Direct Known Subclasses:
ASN1AbstractString, ASN1BitString, ASN1Boolean, ASN1Choice, ASN1Integer, ASN1Null, ASN1ObjectIdentifier, ASN1OctetString, ASN1OpenType, ASN1TaggedType

public abstract class ASN1AbstractType
extends Object
implements ASN1Type, Cloneable, Externalizable

The basic interface for Java objects representing primitive ASN.1 types according to ITU-T Recommendation X.680.

Version:
"$Id: ASN1AbstractType.java,v 1.4 2005/03/23 12:45:51 flautens Exp $"
Author:
Volker Roth
See Also:
Serialized Form

Constructor Summary
ASN1AbstractType()
           
 
Method Summary
 void checkConstraints()
          Checks the constraint on this type if it is set.
abstract  void decode(Decoder dec)
           
abstract  void encode(Encoder enc)
           
 Constraint getConstraint()
          Returns the Constraint of this type or null if there is none.
abstract  int getTag()
          Returns the corresponding ASN.1 tag.
 int getTagClass()
          This default implementation returns UNIVERSAL.
abstract  Object getValue()
          This abstract method should return the value wrapped by the ASN1Type.
 boolean isExplicit()
          Returns code>true if this type is tagged EXPLICIT and false otherwise.
 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.
 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.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ASN1AbstractType

public ASN1AbstractType()
Method Detail

getValue

public abstract Object getValue()
This abstract method should return the value wrapped by the ASN1Type.
Specified by:
getValue in interface ASN1Type
Returns:
the internal value

getTag

public abstract int getTag()
Returns the corresponding ASN.1 tag.
Specified by:
getTag in interface ASN1Type
Returns:
the corresponding ASN.1 tag

encode

public abstract void encode(Encoder enc)
                     throws ASN1Exception,
                            IOException
Specified by:
encode in interface ASN1Type

decode

public abstract void decode(Decoder dec)
                     throws ASN1Exception,
                            IOException
Specified by:
decode in interface ASN1Type

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 if 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()
Returns code>true if this type is tagged EXPLICIT and false otherwise.
Specified by:
isExplicit in interface ASN1Type
Returns:
true if this type is tagged EXPLICIT and false if it is tagged IMPLICIT.

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.

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.

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
Throws:
IOException - if an I/0 error has occured
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
Throws:
IOException - if an I/0 error has occured
See Also:
Externalizable


Copyright © Fraunhofer Gesellschaft. All Rights Reserved.