Package net.sourceforge.jnlp
Class Launcher
- java.lang.Object
-
- net.sourceforge.jnlp.Launcher
-
public class Launcher extends java.lang.ObjectLaunches JNLPFiles either in the foreground or background.An optional LaunchHandler can be specified that is notified of warning and error condition while launching and that indicates whether a launch may proceed after a warning has occurred. If specified, the LaunchHandler is notified regardless of whether the file is launched in the foreground or background.
- Version:
- $Revision: 1.22 $
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classLauncher.TgThreadThis runnable is used to call the appropriate launch method for the application, applet, or installer in its thread group.
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,java.util.List<java.lang.String>>extraprivate LaunchHandlerhandlerthe handlerprivate static LoggerLOGprivate static java.lang.ThreadGroupmainGroupshared thread groupprivate ParserSettingsparserSettingsprivate UpdatePolicyupdatePolicythe update policy
-
Constructor Summary
Constructors Constructor Description Launcher()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddArguments(JNLPFile file, java.util.List<java.lang.String> args)Add the arguments to the JNLP file; only call if file is actually an application (not installer).private voidaddParameters(JNLPFile file, java.util.List<java.lang.String> params)Add the params to the JNLP file; only call if file is actually an applet file.private voidaddProperties(JNLPFile file, java.util.List<java.lang.String> props)Add the properties to the JNLP file.private AppletInstancecreateApplet(JNLPFile file, java.awt.Container cont)Create an AppletInstance.private ApplicationInstancecreateApplication(JNLPFile file)Creates an Application.private java.lang.ThreadGroupcreateThreadGroup(JNLPFile file)Create a thread group for the JNLP file.private static voiddoPerApplicationAppContextHacks()Do hacks on per-application level to allow different AppContexts to work see JNLPRuntime#doMainAppContextHacksprivate JNLPFilefromUrl(java.net.URL location)Returns the JNLPFile for the URL, with error handling.ApplicationInstancelaunch(java.net.URL location)Launches a JNLP file by calling the launch method for the appropriate file type.ApplicationInstancelaunch(JNLPFile file)Launches a JNLP file by calling the launch method for the appropriate file type.ApplicationInstancelaunch(JNLPFile file, java.awt.Container cont)Launches a JNLP file inside the given container if it is an applet.private ApplicationInstancelaunchApplet(JNLPFile file, java.awt.Container cont)Launches a JNLP applet.private ApplicationInstancelaunchApplication(JNLPFile file)Launches a JNLP application.private LaunchExceptionlaunchError(LaunchException ex)Send n launch error to the handler, if set, and also to the caller.private voidlaunchExternal(JNLPFile file, java.util.List<java.lang.String> javawsArgs)Launches the JNLP file at the specified location in a new JVM instance.private ApplicationInstancelaunchInstaller(JNLPFile file)Launches a JNLP installer.private voidmergeExtraInformation(JNLPFile file, java.util.Map<java.lang.String,java.util.List<java.lang.String>> extra)Merges extra information into the jnlp fileprivate voidsetContextClassLoaderForAllThreads(java.lang.ThreadGroup tg, java.lang.ClassLoader classLoader)Set the classloader as the context classloader for all threads in the given threadgroup.voidsetInformationToMerge(java.util.Map<java.lang.String,java.util.List<java.lang.String>> input)Set a map to use when trying to extract extra information, including arguments, properties and parameters, to be merged into the main JNLPvoidsetParserSettings(ParserSettings settings)
-
-
-
Field Detail
-
LOG
private static final Logger LOG
-
mainGroup
private static final java.lang.ThreadGroup mainGroup
shared thread group
-
handler
private final LaunchHandler handler
the handler
-
updatePolicy
private final UpdatePolicy updatePolicy
the update policy
-
parserSettings
private ParserSettings parserSettings
-
extra
private java.util.Map<java.lang.String,java.util.List<java.lang.String>> extra
-
-
Method Detail
-
setParserSettings
public void setParserSettings(ParserSettings settings)
- Parameters:
settings- the parser settings to use when the Launcher initiates parsing of a JNLP file.
-
setInformationToMerge
public void setInformationToMerge(java.util.Map<java.lang.String,java.util.List<java.lang.String>> input)
Set a map to use when trying to extract extra information, including arguments, properties and parameters, to be merged into the main JNLP- Parameters:
input- a map containing extra information to add to the main JNLP. the values for keys "arguments", "parameters", and "properties" are used.
-
launch
public ApplicationInstance launch(JNLPFile file) throws LaunchException
Launches a JNLP file by calling the launch method for the appropriate file type. The application will be started in a new window.- Parameters:
file- the JNLP file to launch- Returns:
- the application instance
- Throws:
LaunchException- if an error occurred while launching (also sent to handler)
-
launch
public ApplicationInstance launch(JNLPFile file, java.awt.Container cont) throws LaunchException
Launches a JNLP file inside the given container if it is an applet. Specifying a container has no effect for Applications and Installers.- Parameters:
file- the JNLP file to launchcont- the container in which to place the application, if it is an applet- Returns:
- the application instance
- Throws:
LaunchException- if an error occurred while launching (also sent to handler)
-
launch
public ApplicationInstance launch(java.net.URL location) throws LaunchException
Launches a JNLP file by calling the launch method for the appropriate file type.- Parameters:
location- the URL of the JNLP file to launch location to get the pristine version- Returns:
- the application instance
- Throws:
LaunchException- if there was an exception
-
mergeExtraInformation
private void mergeExtraInformation(JNLPFile file, java.util.Map<java.lang.String,java.util.List<java.lang.String>> extra) throws LaunchException
Merges extra information into the jnlp file- Parameters:
file- the JNLPFileextra- extra information to merge into the JNLP file- Throws:
LaunchException- if an exception occurs while extracting extra information
-
addProperties
private void addProperties(JNLPFile file, java.util.List<java.lang.String> props) throws LaunchException
Add the properties to the JNLP file.- Throws:
LaunchException- if an exception occurs while extracting extra information
-
addParameters
private void addParameters(JNLPFile file, java.util.List<java.lang.String> params) throws LaunchException
Add the params to the JNLP file; only call if file is actually an applet file.- Throws:
LaunchException- if an exception occurs while extracting extra information
-
addArguments
private void addArguments(JNLPFile file, java.util.List<java.lang.String> args)
Add the arguments to the JNLP file; only call if file is actually an application (not installer).
-
launchExternal
private void launchExternal(JNLPFile file, java.util.List<java.lang.String> javawsArgs) throws LaunchException
Launches the JNLP file at the specified location in a new JVM instance. All streams are properly redirected.- Parameters:
file- the JNLP file to read arguments and JVM details fromjavawsArgs- the arguments to pass to javaws (aka Netx)- Throws:
LaunchException- if there was an exception
-
fromUrl
private JNLPFile fromUrl(java.net.URL location) throws LaunchException
Returns the JNLPFile for the URL, with error handling.- Throws:
LaunchException
-
launchApplication
private ApplicationInstance launchApplication(JNLPFile file) throws LaunchException
Launches a JNLP application. This method should be called from a thread in the application's thread group.- Parameters:
file- jnlpfile - source of application- Returns:
- application to be launched
- Throws:
LaunchException- if launch fails on unrecoverable exception
-
setContextClassLoaderForAllThreads
private void setContextClassLoaderForAllThreads(java.lang.ThreadGroup tg, java.lang.ClassLoader classLoader)Set the classloader as the context classloader for all threads in the given threadgroup. This is required to make some applications work. For example, an application that provides a custom Swing LnF may ask the swing thread to load resources from their JNLP, which would only work if the Swing thread knows about the JNLPClassLoader.- Parameters:
tg- The threadgroup for which the context classloader should be setclassLoader- the classloader to set as the context classloader
-
launchApplet
private ApplicationInstance launchApplet(JNLPFile file, java.awt.Container cont) throws LaunchException
Launches a JNLP applet. This method should be called from a thread in the application's thread group.The enableCodeBase parameter adds the applet's codebase to the locations searched for resources and classes. This can slow down the applet loading but allows browser-style applets that don't use JAR files exclusively to be run from a applet JNLP file. If the applet JNLP file does not specify any resources then the code base will be enabled regardless of the specified value.
- Parameters:
file- the JNLP filecont- container where to put application- Returns:
- application
- Throws:
LaunchException- if deploy unrecoverably die
-
launchInstaller
private ApplicationInstance launchInstaller(JNLPFile file) throws LaunchException
Launches a JNLP installer. This method should be called from a thread in the application's thread group.- Parameters:
file- jnlp file to read installer from- Returns:
- application
- Throws:
LaunchException- if deploy unrecoverably die
-
createApplet
private AppletInstance createApplet(JNLPFile file, java.awt.Container cont) throws LaunchException
Create an AppletInstance.- Parameters:
file- the JNLP filecont- container where to put applet- Returns:
- applet
- Throws:
LaunchException- if deploy unrecoverably die
-
createApplication
private ApplicationInstance createApplication(JNLPFile file) throws LaunchException
Creates an Application.- Parameters:
file- the JNLP file- Returns:
- application
- Throws:
LaunchException- if deploy unrecoverably die
-
createThreadGroup
private java.lang.ThreadGroup createThreadGroup(JNLPFile file)
Create a thread group for the JNLP file.- Parameters:
file- the JNLP file- Returns:
- ThreadGroup for this app/applet
-
launchError
private LaunchException launchError(LaunchException ex)
Send n launch error to the handler, if set, and also to the caller.
-
doPerApplicationAppContextHacks
private static void doPerApplicationAppContextHacks()
Do hacks on per-application level to allow different AppContexts to work see JNLPRuntime#doMainAppContextHacks
-
-