org.demac.impl.j2me.process.base.service.webservices.asn1
Class ASN1OpenType

java.lang.Object
  extended by org.demac.impl.j2me.process.base.service.webservices.asn1.ASN1AbstractType
      extended by org.demac.impl.j2me.process.base.service.webservices.asn1.ASN1OpenType
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable, java.lang.Cloneable, ASN1Type

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().

See Also:
Serialized Form

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.
 java.lang.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.
 java.lang.String toString()
          Returns the string representation of this instance.
 
Methods inherited from class org.demac.impl.j2me.process.base.service.webservices.asn1.ASN1AbstractType
getConstraint, isExplicit, isOptional, readExternal, setOptional, writeExternal
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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.
Throws:
ResolverException

getTag

public int getTag()
Returns the tag of the inner type.

Specified by:
getTag in interface ASN1Type
Specified by:
getTag in class ASN1AbstractType
Returns:
The tag of the inner type.
Throws:
java.lang.IllegalStateException - if the inner type is not yet initialized.

getTagClass

public int getTagClass()
Returns the tag class of the inner type.

Specified by:
getTagClass in interface ASN1Type
Overrides:
getTagClass in class ASN1AbstractType
Returns:
The tag class of the inner type.
Throws:
java.lang.IllegalStateException - if the inner type is not yet initialized.

getValue

public java.lang.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.

Specified by:
getValue in interface ASN1Type
Specified by:
getValue in class ASN1AbstractType
Returns:
The value of the inner type.
Throws:
java.lang.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.

Specified by:
setExplicit in interface ASN1Type
Overrides:
setExplicit in class ASN1AbstractType
Parameters:
explicit - true if this type shall be tagged EXPLICIT and false if it shall be encoded IMPLICIT.
Throws:
java.lang.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.

Specified by:
setConstraint in interface ASN1Type
Overrides:
setConstraint in class ASN1AbstractType
Parameters:
constraint - The Constraint of this type.
Throws:
java.lang.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.

Specified by:
checkConstraints in interface ASN1Type
Overrides:
checkConstraints in class ASN1AbstractType
Throws:
ConstraintException - if this type is not in the appropriate range of values.
java.lang.IllegalStateException - if the inner type is not yet initialized.
See Also:
Constraint, ConstraintCollection

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.

Specified by:
isType in interface ASN1Type
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,
                   java.io.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.

Specified by:
encode in interface ASN1Type
Specified by:
encode in class ASN1AbstractType
Parameters:
enc - The Encoder to use for encoding the inner type.
Throws:
java.lang.IllegalStateException - if the inner type is not yet initialized.
ASN1Exception
java.io.IOException

decode

public void decode(Decoder dec)
            throws ASN1Exception,
                   java.io.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.

Specified by:
decode in interface ASN1Type
Specified by:
decode in class ASN1AbstractType
Parameters:
dec - The decoder to decode to.
Throws:
java.lang.IllegalStateException - if the open type cannot be resolved on runtime.
ASN1Exception
java.io.IOException

toString

public java.lang.String toString()
Returns the string representation of this instance.

Overrides:
toString in class java.lang.Object
Returns:
The string representation of this instance.