Using the ZIE Host Access Toolkit product with macros
The separate ZIE Host Access Toolkit product includes classes that
allow you to dynamically create macro variables, perform macro actions,
and run macros. This section contains an example of using the ZIE
Host Access Toolkit product.
Sample macro that prompts for user's ID and password shows the first version of
a macro that prompts for the user's ID and password, logs on to a
host, and says Welcome! This version of the macro does not use the
ZIE Host Access Toolkit:
Assume that you want to use this macro in a Host Access Beans program
and that you want to store the user ID into a variable and save it
for later use (for example, in the Welcome message). You can do this
directly by modifying the macro, but one reason for writing a program
for this is to avoid having to maintain many different macros for
different situations. You could instead have a basic version of the
macro and use a program to modify it depending on the situation. The
following is an example of how you can do this in Java:
Suppose that you now want to add a second message to the actions
for Screen2. In this message, you want to display the time and date,
which you extract from the screen. You would add the following lines
before macro.setParsedMacro(ms):
Note that at the point when the attribute containing the variable(s)
is associated with the MacroScreens, you must have already created
the variable (through one of the createVariable() methods). For example,
this code sequence would also be valid:
The above sequence is valid because $datetimestamp$ is created
before the MacroActionExtract is added to the MacroActions (which
are already associated with the MacroScreens because they were pulled
from the MacroScreens originally). If the createVariable() method
was called at the end of the sequence above, you would have an invalid
sequence because the variable $datetimestamp$ would not have been
available at the time that the MacroActionExtract and MacroActionMessage
were added to the MacroActions and associated with the MacroScreens.
The default value of the MacroScreens method isUseVars() is false.
However, if you call one of the createVariable() methods on your MacroScreens,
isUseVars() will return true automatically. If you don't create any
variables, but want to have your attributes scanned for variables
and arithmetic anyway (e.g. you might be writing a chained child macro
that has no variables of its own but is anticipating some from the
parent), you must call setUseVars(true) on your MacroScreens.
Attributes that can now take variables or expressions as arguments
have setAttribute(String) and either getAttributeRaw() or isAttributeRaw()
methods available. If you wanted to use an expression now to represent
the row attribute for a MacroActionInput, you could call setRow("$rowvar$
+ 1"). Subsequently calling getRow() would return the evaluated value
of this expression (an integer), whereas calling getRowRaw() would
return "$rowvar$ + 1." Note that if you do the following you will
get a NumberFormatException:
This is because mai has not yet been associated with
any MacroScreens with isUseVars() returning true. Therefore, "$rowvar$
+ 1" is being treated as a string rather than a variable plus one.
Note also that if you had call the setAttribute() methods to set up
variables and expressions after the object containing these attributes
have been associated with the MacroScreens, you will likely experience
a savings in processing time as the attributes would otherwise need
to be reparsed for variables/expressions at the point when they are
added to the MacroScreens.
The VariableException class is available for catching exceptions
such as illegal expressions (e.g., "45 *") or illegal arithmetic operands
(e.g., "'3a' * 2").
A sample program that uses programmed macros, MacroVariablesDemo.java,
can be found in the ZIE Host Access Toolkit samples directory.