Getting started with the Host Access Class Library (HACL) is easy because the object model is relatively simple. The five or six primary classes provide most of the function for a HACL applet. These classes are all associated with a session to a particular host computer and can be obtained from an instance of ECLSession.
To develop the sample application:
The following sample code defines a session to the specified host or TN3270/5250 server, but does not initiate communications:
ECLSession s = null; Properties p = new Properties(); // This is the name of the host or TN server p.put(ECLSession.SESSION_HOST, new String("myHost")); // Set the SESSION_CODEBASE parameter when running from a Web page. // The use of 'this' assumes that the current class extends // java.applet.Applet // p.put(ECLSession.SESSION_APPLET, this); try { s = new ECLSession(p); } catch (ECLErr e) { System.out.println(e.GetMsgText()); }
The following sample code gets an instance of ECLPS from the session established above:
ECLPS ps = s.GetPS()
The following sample code 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.
try { ps.RegisterPSEvent(this); } catch(ECLErr e) { System.out.println(e.GetMsgText()); } // Start the session after registration so we don't // miss any presentation space events. s.StartCommunication()
The ECLPSListener interface is comprised of three methods which will handle different kinds of events occurring within the presentation space. The PSNotifyEvent() method handles normal, non-error events and is the main method for receiving and handling events. The PSNotifyStop() method handles stop events, and the PSNotifyError() method handles errors which occur during event generation.
The following sample defines a simple PSNotifyEvent() method which recognizes screens and takes action on those different screens.
public void PSNotifyEvent(ECLPSEvent evt) { if (ps.SearchText("some text on the login screen", ps.SEARCH_FORWARD)) { ps.SendKeys("myUserID"+ps.FWDTAB_STR+"myPW"+ps.ENTER_STR); } return; }
This 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, PSNotifyStop() and PSNotifyError(), which must be implemented to conform to the ECLPSListener interface.
You can add parameters that are passed to applets when users start sessions or when they run applets after a session has started. In order for an applet to receive parameters, you must implement the following method:
public void initParam(String param)
The variable name, param, may be any valid variable name. The following sample code implements ECLAppletInterface and contains the initParam() method:
// Sample applet that implements ECLAppletInterface; it takes an // input parameter string by implementing the method // public void initParam(String param) // This example prints the value received to the Java console. import com.ibm.eNetwork.ECL.*; import java.awt.*; import java.net.URL; import java.lang.*; public class RunAppParam implements ECLAppletInterface { String inParam = null; public void initParam(String param) { System.out.println ("RunAppParam.initParam(): param = "+param); inParam = param; } public void init(ECLSession eSess) { System.out.println ("RunAppParam.init(): inParam = "+inParam); // do something with inParam and eSess } }
After starting sessions, users can run applets that receive parameters by entering the parameter name into the parameter field, which is accessible either from the Action > Run Applet menu or from the toolbar button Add Button. In order for the applet to receive the parameter name that is entered into the parameters field, the applet must implement the initParam() method. If the applet does not implement this method, it ignores what is entered into the field.
In the sample file Session2.html (located in the samples directory), the StartupApplet
parameter can be used in the HTML file to start an applet automatically. The StartupAppletParam
parameter can also be used in the HTML file to pass a String parameter to the applet.
The parameter is passed to the applet's initParam(String param) method. For
example:
... <PARAM NAME="StartupApplet" VALUE="RunAppSam"> <PARAM NAME="StartupAppletParam" VALUE="a_parameter_value"> ...
If the user applet implements CustomInterface, parameters can be passed from an HTML file that starts Host On-Demand. The user applet can get the Host On-Demand applet from HIFramework by calling the getApplet() method and using the getParameter() method on the applet to retrieve the parameter specified in the HTML file. For example, in the HOD.html file:
... <APPLET archive="hod.jar,sccbase.jar" CODE="com.ibm.eNetwork.HOD.HostOnDemand.class" WIDTH=584 HEIGHT=450> <PARAM NAME=cabinets VALUE=hod.cab,sccbase.cab> <PARAM NAME=BookmarkPage VALUE=AutoHOD.html> <PARAM NAME=AppletParam1 VALUE=apValue> <PARAM NAME=AppletParam2 VALUE="apValue 2"> ...
The following example, RunAppParam.java, is an applet implementing CustomInterface:
public class RunAppParam implements CustomInterface { String p = null; String p2 = null; public void init(HIFramework framework) { java.applet.Applet app = framework.getApplet(); p = app.getParameter("AppletParam1"); //here's the parameter from HTML p2 = app.getParameter("AppletParam2"); //here's the parameter from HTML System.out.println ("p = "+p); System.out.println ("p2 = "+p2); ... } public void update(HIFramework framework) { } }
Host On-Demand provides the ability to load and run user-defined applets. You can launch a user applet from the Run Applet dialog or as a Startup Applet. You can display the Run Applet dialog from either the button bar or the Assist pull-down menu. The dialog prompts for the name of a user-defined class (without the .class extension), constructs an instance of the class using the default constructor, and gives the class access to the current session. You can specify the Startup Applet in the session configuration window on the Advanced tab.
The methods called when an applet is loaded are defined in an interface called ECLAppletInterface and another called CustomInterface. These interfaces must be implemented by the main class of an applet which will be run using the feature.
To enable an applet to run within an active emulator window:
The following sample code defines a default constructor for an applet class called MyClass.
public MyClass() { }
Simply registering for PS events may not trigger the applet to start because it is probably waiting for the first PS event, and there may not be any pending events when the applet is started. To work around this situation, either attempt to recognize the current presentation space right away, or generate your own PS event and let your PSNotifyEvent() method handle it.
The following sample code defines the init() method and shows one way of handling the initial presentation space state. The sample assumes that MyClass implements ECLPSListener, in addition to ECLAppletInterface.
public void init(ECLSession session) { ps = session.GetPS(); // Register with ECLPS to receive updates and new screens try { ps.RegisterPSEvent(this); } catch(Exception e) { System.out.println("Registration Exception"); } // Call our PSNotifyEvent() method to handle the initial state of the PS PSNotifyEvent(new ECLPSEvent(ps)); }
To compile the user applets implementing ECLAppletInterface, the habeans.jar needs to be included in your CLASSPATH.
To run the applet, the compiled applet class must be placed in a directory at the HOD server where the main HOD files (HOD.html and HODAdmin.html) are stored. Then the client can connect to the HOD server and run the applet.
Writing a HACL applet implementing a CustomInterface is very similar to writing a HACL applet implementing an ECLAppletInterface. To write a CustomInterface HACL applet, your applet must implement a CustomInterface which requires an init() method and an update() method. A HIFramework instance is passed for both init() and update() methods. This HIFramework instance can be used to gain access to other class objects such as HostTerminal, Applet, and Frame. From these object instances, you can then gain access to other class objects.
If the applet implements the optional initParam() method, the initParam() method is called before the init() method. (For more information about using the initParam() method, see Passing Parameters to Applets.) This is demonstrated in a sample program provided below.Below is a complete set of sample code for a user applet implementing CustomInterface. This sample also implements ECLRecoNotify interface for screen recognition notification. NotifyError(), NotifyEvent(), and NotifyStop() methods are required to implement the ECLRecoNotify interface.
This sample program assumes that you are already connected to a host login screen. You should change the User ID, password, strings to recognize, and the commands to reflect the host you are connected to. The sample program:
To compile the user applets implementing CustomInterface, the habeans.jar needs to be included in your CLASSPATH.
To run the applet, the compiled applet class must be placed in a directory at the HOD server where the main HOD files (HOD.html and HODAdmin.html) are stored. Then the client can connect to the HOD server and run the applet.
[ Top of Page | Previous Page | Next Page | Table of Contents ]