HomeInterfaceFindByPrimaryKeyArgpublic class HomeInterfaceFindByPrimaryKeyArg extends com.sun.enterprise.tools.verifier.tests.ejb.EjbTest implements com.sun.enterprise.tools.verifier.tests.ejb.EjbCheckDefine findByPrimaryKey method parameter test.
Every entity enterprise home interface must define the findByPrimaryKey
method. The method must declare the primary key class as the method
argument. |
Fields Summary |
---|
Result | result | ComponentNameConstructor | compName |
Methods Summary |
---|
public Result | check(com.sun.enterprise.deployment.EjbDescriptor descriptor)Define findByPrimaryKey method parameter test.
Every entity enterprise home interface must define the findByPrimaryKey
method. The method must declare the primary key class as the method
argument.
result = getInitializedResult();
compName = getVerifierContext().getComponentNameConstructor();
boolean oneFailed = false;
if (descriptor instanceof EjbEntityDescriptor) {
if(descriptor.getHomeClassName() != null && !"".equals(descriptor.getHomeClassName()))
oneFailed = commonToBothInterfaces(descriptor.getHomeClassName(),descriptor);
if(oneFailed == false) {
if(descriptor.getLocalHomeClassName() != null && !"".equals(descriptor.getLocalHomeClassName()))
oneFailed = commonToBothInterfaces(descriptor.getLocalHomeClassName(),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, 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.
Class [] ejbFinderMethodParameterTypes;
boolean findByPrimaryKeyMethodFound = false;
boolean foundOne = false;
boolean oneFailed = false;
boolean paramValid = false;
boolean onlyOneParam = 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();
String primaryKeyType = ((EjbEntityDescriptor)descriptor).getPrimaryKeyClassName();
for (int j = 0; j < ejbFinderMethods.length; ++j) {
// reset all booleans for next method within the loop
paramValid = false;
onlyOneParam = false;
findByPrimaryKeyMethodFound = false;
if (ejbFinderMethods[j].getName().equals("findByPrimaryKey")) {
// Every entity enterprise Bean class must define the
// findByPrimaryKey method. The result type for this method must
// be the primary key type (i.e. the findByPrimaryKey method
// must be a single-object finder).
findByPrimaryKeyMethodFound = true;
ejbFinderMethodParameterTypes = ejbFinderMethods[j].getParameterTypes();
if (ejbFinderMethodParameterTypes.length == 1) {
onlyOneParam = true;
for (int k = 0; k < ejbFinderMethodParameterTypes.length; ++k) {
if (ejbFinderMethodParameterTypes[k].getName().equals(primaryKeyType)) {
paramValid = true;
break;
}
}
} else {
// should already be set...
onlyOneParam = false;
paramValid = false;
}
// report for this particular findByPrimaryKey(...)
if (findByPrimaryKeyMethodFound && paramValid) {
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 with valid parameter type was found."));
foundOne = true;
break;
} else if (findByPrimaryKeyMethodFound && onlyOneParam && !paramValid) {
result.addNaDetails(smh.getLocalString
("tests.componentNameConstructor",
"For [ {0} ]",
new Object[] {compName.toString()}));
result.addNaDetails(smh.getLocalString
(getClass().getName() + ".debug1",
"For home interface [ {0} ] Finder Method [ {1} ]",
new Object[] {homeInterfaceClass.getName(),ejbFinderMethods[j].getName()}));
result.addNaDetails(smh.getLocalString
(getClass().getName() + ".notApplicable2",
"A findByPrimaryKey method was found, but with non-PrimaryKeyClass arg parameter type."));
} else if (findByPrimaryKeyMethodFound && !onlyOneParam) {
result.addNaDetails(smh.getLocalString
("tests.componentNameConstructor",
"For [ {0} ]",
new Object[] {compName.toString()}));
result.addNaDetails(smh.getLocalString
(getClass().getName() + ".debug1",
"For home interface [ {0} ] Finder Method [ {1} ]",
new Object[] {homeInterfaceClass.getName(),ejbFinderMethods[j].getName()}));
result.addNaDetails(smh.getLocalString
(getClass().getName() + ".notApplicable1",
"A findByPrimaryKey method was found, but with non-single arg parameters."));
}
}
}
if (!foundOne) {
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() + ".failed",
"Error: No single arg findByPrimaryKey(PrimaryKeyClass) 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}));
return oneFailed;
}
|
|