Example: Using Java beans in IBM Toolbox for Java
//////////////////////////////////////////////////////////////////////////////////
//
// Beans example. This program uses the Java beans support in the
// IBM Toolbox for Java classes.
//
// Command syntax:
// BeanExample
//
//////////////////////////////////////////////////////////////////////////////////
//
// This source is an example of Java beans in the IBM Toolbox for Java.
// IBM grants you a nonexclusive license to use this as an example
// from which you can generate similar function tailored to
// your own specific needs.
//
// This sample code is provided by IBM for illustrative purposes
// only. These examples have not been thoroughly tested under all
// conditions. IBM, therefore, cannot guarantee or imply
// reliability, serviceability, or function of these programs.
//
// All programs contained herein are provided to you "AS IS"
// without any warranties of any kind. The implied warranties of
// merchantablility and fitness for a particular purpose are
// expressly disclaimed.
//
// IBM Toolbox for Java
// (C) Copyright IBM Corp. 1997
// All rights reserved.
// US Government Users Restricted Rights -
// Use, duplication, or disclosure restricted
// by GSA ADP Schedule Contract with IBM Corp.
//
//////////////////////////////////////////////////////////////////////////////////
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 command call 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);
}
}