Getting started with the Host Access Class Library (ECL) is easy because the object model is so simple. There are five or six primary classes which will provide most of the function for any ECL applet. These classes are all associated with a session to a particular host computer and can be obtained from an instance of ECLSession.
The first thing to do is define a session with a host using the ECLSession class. It is constructed with a java.util.Properties object populated with keyword and value pairs which make up the session configuration. A session has a variety of configuration parameters including type (3270, 5250, VT), host, port, ID, presentation space dimensions (for example, 24 rows by 80 columns), code page, and others specific to the session type. All parameters, except host, have default values for 3270 emulation sessions, including the type.
The sample below defines a session to the specified host or TN3270/5250 server, but does not initiate communications.
After defining a session with the target host, you can gain access to the presentation space and interact with it. The presentation space is encapsulated in the ECLPS class, and an instance of it can be obtained using the GetPS() method on ECLSession. ECLPS provides methods that manipulate text, perform searches, send keystrokes to the host, and work with the cursor.
The sample below gets an instance of ECLPS from the session established above.
Once an instance of ECLPS is established, you can register to receive notification of presentation space changes. Registered objects are notified whenever the presentation space is changed whether it is host or operator initiated. This event notification model is the primary mechanism used by an application to drive interactions with the presentation space.
The sample code below registers the current class with the instance of ECLPS and starts communications with the target host. Notice that the sample waits to start the session with the host (the call to StartCommunication()) until after it has registered with ECLPS. This is done to ensure that no presentation space events are missed which could cause incorrect behavior in the applet.
Now you are registered for presentation space events, but still need to implement methods which allow your class to receive the events. These methods are defined by the ECLPSNotify interface, and the class you want to register must implement this interface.
The ECLPSNotify interface is comprised of three methods which will handle different kinds of events occurring within the presentation space. The NotifyEvent() method handles normal, non-error events and is the main method for receiving and handling events. The NotifyStop() method handles stop events, and the NotifyError() method handles errors which occur during event generation.
The following sample defines a simple NotifyEvent() method which recognizes screens and takes action on those different screens.
The previous sample recognizes a particular host screen, such as a login prompt, then sends a user ID and password to the host starting at the current cursor location. Note that the sample does not show the other two methods, NotifyStop() and NotifyError(), which must be implemented to conform to the ECLPSNotify interface.
That's all you need to get started with your first ECL applet!