KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > agent > client > util > types > DefaultAgentApplicationType


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.util.types;
21
22 import java.io.IOException JavaDoc;
23 import java.util.Enumeration JavaDoc;
24
25 import com.sslexplorer.agent.client.util.AbstractApplicationLauncher;
26 import com.sslexplorer.agent.client.util.ApplicationLauncherEvents;
27 import com.sslexplorer.agent.client.util.Utils;
28 import com.sslexplorer.agent.client.util.XMLElement;
29
30 /**
31  * Application type to use for the <i>SSL-Explorer Agent</i>.
32  *
33  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
34  */

35 public class DefaultAgentApplicationType extends JavaApplicationType {
36     /*
37      * (non-Javadoc)
38      * @see com.sslexplorer.vpn.util.types.JavaApplicationType#prepare(com.sslexplorer.vpn.util.ApplicationLauncher,
39      * com.sslexplorer.vpn.util.ApplicationLauncherEvents,
40      * com.sslexplorer.vpn.util.XMLElement)
41      */

42     public void prepare(AbstractApplicationLauncher launcher, ApplicationLauncherEvents events, XMLElement element)
43                     throws IOException JavaDoc {
44         this.launcher = launcher;
45         this.events = events;
46         if (element.getName().equals("agents")) { //$NON-NLS-1$
47
// Process agent extensions
48
processAgents(launcher, events, element);
49         } else {
50             if (element.getName().equals(getTypeName())) { //$NON-NLS-1$
51
String JavaDoc jre = (String JavaDoc) element.getAttribute("jre"); //$NON-NLS-1$
52
if (isJreSupported(jre)) {
53                     super.prepare(launcher, events, element);
54                 } else {
55                     String JavaDoc mesage = Messages.getString("JavaApplicationType.applicationRequires", new Object JavaDoc[] { jre }); //$NON-NLS-1$
56
if (events != null) {
57                         events.error(mesage);
58                     }
59                     throw new IOException JavaDoc(mesage);
60                 }
61             }
62         }
63     }
64
65     private void processAgents(AbstractApplicationLauncher launcher, ApplicationLauncherEvents events, XMLElement element)
66                     throws IOException JavaDoc {
67         Enumeration JavaDoc e = element.enumerateChildren();
68         String JavaDoc extensionClasses = (String JavaDoc) element.getAttribute("extensionClasses"); //$NON-NLS-1$
69
if (extensionClasses != null) {
70             addArgument("extensionClasses=" + extensionClasses); //$NON-NLS-1$
71
}
72
73         while (e.hasMoreElements()) {
74             XMLElement el = (XMLElement) e.nextElement();
75             if (el.getName().equalsIgnoreCase("agent")) { //$NON-NLS-1$
76
String JavaDoc name = (String JavaDoc) el.getAttribute("name"); //$NON-NLS-1$
77
String JavaDoc jre = (String JavaDoc) el.getAttribute("jre"); //$NON-NLS-1$
78
if (isJreSupported(jre)) {
79                     // Process classpath and/or file elements
80
Enumeration JavaDoc e2 = el.enumerateChildren();
81                     while (e2.hasMoreElements()) {
82                         XMLElement el2 = (XMLElement) e2.nextElement();
83                         processAgentElements(el2, launcher, events, name);
84                     }
85                 } else {
86                     String JavaDoc message = Messages.getString("DefaultAgentApplicationType.applicationRequires", new Object JavaDoc[]{name, jre, System.getProperty("java.version")});
87                     launcher.processErrorMessage(message);
88                 }
89             }
90         }
91     }
92
93     private void processAgentElements(XMLElement el2, AbstractApplicationLauncher launcher, ApplicationLauncherEvents events, String JavaDoc name) throws IOException JavaDoc {
94         if (el2.getName().equalsIgnoreCase("if")) {
95             if (AbstractApplicationLauncher.checkCondition(this, el2, launcher.getDescriptorParams())) {
96                 for (Enumeration JavaDoc e = el2.enumerateChildren(); e.hasMoreElements();) {
97                     processAgentElements((XMLElement) e.nextElement(), launcher, events, name);
98                 }
99             }
100         } else if (el2.getName().equalsIgnoreCase("files")) { //$NON-NLS-1$
101
if (AbstractApplicationLauncher.checkCondition(this, el2, launcher.getDescriptorParams())) {
102                 launcher.processFiles(el2, name);
103             }
104         } else if (el2.getName().equalsIgnoreCase("classpath")) { //$NON-NLS-1$
105
buildClassPath(el2, name);
106         } else if (el2.getName().equalsIgnoreCase("jvm")) { //$NON-NLS-1$
107
if (AbstractApplicationLauncher.checkCondition(this, el2, launcher.getDescriptorParams())) {
108                 addJVMArgument(Utils.trimmedBothOrBlank(el2.getContent()));
109             }
110         }
111     }
112     
113     /**
114      * Must check for null, if no jre is specified then we assume all jres are supported
115      * @param jre
116      * @return true if the supplied JRE value is null or is a supported version
117      */

118     private static boolean isJreSupported(String JavaDoc jre) {
119         return jre == null || Utils.checkVersion(jre);
120     }
121
122     /*
123      * (non-Javadoc)
124      * @see com.sslexplorer.agent.client.util.ApplicationType#getTypeName()
125      */

126     public String JavaDoc getTypeName() {
127         return "defaultAgent";
128     }
129 }
Popular Tags