jp.bitmeister.asn1.type
Class ASN1Type

java.lang.Object
  extended by jp.bitmeister.asn1.type.ASN1Type
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
CollectionType, PrimitiveType, StructuredType, UnknownType

public abstract class ASN1Type
extends java.lang.Object
implements java.lang.Cloneable

The base class for all ASN.1 types.

This class provides general interfaces and common methods for all classes that represent ASN.1 types in this library. Any sub-classes of ASN1Type which to be instantiated must be declared as public (and static if the class is a member class), and have a public constructor with no argument.

User defined ASN.1 types must not extend ASN1Type directly, but use one of built-in (or useful) types as the base class.

Author:
WATANABE, Jun.

Field Summary
static ASN1Processor<java.lang.String,ASN1RuntimeException> stringBuilder
          An ASN1Processor that returns a String, is used in the toString() method.
 
Constructor Summary
protected ASN1Type()
          The constructor with no argument.
 
Method Summary
abstract
<R,E extends java.lang.Throwable>
R
accept(ASN1Visitor<R,E> visitor)
          Accepts the ASN1Visitor and calls a visit method of the visitor.
abstract  void clear()
          Clears the value of this ASN.1 data.
abstract  java.lang.Object clone()
          Creates and returns a copy of this ASN.1 data.
 boolean equals(java.lang.Object other)
          Tests if the type and the value of this ASN.1 data equals the other ASN.1 data.
abstract  int hashCode()
          Returns a hash code value for this ASN.1 data.
abstract  boolean hasValue()
          Tests if this ASN.1 data has value.
static
<T extends ASN1Type>
T
instantiate(java.lang.Class<T> type)
          Instantiates an ASN.1 data of the type specified by the Class parameter.
 boolean matches(ASN1TagClass tagClass, int tagNumber)
          Tests if the ASN.1 tag matches this ASN1 type.
 TypeSpecification specification()
          Returns a TypeSpecification instance that associated to this ASN.1 type.
 java.lang.String toString()
          Returns a string representation of this ASN.1 data.
 void validate()
          Tests if this ASN.1 data has valid value.
abstract  boolean valueEquals(java.lang.Object other)
          Tests if the value of this ASN.1 data equals the value of the other ASN.1 data.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

stringBuilder

public static ASN1Processor<java.lang.String,ASN1RuntimeException> stringBuilder
An ASN1Processor that returns a String, is used in the toString() method. In default, an instance of ASN1StringBuilder is set. To modify output of toString() method of ASN.1 types, user defined processor can be assigned. If null is assigned to this field, toString() returns the result of Object.toString().

See Also:
ASN1Processor, ASN1StringBuilder
Constructor Detail

ASN1Type

protected ASN1Type()
The constructor with no argument.

Method Detail

instantiate

public static <T extends ASN1Type> T instantiate(java.lang.Class<T> type)
Instantiates an ASN.1 data of the type specified by the Class parameter.

Parameters:
type - The ASN.1 type to be instantiated.
Returns:
An instance of the ASN.1 type.

specification

public TypeSpecification specification()
Returns a TypeSpecification instance that associated to this ASN.1 type.

Returns:
A TypeSpecification instance.

matches

public boolean matches(ASN1TagClass tagClass,
                       int tagNumber)
Tests if the ASN.1 tag matches this ASN1 type.

Parameters:
tagClass - The ASN.1 tag class.
tagNumber - The ASN.1 tag number.
Returns:
true when the tag class and the tag number matches this ASN.1 type.

validate

public void validate()
              throws ASN1InvalidDataValue
Tests if this ASN.1 data has valid value.

Throws:
ASN1InvalidDataValue - When the value of this data is invalid.

clear

public abstract void clear()
Clears the value of this ASN.1 data.


hasValue

public abstract boolean hasValue()
Tests if this ASN.1 data has value.

Returns:
true when this ASN.1 data has value.

accept

public abstract <R,E extends java.lang.Throwable> R accept(ASN1Visitor<R,E> visitor)
                  throws E extends java.lang.Throwable
Accepts the ASN1Visitor and calls a visit method of the visitor.

Parameters:
visitor - The visitor.
Returns:
Result.
Throws:
E - When an error occured in the visit method of the visitor.
E extends java.lang.Throwable

valueEquals

public abstract boolean valueEquals(java.lang.Object other)
Tests if the value of this ASN.1 data equals the value of the other ASN.1 data. This method returns true when they have same value even if their types are different.

Parameters:
other - The ASN.1 data which to be compared.
Returns:
true when they have same value.

equals

public boolean equals(java.lang.Object other)
Tests if the type and the value of this ASN.1 data equals the other ASN.1 data.

Overrides:
equals in class java.lang.Object
Parameters:
other - The ASN.1 data which to be compared.
Returns:
true when they have same type and value.

hashCode

public abstract int hashCode()
Returns a hash code value for this ASN.1 data.

Overrides:
hashCode in class java.lang.Object
See Also:
Object.hashCode()

clone

public abstract java.lang.Object clone()
Creates and returns a copy of this ASN.1 data. This method performs a 'deep copy' operation.

Overrides:
clone in class java.lang.Object
See Also:
Object.clone()

toString

public java.lang.String toString()
Returns a string representation of this ASN.1 data.

Overrides:
toString in class java.lang.Object
See Also:
Object.toString()