HomeInterfaceFindByPrimaryKeyReturnpublic class HomeInterfaceFindByPrimaryKeyReturn extends com.sun.enterprise.tools.verifier.tests.ejb.EjbTest implements com.sun.enterprise.tools.verifier.tests.ejb.EjbCheckDefine findByPrimaryKey method which returns the primary key type test.
Every entity enterprise Bean class must define the findByPrimaryKey
method. The return type for this method must be the primary key type.
(i.e. the findByPrimaryKey method must be a single-object finder). |
Fields Summary |
---|
Result | result | ComponentNameConstructor | compName |
Methods Summary |
---|
public Result | check(com.sun.enterprise.deployment.EjbDescriptor descriptor)Define findByPrimaryKey method test.
Every entity enterprise Bean class must define the findByPrimaryKey
method. The return type for this method must be the primary key type.
(i.e. the findByPrimaryKey method must be a single-object finder).
result = getInitializedResult();
compName = getVerifierContext().getComponentNameConstructor();
boolean oneFailed = false;
if (descriptor instanceof EjbEntityDescriptor) {
if(descriptor.getHomeClassName() != null && !"".equals(descriptor.getHomeClassName())&&
descriptor.getRemoteClassName() != null && !"".equals(descriptor.getRemoteClassName()))
oneFailed = commonToBothInterfaces(descriptor.getHomeClassName(), descriptor.getRemoteClassName(),descriptor);
if(oneFailed == false) {
if(descriptor.getLocalHomeClassName() != null && !"".equals(descriptor.getLocalHomeClassName())&&
descriptor.getLocalClassName() != null && !"".equals(descriptor.getLocalClassName()))
oneFailed = commonToBothInterfaces(descriptor.getLocalHomeClassName(),descriptor.getLocalClassName(),descriptor);
}
if (oneFailed) {
result.setStatus(result.FAILED);
} else {
result.setStatus(result.PASSED);
}
return result;
} else {
result.addNaDetails(smh.getLocalString
("tests.componentNameConstructor",
"For [ {0} ]",
new Object[] {compName.toString()}));
result.notApplicable(smh.getLocalString
(getClass().getName() + ".notApplicable",
"[ {0} ] expected {1} bean, but called with {2} bean.",
new Object[] {getClass(),"Entity","Session"}));
return result;
}
| private boolean | commonToBothInterfaces(java.lang.String home, java.lang.String remote, com.sun.enterprise.deployment.EjbDescriptor descriptor)This method is responsible for the logic of the test. It is called for both local and remote interfaces.
boolean findByPrimaryKeyMethodFound = false;
boolean oneFailed = false;
boolean returnValueValid = false;
try {
// retrieve the home interface methods
Context context = getVerifierContext();
ClassLoader jcl = context.getClassLoader();
Class homeInterfaceClass = Class.forName(home, false, getVerifierContext().getClassLoader());
Method [] ejbFinderMethods = homeInterfaceClass.getDeclaredMethods();
Class rc = Class.forName(remote, false, getVerifierContext().getClassLoader());
for (int j = 0; j < ejbFinderMethods.length; ++j) {
// reset all booleans for next method within the loop
returnValueValid = false;
if (ejbFinderMethods[j].getName().equals("findByPrimaryKey")) {
// Every entity enterprise Bean class must define the
// findByPrimaryKey method. The return type for this method must
// be the primary key type (i.e. the findByPrimaryKey method
// must be a single-object finder).
if (!findByPrimaryKeyMethodFound) {
findByPrimaryKeyMethodFound = true;
}
Class returnByPrimaryKeyValue = ejbFinderMethods[j].getReturnType();
// as long as this returns a single object finder, then return type
// is valid
if (((returnByPrimaryKeyValue.getName().equals(rc.getName())) &&
(!((returnByPrimaryKeyValue.getName().equals("java.util.Collection")) ||
(returnByPrimaryKeyValue.getName().equals("java.util.Enumeration")))))) {
returnValueValid = true;
}
// report for this particular findByPrimaryKey(...)
if (findByPrimaryKeyMethodFound && returnValueValid) {
result.addGoodDetails(smh.getLocalString
("tests.componentNameConstructor",
"For [ {0} ]",
new Object[] {compName.toString()}));
result.addGoodDetails(smh.getLocalString
(getClass().getName() + ".debug1",
"For Home interface [ {0} ] Finder Method [ {1} ]",
new Object[] {homeInterfaceClass.getName(),ejbFinderMethods[j].getName()}));
result.addGoodDetails(smh.getLocalString
(getClass().getName() + ".passed",
"A findByPrimaryKey method was found with valid return type."));
} else if (findByPrimaryKeyMethodFound && !returnValueValid) {
oneFailed = true;
result.addErrorDetails(smh.getLocalString
("tests.componentNameConstructor",
"For [ {0} ]",
new Object[] {compName.toString()}));
result.addErrorDetails(smh.getLocalString
(getClass().getName() + ".debug1",
"For Home interface [ {0} ] Finder Method [ {1} ]",
new Object[] {homeInterfaceClass.getName(),ejbFinderMethods[j].getName()}));
result.addErrorDetails(smh.getLocalString
(getClass().getName() + ".failed",
"Error: A findByPrimaryKey method was found, but with invalid return type."));
}
// found findByPrimaryKey, so break out of loop
break;
}
}
if (!findByPrimaryKeyMethodFound) {
oneFailed = true;
result.addErrorDetails(smh.getLocalString
("tests.componentNameConstructor",
"For [ {0} ]",
new Object[] {compName.toString()}));
result.addErrorDetails(smh.getLocalString
(getClass().getName() + ".debug3",
"For Home interface [ {0} ] ",
new Object[] {homeInterfaceClass.getName()}));
result.addErrorDetails(smh.getLocalString
(getClass().getName() + ".failed1",
"Error: No findByPrimaryKey method was found in home interface class [ {0} ].",
new Object[] {homeInterfaceClass.getName()}));
}
return oneFailed;
} catch (ClassNotFoundException e) {
Verifier.debug(e);
result.addErrorDetails(smh.getLocalString
("tests.componentNameConstructor",
"For [ {0} ]",
new Object[] {compName.toString()}));
result.failed(smh.getLocalString
(getClass().getName() + ".failedException",
"Error: Home interface [ {0} ] does not exist or is not loadable.",
new Object[] {home}));
oneFailed = true;
return oneFailed;
}
|
|