1 19 20 package com.sslexplorer.agent.client.util.types; 21 22 import java.io.IOException ; 23 import java.util.Enumeration ; 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 35 public class DefaultAgentApplicationType extends JavaApplicationType { 36 42 public void prepare(AbstractApplicationLauncher launcher, ApplicationLauncherEvents events, XMLElement element) 43 throws IOException { 44 this.launcher = launcher; 45 this.events = events; 46 if (element.getName().equals("agents")) { processAgents(launcher, events, element); 49 } else { 50 if (element.getName().equals(getTypeName())) { String jre = (String ) element.getAttribute("jre"); if (isJreSupported(jre)) { 53 super.prepare(launcher, events, element); 54 } else { 55 String mesage = Messages.getString("JavaApplicationType.applicationRequires", new Object [] { jre }); if (events != null) { 57 events.error(mesage); 58 } 59 throw new IOException (mesage); 60 } 61 } 62 } 63 } 64 65 private void processAgents(AbstractApplicationLauncher launcher, ApplicationLauncherEvents events, XMLElement element) 66 throws IOException { 67 Enumeration e = element.enumerateChildren(); 68 String extensionClasses = (String ) element.getAttribute("extensionClasses"); if (extensionClasses != null) { 70 addArgument("extensionClasses=" + extensionClasses); } 72 73 while (e.hasMoreElements()) { 74 XMLElement el = (XMLElement) e.nextElement(); 75 if (el.getName().equalsIgnoreCase("agent")) { String name = (String ) el.getAttribute("name"); String jre = (String ) el.getAttribute("jre"); if (isJreSupported(jre)) { 79 Enumeration e2 = el.enumerateChildren(); 81 while (e2.hasMoreElements()) { 82 XMLElement el2 = (XMLElement) e2.nextElement(); 83 processAgentElements(el2, launcher, events, name); 84 } 85 } else { 86 String message = Messages.getString("DefaultAgentApplicationType.applicationRequires", new Object []{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 name) throws IOException { 94 if (el2.getName().equalsIgnoreCase("if")) { 95 if (AbstractApplicationLauncher.checkCondition(this, el2, launcher.getDescriptorParams())) { 96 for (Enumeration e = el2.enumerateChildren(); e.hasMoreElements();) { 97 processAgentElements((XMLElement) e.nextElement(), launcher, events, name); 98 } 99 } 100 } else if (el2.getName().equalsIgnoreCase("files")) { if (AbstractApplicationLauncher.checkCondition(this, el2, launcher.getDescriptorParams())) { 102 launcher.processFiles(el2, name); 103 } 104 } else if (el2.getName().equalsIgnoreCase("classpath")) { buildClassPath(el2, name); 106 } else if (el2.getName().equalsIgnoreCase("jvm")) { if (AbstractApplicationLauncher.checkCondition(this, el2, launcher.getDescriptorParams())) { 108 addJVMArgument(Utils.trimmedBothOrBlank(el2.getContent())); 109 } 110 } 111 } 112 113 118 private static boolean isJreSupported(String jre) { 119 return jre == null || Utils.checkVersion(jre); 120 } 121 122 126 public String getTypeName() { 127 return "defaultAgent"; 128 } 129 } | Popular Tags |