Java Reference
In-Depth Information
on a setting in its property file, it is possible for the application helper to launch the application
even if the server connection is not working. The CHECK command (lines 62-87 in Listing
6.2) sends the client id to the server, and eventually receives a list of files to be cached and the
name of the application main class. Being able to send files in cache at first is important
because in this way the server can control which class (consequently which application) is
launched on the client.
The ApplicationHelper class is also the one solely responsible of the deployment cache man-
agement, implemented straightforwardly as a directory in which classes and other resources
are stored when downloaded from the server.
It is interesting to see how the application is started, using the launch method at lines 235-259
in Listing 6.2. After creating the class loader and using it to load the main class (as discussed
later), the launch sequence proceeds as follows:
1. A first try is performed, invoking the mainMethodLaunch method (lines 185-198) to
launch the main class via its main method.
2. If the main class doesn't have a main method, the creationLaunch method is invoked.
This method (lines 203-229) will try to create an instance of the class. The default con-
structor is invoked. If this fails (if it does not exist, it is not accessible, and so on), a con-
structor (the first of the constructor's list returned at line 214) is used, trying to create all
the needed parameters using their respective default constructors. If one of the parameter
class does not have a default constructor, or if it is a primitive type, this attempt fails. If
neither the main method nor the constructors succeeded, the application launch fails.
3. After the application ended, the shutDown method (at lines 265-273) is invoked for exit-
ing the application helper. Note that if the business code will invoke System.exit ,the
shutDown method of the application helper won't be invoked.
Note that the whole launch sequence makes an heavy use of the Java reflection features.
The other piece of our simple application helper is the custom class loader, shown in Listing
L ISTING 6.3 The BankClientLoader Class
import java.util.*;
Search WWH ::

Custom Search