use of org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor in project Payara by payara.
the class InterfacePublic method check.
/**
* Declare local and remote interfaces as public interfaces test.
* All enterprise bean local and/or interfaces must be declared as public.
*
* @param descriptor the Enterprise Java Bean deployment descriptor
*
* @return <code>Result</code> the results for this assertion
*/
public Result check(EjbDescriptor descriptor) {
Result result = getInitializedResult();
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
if (!(descriptor instanceof EjbSessionDescriptor) && !(descriptor instanceof EjbEntityDescriptor)) {
addNaDetails(result, compName);
result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.homeintf.HomeMethodTest.notApplicable1", "Test apply only to session or entity beans."));
return result;
}
String assertionClass = "com.sun.enterprise.tools.verifier.tests.ejb.intf.InterfacePublic";
for (String intfName : getInterfaceNames(descriptor)) {
try {
ClassLoader jcl = getVerifierContext().getClassLoader();
Class c = Class.forName(intfName, false, jcl);
// local and remote interface must be defined as public
if (!Modifier.isPublic(c.getModifiers())) {
addErrorDetails(result, compName);
result.failed(smh.getLocalString(assertionClass + ".failed", "Error: [ {0} ] is not defined as a public interface.", new Object[] { intfName }));
}
} catch (ClassNotFoundException e) {
// ignore as it will be caught in EjbArchiveClassesLoadable
logger.log(Level.FINER, e.getMessage(), e);
}
}
if (result.getStatus() != Result.FAILED) {
addGoodDetails(result, compName);
result.passed(smh.getLocalString(assertionClass + ".passed", "Valid public interface(s)."));
}
return result;
}
use of org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor in project Payara by payara.
the class ASEjbIsReadOnlyBean method testROBSpecific.
public void testROBSpecific(EjbDescriptor descriptor, IASEjbExtraDescriptors iasEjbExtraDesc, Result result) {
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
try {
// Read only Beans can only be Entity Beans
if (descriptor instanceof EjbEntityDescriptor) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed1", "PASSED [AS-EJB ejb] : Read Only Beans can only be Entity Beans"));
} else if (descriptor instanceof EjbSessionDescriptor) {
oneFailed = true;
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed1", "FAILED [AS-EJB ejb] : Read Only Beans cannot be Session Beans. They can only be Entity Beans"));
return;
} else if (descriptor instanceof EjbMessageBeanDescriptor) {
oneFailed = true;
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed2", "FAILED [AS-EJB ejb] : Read Only Beans cannot be Message Driven Beans. They can only be Entity Beans"));
return;
}
// Only Container Managed Transactions are Allowed
String txnType = descriptor.getTransactionType();
if (txnType.equals(descriptor.CONTAINER_TRANSACTION_TYPE)) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed2", "PASSED [AS-EJB ejb] : Read Only Beans can only have Container Managed Transactions"));
} else {
oneFailed = true;
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed3", "FAILED [AS-EJB ejb] : Read Only Beans cannot have Bean Managed Transactions"));
}
// Encourage not to have create/remove methods in Home Interface
String homeName = descriptor.getHomeClassName();
Class homeClass = null;
boolean foundCreateMethod = false;
boolean foundRemoveMethod = false;
homeClass = getVerifierContext().getClassLoader().loadClass(homeName);
Method[] methods = homeClass.getDeclaredMethods();
for (int i = 0; i < methods.length; i++) {
if (methods[i].getName().startsWith("create")) {
foundCreateMethod = true;
break;
}
}
for (int i = 0; i < methods.length; i++) {
if (methods[i].getName().startsWith("remove")) {
foundRemoveMethod = true;
break;
}
}
if (foundCreateMethod) {
oneWarning = true;
result.addWarningDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addWarningDetails(smh.getLocalString(getClass().getName() + ".warning", "WARNING [AS-EJB ejb] : Home interface [ {0} ] should have zero create Methods for Read Only Beans.", new Object[] { homeName }));
} else {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed3", "PASSED [AS-EJB ejb] : Read Only Bean has zero create Methods"));
}
if (foundRemoveMethod) {
oneWarning = true;
result.addWarningDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addWarningDetails(smh.getLocalString(getClass().getName() + ".warning1", "WARNING [AS-EJB ejb] : Home interface [ {0} ] should have zero remove Methods for Read Only Beans.", new Object[] { homeName }));
} else {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed4", "PASSED [AS-EJB ejb] : Read Only Bean has zero remove Methods"));
}
// Refresh Period Test
int refreshPeriod = iasEjbExtraDesc.getRefreshPeriodInSeconds();
if (refreshPeriod != -1) {
long refValue = new Integer(refreshPeriod).longValue();
if (refValue < 0 || refValue > Long.MAX_VALUE) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed4", "FAILED [AS-EJB ejb] : refresh-period-in-seconds is invalid. It should be between 0 and {0}.", new Object[] { new Long(Long.MAX_VALUE) }));
} else {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed5", "PASSED [AS-EJB ejb] : refresh-period-in-seconds is {0}", new Object[] { new Long(refValue) }));
}
} else {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "NOT APPLICABLE [AS-EJB ejb] refresh-period-in-seconds Element not defined"));
}
if (oneFailed)
result.setStatus(Result.FAILED);
} catch (ClassNotFoundException cnfe) {
oneFailed = true;
} catch (RuntimeException ex) {
oneFailed = true;
}
if (oneFailed) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".notRun", "NOT RUN [AS-EJB] : Could not create a descriptor object"));
}
}
use of org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor in project Payara by payara.
the class ASEjbRefreshPeriod method check.
public Result check(EjbDescriptor descriptor) {
Result result = getInitializedResult();
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
boolean oneWarning = false;
boolean oneFailed = false;
boolean isReadOnly = false;
String refreshPeriod = null;
try {
String s1 = ("/sun-ejb-jar/enterprise-beans/ejb[ejb-name=\"" + descriptor.getName() + "\"]/refresh-period-in-seconds");
refreshPeriod = getXPathValue(s1);
IASEjbExtraDescriptors iasEjbExtraDesc = descriptor.getIASEjbExtraDescriptors();
isReadOnly = iasEjbExtraDesc.isIsReadOnlyBean();
if (refreshPeriod != null) {
refreshPeriod = refreshPeriod.trim();
if (refreshPeriod.length() == 0) {
oneFailed = true;
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed", "FAILED [AS-EJB ejb] : refresh-period-in-seconds is invalid. It should be between 0 and " + Integer.MAX_VALUE));
} else {
if (!(descriptor instanceof EjbEntityDescriptor && isReadOnly)) {
oneWarning = true;
result.addWarningDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.warning(smh.getLocalString(getClass().getName() + ".warning", "WARNING [AS-EJB ejb] : refresh-period-in-seconds should be defined for Read Only Beans."));
return result;
}
try {
int refValue = Integer.parseInt(refreshPeriod);
if (refValue < 0 || refValue > Integer.MAX_VALUE) {
oneFailed = true;
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed1", "FAILED [AS-EJB ejb] : refresh-period-in-seconds cannot be greater than " + Integer.MAX_VALUE + " or less than 0"));
} else
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed", "PASSED [AS-EJB ejb] : refresh-period-in-seconds is {0}", new Object[] { new Integer(refValue) }));
} catch (NumberFormatException nfex) {
oneFailed = true;
Verifier.debug(nfex);
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed", "FAILED [AS-EJB ejb] : refresh-period-in-seconds is invalid. It should be between 0 and " + Integer.MAX_VALUE));
}
}
} else {
if ((descriptor instanceof EjbEntityDescriptor) && (isReadOnly)) {
oneWarning = true;
result.addWarningDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.warning(smh.getLocalString(getClass().getName() + ".warning", "WARNING [AS-EJB ejb] : refresh-period-in-seconds should be defined for Read Only Beans"));
} else {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "NOT APPLICABLE [AS-EJB ejb] : refresh-period-in-seconds is not defined"));
}
}
if (oneWarning)
result.setStatus(Result.WARNING);
if (oneFailed)
result.setStatus(Result.FAILED);
} catch (Exception ex) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".notRun", "NOT RUN [AS-EJB cmp] Could not create descriptor Object."));
}
return result;
}
use of org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor in project Payara by payara.
the class ASEjbBeanCache method check.
public Result check(EjbDescriptor descriptor) {
Result result = getInitializedResult();
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
String beanCache = null;
try {
beanCache = getXPathValue("/sun-ejb-jar/enterprise-beans/ejb[ejb-name=\"" + descriptor.getName() + "\"]/bean-cache");
if (beanCache != null) {
if (descriptor instanceof EjbEntityDescriptor || (descriptor instanceof EjbSessionDescriptor && ((EjbSessionDescriptor) descriptor).getSessionType().equals(EjbSessionDescriptor.STATEFUL))) {
addGoodDetails(result, compName);
result.passed(smh.getLocalString(getClass().getName() + ".passed", "PASSED [AS-EJB ejb] : bean-cache Element parsed"));
} else {
addWarningDetails(result, compName);
result.warning(smh.getLocalString(getClass().getName() + ".warning1", "WARNING [AS-EJB ejb] : bean-cache should be defined only for Stateful Session and Entity Beans"));
}
} else {
addNaDetails(result, compName);
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "NOT APPLICABLE [AS-EJB ejb] : bean-cache element not defined"));
}
} catch (Exception ex) {
addErrorDetails(result, compName);
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".notRun", "NOT RUN [AS-EJB] : Could not get a beanCache object"));
}
return result;
}
use of org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor in project Payara by payara.
the class ASEjbBeanPool method check.
public Result check(EjbDescriptor descriptor) {
Result result = getInitializedResult();
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
IASEjbExtraDescriptors ejbJar = descriptor.getIASEjbExtraDescriptors();
if (ejbJar != null) {
try {
beanPool = ejbJar.getBeanPool();
if (beanPool != null) {
if (descriptor instanceof EjbSessionDescriptor && ((EjbSessionDescriptor) descriptor).getSessionType().equals(EjbSessionDescriptor.STATEFUL)) {
result.addWarningDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.warning(smh.getLocalString(getClass().getName() + ".warning", "WARNING [AS-EJB ejb] : bean-pool should be defined for Stateless Session Beans, Entity Beans or Message Driven Beans"));
} else if (descriptor instanceof EjbMessageBeanDescriptor || (descriptor instanceof EjbSessionDescriptor && ((EjbSessionDescriptor) descriptor).getSessionType().equals(EjbSessionDescriptor.STATELESS)) || descriptor instanceof EjbEntityDescriptor) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed", "PASSED [AS-EJB ejb] : bean-pool is correctly defined"));
}
} else {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "NOT APPLICABLE [AS-EJB ejb] : bean-pool element not defined"));
}
return result;
} catch (Exception ex) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".notRun", "NOT RUN [AS-EJB] : Could not create a beanPool object"));
}
} else {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".notRun", "NOT RUN [AS-EJB] : Could not create an IASEjbExtraDescriptor object"));
}
return result;
}
Aggregations