86 lines
4.0 KiB
HTML
86 lines
4.0 KiB
HTML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE html
|
|
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html lang="en-us" xml:lang="en-us">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
<meta name="security" content="public" />
|
|
<meta name="Robots" content="index,follow" />
|
|
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
|
|
<meta name="DC.Type" content="reference" />
|
|
<meta name="DC.Title" content="Conversion classes for composite types" />
|
|
<meta name="abstract" content="Conversion classes for composite types are as follows." />
|
|
<meta name="description" content="Conversion classes for composite types are as follows." />
|
|
<meta name="copyright" content="(C) Copyright IBM Corporation 2006" />
|
|
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 2006" />
|
|
<meta name="DC.Format" content="XHTML" />
|
|
<meta name="DC.Identifier" content="dtadcomp" />
|
|
<meta name="DC.Language" content="en-us" />
|
|
<!-- All rights reserved. Licensed Materials Property of IBM -->
|
|
<!-- US Government Users Restricted Rights -->
|
|
<!-- Use, duplication or disclosure restricted by -->
|
|
<!-- GSA ADP Schedule Contract with IBM Corp. -->
|
|
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
|
|
<link rel="stylesheet" type="text/css" href="./ic.css" />
|
|
<title>Conversion classes for composite types</title>
|
|
</head>
|
|
<body id="dtadcomp"><a name="dtadcomp"><!-- --></a>
|
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
|
<h1 class="topictitle1">Conversion classes for composite types</h1>
|
|
<div><p>Conversion classes for composite types are as follows.</p>
|
|
<div class="section"><ul><li><a href="javadoc/com/ibm/as400/access/AS400Array.html#NAVBAR_TOP"> AS400Array</a> - Allows the Java™ program to work with an array of data
|
|
types.</li>
|
|
<li><a href="javadoc/com/ibm/as400/access/AS400Structure.html#NAVBAR_TOP"> AS400Structure</a> - Allows the Java program to work with a structure whose
|
|
elements are data types.</li>
|
|
</ul>
|
|
</div>
|
|
<div class="section"><h4 class="sectiontitle">Example: Converting composite data types</h4><p>The following
|
|
example shows conversion from a Java structure to a byte array and back
|
|
again. The example assumes that the same data format is used for both sending
|
|
and receiving data.</p>
|
|
<pre> // Create a structure of data types that corresponds to a structure
|
|
// that contains: - a four-byte number
|
|
// - four bytes of pad
|
|
// - an eight-byte number
|
|
// - 40 characters
|
|
AS400DataType[] myStruct =
|
|
{
|
|
new AS400Bin4(),
|
|
new AS400ByteArray(4),
|
|
new AS400Float8(),
|
|
new AS400Text(40)
|
|
};
|
|
|
|
// Create a conversion object using the structure.
|
|
AS400Structure myConverter = new AS400Structure(myStruct);
|
|
|
|
// Create the Java object that holds the data to send to the server.
|
|
Object[] myData =
|
|
{
|
|
new Integer(88), // the four-byte number
|
|
new byte[0], // the pad (let the conversion object 0 pad)
|
|
new Double(23.45), // the eight-byte floating point number
|
|
"This is my structure" // the character string
|
|
};
|
|
|
|
// Convert from Java object to byte array.
|
|
byte[] myAS400Data = myConverter.toBytes(myData);
|
|
|
|
|
|
// ... send the byte array to the server. Get data back from the
|
|
// server. The returned data will also be a byte array.
|
|
|
|
|
|
// Convert the returned data from iSeries to Java format.
|
|
Object[] myRoundTripData = (Object[])myConverter.toObject(myAS400Data,0);
|
|
|
|
// Pull the third object out of the structure. This is the double.
|
|
Double doubleObject = (Double) myRoundTripData[2];
|
|
|
|
// Extract the simple Java type from the Java object.
|
|
double d = doubleObject.doubleValue();</pre>
|
|
</div>
|
|
</div>
|
|
|
|
</body>
|
|
</html> |