Logo Search packages:      
Sourcecode: icedtea-web version File versions  Download package

ApplicationInstance net::sourceforge::jnlp::Launcher::launchApplication ( JNLPFile  file  )  throws LaunchException [inline, protected]

Launches a JNLP application. This method should be called from a thread in the application's thread group.

Definition at line 395 of file Launcher.java.

References net::sourceforge::jnlp::cache::ResourceTracker::addResource(), createApplication(), net::sourceforge::jnlp::runtime::ApplicationInstance::getClassLoader(), net::sourceforge::jnlp::JARDesc::getLocation(), net::sourceforge::jnlp::runtime::ApplicationInstance::getThreadGroup(), net::sourceforge::jnlp::runtime::ApplicationInstance::initialize(), launchError(), launchExternal(), markNetxRunning(), markNetxStopped(), R(), setContextClassLoaderForAllThreads(), and updatePolicy.

                                                                                          {
        if (!file.isApplication())
            throw launchError(new LaunchException(file, null, R("LSFatal"), R("LCClient"), R("LNotApplication"), R("LNotApplicationInfo")));

        markNetxRunning();
        Runtime.getRuntime().addShutdownHook(new Thread() {
            public void run() { markNetxStopped(); }
         });

        try {

            try {
                ServiceUtil.checkExistingSingleInstance(file);
            } catch (InstanceExistsException e) {
                return null;
            }

            if (JNLPRuntime.getForksAllowed() && file.needsNewVM()) {
                List<String> netxArguments = new LinkedList<String>();
                netxArguments.add("-Xnofork");
                netxArguments.addAll(JNLPRuntime.getInitialArguments());
                launchExternal(file.getNewVMArgs(), netxArguments);
                return null;
            }

            final int preferredWidth = 500;
            final int preferredHeight = 400;
            JNLPSplashScreen splashScreen = null;
            URL splashImageURL = file.getInformation().getIconLocation(
                    IconDesc.SPLASH, preferredWidth, preferredHeight);
            if (splashImageURL != null) {
                ResourceTracker resourceTracker = new ResourceTracker(true);
                resourceTracker.addResource(splashImageURL, file.getFileVersion(), updatePolicy);
                splashScreen = new JNLPSplashScreen(resourceTracker, null, null);
                splashScreen.setSplashImageURL(splashImageURL);
                if (splashScreen.isSplashScreenValid()) {
                    splashScreen.setVisible(true);
                }
            }


            ApplicationInstance app = createApplication(file);
            app.initialize();

            String mainName = file.getApplication().getMainClass();

            // When the application-desc field is empty, we should take a
            // look at the main jar for the main class.
            if (mainName == null) {
                JARDesc mainJarDesc = file.getResources().getMainJAR();
                File f = CacheUtil.getCacheFile(mainJarDesc.getLocation(), null);
                if (f != null) {
                        JarFile mainJar = new JarFile(f);
                        mainName = mainJar.getManifest().
                                getMainAttributes().getValue("Main-Class");
                }
            }

            if (mainName == null)
                throw launchError(new LaunchException(file, null,
                        R("LSFatal"), R("LCClient"), R("LCantDetermineMainClass") ,
                        R("LCantDetermineMainClassInfo")));

            Class mainClass = app.getClassLoader().loadClass(mainName);

            Method main = mainClass.getMethod("main", new Class[] {String[].class} );
            String args[] = file.getApplication().getArguments();
            
            SwingUtilities.invokeAndWait(new Runnable() {
                // dummy method to force Event Dispatch Thread creation
                public void run(){}
            });

            setContextClassLoaderForAllThreads(app.getThreadGroup(), app.getClassLoader());

            if (splashScreen != null) {
                if (splashScreen.isSplashScreenValid()) {
                    splashScreen.setVisible(false);
                }
                splashScreen.dispose();
            }

            main.invoke(null, new Object[] { args } );

            return app;
        }
        catch (LaunchException lex) {
            throw launchError(lex);
        }
        catch (Exception ex) {
            throw launchError(new LaunchException(file, ex, R("LSFatal"), R("LCLaunching"), R("LCouldNotLaunch"), R("LCouldNotLaunchInfo")));
        }
    }


Generated by  Doxygen 1.6.0   Back to index