Package com.rs.seagull.emulator.api
This package contains classes and interfaces needed to drive a host application programmatically via an emulator such as IBM 5250, IBM 3270, and VT (aka Ansi Plus). The following information is a high-level overview of the major concepts and classes and how they interact, as well as several detailed examples that show the best way to use the emulator API.
Introduction
Before we get into the details of the API, note that there are three different "audiences" for this documentation.- Standalone Java Program
Someone writing an ordinary Java program must create a host session, then use various APIs to drive the session through various screens, then close the session. Creating a host session usually involves knowledge of screen definition files and such. - Microflow script for a Function action
Someone writing a script for a microflow is "handed" a host session that's ready to use, so there's no need to create a session or deal with screen definition files. - SeagullScript conversion
Someone converting a Classic Screen API project (aka SIP2) to a current (NextGen) Screen API project will need to convert any existing scripts from SeagullScript to JavaScript, including converting Classic host APIs (e.g. HostFieldGetData) to the APIs described here.
Overview
This emulator API is based on a model where a host application is a series of screens that are navigated through by sending text and keystrokes to the host. Each screen is typically comprised of fields represented by a rectangular area.To interact with the host, you normally identify screens by name and define fields by name within each screen to create an application definition. Application definitions are created outside this API using the Rocket API builder tools. For more information, see the Rocket API Screen Developer Guide .
After you've created the application definition using the builder tools, you pass it in as a parameter to this API when creating a new host session. This allows you to address screens and fields by name without using low-level screen coordinates. For example, you can get the name of the current screen, session.getScreenName(). You can also get the contents of a field by name, session.getText("fieldA"), set the value of an input field by name, session.setText("fieldB", "someValue"), and send keystrokes, session.sendKey("ENTER"). Additional operations are also available.
If you do not have an application definition available and your host supports lower-level access (IBMi/5250 and IBMz/3270), you can access screens and fields by addressing areas of the screen using XY coordinates.
Classes
The central class of the whole API isSession
. A
Session provides access to secondary classes such as Screen
, Cursor
,
Keyboard
, and Field
, but you can accomplish just about anything you would typically want
to do using just Session and its superclass. Other useful helper classes include Conditions
, Keys
,
Colors
, and Emulators
.
Note that Session, Screen, Field, and Cursor are used when an application
definition is available. If you do not have an application definition, use the
corresponding bare classes: BareSession, BareField, and so on. These classes are
the superclasses for Session, Field, and so on, so therefore all the bare, or undefined, operations are
also available to a defined object. For example, BareSession contains sendKey(String key),
while Session contains sendKey(String field, String key). The operation in BareSession
sends a keystroke to the host at the current cursor position, whereas the
the operation in Session places the cursor in the named field before sending the keystroke.
Session and Screen extend BareSession and BareScreen so all low-level APIs are available.
Use the BareSession.waitFor(com.rs.seagull.emulator.api.Condition, com.seagullsw.common.toolbox.concurrent.Timeout)
method in BareSession to
wait for a variety of conditions to become true, including writing your own
arbitrary conditions. A starter set of useful conditions are available in
the Conditions
class.
Audience Specific Intro
Standalone Java Program
A standalone Java program must create a session. Sessions are typically created using static methods
in SessionFactory
and BareSessions are created using
BareSessionFactory
). Here are some examples:
Create a (defined) Session
Session session = SessionFactory.create(Emulators.Ibm5250.SCHEME, "iSeriesHost", 23, null, "screens");
- 1st parameter is the so-called "scheme", which is really just the type of emulator. You can see the available types in
Emulators
. - 2nd parameter is the name or IP address of the host system.
- 3rd parameter is the socket port on the host system.
- 4th parameter is an optional Map of connection properties. More on this below in other examples.
- 5th parameter is a classpath-relative directory containing application definition files.
- 1st parameter is the so-called "scheme", which is really just the type of emulator. You can see the available types in
Create a BareSession
BareSession session = BareSessionFactory.create(Emulators.Ibm5250.SCHEME, "iSeriesHost", 23, null);
Similar to the create in the first example, but with no application definition.
Script for a Microflow Function Action
Within a Rocket API microflow, you can write JavaScript to provide custom interaction with the host application. When a microflow is started and this JavaScript is invoked, the host session that is being navigated by the microflow is made available as a JavaScript variable. This variable is called hostSession and is an instance ofSession
. Also note that a host connector
that is executing a microflow will have an application definition associated
with it, so you will normally address screens and fields by name in your JavaScript, using
methods from Session and associated classes. The JavaScript
engine used by the API gateway provides seamless integration with Java and
gives your JavaScript code access to the full emulator API described here.
Currently, the JavaScript engine is Rhino. For additional information, see
https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Rhino/Documentation.
In the following examples, both Java and JavaScript are provided.
SeagullScript Conversion
There are two rather separate aspects to converting SeagullScript scripts to JavaScript NextGen scripts, the language elements (i.e. JavaScript itself), and the emulator API elements (e.g. HostFieldGetData).Language
The JavaScript language is well documented on the web. The particular variant that Rocket API uses is called Rhino, from Mozilla, documented here: https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Rhino/Documentation Mozilla has some nice JavaScript tutorial-ish documentation too, here: https://developer.mozilla.org/en-US/docs/Learn/JavaScript For SeagullScript in particular, here are some obvious "conversions":SeagullScript | JavaScript |
---|---|
if then endif | if () {} |
if x = y | if (x == y) |
and (in an if expression) | && |
<> | != |
for i = 0 to 3 ... next | for (i = 0; i <= 3; i++) {} |
while ... wend | while () {} |
dim x as string | var x |
Emulator APIs
The Classic/SIP2 emulator APIs have equivalents in these APIs. For example:HostFieldGetData(field, variable) | variable = hostSession.getText(field) |
HostFieldGetLineData(field, offset, variable) | variable = hostSession.getField(field).getText(offset) |
HostScreenSendKey(key) | hostSession.sendKey(key) |
HostFieldPutData(field, value) | hostSession.setText(field, value) |
Examples
In the examples below, the Java examples assume you have a Session variable named 'session'. The JavaScript examples assume you have a Session variable named 'hostSession'.Get the name of the current screen
Java:String screen = session.getScreenName();
JavaScript:var screen = hostSession.getScreenName();
Get the contents of a field
Java:String value = session.getText("fieldA");
JavaScript:var value = hostSession.getText("fieldA");
This retrieves the textual content of the field named "fieldA" from the current screen.Set the contents of a field
Java:session.setText("fieldA", "someText");
JavaScript:hostSession.setText("fieldA", "someText");
This sets the textual content of the field named "fieldA" on the current screen to "someText".Send a keystroke
Java:session.sendKey(Keys.Ibm5250.ENTER);
JavaScript:hostSession.sendKey(Keys.Ibm5250.ENTER);
This sends an ENTER key to the host. Note the use of Keys which contains constants for all the allowable keys.Send a keystroke for a particular field
Java:session.sendKey("fieldA", Keys.Ibm5250.ENTER);
JavaScript:hostSession.sendKey("fieldA", Keys.Ibm5250.ENTER);
This positions the cursor to fieldA, then sends an ENTER key to the host.Wait for a specific screen by name
Java:session.waitFor(Conditions.screenNamed("MAINMENU"), Timeout.seconds(10));
JavaScript:hostSession.waitFor(Conditions.screenNamed("MAINMENU"), Timeout.seconds(10));
A number of other useful wait conditions are available in classConditions
.Get the contents of a portion of the screen
Java:session.getText(new Point(34, 0), 9);
JavaScript:hostSession.getText(new Point(34, 0), 9);
This grabs 9 characters from the middle of the top line.
-
ClassDescriptionThe base class for all property conditions.base exception for most/all exceptions thrown from the API these are unchecked exceptions.Implementors of this interface have attributes.These are attributes that can be used in
Attributed.isAvailable(String)
andAttributed.hasAttribute(String)
.A BareCursor represents the current "type-in" point on the screen.This is the type of the cursor.A BareField represents a 'raw' field defined on the host.A BareScreen represents a host screen.A BareSession represents a connection to a host and allows you to "drive" the host application.This Capability is used for theBareSession.hasCapability(Capability)
andBareSession.getCapability(Capability)
methods.Implementors of this interface can accept a text.A factory with static methods for creating bare sessions.A Cell represents one location on the screen.An enumeration of possible Cell types.These are colors that are returned byAttributed.getForegroundColor()
andAttributed.getBackgroundColor()
.These are colors for an AnsiPlus host that are returned byAttributed.getForegroundColor()
andAttributed.getBackgroundColor()
.These are colors for a 3270 host that are returned byAttributed.getForegroundColor()
andAttributed.getBackgroundColor()
.These are colors for a 5250 host that are returned byAttributed.getForegroundColor()
.A Condition is a test, can be true or false.Static methods for creating various common Conditions.A Control represents a named user interface element within a host application.A Cursor represents the current "type-in" point on the screen.Anything related to a host application that has a definition will implement Defined.This class contains information about supported emulators.The emulator that connects to a AnsiPlus host.The emulator that connects to HEMAN recordings.The emulator that connects to a 3270 host.The emulator that connects to a 5250 host.A Field represents a user-defined named control that has text content and attributes.An unchecked exception for when there is a problem with a field.The type of field exceptionAn unchecked exception for when there is a problem validating a field.This class implements 3270 StartupInformationListener, but does not do anything.This class implements 3270 StartupInformationListener, so it can log every change to the logging infrastructure.This class implements 5250 StartupInformationListener, but does not do anything.This class implements 5250 StartupInformationListener, so it can log every change to the logging infrastructure.A Keyboard provides methods for sending keystrokes to a host.Declarations of keys (actions) to be used with Keyboard.sendKey().Declarations of Ansi VT keys (actions) to be used with Keyboard.sendKey().Declarations of IBM 3270 keys (actions) to be used with Keyboard.sendKey().Declarations of IBM 5250 keys (actions) to be used with Keyboard.sendKey().exception thrown when a field cannot be found.An implementation of Condition that includes model property names which indicates when a waitFor should 'wake up' to evaluate the condition.A Screen represents a host screen.A Session expands on the more basic BareSession, adding named screens and named user-defined fields and 'controls'.A factory with static methods for creating (defined) sessions.This interface describes the startup information for a host session.This interface describes the startup information for an IBM 3270 host session.This interface describes the startup information for an IBM 5250 host session.This interface describes a startup information listener.This interface describes a startup information listener for an IBM 3270 host session.This interface describes a startup information listener for an IBM 5250 host session.Static methods for creating common Table.StopCondition's.A StopCondition where the stop condition is a value in a field.An abstract superclass for most concrete StopConditions.A Table represents a collection of rows and columns, often spanning multiple 'pages'.A Row represents one entry in a Table, consisting of a list of Fields.A RowVisitor is called for each row.A Scroll action is invoked when a table iterator (e.g.A StopCondition is a Condition that returns true from its isTrue method when a table iterator (e.g.A 'wait for' condition.An unchecked exception for problems scrolling through tables.Timeout represents a timeout value together with its units.