JPA is a class library, that gives you access to running
applications on the operating system. An application is thereby a
process, which uses system resources. To system resources of a
process also belongs established threads. A special Thread is the
so-called user-interface-thread, in turn this thread creates and
manages the windows and control elements of the user-interface.
Further operating system resources are program modules. A special
feature of the JPA-API is the ability to access user-interfaces of
external processes. Like from a magic hand, the applications are
operated by simulating keyboard inputs and mouse events for windows
and control elements. The operation of an application can be
automated with JPA-API. Complexe and frequent user inputs are
accomplished through program control. From a visual point of view,
JPA-API is like a software-robot, which simplify or extend the
user-interface of an existing software system. To reduce frequent
mouse and keyboard inputs, the JPA-API can accomplish this task for
you. New functionalities can be added to existing applications
without having to know details about their programming. There are
many applications of JPA-API. More to this see use-cases.
|
|
In designing the JPA architecture, a lot of emphasis was made to
make sure that the interfaces for processes, threads, windows and
program modules are independent of the operating system. The JPA
interfaces serves as common denominator for widely-used operating
systems with a window-based user-interface. Implementing JPA-API in
operating systems other than Microsoft Windows is principly feasible
without big changes to the interfaces. The advantage for this
neutral design is that the integrator doesn't have special
programming knowledge of the operating system. Specific extensions
of the operating system are nevertheless made available by extended
classes/interfaces. The interface AppProcess represents for example
a started application. The interface AppProcess_win32 is derived
from the interface AppProcess. AppProcess_win32 makes specific
functionalities of the operating system available. Another simular
example is the interface AppWindow. Through the method
getWindowHandle() of the extended interface AppWindow_win32, which
represents a Win32-window, can the HWND of the window be requested.
The HWND is a handle (number, integer value), which uniquely
identifies a window.
The following is a list of some JPA features:
- launching an application (program)
- getting all running processes on the computer
- getting the running threads of a process
- requesting the toplevel windows(frame and dialogue windows) of
an application
- accessing and manipulating of user-interfaces
- catching of events within user-interfaces
- accessing control elements like pushbuttons, lists, dropdown
lists, labels and input text fields
- requesting program modules (executable file and libraries)
loaded in the memory of a process
- loading program libraries (in Windows: DLL) and calling
functions from the library
The class AutomationManager
and the interface ApplicationController play an important role in
the JPA-API. AutomationManager is a class, which realizes the design
pattern singleton. The design pattern singleton allows requesting a
single instance of the class AutomationManager through the method
getInstance() from anywhere in your source code.
ApplicationController is an interface which can be requested from
the AutomationManager. The ApplicationController represents the
operating system (computer). The ApplicationController allows
launching of applications and requesting of all running processes on
a computer. Furthermore specific extensions of the operating system
offered by a specialized interface. Under Microsoft Windows, the
interface ApplicationController_win32 makes DDE (dynamic DATA
Exchange) for interprocess communication and accessing the Windows
Registry (configuration database) available. Basically, for
integrating JPA-API in your program, the ApplicationController must
be requested. The local ApplicationController refers to the
computer, on which the JVM runs your program. The introductory
code snippet follows: import softhema.system.automation.*;
import softhema.system.automation.win32.*;
.
.
.
AutomationManager manager = AutomationManager.getInstance();
ApplicationController controller = manager.getApplicationControllerLocal();
//Specialized for windows:
ApplicationController_win32 controller_win32 = (ApplicationController_win32) controller;
Through the instance of the ApplicationController one
can request an array with current running processes: AppProcess[] processes = controller.getAppProcesses();
An important task of ApplicationController is starting
an application: AppProcess process = controller.exec("calc.exe");
The return value is an object, which represents the started
application(process). Through the process-object one can request the
main window. After the start of application, the main window is not
started immediately. For this reason one should insert a short delay
period. The source code section follows: Thread.sleep(1000);
AppWindowTopLevel windowMain = process.getWindowMain();
The returned object represents the frame-window of the
application. |
|
A specific usage is possible through the capability to access the
computer remotely. This is realized through a RMI Client/Server
architecture. The server, also called the Remote-Application-Controller,
has to be started on the host. You will find more info about this subject under How to start the
Remote-Application-Controller. Through the IP-address of the host computer
you are able to call the Remote-Application-Controller. The calling computer is
called the RMI-client. This is an ordinary Java application which implements the
JPA-API and calls the operating system objects of the ApplicationController. Technically
you can reuse the same source code as for the local ApplicationController. Only
difference in code compared to previous sample code is the line where the ApplicationControler
is called: ApplicationController controller = manager.getApplicationControllerRemote( "hostname or ip-address" );
When you call the method getApplicationControllerRemote, you have to enter the IP-address or the Hostname of the
computer, where the Remote-Application-Controller is running. Before the Remote-Application-Controller is available
through the Internet/Intranet, you have to set it online. |
|
|
The core-API from Java already has an option to start external applications. You can do
this through the method exec(...) in the runtime class.
|
|
The same functionality is available through the method exec(...)
of the ApplicationController class in the JPA-API. We expanded the exec
method and added a few parameters to it. Now you have the option
to change the display of the main window after you started the
application. The desired position and the display status (maximized,
normal and minimized) of the main window can be set. We need to mention
that some applications may ignore some of these settings and won't work
for those applications. The core functionality of the JPA-API is it,
to allow access to the application. The design of the JPA-API is an object
oriented class library. Each operating object is represented through specialized
Java classes. More detailed explainations follow here.
|
|
There are one ore more threads in one process execting the program
code. Thread have to be viewed as lightweight processes. All threads of
one process share the same virtual (main) memory and have access to the
resources of the program. After a process is started, first a main thread
in the main() function is started to execute the program. If the application
has a user interface, the main thread usually produces the dialogs and windows.
During the execution of a process, the modules are stored in memory.
The picture above shows the relations between the operating systems
objects. A process has one or more threads. The first thread is the main
thread. A thread on the other hand can own windows in a user interface.
If there are any events in the windows, the thread will react accordingly.
Under UML classdiagramm
of the JPA-API, a few important classes and the relations between them are displayed.
|
|