KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > applications > types > ExecutableType


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.applications.types;
21
22 import java.io.IOException JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.Map JavaDoc;
25
26 import javax.servlet.http.HttpServletRequest JavaDoc;
27
28 import org.apache.commons.logging.Log;
29 import org.apache.commons.logging.LogFactory;
30 import org.apache.struts.action.ActionForward;
31 import org.apache.struts.action.ActionMapping;
32 import org.jdom.Element;
33
34 import com.maverick.multiplex.Request;
35 import com.sslexplorer.agent.AgentTunnel;
36 import com.sslexplorer.agent.DefaultAgentManager;
37 import com.sslexplorer.applications.ApplicationLauncherType;
38 import com.sslexplorer.applications.ApplicationService;
39 import com.sslexplorer.applications.ApplicationShortcut;
40 import com.sslexplorer.extensions.ExtensionDescriptor;
41 import com.sslexplorer.extensions.ExtensionException;
42 import com.sslexplorer.policyframework.LaunchSession;
43 import com.sslexplorer.security.SessionInfo;
44
45 /**
46  * Implementation of an
47  * {@link com.sslexplorer.applications.ApplicationLauncherType} that allows
48  * launching of native applications installed the client machine using a running
49  * Agent.
50  *
51  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
52  */

53 public class ExecutableType implements ApplicationLauncherType {
54
55     final static Log log = LogFactory.getLog(ExecutableType.class);
56
57     /**
58      * Type name
59      */

60     public final static String JavaDoc TYPE = "executable";
61
62     /*
63      * (non-Javadoc)
64      *
65      * @see com.sslexplorer.extensions.ExtensionType#start(com.sslexplorer.extensions.ExtensionDescriptor,
66      * org.jdom.Element)
67      */

68     public void start(ExtensionDescriptor descriptor, Element element) throws ExtensionException {
69
70         if (element.getName().equals(TYPE)) {
71             verifyExecutable(element);
72         }
73
74     }
75
76     /*
77      * (non-Javadoc)
78      *
79      * @see com.sslexplorer.extensions.ExtensionType#verifyRequiredElements()
80      */

81     public void verifyRequiredElements() throws ExtensionException {
82
83     }
84
85     /* (non-Javadoc)
86      * @see com.sslexplorer.applications.ApplicationLauncherType#launch(java.util.Map, com.sslexplorer.extensions.ExtensionDescriptor, com.sslexplorer.applications.ApplicationShortcut, org.apache.struts.action.ActionMapping, com.sslexplorer.policyframework.LaunchSession, java.lang.String, javax.servlet.http.HttpServletRequest)
87      */

88     public ActionForward launch(Map JavaDoc<String JavaDoc, String JavaDoc> parameters, ExtensionDescriptor descriptor, ApplicationShortcut shortcut,
89                                 ActionMapping mapping, LaunchSession launchSession, String JavaDoc returnTo, HttpServletRequest JavaDoc request) throws ExtensionException {
90         if (log.isInfoEnabled())
91             log.info("Launching client application " + shortcut.getResourceName());
92
93         // SessionInfo session =
94
// LogonControllerFactory.getInstance().getSessionInfo(request);
95
if (DefaultAgentManager.getInstance().hasActiveAgent(launchSession.getSession())) {
96             try {
97                 Request JavaDoc agentRequest = ((ApplicationService) DefaultAgentManager.getInstance().getService(ApplicationService.class)).launchApplication(launchSession);
98                 AgentTunnel agent = DefaultAgentManager.getInstance().getAgentBySession(launchSession.getSession());
99                 if (!agent.sendRequest(agentRequest, true, 60000)) {
100                     throw new ExtensionException(ExtensionException.AGENT_REFUSED_LAUNCH);
101                 }
102             } catch (ExtensionException ee) {
103                 throw ee;
104             } catch (Exception JavaDoc e) {
105                 throw new ExtensionException(ExtensionException.INTERNAL_ERROR, e);
106             }
107         } else {
108             throw new ExtensionException(ExtensionException.NO_AGENT);
109         }
110         return null;
111     }
112
113     /*
114      * (non-Javadoc)
115      *
116      * @see com.sslexplorer.extensions.ExtensionType#isHidden()
117      */

118     public boolean isHidden() {
119         return false;
120     }
121
122     /*
123      * (non-Javadoc)
124      *
125      * @see com.sslexplorer.extensions.ExtensionType#getType()
126      */

127     public String JavaDoc getType() {
128         return TYPE;
129     }
130
131     /*
132      * (non-Javadoc)
133      *
134      * @see com.sslexplorer.extensions.ExtensionType#stop()
135      */

136     public void stop() throws ExtensionException {
137     }
138
139     /*
140      * (non-Javadoc)
141      *
142      * @see com.sslexplorer.applications.ApplicationLauncherType#isAgentRequired(com.sslexplorer.applications.ApplicationShortcut,
143      * com.sslexplorer.extensions.ExtensionDescriptor)
144      */

145     public boolean isAgentRequired(ApplicationShortcut shortcut, ExtensionDescriptor descriptor) {
146         return true;
147     }
148
149     /*
150      * (non-Javadoc)
151      *
152      * @see com.sslexplorer.extensions.ExtensionType#activate()
153      */

154     public void activate() throws ExtensionException {
155     }
156
157     /*
158      * (non-Javadoc)
159      *
160      * @see com.sslexplorer.extensions.ExtensionType#canStop()
161      */

162     public boolean canStop() throws ExtensionException {
163         return true;
164     }
165
166     private void verifyExecutable(Element element) throws ExtensionException {
167         for (Iterator JavaDoc it = element.getChildren().iterator(); it.hasNext();) {
168             Element e = (Element) it.next();
169             if (e.getName().equalsIgnoreCase("if")) {
170                 verifyExecutable(e);
171             } else if (!e.getName().equalsIgnoreCase("arg") && !e.getName().equalsIgnoreCase("program") && !e.getName().equalsIgnoreCase("jvm")) {
172                 throw new ExtensionException(ExtensionException.FAILED_TO_PROCESS_DESCRIPTOR, "Unexpected element <" + e.getName()
173                     + "> found in <executable>");
174             }
175         }
176
177     }
178
179     /* (non-Javadoc)
180      * @see com.sslexplorer.extensions.ExtensionType#descriptorCreated(org.jdom.Element)
181      */

182     public void descriptorCreated(Element element, SessionInfo session) throws IOException JavaDoc {
183     }
184
185     /* (non-Javadoc)
186      * @see com.sslexplorer.extensions.ExtensionType#getTypeBundle()
187      */

188     public String JavaDoc getTypeBundle() {
189         return "applications";
190     }
191
192     /* (non-Javadoc)
193      * @see com.sslexplorer.applications.ApplicationLauncherType#isServiceSide()
194      */

195     public boolean isServerSide() {
196         return false;
197     }
198 }
Popular Tags