1 3 package com.sslexplorer.extensions.types; 4 5 import java.io.IOException ; 6 import java.util.Iterator ; 7 8 import org.apache.commons.logging.Log; 9 import org.apache.commons.logging.LogFactory; 10 import org.jdom.Element; 11 12 import com.sslexplorer.extensions.ExtensionDescriptor; 13 import com.sslexplorer.extensions.ExtensionException; 14 import com.sslexplorer.extensions.ExtensionType; 15 import com.sslexplorer.security.SessionInfo; 16 17 23 public abstract class AbstractJavaType implements ExtensionType { 24 25 static Log log = LogFactory.getLog(AbstractJavaType.class); 26 27 private String jre; 29 private ExtensionDescriptor descriptor; 30 private String typeName; 31 private boolean canStop; 32 33 38 public AbstractJavaType(String typeName, boolean canStop) { 39 this.typeName = typeName; 40 this.canStop = canStop; 41 } 42 43 49 public void start(ExtensionDescriptor descriptor, Element element) throws ExtensionException { 50 this.descriptor = descriptor; 51 if (element.getName().equals(typeName)) { 52 53 jre = element.getAttribute("jre").getValue(); 54 55 if (jre == null) { 56 throw new ExtensionException(ExtensionException.FAILED_TO_PROCESS_DESCRIPTOR, 57 "<application> element requires attribute 'jre'"); 58 } 59 60 try { 61 ExtensionDescriptor.getVersion(jre); 62 } catch (Throwable ex) { 63 throw new ExtensionException(ExtensionException.FAILED_TO_PROCESS_DESCRIPTOR, "Invalid value '" + jre 64 + "' specified for 'jre' attribute"); 65 } 66 67 for (Iterator it = element.getChildren().iterator(); it.hasNext();) { 68 Element e = (Element) it.next(); 69 70 if (e.getName().equalsIgnoreCase("classpath")) { 71 verifyClasspath(e); 72 } else if (e.getName().equalsIgnoreCase("main")) { 73 verifyMain(e); 74 } else { 75 throw new ExtensionException(ExtensionException.FAILED_TO_PROCESS_DESCRIPTOR, "Unexpected element <" 76 + e.getName() + "> found in <application>"); 77 } 78 } 79 80 } 81 82 } 83 84 public void verifyRequiredElements() throws ExtensionException { 85 } 86 87 92 public boolean isHidden() { 93 return false; 94 } 95 96 101 public String getType() { 102 return typeName; 103 } 104 105 110 public void stop() throws ExtensionException { 111 } 112 113 118 public boolean canStop() { 119 return canStop; 120 } 121 122 125 public void activate() throws ExtensionException { 126 } 127 128 private void verifyClasspath(Element element) throws ExtensionException { 129 for (Iterator it = element.getChildren().iterator(); it.hasNext();) { 130 Element e = (Element) it.next(); 131 if (e.getName().equalsIgnoreCase("jar")) { 132 descriptor.processFile(e); 133 } else if (e.getName().equals("if")) { 134 verifyClasspath(e); 135 } else { 136 throw new ExtensionException(ExtensionException.FAILED_TO_PROCESS_DESCRIPTOR, "Invalid element <" + e.getName() 137 + "> found in <classpath>"); 138 } 139 } 140 } 141 142 private void verifyMain(Element element) throws ExtensionException { 143 for (Iterator it = element.getChildren().iterator(); it.hasNext();) { 144 Element e = (Element) it.next(); 145 if (e.getName().equalsIgnoreCase("if")) { 146 verifyMain(e); 147 } else if (!e.getName().equalsIgnoreCase("env") && !e.getName().equalsIgnoreCase("arg") && !e.getName().equalsIgnoreCase("jvm")) { 148 throw new ExtensionException(ExtensionException.FAILED_TO_PROCESS_DESCRIPTOR, "Unexpected element <" + e.getName() 149 + "> found in <main>"); 150 } 151 } 152 } 153 154 157 public void descriptorCreated(Element element, SessionInfo session) throws IOException { 158 } 159 } | Popular Tags |