|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
|
+--codec.asn1.ASN1AbstractType
|
+--codec.asn1.ASN1Choice
This type represents the ASN.1 CHOICE type as specified in ITU-T Recommendation X.680. On decoding, the decoder must be able to decide umambiguously which alternative choice it has to decode. For this reason all elements in a CHOICE type must have distinctive tags.
This class does not enforce the distinctive tag rule. Instead, the alternative with the first matching tag should be chosen by decoders. The application that builds the CHOICE type must take care not to produce ambiguous sets of alternatives.
This class distinguishes alternative choices and an inner type. Upon
decoding, the inner type is selected from the list of choices based on the
identifier octets encountered in the encoded stream. This type is then
set as the inner type of this instance. Unless an inner
type is set (either explicitly or by means of decoding) the state of the
choice is undefined.
This instance always mimicks its inner type. The methods
getTag, getTagClass,
getValue all return the appropriate results of the
corresponding method of the inner type. On encoding an instance of this class
the inner type is encoded.
No nested CHOICE classes are supported. In principle this is easily supported but it is not good style to build such structures.
| Constructor Summary | |
ASN1Choice()
Creates an instance with an initial capacity of 2. |
|
ASN1Choice(int capacity)
Creates an instance with the given initial capacity. |
|
| Method Summary | |
void |
addType(ASN1Type t)
Adds the given type as an alternative choice to the collection of choices. |
void |
checkConstraints()
Checks the constraint on the inner type if it is set. |
void |
clear()
Clears the internal list of choices. |
void |
decode(Decoder dec)
Decodes the inner type to the given decoder. |
void |
encode(Encoder enc)
Encodes this type to the given encoder. |
ASN1Type |
getInnerType()
Returns the inner ASN.1 type. |
int |
getTag()
Returns the tag of the inner type. |
int |
getTagClass()
Returns the tag class of the inner type. |
ASN1Type |
getType(int tag,
int tagclass)
Returns the choice with the given tag and tagclass if it exists, otherwise null is returned. |
Object |
getValue()
Returns the value of the inner type. |
boolean |
isExplicit()
Returns the tagging of the inner type. |
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 |
setConstraint(Constraint constraint)
Sets the Constraint of the inner type. |
void |
setExplicit(boolean explicit)
Sets the tagging of the inner type as either EXPLICIT or IMPLICIT. |
void |
setInnerType(ASN1Type t)
Sets the inner type. |
String |
toString()
Returns a string representation of this type. |
void |
trimToSize()
Trims the internal list of choices to the actual number of choices stored in it. |
| Methods inherited from class codec.asn1.ASN1AbstractType |
getConstraint, isOptional, readExternal, setOptional, writeExternal |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
public ASN1Choice()
public ASN1Choice(int capacity)
trimToSize() method to trim the internal list
to the number of stored choices in order to reclaim memory.capacity - The initial capacity for storing choices.IllegalArgumentException - if the capacity is less than 1.| Method Detail |
public void addType(ASN1Type t)
CHOICE elements must neither be OPTIONAL nor tagged IMPLICIT. For safety,
this method calls setOptional(false) and
setExplicit(true) on the given type.
Callers must not alter this setting after adding a type to this choice.
However, the CHOICE itself can be declared OPTIONAL.
t - The ASN.1 type to add as a choice.NullPointerException - if the given type is null.IllegalArgumentException - if the given type is a ASN1Choice type.
public ASN1Type getType(int tag,
int tagclass)
null is returned. This method is called by the
decoder in order to determine the appropriate type to decode. The
returned type is set up as the inner type by the decoder.tag - The tag of the type encountered in the encoded stream. The
tags of the various primitive ASN.1 types are defined in
class ASN1.tagclass - The tag class of the type encountered in the encoded
stream. The tag class identifiers are defined in class
ASN1. See for instance
CLASS_UNIVERSAL.null
if no matching choice is found.
public boolean isType(int tag,
int tagclass)
ASN1AbstractTypetrue 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.
isType in class ASN1AbstractTypecodec.asn1.ASN1AbstractTypetag - The tag to compare with.tagclass - The tag class to compare with.true if the given tag and tag class matches this
type and false otherwise.public void trimToSize()
public void clear()
public ASN1Type getInnerType()
public void setInnerType(ASN1Type t)
t - The type to set as the inner type.NullPointerException - if the given type is null.public int getTag()
getTag in class ASN1AbstractTypeIllegalStateException - if the inner type is not set.public int getTagClass()
getTagClass in class ASN1AbstractTypeIllegalStateException - if the inner type is not set.public Object getValue()
ASN1Null. This method calls
getValue on the inner type and returns the
result.getValue in class ASN1AbstractTypeIllegalStateException - if the inner type is not set.public void setExplicit(boolean explicit)
setExplicit in class ASN1AbstractTypeexplicit - true if this type shall be tagged EXPLICIT
and false if it shall be encoded IMPLICIT.IllegalStateException - if the inner type is not set.public boolean isExplicit()
isExplicit in class ASN1AbstractTypetrue if the inner type is tagged EXPLICIT and
false if it is tagged IMPLICIT.IllegalStateException - if the inner type is not set.public void setConstraint(Constraint constraint)
Constraint of the inner 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.setConstraint in class ASN1AbstractTypeconstraint - The Constraint of this type.IllegalStateException - if the inner type is not set.
public void checkConstraints()
throws ConstraintException
checkConstraints in class ASN1AbstractTypeConstraintException - if this type is not in the appropriate range of values.IllegalStateException - if the inner type is not set.
public void encode(Encoder enc)
throws ASN1Exception,
IOException
If this method is declared OPTIONAL then still an exception is thrown.
The OPTIONAL flag is checked only by encoders and
decoders. Transparent handling of CHOICE types can be
achieved by calling
on the encoder. The encoder's method checks if its argument is OPTIONAL.writeType(ASN1Choice choice)
encode in class ASN1AbstractTypeenc - The Encoder to use for encoding.IllegalStateException - if the inner type is not set.
public void decode(Decoder dec)
throws ASN1Exception,
IOException
decoder.decode in class ASN1AbstractTypedec - The decoder to decode to.IllegalStateException - if the open type cannot be resolved on runtime.public String toString()
toString in class Object
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||