com.objsys.asn1j.runtime
Class Asn1OpenType

java.lang.Object
  extended by com.objsys.asn1j.runtime.Asn1Type
      extended by com.objsys.asn1j.runtime.Asn1OctetString
          extended by com.objsys.asn1j.runtime.Asn1OpenType
All Implemented Interfaces:
Asn1TypeIF, java.io.Serializable, java.lang.Cloneable, java.lang.Comparable
Direct Known Subclasses:
Asn1ChoiceExt, Asn1XerOpenType

public class Asn1OpenType
extends Asn1OctetString

This is a container class for holding an ASN.1 open type value.

Where the data is internally stored and how it is interpreted is controlled by a "dataEncoding" field. You can specify the data encoding when creating the object. It will also be set when decoding. The following explains the possible data encodings:

Note especially that the data encoding indicates the encoding rules used to encode the actual value. That result is typically encoded as part of some larger encoding. The data encoding does NOT indicate the rules used for that larger encoding. For example, using an xmlhstring representation, XER and JSON will encode an open type that was previously encoded using any arbitrary encoding rules. When decoding such data, the data encoding will be UNKNOWN, not XER nor JSON.

See Also:
Serialized Form

Nested Class Summary
 class Asn1OpenType.SaxHandler
           
 
Field Summary
static int BER
           
protected  int dataEncoding
          Specifies the nature of the data held by this object.
protected static java.lang.String EDATAMSG
           
static int JSON
           
protected  Asn1EncodeBuffer mEncodeBuffer
           
protected  int mLength
           
static int PER
           
static int UNKNOWN
           
static int XER
           
 
Fields inherited from class com.objsys.asn1j.runtime.Asn1OctetString
TAG, value
 
Fields inherited from class com.objsys.asn1j.runtime.Asn1Type
BIT_STRING, BMPString, BOOLEAN, DATE, DATE_TIME, DURATION, ENUMERATED, EOC, EXTERNAL, GeneralString, GeneralTime, GraphicString, IA5String, INTEGER, NULL, NumericString, OBJECT_IDENTIFIER, ObjectDescriptor, OCTET_STRING, OID_IRI, OpenType, PrintableString, REAL, RELATIVE_OID_IRI, RelativeOID, SEQUENCE, SET, T61String, TeletexString, TIME, TIME_OF_DAY, UniversalString, UTCTime, UTF8String, VideotexString, VisibleString
 
Constructor Summary
Asn1OpenType()
          This constructor creates an empty type that can be used in a decode method call to receive an encoded value.
Asn1OpenType(Asn1EncodeBuffer buffer)
          This constructor initializes an open type using an encoded component.
Asn1OpenType(byte[] data)
          This constructor initializes an open type from the given byte array.
Asn1OpenType(byte[] data, int encoding)
          This constructor initializes an open type from the given byte array.
Asn1OpenType(byte[] data, int offset, int nbytes)
          This constructor initializes the open type from a portion of the given byte array.
Asn1OpenType(byte[] data, int offset, int nbytes, int encoding)
          This constructor initializes the open type from a portion of the given byte array.
Asn1OpenType(char[] data, int encoding)
          Create Asn1OpenType on the given character data.
Asn1OpenType(int length)
          Deprecated.  
Asn1OpenType(java.lang.String data, int encoding)
          Convenience constructor.
 
Method Summary
 void decode(Asn1BerDecodeBuffer buffer, boolean explicit, int implicitLength)
          This method decodes an ASN.1 open type value.
 void decode(Asn1JsonDecodeBuffer buffer)
          Decode ASN.1 open type value from JSON.
 void decode(Asn1PerDecodeBuffer buffer)
          This method decodes an ASN.1 open type value using the packed encoding rules (PER).
 void decodeExtension(Asn1JsonDecodeBuffer buffer, java.lang.String name)
          Decode an extension from JSON.
 int encode(Asn1BerEncodeBuffer buffer, boolean explicit)
          This method encodes an ASN.1 open type value.
 void encode(Asn1BerOutputStream out, boolean explicit)
          This method encodes and writes to the stream an ASN.1 open type value including the UNIVERSAL tag value and length if explicit tagging is specified.
 void encode(Asn1JsonOutputStream outstream)
          Encode this octet string to JSON.
 void encode(Asn1PerEncodeBuffer buffer)
          This method encodes an ASN.1 open type value using the Packed Encoding Rules (PER).
 void encode(Asn1PerOutputStream out)
          This method encodes an ASN.1 open type value using the Packed Encoding Rules (PER).
 void encode(Asn1XerEncoder buffer)
          This method encodes an ASN.1 open type value using the XML Encoding Rules (XER).
 void encode(Asn1XerEncoder buffer, java.lang.String elemName)
          This method encodes an ASN.1 open type value using the XML Encoding Rules (XER).
 void encode(Asn1XmlEncoder buffer)
          This method encodes an ASN.1 open type value using the XML Encoding as specified in the XML schema standard(asn2xsd).
 void encode(Asn1XmlEncoder buffer, java.lang.String elemName, java.lang.String nsPrefix)
          This method encodes an ASN.1 open type value using the XML Encoding as specified in the XML schema standard(asn2xsd).
 void encodeAsExtension(Asn1JsonOutputStream outstream)
          This method encodes an extension element to JSON.
 void encodeAsExtension(Asn1XerEncoder buffer)
          This method encodes an extension element to XML.
 void encodeAsExtension(Asn1XmlEncoder buffer)
          This method encodes an extension element to XML.
 char[] getCharData()
          Returns the character data for the open type.
 int getDataEncoding()
          Return the data encoding of the data.
 Asn1XerSaxHandler getSaxHandler()
          Get a SAX handler for this object.
 Asn1XerSaxHandler getSaxHandler(boolean captureOuterElem)
          Get a SAX handler for this object.
 void setBinaryData(byte[] data, int encoding)
          Sets the binary data for the open type and assigns the data encoding to the given encoding.
 void setCharData(char[] data, int encoding)
          Sets the character data for the open type and assigns the data encoding to the given encoding.
 void setCharData(java.lang.String data, int encoding)
          Convenience method; same as setCharData(value.toCharArray(), encoding)
 java.lang.String toString()
          This method will return a string representation of the open type value.
 
Methods inherited from class com.objsys.asn1j.runtime.Asn1OctetString
compareTo, decode, decode, decode, decodeXER, decodeXML, encode, encode, encode, encode, encode, encodeAttribute, encodeBase64Binary, equals, equals, getLength, getMderLength, hashCode, toInputStream
 
Methods inherited from class com.objsys.asn1j.runtime.Asn1Type
clone, decode, decode, decode, decode, decode, encode, equals, getTypeName, indent, isOpenType, matchTag, matchTag, pdiag, print, setKey, setOpenType
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

UNKNOWN

public static final int UNKNOWN
See Also:
Constant Field Values

BER

public static final int BER
See Also:
Constant Field Values

PER

public static final int PER
See Also:
Constant Field Values

XER

public static final int XER
See Also:
Constant Field Values

JSON

public static final int JSON
See Also:
Constant Field Values

mLength

protected transient int mLength

mEncodeBuffer

protected transient Asn1EncodeBuffer mEncodeBuffer

dataEncoding

protected int dataEncoding
Specifies the nature of the data held by this object.


EDATAMSG

protected static final java.lang.String EDATAMSG
See Also:
Constant Field Values
Constructor Detail

Asn1OpenType

public Asn1OpenType()
This constructor creates an empty type that can be used in a decode method call to receive an encoded value. The data encoding is UNKNOWN.


Asn1OpenType

public Asn1OpenType(byte[] data)
This constructor initializes an open type from the given byte array. The array is assumed to contain a previously encoded message component. The data encoding is UNKNOWN.

Parameters:
data - Byte array containing a previously encoded value.

Asn1OpenType

public Asn1OpenType(byte[] data,
                    int encoding)
This constructor initializes an open type from the given byte array. The array is assumed to contain a previously encoded message component.

Parameters:
data - Byte array containing a previously encoded value.
encoding - The encoding that describes the meaning of data. Any of the encodings other than JSON.

Asn1OpenType

public Asn1OpenType(byte[] data,
                    int offset,
                    int nbytes)
This constructor initializes the open type from a portion of the given byte array. A new byte array is created starting at the given offset and consisting of the given number of bytes. The data encoding is UNKNOWN.

Parameters:
data - Byte array containing a previously encoded value.
offset - Starting offset in data from which to copy bytes
nbytes - Number of bytes to copy from target array

Asn1OpenType

public Asn1OpenType(byte[] data,
                    int offset,
                    int nbytes,
                    int encoding)
This constructor initializes the open type from a portion of the given byte array. A new byte array is created starting at the given offset and consisting of the given number of bytes.

Parameters:
data - Byte array containing a previously encoded value.
offset - Starting offset in data from which to copy bytes
nbytes - Number of bytes to copy from target array
encoding - The encoding that describes the meaning of data. Any of the encodings other than JSON.

Asn1OpenType

public Asn1OpenType(Asn1EncodeBuffer buffer)
This constructor initializes an open type using an encoded component. This can be used if a header (for example, a ROSE header) is being prepended to a pre-encoded component. The data encoding is derived from the type of Asn1EncodeBuffer given, and is possibly UNKNOWN.

Parameters:
buffer - Reference to encode buffer into which component type was encoded.

Asn1OpenType

public Asn1OpenType(int length)
Deprecated. 

This constructor initializes an open type using just an encoded component length. This can be used if a header (for example, a ROSE header) is being prepended to a pre-encoded component. This form of the constructor is only being maintained for compatibility with previous versions. The preferred way to use a pre-encoded component is to use the version of the constructor that takes an Asn1BerEncodeBuffer argument. The result is the same, but the print method will not work if this version is used. The data encoding is UNKNOWN.

Parameters:
length - Length of the pre-encoded component. This must be the last item in the type and already exist in the encode buffer.

Asn1OpenType

public Asn1OpenType(java.lang.String data,
                    int encoding)
Convenience constructor. Same as Asn1OpenType(data.toCharArray(), encoding)


Asn1OpenType

public Asn1OpenType(char[] data,
                    int encoding)
Create Asn1OpenType on the given character data.

Parameters:
data - The character data array.
encoding - The encoding. Either XER or JSON. If JSON, data is taken to be the JSON encoding of the actual value. The array is not copied, so beware using it after passing it here. The value field will be assigned null. If XER, data is taken to be the XER encoding of the actual value. The value field will be assigned the UTF-8 character encoding of the given characters.
Method Detail

getCharData

public char[] getCharData()
Returns the character data for the open type. Currently, this is only supported when getDataEncoding() returns JSON.

Returns:
The char data. The actual internal array is returned; a copy is not made.
Throws:
java.lang.RuntimeException - if data encoding indicates there is no char data.

setBinaryData

public void setBinaryData(byte[] data,
                          int encoding)
Sets the binary data for the open type and assigns the data encoding to the given encoding.

Parameters:
data - The binary data that make up an encoding of the actual value.
encoding - Identifies the encoding rules for which data is an encoding. This can be any of the encodings except JSON.

setCharData

public void setCharData(java.lang.String data,
                        int encoding)
Convenience method; same as setCharData(value.toCharArray(), encoding)


setCharData

public void setCharData(char[] data,
                        int encoding)
Sets the character data for the open type and assigns the data encoding to the given encoding.

Parameters:
data - The character data that make up an encoding of the actual value.
encoding - Permissible values are JSON and XER. If XER, the given data will be converted to bytes using UTF-8 and held in the value field. If JSON, the given data will be held as-is. The array will not be copied. The value field will be assigned null.

getDataEncoding

public int getDataEncoding()
Return the data encoding of the data.

Returns:

decode

public void decode(Asn1BerDecodeBuffer buffer,
                   boolean explicit,
                   int implicitLength)
            throws Asn1Exception,
                   java.io.IOException
This method decodes an ASN.1 open type value. The data encoding will be set to BER.

Specified by:
decode in interface Asn1TypeIF
Overrides:
decode in class Asn1OctetString
Parameters:
buffer - Decode message buffer object
explicit - Flag indicating element is explicitly tagged
implicitLength - Length of contents if implicit
Throws:
Asn1Exception
java.io.IOException

encode

public int encode(Asn1BerEncodeBuffer buffer,
                  boolean explicit)
           throws Asn1Exception
This method encodes an ASN.1 open type value. The value is assumed to be an already-encoded BER message component and will be copied to the encoded buffer. An optimization is available in which no copy will performed if the encoded component is already present in the encode buffer. This is done if the form of constructor specifiying only a component length is used.

Specified by:
encode in interface Asn1TypeIF
Overrides:
encode in class Asn1OctetString
Parameters:
buffer - Encode message buffer object
explicit - Flag indicating element is explicitly tagged
Returns:
Length of encoded component
Throws:
Asn1Exception

decode

public void decode(Asn1PerDecodeBuffer buffer)
            throws Asn1Exception,
                   java.io.IOException
This method decodes an ASN.1 open type value using the packed encoding rules (PER). The data encoding will be set to PER.

Specified by:
decode in interface Asn1TypeIF
Overrides:
decode in class Asn1OctetString
Parameters:
buffer - Decode message buffer object
Throws:
Asn1Exception
java.io.IOException

encode

public void encode(Asn1PerEncodeBuffer buffer)
            throws Asn1Exception,
                   java.io.IOException
This method encodes an ASN.1 open type value using the Packed Encoding Rules (PER). The data should be the value pre-encoded encoded in PER.

Specified by:
encode in interface Asn1TypeIF
Overrides:
encode in class Asn1OctetString
Parameters:
buffer - Encode message buffer object
Throws:
Asn1Exception
java.io.IOException

encodeAsExtension

public void encodeAsExtension(Asn1XmlEncoder buffer)
                       throws java.io.IOException,
                              Asn1Exception
This method encodes an extension element to XML. If the data encoding is other than XER, the hexadecimal representation of the data is encoded inside an XML comment.

Parameters:
buffer - Encode message buffer object
Throws:
java.io.IOException
Asn1Exception

encode

public void encode(Asn1XmlEncoder buffer,
                   java.lang.String elemName,
                   java.lang.String nsPrefix)
            throws java.io.IOException,
                   Asn1Exception
This method encodes an ASN.1 open type value using the XML Encoding as specified in the XML schema standard(asn2xsd). If the data encoding is XER, the data is written as-is. Otherwise, the data's hexadecimal representation is encoded (i.e. xmlhstring).

Overrides:
encode in class Asn1OctetString
Parameters:
buffer - Encode message buffer object
elemName - Ignored
nsPrefix - Ignored
Throws:
java.io.IOException
Asn1Exception

encode

public void encode(Asn1XmlEncoder buffer)
            throws java.io.IOException,
                   Asn1Exception
This method encodes an ASN.1 open type value using the XML Encoding as specified in the XML schema standard(asn2xsd). If the data encoding is XER, the data is written as-is. Otherwise, the data's hexadecimal representation is encoded (i.e. xmlhstring).

Parameters:
buffer - Encode message buffer object
Throws:
java.io.IOException
Asn1Exception

encode

public void encode(Asn1XerEncoder buffer,
                   java.lang.String elemName)
            throws java.io.IOException,
                   Asn1Exception
This method encodes an ASN.1 open type value using the XML Encoding Rules (XER). If the data encoding is XER, the data is written as-is. Otherwise, the data's hexadecimal representation is encoded (i.e. xmlhstring).

Specified by:
encode in interface Asn1TypeIF
Overrides:
encode in class Asn1OctetString
Parameters:
buffer - Encode message buffer object
elemName - Ignored
Throws:
java.io.IOException - Any exception thrown by the underlying stream.
Asn1Exception - Thrown, if operation is failed.

encodeAsExtension

public void encodeAsExtension(Asn1XerEncoder buffer)
                       throws java.io.IOException,
                              Asn1Exception
This method encodes an extension element to XML. If the data encoding is other than XER, its hexadecimal representation is encoded inside an XML comment.

Throws:
java.io.IOException
Asn1Exception

encode

public void encode(Asn1XerEncoder buffer)
            throws java.io.IOException,
                   Asn1Exception
This method encodes an ASN.1 open type value using the XML Encoding Rules (XER). If the data encoding is XER, the data is written as-is. Otherwise, the data's hexadecimal representation is encoded (i.e. xmlhstring).

Specified by:
encode in interface Asn1TypeIF
Overrides:
encode in class Asn1Type
Parameters:
buffer - Encode message buffer object
Throws:
java.io.IOException - Any exception thrown by the underlying stream.
Asn1Exception - Thrown, if operation is failed.

decodeExtension

public void decodeExtension(Asn1JsonDecodeBuffer buffer,
                            java.lang.String name)
                     throws java.io.IOException
Decode an extension from JSON. There should be, possibly after some leading whitespace, a JSON value on the input. After decoding, this object's data encoding will be JSON and the character data will be the a JSONNamedValue, formed from the given (previously decoded) name and the decoded value.

Throws:
java.io.IOException

encodeAsExtension

public void encodeAsExtension(Asn1JsonOutputStream outstream)
                       throws java.io.IOException
This method encodes an extension element to JSON. If the data encoding is other than JSON, it cannot be encoded and the data is dropped.

Throws:
java.io.IOException

decode

public void decode(Asn1JsonDecodeBuffer buffer)
            throws java.io.IOException
Decode ASN.1 open type value from JSON. If the JSON value was a JSONNestedValue, the data encoding will be JSON, and the data will be character data. If the JSON value was a JSON string (a quoted xmlhstring), the data encoding will be UNKNOWN and the data will be byte data. For decoding an unknown extension element, use decodeExtension.

Overrides:
decode in class Asn1OctetString
Parameters:
buffer -
Throws:
java.io.IOException

encode

public void encode(Asn1JsonOutputStream outstream)
            throws java.io.IOException
Description copied from class: Asn1OctetString
Encode this octet string to JSON.

Overrides:
encode in class Asn1OctetString
Throws:
java.io.IOException

toString

public java.lang.String toString()
This method will return a string representation of the open type value. If the data encoding is XER or JSON, the string will consist of the corresponding characters (in the case of XER, the byte data is converted to characters using UTF-8). In all other cases, the hexadecimal representation of the byte data is returned.

Overrides:
toString in class Asn1OctetString
Returns:
Stringified representation of the value

encode

public void encode(Asn1BerOutputStream out,
                   boolean explicit)
            throws Asn1Exception,
                   java.io.IOException
This method encodes and writes to the stream an ASN.1 open type value including the UNIVERSAL tag value and length if explicit tagging is specified. This overloaded version uses the Basic Encoding Rules (BER). The data should be the value pre-encoded in BER.

Specified by:
encode in interface Asn1TypeIF
Overrides:
encode in class Asn1OctetString
Parameters:
out - BER Output Stream object
explicit - Flag indicating explicit tagging should be done
Throws:
java.io.IOException - Any exception thrown by the underlying OutputStream.
Asn1Exception - Thrown, if operation is failed.

encode

public void encode(Asn1PerOutputStream out)
            throws Asn1Exception,
                   java.io.IOException
This method encodes an ASN.1 open type value using the Packed Encoding Rules (PER). The data should be the value pre-encoded in PER.

Specified by:
encode in interface Asn1TypeIF
Overrides:
encode in class Asn1OctetString
Parameters:
out - PER Output Stream object
Throws:
java.io.IOException - Any exception thrown by the Asn1PerOutputStream.
Asn1Exception - Thrown, if operation is failed.

getSaxHandler

public Asn1XerSaxHandler getSaxHandler()
Get a SAX handler for this object. If this is the first invocation of any of the getSaxHandler methods on this object, the returned handler will capture the outer element start/end tags. Otherwise, this will simply return the same SAX handler as previously returned.

Returns:

getSaxHandler

public Asn1XerSaxHandler getSaxHandler(boolean captureOuterElem)
Get a SAX handler for this object.

Parameters:
captureOuterElem - Pass true if the outer element start and end tags (if present) should be captured. The outer element is the element for which startElement is called when the level is the start level. Note that this parameter is ignored if you have previously invoked one of the getSaxHandler methods on this object.
Returns: