C H A P T E R  6

Sun 3270 Pathway Bean Programmable Interface

The Sun 3270 Pathway Bean supports a programmable interface that enables developers to have direct access to manipulate and customize the 3270 emulator for their programs.

This chapter contains the following topics:


Available Classes

Within the com.sun.emp.pathway.bean package there are three classes:

TABLE 6-1 Pathway Bean Classes

Class

Description

Terminal

The actual 3270 emulator. This is a subclass of javax.swing.JComponent and can be made visible and used in the same way as other Java Foundation Classes (JFC/Swing) components. However, it is not necessary to display a Terminal. It is fully functional whether it is visible or not.

When a Terminal is visible, it displays a customizable representation of the 3270 screen. When not visible, there is a slight performance advantage.

This class generates two event types:

java.beans.PropertyChangeEvent

com.sun.emp.pathway.bean.TerminalEvent

TerminalEvent

One of the event types generated by the Terminal class.

TerminalField

The representation of a 3270 field.


There are two Java interfaces:

TABLE 6-2 Pathway Bean Interfaces

Interface

Description

TerminalListener

An interface that classes should implement when listening for TerminalEvent events.

TerminalCondition

An abstract condition used in waiting for a terminal.


There is one exception:

TABLE 6-3 Pathway Bean Exception

Exception

Description

TerminalConditionException

An exception thrown as a result of a runtime exception being thrown by a TerminalCondition.


Most programming is done directly to the Terminal class. For a complete description of the available classes and methods, refer to the HTML API documentation that is located at:

INSTROOT/doc/index.html


Instantiating a Terminal Object

The Java Bean specification states that all beans should have a zero parameter constructor. The primary method of constructing a Terminal object uses the zero parameter constructor.

The Terminal class has two constructors, as shown in the following table:

Constructor

Description

public Terminal()

This zero parameter constructor is the primary means for creating a Terminal object. It sets all its properties to default values.

public Terminal
(Terminal terminalSource)

This constructor enables an application to have two views of the same underlying TN3270 connection. After the new object is created, both the source and created objects share the underlying transportation mechanisms and can be thought of as representing the same connection.

The public Terminal (Terminal terminalSource) constructor enables the application to present the 3270 screen to the user in different ways.

All network-type properties of the emulator are shared between the two Terminal objects. For example, if you call setTN3270Host("fred") on one, the result of calling getTN3270Host() on the other is "fred".

All presentation-type properties of the emulator are separate for the two Terminal objects. For example, if you call the setFont(f) on one, the other emulator is not affected.

A Terminal that was created using this constructor is considered to be entirely symmetric with the terminalSource Terminal from which it was constructed, that is, equal siblings rather than parent and child.



Connecting a Terminal

When you create an instance of a Terminal, it is not connected to any host system. You use the connect() method with a valid set of values assigned to the following properties to connect a Terminal to a TN3270 host.

Property

Description

host

The host to which to connect this emulator. Default is localhost.

Set the property using the setTN3270Host(String host) method.

port

The TCP/IP port to which to connect. Default is 2001.

Set the property using the setTN3270Port(int portnumber) method.

model

The terminal model to emulate. Default is Model 2-E.

Set the property using the setModel(int model) method.


The connect() method is an asynchronous call. Attempting to call it when the connection state is anything other than disconnected results in the generation of an IllegalStateException.

The following properties also affect the connection process:

Property

Description

TN3270EAllowed

If true, the Terminal uses the TN3270E protocol if the host asks it to do so. This is the default behavior.

If false, the Terminal acts as if it does not support the TN3270E protocol.

Set the property using the setTN3270EAllowed(boolean allowed) method.

preferredNetname

If this property has a non-empty value, the Terminal attempts to connect to the TN3270E system as the specified netname. Default is empty.

Set the property using the setPreferredNetname(String netname) method.


The following example shows an easy way to create and start a 3270 emulator:

Terminal term = new Terminal();
term.setTN3270Host("www.myhost.com");
term.setTN3270Port(9993);
term.connect();

There are special considerations when connecting in an applet environment. Normally, the TN3270 host must be the same as that from which the HTML of the containing web page was served. To obtain this information, you can use the getDocumentBase() method in the java.awt.Applet; for example:

term.setTN3270Host(getDocumentBase().getHost());

This technique is illustrated in the Sample1Applet.java program.


Determining When a Terminal is Connected

A Terminal has four connection states:

You can think of it as a single property that has one of four values, or you can view it as four separate boolean properties:

Both views are supported by the properties of Terminal:

The getConnectionState() method returns an int representing one of the four connection states.

The isConnected(), isConnecting(), isDisconnected(), and isDisconnecting() methods return a boolean equal to true or false depending on the connection state of the 3270 emulator.

These five methods correspond to five of the Java Bean properties of the Terminal class. For a complete list of all the Terminal class properties, refer to the Javadoctrademark supplied with the Sun 3270 Pathway product.

The five connection-related properties are bound properties, which means that the Terminal class raises java.beans.PropertyChangeEvent events when any of these properties change. For additional information about property change events and how to listen for them, refer to your JDK API documentation. Also examine the source code of the Sample2.java program.


Determining When the Keyboard is Locked

The keyboardLockState property determines if the keyboard is locked. You can use this property to determine when the host system has finished processing the last instruction and has returned control back to the user. Use the isKeyboardLocked() method to determine the keyboard lock state. The Sample3.java program illustrates the use of this property.

keyboardLockState is also a bound property; therefore, java.beans.PropertyChangeEvent events are raised whenever the keyboard lock state changes.


Disconnecting a Terminal

A Terminal can become disconnected in one of the following ways:

When you are finished with a Terminal, you should disconnect it from the host system either by issuing a disconnect() call or by logging off the host system. This minimizes resource usage on the host system.

When a Terminal is connected, a number of Java threads are active, raising events and maintaining the network connection. This means that a connected Terminal is not eligible for garbage collection by the Java runtime environment. Therefore, you must ensure that a Terminal is disconnected before it is dereferenced, to enable the cleanup of the resources associated with the Terminal. Perform a call to the dispose() method of the Terminal when the program has finished using it to ensure an efficient cleanup of its resource.


Terminal Wait Methods

The Terminal has several methods that enable the application to wait until something significant has happened:

waitUntilDisconnected()

waitUntilConnected()

waitUntilKeyboardUnlocked()

waitHeuristic()

waitCondition(TerminalCondition terminalCondition)

waitForReadableString(String readableString, int offset)

In NVT mode, the keyboard is always unlocked. Therefore, the waitUntilKeyboardUnlocked() method always returns immediately.


Obtaining Information From a Terminal

A 3270 terminal can have two types of display: formatted (the screen consists of 3270 fields) and unformatted. This enables you to obtain information from a Terminal on a field basis or a screen buffer basis.

You can interrogate a Terminal object using the isFormatted() method to determine if the current screen is formatted or unformatted. When the terminal is in NVT mode, there are never any fields; therefore, the isFormatted() method returns false.

Obtaining Field Information

For a formatted display, each 3270 field is represented by a TerminalField object. You can obtain a field from a Terminal by calling one of the following methods:

After a TerminalField is obtained, you can interrogate it using one of the methods described in the Javadoc API of TerminalField. For example, you can obtain the text from a TerminalField using the getText() method.

You can programmatically modify an unprotected TerminalField using the setText() and setData() methods. These methods alter the contents of the field the same way a terminal user can alter it. An attempt to modify a protected field results in an IllegalStateException.



Note - You can only obtain fields on formatted 3270 screens. Attempting to perform getFields() on an unformatted screen results in an empty vector. Attempting to perform findField() on an unformatted screen returns null.



Obtaining Screen Buffer Information

There are three buffers that describe the screen contents:

Performing the appropriate get method for each returns an array of characters. Because they are copies of the buffers, modifications have no effect on the 3270 terminal.

You can enter data on a formatted or unformatted screen using the typeChar() method of the Terminal class. You can obtain buffers from both formatted and unformatted screens.

You can also obtain an area of the screen using the getReadableString() method. This method returns an area of the screen as it appears to the user, that is, with attribute bytes and nulls returned as spaces.

When the terminal is in NVT mode, the color and extended attribute buffers have no meaning and are filled with default values.


Screen Change Notification

When the host sends a data stream to a Terminal, it can cause the display to change in a manner asynchronous to an application program using that Terminal.

To tell an application program about an occurrence, the Terminal class raises com.sun.emp.pathway.bean.TerminalEvent events. An application program listening for these events must implement the com.sun.emp.pathway.bean.TerminalListener interface. These events are generated regardless of the terminal mode.

The TerminalListener interface currently has a single method, hostChangedScreen(), which is called when the screen is changed by a data stream from the host system, indicating that new data was received from the system.

You can register and deregister listeners of this type using the Terminal methods addTerminalListener() and removeTerminalListener().

This event is not implemented as a java.beans.PropertyChangeEvent because it does not have an associated value that changes.


Supplying Data to a Terminal

A user can manipulate a visible Terminal by clicking it to give it focus, then using the keyboard to enter data.

There is also a set of Terminal methods to perform the following functions:

When a terminal is in NVT mode, a restricted set of methods are available. Calling methods that have a pure 3270 meaning when in NVT mode generates an IllegalStateException. Refer to the Javadoctrademark supplied with Sun 3270 Pathway for a list of Terminal methods.


The Visible Terminal

When the Terminal is made visible, you can see that it is made up of two areas: the emulator area and the status bar at the bottom. The status bar can be hidden by calling the method setStatusBarShowing(false).

The Status Bar

The status bar displays information about the Terminal and is divided into sections.

 FIGURE 6-1 Status Bar

Screen shot showing the status bar. Each section of the status bar is labeled.

The labels in FIGURE 6-1 indicate each section of the status bar and are described in the following table:

Label

Description

Cursor Position

Indicates the row and column numbers of the cursor position.

Keybd Lock

Indicates if the keyboard is locked.

Unused

Indicates that this section is not used.

Term Mode

Indicates the terminal mode. Displays 3270, NVT, or SUSP.

Netname

indicates the netname of the terminal, if there is one.

Byte Set

The byte set of the field that the cursor is currently on: either SBCS (pure single byte), SOSI (a combination of single and double byte), or DBCS (pure double byte). These values are displayed only when the host is connected using a double-byte codepage. If the terminal is connected using a single-byte codepage, this area is blank.

Num

Indicates whether the field is numeric. Displays Numeric if the current field is numeric, or else it is blank.

Typing Mode

Indicates the typing mode. This displays either Insert or OverType.


Keyboard Handling

The Terminal provides a default mapping of keystrokes to functionality within the Terminal.

Automatic Font Resizing

By default, the Terminal is set to automatically attempt to set the font size of the emulator so the whole of the emulator fills the container it is placed on. If the container changes size, the font size might increase or decrease accordingly. To turn off this behavior, call the method setAutoFontResizingEnabled(false).


Current and Maximum Display Sizes

Terminal has the following properties in the property list:

Current Display Property

Maximum Display Size Property

rows

maximumRows

columns

maximumColumns

displaySize

maximumDisplaySize


Model 3, 4, and 5 terminals allow the host system application to set the display size of the data on the screen when it sends a datastream to the Terminal. If the host system sends data instructions to use the alternate screen size, the current values equal the respective maximum values. If using the non-alternate screen size, the current values are set to the default values of a 3270 model 2 terminal, 80 rows, 24 columns, 1920 characters for the displaySize.

The following table defines the maximum values for each terminal model.

TABLE 6-4 Maximum Display Values for Terminals

Model

maximumRows

maximumColumns

maximumDisplaySize

3

32

80

2560

4

43

80

3440

5

27

132

3564