Methods Summary |
---|
protected void | addErrorDetails(com.sun.enterprise.tools.verifier.Result result, ComponentNameConstructor compName)
// make sure that this message is added only once
if(addedError) return;
addedError = true;
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor",
"For [ {0} ]",
new Object[] {compName.toString()}));
|
protected void | addGoodDetails(com.sun.enterprise.tools.verifier.Result result, ComponentNameConstructor compName)These methods are used to add details to the result. Since this
Class is the base class of all the Ejb Tests, all the tests
can use these methods. Currently only runtime tests are using them.
// make sure that this message is added only once
if(addedGood) return;
addedGood = true;
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor",
"For [ {0} ]",
new Object[] {compName.toString()}));
|
protected void | addNaDetails(com.sun.enterprise.tools.verifier.Result result, ComponentNameConstructor compName)
// make sure that this message is added only once
if(addedNa) return;
addedNa = true;
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor",
"For [ {0} ]",
new Object[] {compName.toString()}));
|
protected void | addWarningDetails(com.sun.enterprise.tools.verifier.Result result, ComponentNameConstructor compName)
// make sure that this message is added only once
if(addedWarning) return;
addedWarning = true;
result.addWarningDetails(smh.getLocalString("tests.componentNameConstructor",
"For [ {0} ]",
new Object[] {compName.toString()}));
|
public java.lang.Class | checkIfPrimitive(java.lang.String param)If the param string is of primitive type this method return that class
representation of the primitive type
if (param.equals("int"))
return int.class;
if (param.equals("boolean"))
return boolean.class;
if (param.equals("float"))
return float.class;
if (param.equals("double"))
return(double.class);
if (param.equals("byte"))
return byte.class;
if (param.equals("long"))
return long.class;
if (param.equals("char"))
return char.class;
if (param.equals("short"))
return short.class;
if (param.equals("void"))
return void.class;
return null;
|
public int | getCountNodeSet(java.lang.String xpath)
try{
// int value = -1;
Document d = getVerifierContext().getRuntimeDocument();
if (d==null)
return -1;
NodeSet ns = new NodeSet(XPathAPI.selectNodeList(d, xpath));
return ns.getLength();
}catch(Exception ex){
ex.printStackTrace();
return -1;
}
|
public static java.lang.reflect.Method | getDeclaredMethod(java.lang.Class clazz, java.lang.String methodName, java.lang.Class[] parmTypes)
utility method to return a method if it is implemented by a class or one
of its superclass irrespective of the method being public, private or protected
Method m=null;
Class c = clazz;
do {
try {
m = clazz.getDeclaredMethod(methodName, parmTypes);
} catch(NoSuchMethodException nsme) {
} catch(SecurityException se) {
}
c = c.getSuperclass();
} while (m != null && c != null);
return m;
|
protected com.sun.enterprise.tools.verifier.Result | getInitializedResult()
Common traces and initialization of the result object that will
hold the result of the assertion tested by this verifier test
logger.log(Level.FINE, "which.class.called.string",
new Object[] {getClass()}) ;
Result result = new Result();
String version = "";
// This is only needed because of ParseDD test which runs before
// context is set in VerifierTest object, else we shall get a NPE.
String compName = "";
if (context!=null) {
version = context.getSchemaVersion();
compName = context.getComponentNameConstructor().toString();
} else {
logger.fine(getClass().getName() + " context is null.");
}
result.init(getClass(), version, compName);
logger.log(Level.FINE, "test.string.assertion", new Object[] {result.getAssertion()});
return result;
|
public static java.lang.reflect.Method | getMethod(java.lang.Class clazz, java.lang.String methodName, java.lang.Class[] parmTypes)
utility method to return a method if ig is implemented by a class or one
of its superclass and it is defined as public
Method m=null;
Class c = clazz;
do {
try {
m = clazz.getMethod(methodName, parmTypes);
} catch(NoSuchMethodException nsme) {
} catch(SecurityException se) {
}
c = c.getSuperclass();
} while (m != null && c != null);
return m;
|
public int | getNonRuntimeCountNodeSet(java.lang.String xpath)
try{
// int value = -1;
Document d = getVerifierContext().getDocument();
if (d==null)
return -1;
XObject result = XPathAPI.eval(d, xpath,
(PrefixResolver)new XpathPrefixResolver (d));
NodeList nl = result.nodelist();
NodeSet ns = new NodeSet(nl);
return ns.getLength();
}catch(Exception ex){
ex.printStackTrace();
return -1;
}
|
public java.lang.Float | getRuntimeSpecVersion()
String docType = null;
String versionStr = null;
Float versionFloat=null;
try{
DocumentType dt = getVerifierContext().getRuntimeDocument().getDoctype();
if (dt==null) return null;
docType = dt.getPublicId();
StringTokenizer st = new StringTokenizer(docType, "//");
while (st.hasMoreElements()) {
String tmp = st.nextToken();
if (tmp.startsWith("DTD")) {
// this is the string we are interested in
StringTokenizer versionST = new StringTokenizer(tmp);
while (versionST.hasMoreElements()) {
versionStr = versionST.nextToken();
try {
versionFloat = Float.valueOf(versionStr);
} catch(NumberFormatException nfe) {
// ignore, this is just the other info of the publicID
}
}
}
}
return versionFloat;
}catch(Exception ex){
//ex.printStackTrace();
return null;
}
|
public com.sun.enterprise.tools.verifier.Context | getVerifierContext()This method provides the Context object
return context;
|
public java.lang.String | getXPathValue(java.lang.String xpath)
try{
String value = null;
Document d = getVerifierContext().getRuntimeDocument();
if (d==null) return null;
NodeList nl = XPathAPI.selectNodeList(d, xpath);
for(int i=0; i<nl.getLength();i++){
Node n = ((Node)nl.item(i)).getFirstChild();
if (n==null) return null;
value = n.getNodeValue();
}
return value;
}catch(Exception ex){
ex.printStackTrace();
return null;
}
|
public java.lang.String | getXPathValueForNonRuntime(java.lang.String xpath)
try{
String value = null;
Document d = getVerifierContext().getDocument();
if (d==null) return null;
XObject result = XPathAPI.eval(d, xpath,
(PrefixResolver)new XpathPrefixResolver (d));
NodeList nl = result.nodelist();
for(int i=0; i<nl.getLength();i++){
Node n = ((Node)nl.item(i)).getFirstChild();
if (n==null) return null;
value = n.getNodeValue();
}
return value;
}catch(Exception ex){
ex.printStackTrace();
return null;
}
|
public static boolean | isImplementorOf(java.lang.Class c, java.lang.String interfaceName)
Test if a class or its superclasses implements an interface
if (c==null || interfaceName==null)
return false;
// try this first because the code in the rest of the method
// is buggy
try {
Class<?> intf = Class.forName(interfaceName);
if (intf.isAssignableFrom(c))
return true;
else
return false;
}catch(Exception e) { }
do {
if (isSubclassOf(c, interfaceName)) {
return true;
}
// get the list of implemented interfaces
Class[] interfaces = c.getInterfaces();
for (int i=0; i<interfaces.length;i++) {
if (isSubclassOf(interfaces[i], interfaceName)) {
return true;
}
}
// we haven't found for this implementation, look in the superclass
c = c.getSuperclass();
} while (c != null);
return false;
|
public static boolean | isSubclassOf(java.lang.Class subClass, java.lang.String superClassName)
check if the class is a sublcass or the class itself of the passed class name
if (subClass==null || superClassName==null) {
return false;
}
Class c = subClass;
do {
if (c.getName().equals(superClassName)) {
return true;
}
Class[] interfaces = c.getInterfaces();
for (int i=0; i<interfaces.length;i++) {
if (interfaces[i].getName().equals(superClassName)) {
return true;
}
else {
if (isSubclassOf(interfaces[i], superClassName)) {
return true;
}
}
}
c = c.getSuperclass();
} while (c!=null);
return false;
|
public static boolean | methodThrowException(java.lang.reflect.Method method, java.lang.String exception)
test if a method throws a particular exception
Class[] exceptions = method.getExceptionTypes();
for (int i=0;i<exceptions.length;i++) {
if (isSubclassOf(exceptions[i], exception))
return true;
}
return false;
|
public void | setVerifierContext(com.sun.enterprise.tools.verifier.Context context)This method sets the Context object
this.context = context;
|
public static void | testFileExistence(java.lang.String uri, java.lang.String fileName, java.lang.String fileID, com.sun.enterprise.tools.verifier.Result result)
Test for a file existence in the archive file
FileArchive arch=null;
// ZipEntry ze=null;
JarFile jarFile=null;
if (fileName == null || fileName.length()==0) {
result.notApplicable(smh.getLocalString
("com.sun.enterprise.tools.verifier.tests.VerifierTest.fileexistence.notApplicable",
"No {0} defined in deployment descriptors",
new Object[] {fileID}));
return;
}
// if (file==null){
try{
arch = new FileArchive();
arch.open(uri);
}catch(Exception e){}
// }else{
// try {
// jarFile = new JarFile(file);
// } catch (java.io.IOException ioe) {
// Verifier.debug(ioe);
// result.failed(smh.getLocalString
// ("com.sun.enterprise.tools.verifier.tests.VerifierTest.fileexistence.failed",
// "Error: {0} [ {1} ] not found in the archive",
// new Object[] {fileID, fileName}));
// return;
// }
// }
try{
// if (file!=null){
// ze = jarFile.getEntry(fileName);
// if (ze == null) {
// result.failed(smh.getLocalString
// ("com.sun.enterprise.tools.verifier.tests.VerifierTest.fileexistence.failed",
// "Error: {0} [ {1} ] not found in the archive",
// new Object[] {fileID, fileName}));
// }else{
// result.passed(smh.getLocalString
// ("com.sun.enterprise.tools.verifier.tests.VerifierTest.fileexistence.passed",
// "{0} [ {1} ] found in the archive",
// new Object[] {fileID, fileName}));
// }
// }
// else{
File urif = new File(arch.getArchiveUri()+File.separator+fileName);
if(urif.exists()){
result.passed(smh.getLocalString
("com.sun.enterprise.tools.verifier.tests.VerifierTest.fileexistence.passed",
"{0} [ {1} ] found in the archive",
new Object[] {fileID, fileName}));
}else{
result.warning(smh.getLocalString
("com.sun.enterprise.tools.verifier.tests.VerifierTest.fileexistence.warning",
"{0} [ {1} ] not found in the archive",
new Object[] {fileID, fileName}));
}
urif = null;
// }
if (jarFile!=null)
jarFile.close();
}catch(Exception ex){}
|
public static boolean | testImplementationOf(java.lang.Class clazz, java.lang.String interfaceName, com.sun.enterprise.tools.verifier.Result result)
verify that a class or one of its superclass is implementing an interface
if (isImplementorOf(clazz, interfaceName)) {
result.passed(smh.getLocalString
("com.sun.enterprise.tools.verifier.tests.VerifierTest.interfaceimplementation.passed",
"The class [ {0} ] implements the [ {1} ] interface",
new Object[] {clazz.getName(), interfaceName}));
return true;
} else {
result.failed(smh.getLocalString
("com.sun.enterprise.tools.verifier.tests.VerifierTest.interfaceimplementation.failed",
"Error: The class [ {0} ] does not implement the [ {1} ] interface",
new Object[] {clazz.getName(), interfaceName}));
return false;
}
|