KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > agent > client > applications > Application


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.agent.client.applications;
21
22 import java.io.File JavaDoc;
23 import java.io.FileNotFoundException JavaDoc;
24 import java.io.FileOutputStream JavaDoc;
25 import java.io.IOException JavaDoc;
26 import java.text.MessageFormat JavaDoc;
27 import java.util.Hashtable JavaDoc;
28
29 import com.sslexplorer.agent.client.Agent;
30 import com.sslexplorer.agent.client.Messages;
31 import com.sslexplorer.agent.client.util.AbstractApplicationLauncher;
32 import com.sslexplorer.agent.client.util.ProcessMonitor;
33
34 /**
35  * Thread that downloads an <i>Application Extension</i> from the SSL-Explorer
36  * server, processes its extension descriptor and launches it.
37  *
38  * @author Lee David Painter <a HREF="mailto: lee@3sp.com">&lt;lee@3sp.com&gt;</a>
39  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
40  */

41 public class Application extends Thread JavaDoc {
42
43     // Private instance variables
44
private Agent client;
45     String JavaDoc name;
46     Hashtable JavaDoc parameters;
47     private AbstractApplicationLauncher launcher;
48     private ApplicationEventListener events;
49     private String JavaDoc descriptor;
50     
51     // #ifdef DEBUG
52
static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(Application.class);
53
54     // #endif
55

56     /**
57      * Constructor.
58      *
59      * @param client client
60      * @param parameters application parameters
61      * @param name application name
62      * @throws IOException on any error
63      */

64     public Application(Agent client, Hashtable JavaDoc parameters, String JavaDoc name, String JavaDoc descriptor) throws IOException JavaDoc {
65         super(MessageFormat.format(Messages.getString("Application.threadName"), new Object JavaDoc[] { name })); //$NON-NLS-1$
66
this.client = client;
67         this.name = name;
68         this.descriptor = descriptor;
69         this.parameters = parameters;
70         events = new ApplicationEventListener(this.client);
71         events.startingLaunch(name);
72         launcher = new AgentApplicationLauncher(this.client, name, parameters, descriptor, events);
73         launcher.prepare();
74
75     }
76     
77    /**
78     * Get the launcher
79     *
80     * @return launcher
81     */

82     public AbstractApplicationLauncher getLauncher() {
83         return launcher;
84     }
85
86     /**
87      * Get the redirect parameters for the application type.
88      *
89      * @return redirect parameters
90      */

91     public String JavaDoc getRedirectParameters() {
92         return launcher.getApplicationType().getRedirectParameters();
93     }
94
95     /*
96      * (non-Javadoc)
97      *
98      * @see java.lang.Thread#run()
99      */

100     public void run() {
101         
102         
103         FileOutputStream JavaDoc out = null;
104         boolean hasErrored = false;;
105         
106         try {
107             launcher.start();
108                         
109         } catch (Throwable JavaDoc t) {
110             hasErrored = true;
111             
112             // #ifdef DEBUG
113
log.error("Failed to launch application " + name, t); //$NON-NLS-1$
114
// #endif
115

116             client.getGUI().popup(null,
117                     MessageFormat.format(Messages.getString("Application.error.message"), new Object JavaDoc[] { launcher.getName(), t.getMessage()}),
118                     Messages.getString("Application.error.title"), "popup-error", 0);
119             
120         } finally {
121             
122             events.finishedLaunch();
123             
124             if(!hasErrored) {
125                 try {
126                     out = new FileOutputStream JavaDoc(new File JavaDoc(launcher.getInstallDir(), launcher.getName() + ".out")); //$NON-NLS-1$
127
ProcessMonitor monitor = launcher.getApplicationType().getProcessMonitor();
128                     if (monitor != null) {
129                         monitor.watch(out, out);
130                     }
131                 } catch (Throwable JavaDoc e) {
132                 } finally {
133                     if (out != null) {
134                         try {
135                             out.close();
136                         } catch (IOException JavaDoc ioe) {
137
138                         }
139                     }
140                 }
141             }
142             
143           
144         }
145     }
146 }
Popular Tags