|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectcom.marringtons.util.Application
A class of static data and methods designed to be used application wide - including properties, operating system, configurationd details and thread control. A start() routine must be called when an application starts. After this initialisation, properties, including application name and command line are available. These properties come from system.properties.txt on the classpath and default Java properties. Independant of the application, the home, user and temp directories are made available.
public static void main(String[] args)
{
Application.start( "Adept", args);
...
}
A list of paths are available and used to find files like the properties files. This comes from the Java classpath, the command line or existing properties files as property data.path . The property file.base is added to each file in the path when searching. In this way a file can be in com/marringtons/MyProject/test.txt and MyProject/test.txt will file the same file if the file base is com/marringtons. This path includes directories and zip files. As more files are added, the previous paths are searched, so zip files on the existing path can be found and processed.
The directory to write files to should be retrieved with getPrimaryPath().
Any class that retains resources other than memory has a finalize() method that makes sure the resource was freed before the memory is to be reclaimed. If this requirement fails they call garbageCollectionError() that sets garbageCollectionErrors for the unit tests to check.
public void finalize()
{
if (fileHandle != null)
{
fileHandle.close();
Application
.garbageCollectionError("An active myClass was garbaged collected");
}
}
Lastly there is thread management support including snooze and sleep.
int tenSeconds = 10000;
if (!snooze(tenSeconds)) Application.log("10 second sleep interrupted");
sleep(tenSeconds); // will sleep 10 seconds not matter what
| Field Summary | |
static String[] |
commandLine
String array passed into the program with command line arguments. |
static Properties |
configuration
Application configuration - properties change by the user to reflect customisation of the application. |
static String |
defaultDatabase
Many applications keep all persistent data in a single database. |
static boolean |
garbageCollectionErrors
Set true by any routine that implements finalize() and finds that garbage collection has occurred on an object that still holds resources. |
static boolean |
isWindows
return true if running on a MS Windows platform. |
static boolean |
isWindows16
return true if running on a MS Windows 16-bit based (95, 98 or ME) platform. |
static String |
name
Name of the currently running application. |
static String |
osName
Name of the Operating System (Windows, Linux, etc). |
static Properties |
properties
Application and system properties - typically created when the application was installed - or retrieved from the system at run-time. |
| Method Summary | |
static void |
changeConfiguration(String key,
String value)
Application functionality can be modified with properties loaded from properties files. |
static void |
garbageCollectionError(String message)
Any class that retains resources other than memory has a finalize() method that makes sure the resource was freed before the memory is to be reclaimed. |
static boolean |
sleep(int milliseconds)
Let this thread sleep (lightly) for the required time - but drop out if interrupted. |
static void |
sleepSoundly(int milliseconds)
Let this thread sleep for the required time - independant of interrupts. |
static void |
start(Object object)
Units tests don't have a command line to enter - and their idea of a current directory is coloured by the IDE that is running it. |
static void |
start(String applicationName,
String[] arguments)
Called by every application when it starts with the name of the application and the command line arguments. |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static String name
public static String[] commandLine
public static Properties properties
public static Properties configuration
public static String defaultDatabase
public static final String osName
public static final boolean isWindows
public static final boolean isWindows16
public static boolean garbageCollectionErrors
| Method Detail |
public static void start(String applicationName,
String[] arguments)
applicationName - can be a combination of output path and name (i.e. MyDir/MyAppName)arguments - on command line.Output.set(String)public static void start(Object object)
object - normally this for the test class
public static void changeConfiguration(String key,
String value)
throws FileNotFoundException
key - of the configuration item to add or change.value - to change the configuration item to.
FileNotFoundException - if the file cannot be created (i.e. is a directory)public static void garbageCollectionError(String message)
message - to record in the log.public static boolean sleep(int milliseconds)
milliseconds - to sleep for.
public static void sleepSoundly(int milliseconds)
milliseconds - to sleep for.
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||