JavaGantt 2011.1 API

eu.beesoft.gaia.launcher
Class Launcher

java.lang.Object
  extended by eu.beesoft.gaia.launcher.Launcher

public class Launcher
extends java.lang.Object

The main class of the launch system. It supports processing of the instruction file, building a splash screen, building the class paths and invoking main method on another class.

You can use this class in JAR file as is, or you can subclass this class, build your own JAR file (copy to it all files from this JAR) and use it to launch your application.

Launcher processes launch file. It is a file with the instructions. Enabled instructions are:

You can extend this instruction set when you override method processInstruction(String) and process the new instructions in it.

Here is an example of the standard launch file:

 path c:/myapp/lib/first.jar
 path c:/myapp/lib/second.jar
 path c:/myapp/classes
 run mypackage.MyClass firstArgument "second argument"
 

It creates a classpath from two JAR files and one directory and then invokes method main() on MyClass with two arguments.


Constructor Summary
protected Launcher()
          Creates a new instance of Launcher.
 
Method Summary
protected  void addClassPath(java.lang.String classPath)
          Adds given argument to the classpath list.
protected  void addSystemProperty(java.lang.String configurationArgument)
          Parses given configurationArgument to property name and property value and adds it to system properties.
protected  java.lang.ClassLoader buildClassLoader()
          Builds a class loader initialized by the class paths set by addClassPath(String) and scanClassPath(String).
protected  void buildProgressMediator(java.lang.String configurationArgument)
          Builds a progress mediator as an instance of given configurationArgument.
protected  void buildSplashScreen(java.lang.String configurationArgument)
          Builds a splash screen as instance of SplashScreen with image which resource name is given configurationArgument.
protected  void clearClassPath()
          Clears a list of class pathes prepared to invoke some class.
protected  java.util.List<java.lang.String> getClassPath()
          Returns a list of class pathes prepared to invoke some class.
protected  java.io.File getFile(java.lang.String name)
          Returns a file with given name from a directory where JAR file of this Launcher is located.
static Launcher getInstance()
          Returns a current instance of Launcher.
 java.io.File getLauncherJarFile()
          Returns a JAR file where this Launcher resides.
 java.util.jar.Manifest getManifest()
          Returns a manifest from JAR file where this Launcher resides.
 ProgressMediator getProgressMediator()
          Returns progress mediator instance.
protected  void invokeMain(java.lang.String configurationArgument)
          Invokes a static main() method on the class and with arguments that are in the given configurationArgument.
protected  void invokeMain(java.lang.String className, java.lang.String[] arguments)
          Invokes a static main() method on the class with given className() and with given arguments.
static void main(java.lang.String[] arg)
          Creates and starts (not subclassed) instance of Launcher.
protected  void processInstruction(java.lang.String instructionLine)
          Processes one-line instruction.
protected  void processInstruction(java.lang.String instruction, java.lang.String argument)
          Processes given instruction.
protected  void processInstructions(java.io.File file)
          Processes instructions from a given file.
protected  void processInstructions(java.lang.String fileName)
          Processes instructions from file with given name.
protected  void scanClassPath(java.lang.String classPath)
          Scans directory with given name (= argument classPath) and all its subdirectories.
protected  void setProgressMediator(ProgressMediator progressMediator)
          Sets a new progress mediator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Launcher

protected Launcher()
Creates a new instance of Launcher. Sets it as current instance (it is returned by method getInstance()).

Method Detail

getInstance

public static Launcher getInstance()
Returns a current instance of Launcher.


getProgressMediator

public ProgressMediator getProgressMediator()
Returns progress mediator instance.

Returns:
the progress mediator

setProgressMediator

protected void setProgressMediator(ProgressMediator progressMediator)
Sets a new progress mediator.

Parameters:
progressMediator - - the progress mediator to set

getManifest

public java.util.jar.Manifest getManifest()
Returns a manifest from JAR file where this Launcher resides.

Returns:
a manifest from launcher JAR file.

getLauncherJarFile

public java.io.File getLauncherJarFile()
Returns a JAR file where this Launcher resides. This method is useful to determine where in file system is located your application.

Returns:
a launcher JAR file.

getFile

protected java.io.File getFile(java.lang.String name)
Returns a file with given name from a directory where JAR file of this Launcher is located.

Parameters:
name - - a name of the requested file
Returns:
a file with given name
Throws:
java.lang.RuntimeException - if cannot find file

processInstructions

protected void processInstructions(java.lang.String fileName)
Processes instructions from file with given name.

Parameters:
fileName - - a name of the requested file with instructions

processInstructions

protected void processInstructions(java.io.File file)
Processes instructions from a given file.

Parameters:
file - - file with instructions

processInstruction

protected void processInstruction(java.lang.String instructionLine)
Processes one-line instruction. Ignores null, empty and comment lines (they begin with '#'). Splits given line to instruction (before first space) and argument (after first space) and invokes method processInstruction(String, String) to process it.

Parameters:
instructionLine - - instruction to process

processInstruction

protected void processInstruction(java.lang.String instruction,
                                  java.lang.String argument)
Processes given instruction. It supports these commands:

Parameters:
instruction - - instruction to process
argument - - argument for instruction

addClassPath

protected void addClassPath(java.lang.String classPath)
Adds given argument to the classpath list.

Parameters:
classPath - - a class path to add

scanClassPath

protected void scanClassPath(java.lang.String classPath)
Scans directory with given name (= argument classPath) and all its subdirectories. Each found JAR file is added to the classpath list.

Parameters:
classPath - - a name of the directory to scan

getClassPath

protected java.util.List<java.lang.String> getClassPath()
Returns a list of class pathes prepared to invoke some class.

Returns:
prepared class pathes

clearClassPath

protected void clearClassPath()
Clears a list of class pathes prepared to invoke some class.


addSystemProperty

protected void addSystemProperty(java.lang.String configurationArgument)
Parses given configurationArgument to property name and property value and adds it to system properties. If configurationArgument is null, is empty, or does not contain separator character like '=', ':' or ' ' (space), it does nothing.

Parameters:
configurationArgument - - property name and property value separated by separator character like '=', ':' or ' ' (space)

buildSplashScreen

protected void buildSplashScreen(java.lang.String configurationArgument)
Builds a splash screen as instance of SplashScreen with image which resource name is given configurationArgument.

Parameters:
configurationArgument - - file or class path name of the image for splash screen

buildProgressMediator

protected void buildProgressMediator(java.lang.String configurationArgument)
Builds a progress mediator as an instance of given configurationArgument.

Parameters:
configurationArgument - - class name of the progress mediator

buildClassLoader

protected java.lang.ClassLoader buildClassLoader()
Builds a class loader initialized by the class paths set by addClassPath(String) and scanClassPath(String).

Returns:
newly created class loader

invokeMain

protected void invokeMain(java.lang.String configurationArgument)
Invokes a static main() method on the class and with arguments that are in the given configurationArgument. After parsing of it this method invokes invokeMain(String, String[]).

Parameters:
configurationArgument - - contains a class name and arguments for main method. Single items are separated by space. A multi-word argument should be in quotes.

invokeMain

protected void invokeMain(java.lang.String className,
                          java.lang.String[] arguments)
Invokes a static main() method on the class with given className() and with given arguments. A class is loaded with new class loader returned by buildClassLoader() method.

Parameters:
className - - name of the class on which shold be method main() invoked
arguments - - arguments for main() method

main

public static void main(java.lang.String[] arg)
Creates and starts (not subclassed) instance of Launcher. If there is no value in arg[0], it searches for the file with the same name as has a JAR file with this Launcher class and with extension '.launch'. Otherwise it uses arg[0] as name of that file. This file is in next processed by processInstructions(String) method.

Parameters:
arg - - if is not null, first argument must contain name of the launch file

JavaGantt 2011.1 API