153 lines
5.8 KiB
HTML
153 lines
5.8 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="Example: Using DataQueueDocument" />
|
|
<meta name="abstract" content="" />
|
|
<meta name="description" content="" />
|
|
<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="dataqueuedocumentexample" />
|
|
<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>Example: Using DataQueueDocument</title>
|
|
</head>
|
|
<body id="dataqueuedocumentexample"><a name="dataqueuedocumentexample"><!-- --></a>
|
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
|
<h1 class="topictitle1">Example: Using DataQueueDocument</h1>
|
|
<div><p></p>
|
|
<div class="section"><div class="note"><span class="notetitle">Note:</span> Read the <a href="codedisclaimer.htm#codedisclaimer">Code
|
|
example disclaimer</a> for important legal information.</div>
|
|
<pre>/////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Data queue document example. This program demonstrates how to
|
|
// use a document that is associated with a server data queue.
|
|
//
|
|
// Command syntax:
|
|
// DataQueueDocumentExample system read|write
|
|
//
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
import com.ibm.as400.access.*;
|
|
import com.ibm.as400.vaccess.*;
|
|
import javax.swing.*;
|
|
import java.awt.*;
|
|
import java.awt.event.*;
|
|
|
|
public class DataQueueDocumentExample
|
|
{
|
|
private static DataQueueDocument dqDocument;
|
|
private static JTextField text;
|
|
private static boolean rw;
|
|
|
|
public static void main (String[] args)
|
|
{
|
|
// If a system or read|write was not specified, then display
|
|
// help text and exit.
|
|
if (args.length != 2)
|
|
{
|
|
System.out.println("Usage: DataQueueDocumentExample system read|write");
|
|
return;
|
|
}
|
|
|
|
rw = args[1].equalsIgnoreCase ("read");
|
|
String mode = rw ? "Read" : "Write";
|
|
|
|
try
|
|
{
|
|
// Create two frames.
|
|
JFrame f =
|
|
new JFrame ("Data queue document example - " + mode);
|
|
|
|
// Create an error dialog adapter. This will display
|
|
// any errors to the user.
|
|
ErrorDialogAdapter errorHandler = new ErrorDialogAdapter (f);
|
|
|
|
// Create a working cursor adapter. This will adjust
|
|
// the cursor whenever a data queue is read or written.
|
|
WorkingCursorAdapter cursorAdapter = new WorkingCursorAdapter (f);
|
|
|
|
// Create an AS400 object. The system name was passed
|
|
// as the first command line argument.
|
|
AS400 system = new AS400 (args[0]);
|
|
|
|
// Create the data queue path name.
|
|
QSYSObjectPathName dqName = new QSYSObjectPathName ("QGPL", "JAVATALK", "DTAQ");
|
|
|
|
// Make sure the the data queue exists.
|
|
DataQueue dq = new DataQueue (system, dqName.getPath ());
|
|
try
|
|
{
|
|
dq.create (200);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
// Ignore exceptions. Most likely, the data queue
|
|
// already exists.
|
|
}
|
|
|
|
// Create a DataQueueDocument object.
|
|
dqDocument = new DataQueueDocument (system, dqName.getPath ());
|
|
dqDocument.addErrorListener (errorHandler);
|
|
dqDocument.addWorkingListener (cursorAdapter);
|
|
|
|
// Create a text field used to present the document.
|
|
text = new JTextField (dqDocument, "", 40);
|
|
text.setEditable (! rw);
|
|
|
|
// When the program runs, we need a way to control when
|
|
// the reads and writes take place. We will let the
|
|
// use control this with a button.
|
|
Button button = new Button (mode);
|
|
button.addActionListener (new ActionListener ()
|
|
{
|
|
public void actionPerformed (ActionEvent event)
|
|
{
|
|
if (rw)
|
|
dqDocument.read ();
|
|
else {
|
|
dqDocument.write ();
|
|
text.setText ("");
|
|
}
|
|
}
|
|
});
|
|
|
|
// When the the frame closes, exit.
|
|
f.addWindowListener (new WindowAdapter () {
|
|
public void windowClosing (WindowEvent event)
|
|
{
|
|
System.exit (0);
|
|
}
|
|
});
|
|
|
|
// Layout the frame.
|
|
f.getContentPane ().setLayout (new FlowLayout ());
|
|
f.getContentPane ().add (text);
|
|
f.getContentPane ().add (button);
|
|
f.pack ();
|
|
f.show ();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
System.out.println ("Error: " + e.getMessage ());
|
|
System.exit (0);
|
|
}
|
|
}
|
|
}</pre>
|
|
</div>
|
|
</div>
|
|
|
|
</body>
|
|
</html> |