ConnectorTestpublic abstract class ConnectorTest extends com.sun.enterprise.tools.verifier.tests.VerifierTest implements ConnectorCheck, com.sun.enterprise.tools.verifier.tests.VerifierCheckSuperclass for all connector tests, contains common services. |
Methods Summary |
---|
public com.sun.enterprise.tools.verifier.Result | check(com.sun.enterprise.deployment.Descriptor descriptor)
run an individual test against the deployment descriptor for the
archive the verifier is performing compliance tests against.
return check((ConnectorDescriptor) descriptor);
| public abstract com.sun.enterprise.tools.verifier.Result | check(com.sun.enterprise.deployment.ConnectorDescriptor descriptor)
all connector tests should implement this method. it run an individual
test against the resource adapter deployment descriptor.
| protected boolean | checkMethodImpl(java.lang.Class clazz, java.lang.String methodName, java.lang.Class[] parmTypes, java.lang.String methodSignature, com.sun.enterprise.tools.verifier.Result result)
Check that a class overrides some methods defined in the java.lang.Object class
Method m=null;
Class c = clazz;
do {
try {
m = c.getDeclaredMethod(methodName, parmTypes);
} catch(NoSuchMethodException nsme) {
} catch(SecurityException se) {
}
c = c.getSuperclass();
} while (m != null && c!=null && c != Object.class);
if (m==null) {
result.failed(smh.getLocalString
("com.sun.enterprise.tools.verifier.tests.connector.ConnectorTest.MethodOverride.failed",
"Warning: The class [ {0} ] does not override the method [ {1} ]",
new Object[] {clazz.getName(), methodSignature }));
return false;
} else {
result.passed(smh.getLocalString
("com.sun.enterprise.tools.verifier.tests.connector.ConnectorTest.MethodOverride.passed",
"The class [ {0} ] overrides the method [ {1} ]",
new Object[] {clazz.getName(), methodSignature }));
return true;
}
| protected java.lang.Class | findImplementorOf(com.sun.enterprise.deployment.ConnectorDescriptor desc, java.lang.String interfaceName)
Find a class implementating the interface in the jar files contained
in the connector rar file.
/**
* This is a little bit hectic but we have to go through all the
* jar files included in the rar file and load all classes implemented
* in these jar files. For each class, we should look if the class
* implements the requested interface "interfaceName"
*/
// let's get the rar file
try {
String uri=getAbstractArchiveUri(desc);
FileArchive arch = new FileArchive();
arch.open(uri);
for(Enumeration en = arch.entries();en.hasMoreElements();) {
String entry = (String)en.nextElement();
if (entry.endsWith(".jar")) {
// we found a jar file, let's load it
JarInputStream jis = new JarInputStream(arch.getEntry(entry));
try {
// Now we are going to iterate over the element of the jar file
ZipEntry ze = jis.getNextEntry();
while(ze!=null) {
String elementName = (String) ze.getName();
// Is this jar entry a java class file ?
if (elementName.endsWith(".class")) {
// we found a .class file let's load it and see if it does implement the interface
String className = elementName.substring(0, elementName.length()-".class".length()).replace('/",'.");
//try {
ClassLoader jcl = getVerifierContext().getRarClassLoader();
Class c = Class.forName(className, false, jcl);
if (isImplementorOf(c, interfaceName))
if(c.getSuperclass() != null)
return c;
}
ze = jis.getNextEntry();
}
} catch(ClassNotFoundException cnfe) {
// We ignore this for now
} catch(NoClassDefFoundError cdnf) {
//continue to search other classes
} finally {
try {
if(jis != null)
jis.close();
} catch(Exception e) {}
}
}
}
} catch(java.io.IOException ioe) {
Verifier.debug(ioe);
}
return null;
| protected boolean | findImplementorOf(com.sun.enterprise.deployment.ConnectorDescriptor desc, java.lang.String interfaceName, com.sun.enterprise.tools.verifier.Result result)
Look for an implementation of an interface in all the classes present
in a jar file, setting the result object with the look up result
Class c = findImplementorOf(desc, interfaceName);
if (c != null) {
result.passed(smh.getLocalString
("com.sun.enterprise.tools.verifier.tests.connector.ConnectorTest.findImplementor.passed",
"The class [ {0} ] implements the [ {1} ] interface",
new Object[] {c.getName(), interfaceName}));
return true;
} else {
result.failed(smh.getLocalString
("com.sun.enterprise.tools.verifier.tests.connector.ConnectorTest.findImplementor.failed",
"Error: There is no implementation of the [ {0} ] provided",
new Object[] {interfaceName}));
return false;
}
| protected java.lang.String | getAbstractArchiveUri(com.sun.enterprise.deployment.ConnectorDescriptor desc)
String archBase = getVerifierContext().getAbstractArchive().
getArchiveUri();
final ModuleDescriptor moduleDescriptor = desc.getModuleDescriptor();
if (moduleDescriptor.isStandalone()) {
return archBase; // it must be a stand-alone module; no such physical dir exists
} else {
return archBase + File.separator +
FileUtils.makeFriendlyFileName(moduleDescriptor.getArchiveUri());
}
| protected boolean | isClassLoadable(java.lang.String className, com.sun.enterprise.tools.verifier.Result result)
Check if a class or interface can be loaded from the archive file
ClassLoader jcl = getVerifierContext().getClassLoader();
try {
Class.forName(className, false, jcl);
result.passed(smh.getLocalString
("com.sun.enterprise.tools.verifier.tests.connector.ConnectorTest.isClassLoadable.passed",
"The class [ {0} ] is contained in the archive file",
new Object[] {className}));
return true;
} catch(ClassNotFoundException cnfe) {
result.failed(smh.getLocalString
("com.sun.enterprise.tools.verifier.tests.connector.ConnectorTest.isClassLoadable.failed",
"The class [ {0} ] is not contained in the archive file",
new Object[] {className}));
return true;
}
|
|