codec.asn1
Class ASN1OpenType

java.lang.Object
  |
  +--codec.asn1.ASN1AbstractType
        |
        +--codec.asn1.ASN1OpenType
All Implemented Interfaces:
ASN1Type, Cloneable, Externalizable, Serializable

public class ASN1OpenType
extends ASN1AbstractType

This type represents what was formerly called the ASN.1 ANY type. The ANY and ANY DEFINED BY types are superseded as of ITU-T Recommendation X.680 version current December 1997 by the ability to define type classes. Modelling type classes is beyond the scope of this ASN.1 package although the package can be enhanced accordingly. ASN.1 type classes can contain components whose type is unspecified. Such components are called "open types". This class mimics an open type insofar as it decodes any type encountered in an encoded stream of ASN.1 types. On encoding the proper type is encoded in place of the open type. Decoding an open type that was not properly initialized either by a call to a creator with an argument or by decoding it from a valid ASN.1 encoding results in an ASN1Null being decoded.

This class enforces as an invariant that inner types have the same tagging as the type itself. For instance:

 ASN1OpenType ot;
 ASN1Integer n;
 n = new Integer("42");
 n.setExplicit(true);
 ot = new OpenType(new FooResolver());
 ot.setExplicit(false);
 ot.setInnerType(n);
 
will cause the tagging method of n to be changed into EXPLICIT upon the call to ot.setInnerType().

Version:
"$Id: ASN1OpenType.java,v 1.4 2004/08/06 15:13:01 flautens Exp $"
Author:
Volker Roth
See Also:
Serialized Form

Field Summary
protected  Resolver resolver_
           
 
Constructor Summary
ASN1OpenType()
           
ASN1OpenType(ASN1ObjectIdentifier oid)
           
ASN1OpenType(OIDRegistry registry, ASN1ObjectIdentifier oid)
          This constructor corresponds to the superseded ANY DEFINED BY type.
ASN1OpenType(Resolver resolver)
          Creates an instance that attempts to resolve the actual type on decoding using the given Resolver.
 
Method Summary
 void checkConstraints()
          Checks the constraint on the inner type if it is set.
 void decode(Decoder dec)
          Decodes the inner type to the given decoder.
 void encode(Encoder enc)
          Encodes the inner typeof this open type using 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.
 Object getValue()
          Returns the value of the inner type.
 boolean isType(int tag, int tagclass)
          This method compares the given tag and tag class with the tag and tag class of the resolved type.
 void setConstraint(Constraint constraint)
          Sets the Constraint of the inner type.
 void setExplicit(boolean explicit)
          Sets the tagging to either EXPLICIT or IMPLICIT.
protected  void setInnerType(ASN1Type t)
          Sets the inner type.
 String toString()
          Returns the string representation of this instance.
 
Methods inherited from class codec.asn1.ASN1AbstractType
getConstraint, isExplicit, isOptional, readExternal, setOptional, writeExternal
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

resolver_

protected Resolver resolver_
Constructor Detail

ASN1OpenType

public ASN1OpenType()

ASN1OpenType

public ASN1OpenType(Resolver resolver)
Creates an instance that attempts to resolve the actual type on decoding using the given Resolver.
Parameters:
resolver - The instance that is asked to deliver the type to decode.

ASN1OpenType

public ASN1OpenType(OIDRegistry registry,
                    ASN1ObjectIdentifier oid)
This constructor corresponds to the superseded ANY DEFINED BY type. The open type attempts to resolve the type to decode right before decoding by a call to the given registry with the given OID as the argument. The exact OID instance is used that is passed to this method as the argument. If this instance is decoded before the open type is decoded (because the OID is encountered earlier in a decoded stream) then the open type can determine the exact type to decode by a call to the registry.
Parameters:
oid - The OID that is passed to the given registry on resolving.

ASN1OpenType

public ASN1OpenType(ASN1ObjectIdentifier oid)
Method Detail

getInnerType

public ASN1Type getInnerType()
                      throws ResolverException
Returns the inner ASN.1 type. If the inner type is not set and a Resolver is set then the Resolver is asked to resolve the inner type. The resulting type is then returned.

This method may return null if the resolver cannot determine the inner type of the open type. In particular, if the Resolver is null and no inner type is already set then null is returned.

Returns:
The inner ASN.1 type.

setInnerType

protected void setInnerType(ASN1Type t)
Sets the inner type. The inner type inherits the tagging of this type.
Parameters:
t - The type to set as the inner type.
Throws:
NullPointerException - if the given type is null.

getTag

public int getTag()
Returns the tag of the inner type.
Overrides:
getTag in class ASN1AbstractType
Returns:
The tag of the inner type.
Throws:
IllegalStateException - if the inner type is not yet initialized.

getTagClass

public int getTagClass()
Returns the tag class of the inner type.
Overrides:
getTagClass in class ASN1AbstractType
Returns:
The tag class of the inner type.
Throws:
IllegalStateException - if the inner type is not yet initialized.

getValue

public Object getValue()
Returns the value of the inner type. The default inner type is ASN1Null. This method calls getValue on the inner type and returns the result.
Overrides:
getValue in class ASN1AbstractType
Returns:
The value of the inner type.
Throws:
IllegalStateException - if the inner type is not yet initialized.

setExplicit

public void setExplicit(boolean explicit)
Sets the tagging to either EXPLICIT or IMPLICIT. If this type already has an inner type set then the tagging of the inner type is set to the same tagging.
Overrides:
setExplicit in class ASN1AbstractType
Parameters:
explicit - true if this type shall be tagged EXPLICIT and false if it shall be encoded IMPLICIT.
Throws:
IllegalStateException - if the inner type is not yet initialized.

setConstraint

public void setConstraint(Constraint constraint)
Sets the 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.
Overrides:
setConstraint in class ASN1AbstractType
Parameters:
constraint - The Constraint of this type.
Throws:
IllegalStateException - if the inner type is not yet initialized.

checkConstraints

public void checkConstraints()
                      throws ConstraintException
Checks the constraint on the inner type if it is set. Otherwise this method returns silently.
Overrides:
checkConstraints in class ASN1AbstractType
Throws:
ConstraintException - if this type is not in the appropriate range of values.
IllegalStateException - if the inner type is not yet initialized.

isType

public boolean isType(int tag,
                      int tagclass)
This method compares the given tag and tag class with the tag and tag class of the resolved type.

If an exception is thrown by the Resolver upon resolving the inner type of this type then false is returned in order to provoke a decoding error.

If no inner type can be resolved then true is returned. In that case this type behaves like the ANY type known from previous ASN.1 versions.

Overrides:
isType in class ASN1AbstractType
Parameters:
tag - The tag to match.
tagclass - The tag class to match.
Returns:
true iff the given tag and tag class match one of the alternative types represented by this variable type.

encode

public void encode(Encoder enc)
            throws ASN1Exception,
                   IOException
Encodes the inner typeof this open type using the given Encoder. If the inner type is not yet initialized then an exception is thrown.
Overrides:
encode in class ASN1AbstractType
Parameters:
enc - The Encoder to use for encoding the inner type.
Throws:
IllegalStateException - if the inner type is not yet initialized.

decode

public void decode(Decoder dec)
            throws ASN1Exception,
                   IOException
Decodes the inner type to the given decoder. If a resolver was specified then it is asked to provide an ASN.1 type to decode.
Overrides:
decode in class ASN1AbstractType
Parameters:
dec - The decoder to decode to.
Throws:
IllegalStateException - if the open type cannot be resolved on runtime.

toString

public String toString()
Returns the string representation of this instance.
Overrides:
toString in class Object
Returns:
The string representation of this instance.


Copyright © Fraunhofer Gesellschaft. All Rights Reserved.