com.objsys.asn1j.runtime
Class Asn1XmlEncodeBuffer

java.lang.Object
  extended by com.objsys.asn1j.runtime.Asn1MessageBufferBase
      extended by com.objsys.asn1j.runtime.Asn1MessageBuffer
          extended by com.objsys.asn1j.runtime.Asn1EncodeBuffer
              extended by com.objsys.asn1j.runtime.Asn1XmlEncodeBuffer
All Implemented Interfaces:
Asn1XmlEncoder, Asn1XmlXerEncoder

public class Asn1XmlEncodeBuffer
extends Asn1EncodeBuffer
implements Asn1XmlEncoder

This class handles the encoding of ASN.1 messages as specified in the XML Encoding (non-XER) as specified in the XML schema standard.


Field Summary
 
Fields inherited from class com.objsys.asn1j.runtime.Asn1EncodeBuffer
INITIAL_SIZE, mByteIndex, mData
 
Fields inherited from class com.objsys.asn1j.runtime.Asn1MessageBufferBase
context, mTypeCode
 
Fields inherited from interface com.objsys.asn1j.runtime.Asn1XmlEncoder
XMLDATA, XMLEND, XMLINDENT, XMLINIT, XMLSTART
 
Constructor Summary
Asn1XmlEncodeBuffer()
          The default constructor creates an XML encode buffer object with the default initial size and canonical set to false.
Asn1XmlEncodeBuffer(int size)
          The parameterized constructor creates an XML encode buffer object with initial size set to the given value.
 
Method Summary
 void binDump(java.io.PrintStream out, java.lang.String varName)
          This method dumps the encoded message in a human-readable format showing a bit trace of all fields to the given print output stream.
 void copy(byte value)
          This method is used to copy a single byte to the encode buffer.
 void copy(byte[] value)
          This method copies multiple bytes to the encode buffer.
 void copy(byte[] value, int off, int len)
          This method copies multiple bytes to the encode buffer.
 void copy(java.lang.String value)
          This method copies a character string to the encode buffer.
 void decrLevel()
          This method decrements the element nesting level counter.
 void encodeAttr(java.lang.String qname, java.lang.String value)
          This method encodes an XML attribute value.
 void encodeBinStrValue(byte[] bits, int nbits)
          This method encodes XML binary string data
 void encodeData(java.lang.String value)
          This method encodes XML string data
 void encodeDoubleValue(double value, java.lang.String elemName, java.lang.String nsPrefix)
          This method encodes an XML REAL (double) value (with start and end tags).
 void encodeEmptyElement(java.lang.String elemName, java.lang.String nsPrefix)
          This method encodes an XML empty element tag
 void encodeEndDocument()
          This method encodes standard trailor information at the end of the XML document.
 void encodeEndElement(java.lang.String elemName, java.lang.String nsPrefix)
          This method encodes an XML end element tag
 void encodeHexStrValue(byte[] data)
          This method encodes XML hexadecimal string data
 void encodeNamedValue(java.lang.String valueName, java.lang.String elemName, java.lang.String nsPrefix)
          This method encodes an XML named value (with start and end tags)
 void encodeNamedValueElement(java.lang.String elemName)
          This method encodes an XML named value element.
 void encodeStartDocument()
          This method encodes standard header information at the beginning of the XML document.
 void encodeStartElement(java.lang.String elemName, java.lang.String nsPrefix, boolean terminate)
          This method encodes an XML start element tag.
 void encodeXSIAttrs()
          This method encodes XSI attributes.
 byte[] getBuffer()
          This method returns a reference to the byte buffer used to hold the encoded message.
 Asn1XmlEncodeHelper getHelper()
          This method returns a reference to the internal helper object.
 java.io.InputStream getInputStream()
          This method returns an input stream object reference to the message buffer contents (i.e. the encoded data).
 byte[] getMsgCopy()
          This method returns the encoded message in a byte array.
 int getMsgLength()
          This method returns the length (in bytes) of the encoded message component.
 void incrLevel()
          This method increments the element nesting level counter.
 void indent()
          This methods indents by adding a new-line followed by whitespace corresponding to the current nesting level to the encode buffer.
 void reset()
          This method resets the buffer to allow a new record to be encoded into it.
 void setIndent(int value)
          This method sets the number of spaces per indentation.
 void setMixedContent(boolean value)
          This method sets the mixed content flag which indicates that this buffer will be used to encode mixed content.
 void setTermStart(boolean value)
          This method sets the start element termination required flag.
 void setXSIAttrs(Asn1XmlXSIAttrs value)
          This method sets the XSI attributes object to the given value.
 void write(java.io.OutputStream out)
          This method writes the encoded record to the given output stream.
 
Methods inherited from class com.objsys.asn1j.runtime.Asn1EncodeBuffer
binDump, checkSize, hexDump, hexDump, initBuffer, trimBitString
 
Methods inherited from class com.objsys.asn1j.runtime.Asn1MessageBuffer
addNamedEventHandler, getEventHandlerListCount, hasEventHandlers, invokeCharacters, invokeEndElement, invokeStartElement, setEventHandlerList
 
Methods inherited from class com.objsys.asn1j.runtime.Asn1MessageBufferBase
getContext, hexDump, hexDump, setKey, setTypeCode
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.objsys.asn1j.runtime.Asn1XmlXerEncoder
getContext
 

Constructor Detail

Asn1XmlEncodeBuffer

public Asn1XmlEncodeBuffer()
The default constructor creates an XML encode buffer object with the default initial size and canonical set to false.


Asn1XmlEncodeBuffer

public Asn1XmlEncodeBuffer(int size)
The parameterized constructor creates an XML encode buffer object with initial size set to the given value.

Parameters:
size - The initial size in bytes of an encode buffer. If this parameter is set to zero, the default increment will be used.
Method Detail

binDump

public void binDump(java.io.PrintStream out,
                    java.lang.String varName)
This method dumps the encoded message in a human-readable format showing a bit trace of all fields to the given print output stream.

Specified by:
binDump in class Asn1EncodeBuffer

copy

public void copy(byte value)
This method is used to copy a single byte to the encode buffer. It first converts the byte to a hex character representation and then copies it to the output buffer.

Specified by:
copy in interface Asn1XmlXerEncoder
Specified by:
copy in class Asn1EncodeBuffer
Parameters:
value - The byte value to copy

copy

public void copy(byte[] value)
          throws Asn1Exception
This method copies multiple bytes to the encode buffer. It is assumed the byte are already formatted into a valid XML encoding type (for example, UTF-8).

Specified by:
copy in interface Asn1XmlXerEncoder
Specified by:
copy in class Asn1EncodeBuffer
Parameters:
value - Array of bytes to copy to the encode buffer
Throws:
Asn1Exception - Thrown, if operation is failed.

copy

public void copy(byte[] value,
                 int off,
                 int len)
          throws java.io.IOException,
                 Asn1Exception
This method copies multiple bytes to the encode buffer. It is assumed the byte are already formatted into a valid XML encoding type (for example, UTF-8).

Specified by:
copy in interface Asn1XmlXerEncoder
Parameters:
value - Array of bytes to copy to the encode buffer
off - Starting offset in array
len - The length to be encoded
Throws:
java.io.IOException - If I/O error occurs.
Asn1Exception - Thrown, if operation is failed.

copy

public void copy(java.lang.String value)
          throws java.io.IOException,
                 Asn1Exception
This method copies a character string to the encode buffer.

Specified by:
copy in interface Asn1XmlXerEncoder
Parameters:
value - The string value to copy
Throws:
java.io.IOException - If I/O error occurs.
Asn1Exception - Thrown, if operation is failed.

decrLevel

public void decrLevel()
This method decrements the element nesting level counter.

Specified by:
decrLevel in interface Asn1XmlXerEncoder

encodeData

public void encodeData(java.lang.String value)
                throws java.io.IOException,
                       Asn1Exception
This method encodes XML string data

Specified by:
encodeData in interface Asn1XmlXerEncoder
Parameters:
value - String value to encode
Throws:
java.io.IOException - If I/O error occurs.
Asn1Exception - Thrown, if operation is failed.

encodeAttr

public void encodeAttr(java.lang.String qname,
                       java.lang.String value)
                throws java.io.IOException,
                       Asn1Exception
This method encodes an XML attribute value.

Specified by:
encodeAttr in interface Asn1XmlEncoder
Parameters:
qname - Attribute qualified name.
value - Attribute value in string form.
Throws:
java.io.IOException
Asn1Exception

encodeBinStrValue

public void encodeBinStrValue(byte[] bits,
                              int nbits)
                       throws java.io.IOException,
                              Asn1Exception
This method encodes XML binary string data

Specified by:
encodeBinStrValue in interface Asn1XmlXerEncoder
Parameters:
bits - Bit string to encode
Throws:
java.io.IOException - If I/O error occurs.
Asn1Exception - Thrown, if operation is failed.

encodeDoubleValue

public void encodeDoubleValue(double value,
                              java.lang.String elemName,
                              java.lang.String nsPrefix)
                       throws java.io.IOException,
                              Asn1Exception
This method encodes an XML REAL (double) value (with start and end tags).

Specified by:
encodeDoubleValue in interface Asn1XmlEncoder
Parameters:
value - The value to be encoded.
elemName - The name of element. If null, then start and end tags won't be encoded.
nsPrefix - Element namespace prefix value
Throws:
java.io.IOException - If I/O error occurs.
Asn1Exception - Thrown, if operation is failed.

encodeEmptyElement

public void encodeEmptyElement(java.lang.String elemName,
                               java.lang.String nsPrefix)
                        throws java.io.IOException,
                               Asn1Exception
This method encodes an XML empty element tag

Specified by:
encodeEmptyElement in interface Asn1XmlEncoder
Parameters:
elemName - The name of element.
nsPrefix - The namespace prefix of element.
Throws:
java.io.IOException - If I/O error occurs.
Asn1Exception - Thrown, if operation is failed.

encodeEndDocument

public void encodeEndDocument()
                       throws java.io.IOException,
                              Asn1Exception
This method encodes standard trailor information at the end of the XML document.

Specified by:
encodeEndDocument in interface Asn1XmlXerEncoder
Throws:
java.io.IOException - If I/O error occurs.
Asn1Exception - Thrown, if operation is failed.

encodeEndElement

public void encodeEndElement(java.lang.String elemName,
                             java.lang.String nsPrefix)
                      throws java.io.IOException,
                             Asn1Exception
This method encodes an XML end element tag

Specified by:
encodeEndElement in interface Asn1XmlEncoder
Parameters:
elemName - The name of element.
nsPrefix - Namespace prefix.
Throws:
java.io.IOException - If I/O error occurs.
Asn1Exception - Thrown, if operation is failed.

encodeHexStrValue

public void encodeHexStrValue(byte[] data)
                       throws java.io.IOException,
                              Asn1Exception
This method encodes XML hexadecimal string data

Specified by:
encodeHexStrValue in interface Asn1XmlXerEncoder
Parameters:
data - Data to encode
Throws:
java.io.IOException - If I/O error occurs.
Asn1Exception - Thrown, if operation is failed.

encodeNamedValue

public void encodeNamedValue(java.lang.String valueName,
                             java.lang.String elemName,
                             java.lang.String nsPrefix)
                      throws Asn1Exception,
                             java.io.IOException
This method encodes an XML named value (with start and end tags)

Specified by:
encodeNamedValue in interface Asn1XmlEncoder
Parameters:
valueName - The name of value.
elemName - The name of element.
nsPrefix - Element namespace prefix value
Throws:
Asn1Exception - Thrown, if operation is failed.
java.io.IOException - If I/O error occurs.

encodeNamedValueElement

public void encodeNamedValueElement(java.lang.String elemName)
                             throws Asn1Exception,
                                    java.io.IOException
This method encodes an XML named value element.

Specified by:
encodeNamedValueElement in interface Asn1XmlXerEncoder
Parameters:
elemName - The name of element.
Throws:
Asn1Exception - Thrown, if operation is failed.
java.io.IOException - If I/O error occurs.

encodeStartDocument

public void encodeStartDocument()
                         throws java.io.IOException,
                                Asn1Exception
This method encodes standard header information at the beginning of the XML document.

Specified by:
encodeStartDocument in interface Asn1XmlXerEncoder
Throws:
Asn1Exception - Thrown, if operation is failed.
java.io.IOException - If I/O error occurs.

encodeStartElement

public void encodeStartElement(java.lang.String elemName,
                               java.lang.String nsPrefix,
                               boolean terminate)
                        throws Asn1Exception,
                               java.io.IOException
This method encodes an XML start element tag.

Specified by:
encodeStartElement in interface Asn1XmlEncoder
Parameters:
elemName - The name of element.
nsPrefix - The namespace prefix of element.
Throws:
Asn1Exception - Thrown, if operation is failed.
java.io.IOException - If I/O error occurs.

encodeXSIAttrs

public void encodeXSIAttrs()
                    throws Asn1Exception,
                           java.io.IOException
This method encodes XSI attributes.

Specified by:
encodeXSIAttrs in interface Asn1XmlEncoder
Throws:
Asn1Exception
java.io.IOException

getBuffer

public byte[] getBuffer()
This method returns a reference to the byte buffer used to hold the encoded message.

Returns:
Byte buffer reference

getHelper

public Asn1XmlEncodeHelper getHelper()
This method returns a reference to the internal helper object.

Specified by:
getHelper in interface Asn1XmlEncoder
Returns:
Reference to mHelper object.

getInputStream

public java.io.InputStream getInputStream()
This method returns an input stream object reference to the message buffer contents (i.e. the encoded data). If an output stream was selected as the output method, this method returns null.

Specified by:
getInputStream in class Asn1MessageBuffer
Returns:
Input stream object reference

getMsgCopy

public byte[] getMsgCopy()
This method returns the encoded message in a byte array.

Specified by:
getMsgCopy in class Asn1EncodeBuffer
Returns:
byte array containing encoded message

getMsgLength

public int getMsgLength()
This method returns the length (in bytes) of the encoded message component.

Specified by:
getMsgLength in class Asn1EncodeBuffer
Returns:
length of encoded message component

incrLevel

public void incrLevel()
This method increments the element nesting level counter.

Specified by:
incrLevel in interface Asn1XmlXerEncoder

indent

public void indent()
            throws Asn1Exception,
                   java.io.IOException
This methods indents by adding a new-line followed by whitespace corresponding to the current nesting level to the encode buffer.

Specified by:
indent in interface Asn1XmlXerEncoder
Throws:
Asn1Exception - Thrown, if operation is failed.
java.io.IOException - If I/O error occurs.

reset

public void reset()
This method resets the buffer to allow a new record to be encoded into it. Any previously encoded data is lost.

Specified by:
reset in class Asn1EncodeBuffer

setIndent

public void setIndent(int value)
This method sets the number of spaces per indentation. If the value is set to zero, no indentation of the XML data is done.

Specified by:
setIndent in interface Asn1XmlEncoder
Parameters:
value - Number of spaces per indentation level.

setMixedContent

public void setMixedContent(boolean value)
This method sets the mixed content flag which indicates that this buffer will be used to encode mixed content.

Parameters:
value - Boolean value

setTermStart

public void setTermStart(boolean value)
This method sets the start element termination required flag.

Parameters:
value - Boolean value

setXSIAttrs

public void setXSIAttrs(Asn1XmlXSIAttrs value)
This method sets the XSI attributes object to the given value.

Specified by:
setXSIAttrs in interface Asn1XmlEncoder
Parameters:
value - XSI attributes object

write

public void write(java.io.OutputStream out)
           throws java.io.IOException
This method writes the encoded record to the given output stream.

Specified by:
write in class Asn1EncodeBuffer
Parameters:
out - Output stream to which record is to be written
Throws:
java.io.IOException