DESY ACOP Beans Home

de.desy.acop.launcher
Class Launcher

java.lang.Object
  extended by de.desy.acop.launcher.Launcher

public class Launcher
extends java.lang.Object

Launcher is a utility class which can launch an application according to its type and supplied parameters.

Version:
$Id: Templates.xml,v 1.10 2004/01/13 16:17:13 jbobnar Exp $
Author:
Jaka Bobnar

Field Summary
static java.lang.String CAMNAME
           
 
Constructor Summary
Launcher()
           
 
Method Summary
static
<T> T
launch(java.lang.Class<T> applicationClass, java.lang.String[] args)
          Launches an application using the input arguments.
static
<T> T
launch(java.lang.Class<T> applicationClass, java.lang.String[] args, boolean shouldExitOnClose)
          Launches an application defined by the applicationClass.
static void main(java.lang.String[] args)
           
static void runCommand(java.lang.String command, java.io.OutputStream outputStream, java.io.OutputStream errorOutput, boolean waitForCompletion)
          Runs the specified command.
static void runWebstartApplication(java.lang.String completeJNLP_URL, boolean waitForCompletion)
          Method will start a webstart application.
static void runWebstartApplication(java.lang.String completeJNLP_URL, java.io.OutputStream outputStream, java.io.OutputStream errorOutput, boolean waitForCompletion)
          Method will start a webstart application.
static void runWebstartApplication(java.lang.String jnlpURL, java.lang.String[] jvmParameters, boolean waitForCompletion)
          Method will start a webstart application.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CAMNAME

public static final java.lang.String CAMNAME
See Also:
Constant Field Values
Constructor Detail

Launcher

public Launcher()
Method Detail

runWebstartApplication

public static void runWebstartApplication(java.lang.String jnlpURL,
                                          java.lang.String[] jvmParameters,
                                          boolean waitForCompletion)
                                   throws java.io.IOException
Method will start a webstart application. The provided String should be the url to the jnlp file. This method will construct a webstart start command composed of all provided parameters and forward the call to runWebstartApplication(String, boolean).

Parameters:
jnlpURL - the url of the jnlp file to be started
jvmParameters - the virtual machine parameters (without the -D)
waitForCompletion - the flag indicating if the calling thread should be blocked until the execution is completed
Throws:
java.io.IOException - if execution of the command failed

runWebstartApplication

public static void runWebstartApplication(java.lang.String completeJNLP_URL,
                                          boolean waitForCompletion)
                                   throws java.io.IOException
Method will start a webstart application. The provided String should be a complete url to the jnlp file. The provided url can also include several program or JVM arguments. They have to be supplied as prescribed by the Java API. This method will forward the call to runWebstartApplication(String, OutputStream, OutputStream, boolean) where the streams are null.

Parameters:
completeJNLP_URL - the url which will be loaded using the java webstart command (javaws)
waitForCompletion - the flag indicating if the calling thread should be blocked until the execution is completed
Throws:
java.io.IOException - if execution of the command failed
See Also:
runCommand(String, OutputStream, OutputStream, boolean)

runWebstartApplication

public static void runWebstartApplication(java.lang.String completeJNLP_URL,
                                          java.io.OutputStream outputStream,
                                          java.io.OutputStream errorOutput,
                                          boolean waitForCompletion)
                                   throws java.io.IOException
Method will start a webstart application. The provided String should be a complete url to the jnlp file. The provided url can also include several program or JVM arguments. They have to be supplied as prescribed by the Java API.

Parameters:
completeJNLP_URL - the url which will be loaded using the java webstart command (javaws)
outputStream - the output stream where all the output from the input stream of the executed process will be forwarded
errorOutput - the output stream where all the output from the error stream of the executed process will be forwarded
waitForCompletion - the flag indicating if the calling thread should be blocked until the execution is completed
Throws:
java.io.IOException - if execution of the command failed
See Also:
runCommand(String, OutputStream, OutputStream, boolean)

runCommand

public static void runCommand(java.lang.String command,
                              java.io.OutputStream outputStream,
                              java.io.OutputStream errorOutput,
                              boolean waitForCompletion)
                       throws java.io.IOException
Runs the specified command. This method will invoke the Runtime.exec(String), where the provided string parameters is the command. The output generated by the execution of this command is forwarded to the provided OutputStreams. If any of these stream are null the output from that part of execution will be skipped.

The invoker has the possibility to block the current thread until the process created by this method is completed. The lifecycle of the process is specified by the command itself and the process which will be executed by that command.

Parameters:
command - the command to be executed
outputStream - the output stream where all the data from the Process's input stream will be forwarded (null is allowed)
errorOutput - the output stream where all the data from the Process's error stream will be forwarded (null is allowed)
waitForCompletion - a flag indicating if the calling thread should be blocked until the process is completed
Throws:
java.io.IOException - if execution of the command failed

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException
Throws:
java.io.IOException

launch

public static <T> T launch(java.lang.Class<T> applicationClass,
                           java.lang.String[] args)
Launches an application using the input arguments. This call is forwarded to launch(Class, String[], boolean), where shouldExitOnClose is false.

Type Parameters:
T - the object which should be constructed and returned
Parameters:
applicationClass - the class decribing that object
args - program arguments
Returns:
the instance of the application

launch

public static <T> T launch(java.lang.Class<T> applicationClass,
                           java.lang.String[] args,
                           boolean shouldExitOnClose)
Launches an application defined by the applicationClass. The method will try to create an object of the given instance using the constructor with String[] parameter. If this fails, it will call invoke the main method on the the give application class using the args arguments. If the main method doesn't exist an object's default constructor will be used (in this case args array is useless).

If the application is not a window type but it is at least a Component, a JFrame will be created and the component will be added to that frame. DefaultCloseOperation for the frame is EXIT or DISPOSE and it depends on the shouldExitOnClose parameter.

This method is not thread safe and will block the current thread until the application is loaded. One should take of appropriate multithreading to avoid GUI freezing.

Type Parameters:
T - the object which should be constructed and returned
Parameters:
applicationClass - the class describing that object
args - the program arguments
shouldExitOnClose - if true the frame will have EXIT_ON_CLOSE defaultCloseOperation
Returns:
the instance of application if it was started


Copyright © 2010. All Rights Reserved.