1 23 28 29 package com.sun.enterprise.tools.verifier.tests.connector; 30 31 import com.sun.enterprise.deployment.ConnectorDescriptor; 32 import com.sun.enterprise.deployment.Descriptor; 33 import com.sun.enterprise.deployment.util.ModuleDescriptor; 34 import com.sun.enterprise.deployment.deploy.shared.FileArchive; 35 import com.sun.enterprise.tools.verifier.Result; 36 import com.sun.enterprise.tools.verifier.Verifier; 37 import com.sun.enterprise.tools.verifier.tests.VerifierCheck; 38 import com.sun.enterprise.tools.verifier.tests.VerifierTest; 39 import com.sun.enterprise.util.io.FileUtils; 40 41 import java.io.File ; 42 import java.lang.reflect.Method ; 43 import java.util.Enumeration ; 44 import java.util.jar.JarInputStream ; 45 import java.util.zip.ZipEntry ; 46 52 public abstract class ConnectorTest extends VerifierTest implements VerifierCheck, ConnectorCheck 53 { 54 55 65 public Result check(Descriptor descriptor) { 66 return check((ConnectorDescriptor) descriptor); 67 } 68 69 79 public abstract Result check(ConnectorDescriptor descriptor); 80 81 90 protected Class findImplementorOf(ConnectorDescriptor desc, String interfaceName) { 91 97 98 try { 100 String uri=getAbstractArchiveUri(desc); 101 FileArchive arch = new FileArchive(); 102 arch.open(uri); 103 for(Enumeration en = arch.entries();en.hasMoreElements();) { 104 String entry = (String )en.nextElement(); 105 if (entry.endsWith(".jar")) { 106 JarInputStream jis = new JarInputStream (arch.getEntry(entry)); 108 try { 109 ZipEntry ze = jis.getNextEntry(); 111 while(ze!=null) { 112 String elementName = (String ) ze.getName(); 113 if (elementName.endsWith(".class")) { 115 String className = elementName.substring(0, elementName.length()-".class".length()).replace('/','.'); 117 ClassLoader jcl = getVerifierContext().getRarClassLoader(); 119 Class c = Class.forName(className, false, jcl); 120 121 if (isImplementorOf(c, interfaceName)) 122 if(c.getSuperclass() != null) 123 return c; 124 125 } 126 ze = jis.getNextEntry(); 127 } 128 } catch(ClassNotFoundException cnfe) { 129 } catch(NoClassDefFoundError cdnf) { 131 } finally { 133 try { 134 if(jis != null) 135 jis.close(); 136 } catch(Exception e) {} 137 } 138 } 139 } 140 } catch(java.io.IOException ioe) { 141 Verifier.debug(ioe); 142 } 143 return null; 144 } 145 146 158 protected boolean checkMethodImpl(Class clazz, String methodName, Class [] parmTypes, 159 String methodSignature, Result result) { 160 161 Method m=null; 162 Class c = clazz; 163 164 do { 165 try { 166 m = c.getDeclaredMethod(methodName, parmTypes); 167 } catch(NoSuchMethodException nsme) { 168 } catch(SecurityException se) { 169 } 170 c = c.getSuperclass(); 171 } while (m != null && c!=null && c != Object .class); 172 173 if (m==null) { 174 result.failed(smh.getLocalString 175 ("com.sun.enterprise.tools.verifier.tests.connector.ConnectorTest.MethodOverride.failed", 176 "Warning: The class [ {0} ] does not override the method [ {1} ]", 177 new Object [] {clazz.getName(), methodSignature })); 178 return false; 179 } else { 180 result.passed(smh.getLocalString 181 ("com.sun.enterprise.tools.verifier.tests.connector.ConnectorTest.MethodOverride.passed", 182 "The class [ {0} ] overrides the method [ {1} ]", 183 new Object [] {clazz.getName(), methodSignature })); 184 return true; 185 } 186 } 187 188 197 protected boolean findImplementorOf(ConnectorDescriptor desc, String interfaceName, Result result) 198 { 199 Class c = findImplementorOf(desc, interfaceName); 200 if (c != null) { 201 result.passed(smh.getLocalString 202 ("com.sun.enterprise.tools.verifier.tests.connector.ConnectorTest.findImplementor.passed", 203 "The class [ {0} ] implements the [ {1} ] interface", 204 new Object [] {c.getName(), interfaceName})); 205 return true; 206 } else { 207 result.failed(smh.getLocalString 208 ("com.sun.enterprise.tools.verifier.tests.connector.ConnectorTest.findImplementor.failed", 209 "Error: There is no implementation of the [ {0} ] provided", 210 new Object [] {interfaceName})); 211 return false; 212 } 213 } 214 215 224 protected boolean isClassLoadable(String className, Result result) { 225 ClassLoader jcl = getVerifierContext().getClassLoader(); 226 try { 227 Class.forName(className, false, jcl); 228 result.passed(smh.getLocalString 229 ("com.sun.enterprise.tools.verifier.tests.connector.ConnectorTest.isClassLoadable.passed", 230 "The class [ {0} ] is contained in the archive file", 231 new Object [] {className})); 232 return true; 233 } catch(ClassNotFoundException cnfe) { 234 result.failed(smh.getLocalString 235 ("com.sun.enterprise.tools.verifier.tests.connector.ConnectorTest.isClassLoadable.failed", 236 "The class [ {0} ] is not contained in the archive file", 237 new Object [] {className})); 238 return true; 239 } 240 } 241 242 protected String getAbstractArchiveUri(ConnectorDescriptor desc) { 243 String archBase = getVerifierContext().getAbstractArchive(). 244 getArchiveUri(); 245 final ModuleDescriptor moduleDescriptor = desc.getModuleDescriptor(); 246 if (moduleDescriptor.isStandalone()) { 247 return archBase; } else { 249 return archBase + File.separator + 250 FileUtils.makeFriendlyFileName(moduleDescriptor.getArchiveUri()); 251 } 252 } 253 254 } 255 | Popular Tags |