128 lines
4.6 KiB
HTML
128 lines
4.6 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: IBM Toolbox for Java bean code" />
|
|
<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="jbeanex" />
|
|
<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: IBM Toolbox
|
|
for Java bean
|
|
code</title>
|
|
</head>
|
|
<body id="jbeanex"><a name="jbeanex"><!-- --></a>
|
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
|
<h1 class="topictitle1">Example: IBM<sup>®</sup> Toolbox
|
|
for Java™ bean
|
|
code</h1>
|
|
<div><p></p>
|
|
<div class="section"><p>The following example creates an AS400 object and a CommandCall
|
|
object, and then registers listeners on the objects. The listeners on the
|
|
objects print a comment when the server connects or disconnects and when the
|
|
CommandCall object completes the running of a command.</p>
|
|
<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>//////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Beans example. This program uses the JavaBeans support in the
|
|
// IBM Toolbox for Java classes.
|
|
//
|
|
// Command syntax:
|
|
// BeanExample
|
|
//
|
|
//////////////////////////////////////////////////////////////////////////////////
|
|
|
|
import com.ibm.as400.access.AS400;
|
|
import com.ibm.as400.access.CommandCall;
|
|
import com.ibm.as400.access.ConnectionListener;
|
|
import com.ibm.as400.access.ConnectionEvent;
|
|
import com.ibm.as400.access.ActionCompletedListener;
|
|
import com.ibm.as400.access.ActionCompletedEvent;
|
|
|
|
class BeanExample
|
|
{
|
|
AS400 as400_ = new AS400();
|
|
CommandCall cmd_ = new CommandCall( as400_ );
|
|
|
|
BeanExample()
|
|
{
|
|
// Whenever the system is connected or disconnected print a
|
|
// comment. Do this by adding a listener to the AS400 object.
|
|
// When a system is connected or disconnected, the AS400 object
|
|
// will call this code.
|
|
|
|
as400_.addConnectionListener
|
|
(new ConnectionListener()
|
|
{
|
|
public void connected(ConnectionEvent event)
|
|
{
|
|
System.out.println( "System connected." );
|
|
}
|
|
public void disconnected(ConnectionEvent event)
|
|
{
|
|
System.out.println( "System disconnected." );
|
|
}
|
|
}
|
|
);
|
|
|
|
// Whenever a command runs to completion print a comment. Do this
|
|
// by adding a listener to the commandCall object. The commandCall
|
|
// object will call this code when it runs a command.
|
|
|
|
cmd_.addActionCompletedListener(
|
|
new ActionCompletedListener()
|
|
{
|
|
public void actionCompleted(ActionCompletedEvent event)
|
|
{
|
|
System.out.println( "Command completed." );
|
|
}
|
|
}
|
|
);
|
|
}
|
|
|
|
void runCommand()
|
|
{
|
|
try
|
|
{
|
|
// Run a command. The listeners will print comments when the
|
|
// system is connected and when the command has run to
|
|
// completion.
|
|
cmd_.run( "TESTCMD PARMS" );
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
System.out.println( ex );
|
|
}
|
|
}
|
|
|
|
public static void main(String[] parameters)
|
|
{
|
|
BeanExample be = new BeanExample();
|
|
|
|
be.runCommand();
|
|
|
|
System.exit(0);
|
|
}
|
|
}
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
|
|
</body>
|
|
</html> |