Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2003, 2007 s IT Solutions AT Spardat GmbH . All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: s IT Solutions AT Spardat GmbH - initial API and implementation /
 
 
 package at.spardat.xma.boot;
 
 import java.io.File;
 import java.net.URL;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
 
Entry class for xma component calls. This class starts an XMA client by its main() method. Possible are also calls to Launcher.lauch() (e.g. from JNI). This class is works directly from a commandline (java) as well as by a browser call via the .xma mime type linking. Typically a script or some java launch programm attached to the .xma mime type would start the XMA client with a call to this classes main method. When an XMA client is started by some link inside a browser then first the XMA server is connected. In this case the XmaLauncherServlet sends back some response attached to the .xma mime type which so will activate the XMA client launcher. Unfortunatly the XmaLauncherServlet response differs in its format from the arguments of a command line call. As this class cannot know per se how it was started some preprocessing has to be done before the XMA client is launched. If this classes main was started by commandline the first argument must be a valid URL of an XMA component (without .xma!). In the case of activation by a browser the first argument to main() is a path of a temporary file holding the XmaLauncherServlet response. Before starting Launcher.main this class checks the first argument. If this is a valid URL then an commandline start is assumed, if it is not a valid URL than a path to an XmaLauncherServlet response is assumed. Example Commandline java at.spardat.xma.Launcher <ComponentName> [key value] java at.spardat.xma.boot.Launcher http://localhost:8080/jndiTest/Test param1 value1 Example Browsercall The XmaLauncherServlet creates a response from which the Browser creates a temp file. In this case the launcher is started by the browser with the path to this file as argument java at.spardat.xma.boot.Launcher <path-to-response-file> java at.spardat.xma.boot.Launcher "C:\Documents and Settings\s3460\Local Settings\Temporary Internet Files\Content.IE5\0P2F4PYN\Test[1].xma" The response from the XmaLauncherServlet has the form of an ini file: ----------------------------------------------- [Component] name=http://localhost:8080/localtest/Test [Params] showPopUp=true reuseWin=testappl ----------------------------------------------- (Note: In former XMA versions only a C-programm "xmalaunchw.exe" dealt with the maLauncherServlet response and called at.spardat.xma.boot.Launcher by JNI)

Author(s):
s2877, s3595
Version:
$Id: Launcher.java 10005 2012-11-06 11:56:58Z dschwarz $
 
 public class Launcher {
 
     private static final String SELFTEST = "selftest";

    
Singleton BootRuntime
 
     private static BootRuntime br_ = null;

    
logger
 
     private static Logger log_;


    
common launch method
    public static KeyValue[] launchString componentKeyValue[] parameters) {
       return launchImpl(component,parameters,true);
    }
    public static KeyValue[] launchGUILess(String componentKeyValue[] parameters) {
        return launchImpl(component,parameters,false);
    }
    private static KeyValue[] launchImplString componentKeyValue[] parametersboolean showErrors) {
        KeyValue[] out = new KeyValue[0];
        
        try {
            /*
             * initialize boot runtime
             */
            Launcher.init();
            
            if (.equalsIgnoreCase(component)) {
                BRNotificationBox.showDetailsDialog("Bootruntime", (Throwablenull);
            } else {
                out = launchComponent(componentparameters);
            }
        } catchException ex ){
            if( != null){
                .log(.ex.getLocalizedMessage(), ex );
            }
            else{
                ex.printStackTrace();
            }
            if(showErrors) {
                BRNotificationBox.show(ex);
            }
            else{
                throw new RuntimeException(ex);
            }
        } catchError err ){
            if( != null){
                .log(.err.getLocalizedMessage(), err );
            }
            else{
                err.printStackTrace();
            }
            if(showErrors){
                BRNotificationBox.show(err);
            }
            throw err;
        }
        finally {
            if(!=null) {
                AppManager appM = .getAppManager();
                if(appM!=null) {
                    IComponentHelper compHelp = appM.getCompHelper();
                    if(compHelp!=nullcompHelp.cleanupSWTDisplay();
                }
            }
        }
        
        for (Window window : Window.getWindows()) {
            if(!=null.log(."Disposing window " + window);
            window.dispose();
        }
        
        // Stop all threads brute force except daemons and main
        // Mantis 0049971: Previous solution cleaning up frames using 'javax.swing.SwingUtilities.invokeLater(...'
        // isn't sufficient on some workstations any more
        
        Thread[] threads = new Thread[Thread.activeCount()+10];
        int threadCount = Thread.enumerate(threads);
        for (int i = 0; i < threadCounti++) {
            Thread thread = threads[i];
            if (thread != null) {
                if(!=null.log(.,"Thread " + thread.getName() +
                        ", isAlive:" + thread.isAlive() + " isDaemon:" + thread.isDaemon());
                if (thread.isAlive()
                    && ! thread.isDaemon()
                    && thread != Thread.currentThread()) {
                    
                    if(!=null.log(.,"Stopping thread " + thread.getName());
                    thread.stop();
                }
            }
        }
        return out;
    }
    private static KeyValue[] launchComponent(String componentKeyValue[] parametersthrows BootRuntimeExceptionException {
        
        Properties input = new Properties();
        .log(.parameters.length == 0 ? "No Input Data""Input Data: " ); //$NON-NLS-1$ //$NON-NLS-2$
        for (int i = 0; i < parameters.lengthi++) {
            input.setProperty(parameters[i].getKey(), parameters[i].getValue());
            .log(."key: {0} value: {1}"new Object[] { parameters[i].getKey(), parameters[i].getValue() } ); //$NON-NLS-1$
        }
        try {
            new XMA_URI(component);
        } catchMalformedURLException ex) {
            String strMessage = BRTCodes.getText(.);
            brtExc.setMessage(strMessage + " \"" + component +"\"");
            throw brtExc;
        }
        /*
         * launch component
         */
        Properties output = .getAppManager().launch(component,input);
        /*
         * prepare output list
         */
        .log(."Output Data: " ); //$NON-NLS-1$
        KeyValue[] out = new KeyValue[output.size()];
        Enumeration enumer = output.keys();
        for (int i = 0; enumer.hasMoreElements(); i++) {
            String key = (Stringenumer.nextElement();
            out[i] = new KeyValue(keyoutput.getProperty(key));
            .log(."key: {0} value: {1}"new Object[] {keyout[i].getValue() } ); //$NON-NLS-1$
        }
        return out;
    }


    
main
    public static void main(String[] args) {
        try {
        if (args.length < 1 || args.length % 2 != 1) {
            Launcher.usage();
           return;
        }
        String component = null;
        KeyValue[] input = null;
        if(isUrl(args[0])){ //started by commandline
            component = args[0];
            int keyValues = (args.length - 1)/2;
            input = new KeyValuekeyValues ];
            int j=1;
            for (int i=0; i < keyValuesi++ ) {
              input[i] = new KeyValueargs[j], args[j+1] );
              j+=2;
            }
        }else//started by browser -> path to XmaLauncherServlet response file
            IniFileReader reader = new IniFileReader(args[0]);
            component = reader.getProperty("Component""name");
            Map params = reader.getSection("Params");
            if(params != null){
                input = new KeyValue[params.size()];
                int i = 0;
                for (Iterator iter = params.keySet().iterator(); iter.hasNext(); i++) {
                    String  key =  (Stringiter.next();
                    String  value = (Stringparams.get(key);
                    input[i] = new KeyValue(keyvalue);
                }
            } else{
                input = new KeyValue[0];
            }
        }
        //actual launch of XMA client
        KeyValue[] output = launchcomponentinput );
        //print out return values
        for(int i = 0; i < output.length ; i++) {
          ..println("key: " + output[i].getKey() + " value: " + output[i].getValue());       //$NON-NLS-1$ //$NON-NLS-2$
        }
        } finally {
            System.exit(0); // for Webstart/Applet and such
        }
    }

    
Tests if the argument is a valid URL

Parameters:
url
Returns:
Author(s):
s3460
Since:
version_number
    private static boolean isUrl(String url) {
        boolean isUrl;
        try {
            new URL(url);
            isUrl = true;
        } catch (MalformedURLException e) {
            isUrl = false;
        }
        return isUrl;
    }

    
Reads a XmaLauncherServlet response file and transforms in an String[] array filled like XMA commandline arguments: <ComponentName> [key value]

Parameters:
filePath
Returns:
Author(s):
s3460
Since:
version_number
    private static String[] argsFromXMAFile(String filePath){
        List list = new ArrayList();
        IniFileReader reader = new IniFileReader(filePath);
        String comp = reader.getProperty("Component""name");
        list.add(comp);
        Map params = reader.getSection("Params");
        for (Iterator iter = params.keySet().iterator(); iter.hasNext();) {
            Object key =  iter.next();
            Object value = params.get(key);
            list.add(key);
            list.add(value);
        }
        return (String[]) list.toArray(new String[list.size()]);
    }

    
usage
    private static void usage() {
       ..println("usage:\n java at.spardat.xma.Launcher <ComponentName> [key value]..."); //$NON-NLS-1$
    }


    
initialize the runtime if necessary

    public static synchronized void init () throws IOException {
        if == null ) {
             = Logger.getLogger("bootrt.launcher"); //$NON-NLS-1$
            SimpleDateFormat sdf = new SimpleDateFormat"EEE, dd MMM yyyy hh:mm:ss zzz", Locale.getDefault() );            //$NON-NLS-1$
            .log."initializing xma runtime: {0} "sdf.format(new Date() )); //$NON-NLS-1$
            // initialize Swing
            // There is a bug in the Linux JVM and SWT: if the Swing System look and feel is set by the UIManager.setLookAndFeel() then SWT works not properly.
            // So in Linux start XMA with the VM argument: -Dxma.boot.skipSetSwingSystemLookAndFeel=true.
            // For details about the bug see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=320524
            String skip = System.getProperty("xma.boot.skipSetSwingSystemLookAndFeel"); //$NON-NLS-1$
            if (skip == null || "true".equalsIgnoreCase(skip) == false) {
                try {
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                } catch (Exception e) {
                    .log(."error setting swing look and feel: "e);
                }
            }
            String strHome = System.getProperty("xma.boot.homedir"); //$NON-NLS-1$
            ifstrHome == null) {
                strHome = System.getProperty"user.dir");
                .log."fallback::boot runtime installation directory defaults to: {0} "strHome ); //$NON-NLS-1$
            }
            .log."boot runtime installation directory is: {0} "strHome ); //$NON-NLS-1$
            File f = new FilestrHome );
             = BootRuntime.initialize(f );
        } // if br
    }// init

    
Get the properties loaded by the BootRuntime from bootcfg.properties.

Returns:
the properties or null if the BootRuntime is not initialized yet.
Since:
1.7.0
    public static Properties getBootRuntimeProperties() {
        if(==null) {
            return null;
        } else {
            return .getConfigProperties();
        }
    }
New to GrepCode? Check out our FAQ X