Verastream Transaction Integrator 4.0

com.attachmate.transaction.runtime.common.util
Class DataToolKit

java.lang.Object
  extended by com.attachmate.transaction.runtime.common.util.DataToolKit

public class DataToolKit
extends java.lang.Object

Utility class for conversion of data from Java variables to host COBOL variable memory representation, and vice-versa. The specification of the Java variable is contained in the method signature. The description of the COBOL variable is indicated as a PICTURE specification in a String parameter of the API. The host COBOL variable memory representation is represented as an array of bytes, encoded in the format and encoding of the host. Context for the code page of the host, and the specification of a decimal point as a comma or as a period is also provided.


Constructor Summary
DataToolKit()
          Constructor for DataToolKit.
DataToolKit(int hostCodePage)
          Constructor for DataToolKit, with option to override default host code page
 
Method Summary
 boolean getDecimalPointIsComma()
          Returns current setting to use a comma as a decimal point in numeric data.
 double getDoubleFromHostBytes(java.lang.String pictureDescription, byte[] hostBytes)
          Returns the double value obtained by decoding the input bytes, which represent a host memory image of a COBOL field defined with the input pictureDescription.
 float getFloatFromHostBytes(java.lang.String pictureDescription, byte[] hostBytes)
          Returns the float value obtained by decoding the input bytes, which represent a host memory image of a COBOL field defined with the input pictureDescription.
 byte[] getHostBytesFromDouble(double doubleValue, java.lang.String pictureDescription)
          Returns a byte array containing the host memory representation of a COBOL field defined according to the supplied COBOL PICTURE specification, and containing the value represented by the input double variable.
 byte[] getHostBytesFromFloat(float floatValue, java.lang.String pictureDescription)
          Returns a byte array containing the host memory representation of a COBOL field defined according to the supplied COBOL PICTURE specification, and containing the value represented by the input floating point variable.
 byte[] getHostBytesFromInt(int intValue, java.lang.String pictureDescription)
          Returns a byte array containing the host memory representation of a COBOL field defined according to the supplied COBOL PICTURE specification, and containing the value represented by the input int variable.
 byte[] getHostBytesFromLong(long longValue, java.lang.String pictureDescription)
          Returns a byte array containing the host memory representation of a COBOL field defined according to the supplied COBOL PICTURE specification, and containing the value represented by the input long variable.
 byte[] getHostBytesFromShort(short shortValue, java.lang.String pictureDescription)
          Returns a byte array containing the host memory representation of a COBOL field defined according to the supplied COBOL PICTURE specification, and containing the value represented by the input short variable.
 byte[] getHostBytesFromString(java.lang.String stringValue, java.lang.String pictureDescription)
          Returns a byte array containing the host memory representation of a COBOL field defined according to the supplied COBOL PICTURE specification, and containing the value represented by the input client codepage String variable.
 int getHostCodePage()
          Returns the codepage value set for host-formatted representations.
 int getIntFromHostBytes(java.lang.String pictureDescription, byte[] hostBytes)
          Returns the int value obtained by decoding the input bytes, which represent a host memory image of a COBOL field defined with the input pictureDescription.
 long getLongFromHostBytes(java.lang.String pictureDescription, byte[] hostBytes)
          Returns the long value obtained by decoding the input bytes, which represent a host memory image of a COBOL field defined with the input pictureDescription.
 short getShortFromHostBytes(java.lang.String pictureDescription, byte[] hostBytes)
          Returns the short value obtained by decoding the input bytes, which represent a host memory image of a COBOL field defined with the input pictureDescription.
 java.lang.String getStringFromHostBytes(java.lang.String pictureDescription, byte[] hostBytes)
          Returns the String value obtained by decoding the input bytes, which represent a host memory image of a COBOL field defined with the input pictureDescription.
 void parseOneCopybookLine(java.lang.String pictureDescription)
           
 void setDecimalPointIsComma(boolean decimalIsComma)
          Select whether to use a comma as a decimal point in numeric data.
 void setHostCodePage(int hostCodePage)
          Sets the codepage to be used for host-formatted representations.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataToolKit

public DataToolKit()
Constructor for DataToolKit. Default values for Host Code Page and decimal point representations are used.

See Also:
getHostCodePage( ), getDecimalPointIsComma( )

DataToolKit

public DataToolKit(int hostCodePage)
Constructor for DataToolKit, with option to override default host code page

Parameters:
hostCodePage - the code page to be used for host data representations.
See Also:
getHostCodePage( ), getDecimalPointIsComma( )
Method Detail

setHostCodePage

public void setHostCodePage(int hostCodePage)
Sets the codepage to be used for host-formatted representations. Note: default value is '37'.

Parameters:
hostCodePage - the code page to be used for host data representations.
See Also:
getHostCodePage( )

getHostCodePage

public int getHostCodePage()
Returns the codepage value set for host-formatted representations.

See Also:
setHostCodePage( int )

setDecimalPointIsComma

public void setDecimalPointIsComma(boolean decimalIsComma)
Select whether to use a comma as a decimal point in numeric data. This setting affects the way that PICTURE descriptions are interpreted for the DataToolKit APIs. Comma may be required for some European systems. If set to 'true' 9,999.99 becomes 9.999,99, and a PIC value of 999.99 becomes 999,99. Note: the default value for this attribute is 'false'.

Parameters:
decimalIsComma - boolean value indicating whether a comma should be used as the decimal point indicator.
See Also:
getDecimalPointIsComma( ), setHostCodePage( int ), getHostCodePage( )

getDecimalPointIsComma

public boolean getDecimalPointIsComma()
Returns current setting to use a comma as a decimal point in numeric data. If set to 'true' 9,999.99 becomes 9.999,99, and a PICTURE description of 999.99 would be specified as 999,99

See Also:
setDecimalPointIsComma( boolean ), setHostCodePage( int ), getHostCodePage( )

getHostBytesFromShort

public byte[] getHostBytesFromShort(short shortValue,
                                    java.lang.String pictureDescription)
                             throws TaskException
Returns a byte array containing the host memory representation of a COBOL field defined according to the supplied COBOL PICTURE specification, and containing the value represented by the input short variable.

Parameters:
shortValue - short integral value that will be encoded into the returned host formatted bytes
pictureDescription - COBOL PICTURE specification describing the format and encoding to be used in creating the response bytes as a memory representation of a COBOL variable. Example: to get bytes for a field defined as "PIC S9(4) COMP", specify this field as "S9(4) COMP"
Returns:
a byte array representation of the memory contents behind a COBOL data field defined with the input PICTURE description, and containing the input short value. The number of bytes in the array will match the size of the PICTURE supplied.
Throws:
TaskException - if an error occurs converting the input value into the memory representation described by pictureDescription.

getHostBytesFromInt

public byte[] getHostBytesFromInt(int intValue,
                                  java.lang.String pictureDescription)
                           throws TaskException
Returns a byte array containing the host memory representation of a COBOL field defined according to the supplied COBOL PICTURE specification, and containing the value represented by the input int variable.

Parameters:
intValue - int value that will be encoded into the returned host formatted bytes
pictureDescription - COBOL PICTURE specification describing the format and encoding to be used in creating the response bytes as a memory representation of a COBOL variable. Example: to get bytes for a field defined as "PIC S9(8) USAGE IS COMP", specify this field as "S9(8) USAGE IS COMP"
Returns:
a byte array representation of the memory contents behind a COBOL data field defined with the input PICTURE description, and containing the input int value. The number of bytes in the array will match the size of the PICTURE supplied.
Throws:
TaskException - if an error occurs converting the input value into the memory representation described by pictureDescription.

getHostBytesFromLong

public byte[] getHostBytesFromLong(long longValue,
                                   java.lang.String pictureDescription)
                            throws TaskException
Returns a byte array containing the host memory representation of a COBOL field defined according to the supplied COBOL PICTURE specification, and containing the value represented by the input long variable.

Parameters:
longValue - long value that will be encoded into the returned host formatted bytes
pictureDescription - COBOL PICTURE specification describing the format and encoding to be used in creating the response bytes as a memory representation of a COBOL variable. Example: to get bytes for a field defined as "PIC S9(18) COMP-4", specify this field as "S9(18) COMP-4"
Returns:
a byte array representation of the memory contents behind a COBOL data field defined with the input PICTURE description, and containing the input long value. The number of bytes in the array will match the size of the PICTURE supplied.
Throws:
TaskException - if an error occurs converting the input value into the memory representation described by pictureDescription.

getHostBytesFromDouble

public byte[] getHostBytesFromDouble(double doubleValue,
                                     java.lang.String pictureDescription)
                              throws TaskException
Returns a byte array containing the host memory representation of a COBOL field defined according to the supplied COBOL PICTURE specification, and containing the value represented by the input double variable.

Parameters:
doubleValue - double value that will be encoded into the returned host formatted bytes
pictureDescription - COBOL PICTURE specification describing the format and encoding to be used in creating the response bytes as a memory representation of a COBOL variable. Example: to get bytes for a field defined as "USAGE IS COMP-2", specify this field as "USAGE IS COMP-2"
Returns:
a byte array representation of the memory contents behind a COBOL data field defined with the input PICTURE description, and containing the input double value. The number of bytes in the array will match the size of the PICTURE supplied.
Throws:
TaskException - if an error occurs converting the input value into the memory representation described by pictureDescription.

getHostBytesFromFloat

public byte[] getHostBytesFromFloat(float floatValue,
                                    java.lang.String pictureDescription)
                             throws TaskException
Returns a byte array containing the host memory representation of a COBOL field defined according to the supplied COBOL PICTURE specification, and containing the value represented by the input floating point variable.

Parameters:
floatValue - floating point value that will be encoded into the returned host formatted bytes
pictureDescription - COBOL PICTURE specification describing the format and encoding to be used in creating the response bytes as a memory representation of a COBOL variable. Example: to get bytes for a field defined as "USAGE IS COMPUTATIONAL-1", specify this field as "USAGE IS COMPUTATIONAL-1"
Returns:
a byte array representation of the memory contents behind a COBOL data field defined with the input PICTURE description, and containing the input float value. The number of bytes in the array will match the size of the PICTURE supplied.
Throws:
TaskException - if an error occurs converting the input value into the memory representation described by pictureDescription.

getHostBytesFromString

public byte[] getHostBytesFromString(java.lang.String stringValue,
                                     java.lang.String pictureDescription)
                              throws TaskException
Returns a byte array containing the host memory representation of a COBOL field defined according to the supplied COBOL PICTURE specification, and containing the value represented by the input client codepage String variable.

Parameters:
stringValue - String value that will be encoded into the returned host formatted bytes
pictureDescription - COBOL PICTURE specification describing the format and encoding to be used in creating the response bytes as a memory representation of a COBOL variable. Example: to get bytes for a field defined as "PIC X(100)", specify this field as "X(100)"
Returns:
a byte array representation of the memory contents behind a COBOL data field defined with the input PICTURE description, and containing the input String value. The number of bytes in the array will match the size of the PICTURE supplied.
Throws:
TaskException - if an error occurs converting the input value into the memory representation described by pictureDescription.
See Also:
setHostCodePage( int )

getShortFromHostBytes

public short getShortFromHostBytes(java.lang.String pictureDescription,
                                   byte[] hostBytes)
                            throws TaskException
Returns the short value obtained by decoding the input bytes, which represent a host memory image of a COBOL field defined with the input pictureDescription.

Parameters:
pictureDescription - the COBOL PICTURE specification that was used to encode the value represented by the input host bytes. Example: to get the value of a field defined as "PIC S9(4) COMP", specify this field as "S9(4) COMP"
hostBytes - a byte array representation of the memory contents behind a host COBOL data field defined with the input PICTURE description and containing a valid value for that PICTURE specification.
Returns:
a short variable containing the value represented by the input bytes as interpreted according to the input pictureDescription.
Throws:
TaskException - if an error occurs decoding the input host COBOL memory representation bytes using the input pictureDescription.

getIntFromHostBytes

public int getIntFromHostBytes(java.lang.String pictureDescription,
                               byte[] hostBytes)
                        throws TaskException
Returns the int value obtained by decoding the input bytes, which represent a host memory image of a COBOL field defined with the input pictureDescription.

Parameters:
pictureDescription - the COBOL PICTURE specification that was used to encode the value represented by the input host bytes. Example: to get the value of a field defined as "PIC S9(8) COMP", specify this field as "S9(8) COMP"
hostBytes - a byte array representation of the memory contents behind a host COBOL data field defined with the input PICTURE description and containing a valid value for that PICTURE specification.
Returns:
an int variable containing the value represented by the input bytes as interpreted according to the input pictureDescription.
Throws:
TaskException - if an error occurs decoding the input host COBOL memory representation bytes using the input pictureDescription.

getLongFromHostBytes

public long getLongFromHostBytes(java.lang.String pictureDescription,
                                 byte[] hostBytes)
                          throws TaskException
Returns the long value obtained by decoding the input bytes, which represent a host memory image of a COBOL field defined with the input pictureDescription.

Parameters:
pictureDescription - the COBOL PICTURE specification that was used to encode the value represented by the input host bytes. Example: to get the value of a field defined as "PIC S9(18) BINARY", specify this field as "S9(18) BINARY"
hostBytes - a byte array representation of the memory contents behind a host COBOL data field defined with the input PICTURE description and containing a valid value for that PICTURE specification.
Returns:
a long variable containing the value represented by the input bytes as interpreted according to the input pictureDescription.
Throws:
TaskException - if an error occurs decoding the input host COBOL memory representation bytes using the input pictureDescription.

getDoubleFromHostBytes

public double getDoubleFromHostBytes(java.lang.String pictureDescription,
                                     byte[] hostBytes)
                              throws TaskException
Returns the double value obtained by decoding the input bytes, which represent a host memory image of a COBOL field defined with the input pictureDescription.

Parameters:
pictureDescription - the COBOL PICTURE specification that was used to encode the value represented by the input host bytes. Example: to get the value of a field defined as "USAGE COMP-2", specify this field as "USAGE COMP-2"
hostBytes - a byte array representation of the memory contents behind a host COBOL data field defined with the input PICTURE description and containing a valid value for that PICTURE specification.
Returns:
a double variable containing the value represented by the input bytes as interpreted according to the input pictureDescription.
Throws:
TaskException - if an error occurs decoding the input host COBOL memory representation bytes using the input pictureDescription.

getFloatFromHostBytes

public float getFloatFromHostBytes(java.lang.String pictureDescription,
                                   byte[] hostBytes)
                            throws TaskException
Returns the float value obtained by decoding the input bytes, which represent a host memory image of a COBOL field defined with the input pictureDescription.

Parameters:
pictureDescription - the COBOL PICTURE specification that was used to encode the value represented by the input host bytes. Example: to get the value of a field defined as "USAGE IS COMPUTATIONAL-1", specify this field as "USAGE IS COMPUTATIONAL-1"
hostBytes - a byte array representation of the memory contents behind a host COBOL data field defined with the input PICTURE description and containing a valid value for that PICTURE specification.
Returns:
a float variable containing the value represented by the input bytes as interpreted according to the input pictureDescription.
Throws:
TaskException - if an error occurs decoding the input host COBOL memory representation bytes using the input pictureDescription.

getStringFromHostBytes

public java.lang.String getStringFromHostBytes(java.lang.String pictureDescription,
                                               byte[] hostBytes)
                                        throws TaskException
Returns the String value obtained by decoding the input bytes, which represent a host memory image of a COBOL field defined with the input pictureDescription.

Parameters:
pictureDescription - the COBOL PICTURE specification that was used to encode the value represented by the input host bytes. Example: to get the value of a field defined as "PIC X(25)", specify this field as "X(25)"
hostBytes - a byte array representation of the memory contents behind a host COBOL data field defined with the input PICTURE description and containing a valid value for that PICTURE specification.
Returns:
a String variable in client codepage containing the value represented by the input bytes as interpreted according to the input pictureDescription.
Throws:
TaskException - if an error occurs decoding the input host COBOL memory representation bytes using the input pictureDescription.

parseOneCopybookLine

public void parseOneCopybookLine(java.lang.String pictureDescription)
                          throws ParseException,
                                 TokenMgrError
Throws:
ParseException
TokenMgrError

Verastream Transaction Integrator 4.0