use of org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor in project Payara by payara.
the class EjbBeanType method check.
/**
* Bean Type Test.
* The bean provider must use the appropriate session or entity element
* to declare the bean type.
*
* @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)) {
try {
Class c = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
boolean validBean = false;
// walk up the class tree (bug #4243606)
do {
Class[] interfaces = c.getInterfaces();
for (int i = 0; i < interfaces.length; i++) {
logger.log(Level.FINE, getClass().getName() + ".debug1", new Object[] { interfaces[i].getName() });
if (interfaces[i].getName().equals("javax.ejb.EntityBean") && (descriptor instanceof EjbEntityDescriptor)) {
validBean = true;
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed", "[ {0} ] properly implements the {1}Bean interface.", new Object[] { descriptor.getEjbClassName(), "Entity" }));
break;
} else if (interfaces[i].getName().equals("javax.ejb.SessionBean") && descriptor instanceof EjbSessionDescriptor) {
validBean = true;
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed", "[ {0} ] properly implements the {1}Bean interface.", new Object[] { descriptor.getEjbClassName(), "Session" }));
break;
}
}
} while ((((c = c.getSuperclass()) != null) && (!validBean)));
if (!validBean) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: [ {0} ] is not a valid bean. The bean provider must use the appropriate {1} or {2} element to declare the bean type.", new Object[] { descriptor.getEjbClassName(), "session", "entity" }));
}
} 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: [ {0} ] class not found.", new Object[] { descriptor.getEjbClassName() }));
}
return result;
} else {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "[ {0} ] not called with a Session or Entity Bean.", new Object[] { getClass() }));
return result;
}
}
use of org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor in project Payara by payara.
the class TransactionDemarcationBeanManaged method check.
/**
* Session/Entity Bean bean-managed transaction demarcation type test.
* The Application Assembler must not define transaction attributes for an
* enterprise bean with bean-managed transaction demarcation.
*
* @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();
// <ejb-class>verifier.ejb.hello.BogusEJB...
try {
// enterprise bean with bean-managed transaction demarcation.
if ((descriptor instanceof EjbSessionDescriptor) || (descriptor instanceof EjbEntityDescriptor)) {
String transactionType = descriptor.getTransactionType();
if (EjbDescriptor.BEAN_TRANSACTION_TYPE.equals(transactionType)) {
ContainerTransaction containerTransaction = null;
if (!descriptor.getMethodContainerTransactions().isEmpty()) {
for (Enumeration ee = descriptor.getMethodContainerTransactions().keys(); ee.hasMoreElements(); ) {
MethodDescriptor methodDescriptor = (MethodDescriptor) ee.nextElement();
containerTransaction = (ContainerTransaction) descriptor.getMethodContainerTransactions().get(methodDescriptor);
try {
String transactionAttribute = containerTransaction.getTransactionAttribute();
// don't need this check here
if (ContainerTransaction.NOT_SUPPORTED.equals(transactionAttribute) || ContainerTransaction.SUPPORTS.equals(transactionAttribute) || ContainerTransaction.REQUIRED.equals(transactionAttribute) || ContainerTransaction.REQUIRES_NEW.equals(transactionAttribute) || ContainerTransaction.MANDATORY.equals(transactionAttribute) || ContainerTransaction.NEVER.equals(transactionAttribute) || (!transactionAttribute.equals(""))) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: TransactionAttribute [ {0} ] for method [ {1} ] is not valid. The Application Assembler must not define transaction attributes for an enterprise bean [ {2} ] with bean-managed transaction demarcation.", new Object[] { transactionAttribute, methodDescriptor.getName(), descriptor.getName() }));
} else {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed", "Valid: TransactionAttribute [ {0} ] for method [ {1} ] is not defined for an enterprise bean [ {2} ] with bean-managed transaction demarcation.", new Object[] { transactionAttribute, methodDescriptor.getName(), descriptor.getName() }));
}
} catch (NullPointerException e) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed1", "Valid: TransactionAttribute is null for method [ {0} ] in bean [ {1} ]", new Object[] { methodDescriptor.getName(), descriptor.getName() }));
return result;
}
}
} else {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed2", "Valid: There are no method permissions within this bean [ {0} ]", new Object[] { descriptor.getName() }));
}
return result;
} else {
// not container managed, but is a session/entity bean
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable2", "Bean [ {0} ] is not [ {1} ] managed, it is [ {2} ] managed.", new Object[] { descriptor.getName(), EjbDescriptor.BEAN_TRANSACTION_TYPE, transactionType }));
}
return result;
} else {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "[ {0} ] not called \n with a Session or Entity bean.", new Object[] { getClass() }));
return result;
}
} catch (Throwable t) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: [ {0} ] does not contain class [ {1} ] within bean [ {2} ]", new Object[] { descriptor.getName(), t.getMessage(), descriptor.getName() }));
return result;
}
}
use of org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor in project Payara by payara.
the class EjbClassModifiersAbstract method check.
/**
* Enterprise Java Bean class modifiers test. The class must not be defined
* as abstract.
*
* @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();
boolean shouldBeAbstract = false;
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
if (descriptor instanceof EjbEntityDescriptor) {
String persistentType = ((EjbEntityDescriptor) descriptor).getPersistenceType();
if (EjbEntityDescriptor.CONTAINER_PERSISTENCE.equals(persistentType)) {
if (EjbCMPEntityDescriptor.CMP_1_1 != ((EjbCMPEntityDescriptor) descriptor).getCMPVersion()) {
shouldBeAbstract = true;
}
}
}
Class c = loadEjbClass(descriptor, result);
if (c != null) {
boolean isAbstract = false;
int modifiers = c.getModifiers();
if (Modifier.isAbstract(modifiers)) {
isAbstract = true;
}
if (!isAbstract && !shouldBeAbstract) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed", "[ {0} ] properly declares non-abstract class modifier.", new Object[] { descriptor.getEjbClassName() }));
}
if (isAbstract && shouldBeAbstract) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed2", "[ {0} ] properly declares abstract class modifier.", new Object[] { descriptor.getEjbClassName() }));
}
if (isAbstract && !shouldBeAbstract) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: Ejb Class [ {0} ] was found, but was declared as abstract. The class [ {1} ] must not be abstract.", new Object[] { descriptor.getEjbClassName(), descriptor.getEjbClassName() }));
}
if (!isAbstract && shouldBeAbstract) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed2", "Error: CMP 2.0 Entity Bean Class [ {0} ] was found, but was declared as non abstract. The class [ {1} ] must be abstract.", new Object[] { descriptor.getEjbClassName(), descriptor.getEjbClassName() }));
}
}
return result;
}
use of org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor in project Payara by payara.
the class ContainerTransactionMethodExists method check.
/**
* @param descriptor the Enterprise Java Bean deployment descriptor
* @return <code>Result</code> the results for this assertion
*/
public Result check(EjbDescriptor descriptor) {
result = getInitializedResult();
compName = getVerifierContext().getComponentNameConstructor();
if ((descriptor instanceof EjbSessionDescriptor) || (descriptor instanceof EjbEntityDescriptor)) {
Map<MethodDescriptor, ContainerTransaction> transactionalMethods = descriptor.getMethodContainerTransactions();
if (transactionalMethods != null) {
for (MethodDescriptor methodDescriptor : transactionalMethods.keySet()) checkMethodStyles(methodDescriptor, descriptor);
}
}
if (result.getStatus() != Result.FAILED) {
addGoodDetails(result, compName);
result.passed(smh.getLocalString(getClass().getName() + ".passed", "Valid container transaction method(s) found."));
}
return result;
}
use of org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor in project Payara by payara.
the class EjbReferencesElement method check.
// Logger to log messages
/**
* The Bean Provider must declare all enterprise bean's references to the homes
* of other enterprise beans as specified in section 14.3.2 of the Moscone spec.
* Check for one within the same jar file, can't check outside of jar file.
* Load/locate & check other bean's home/remote/bean, ensure they match with
* what the linking bean says they should be; check for pair of referencing and
* referenced beans exist.
*
* @param descriptor the Enterprise Java Bean deployment descriptor
*
* @return <code>Result</code> the results for this assertion
*/
public Result check(EjbDescriptor descriptor) {
result = getInitializedResult();
compName = getVerifierContext().getComponentNameConstructor();
if ((descriptor instanceof EjbEntityDescriptor) || (descriptor instanceof EjbSessionDescriptor)) {
// RULE: References to other beans must be declared in the form of
// references to other beans homes as specified in section
// 14.3.2 of the Moscone spec.
// check for one bean within the same jar file; can't check outside of
// jar file. need to load/locate and check other beans remote, home, bean
// match with the linking bean says they should be. i.e. check for pair
// of referencing & referenced bean exist, using reflection API
EjbReferenceDescriptor ejbReference;
// EjbAbstractDescriptor ejbDescriptor;
try {
String fName = null;
Set references = descriptor.getEjbReferenceDescriptors();
if (references == null) {
logger.log(Level.INFO, getClass().getName() + ".refnull");
return result;
}
Iterator iterator = references.iterator();
if (iterator.hasNext()) {
boolean oneFailed = false;
// boolean foundBeanClassName = false;
// boolean foundHomeClassName = false;
// boolean foundRemoteClassName = false;
// File fileName = Verifier.getArchiveFile(descriptor.getEjbBundleDescriptor().getModuleDescriptor().getArchiveUri());
// if (fileName!=null){
// fName = fileName.getName();
// }else{
fName = descriptor.getEjbBundleDescriptor().getModuleDescriptor().getArchiveUri();
// }
while (iterator.hasNext()) {
ejbReference = (EjbReferenceDescriptor) iterator.next();
if (ejbReference.isLinked()) {
// reset
if (ejbReference.getEjbHomeInterface() != null && ejbReference.getEjbInterface() != null) {
oneFailed = commonToBothInterfaces(ejbReference.getEjbHomeInterface(), ejbReference.getEjbInterface(), fName);
}
} else {
// (e.g. external references)
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable2", "Not Applicable: [ {0} ] must be external reference to bean outside of [ {1} ].", new Object[] { ejbReference.getName(), fName }));
}
}
if (oneFailed) {
result.setStatus(result.FAILED);
} else {
result.setStatus(result.PASSED);
}
} else {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "There are no ejb references to other beans within this bean [ {0} ]", new Object[] { descriptor.getName() }));
}
return result;
} catch (Exception e) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failedRef", "Exception occurred : [ {0} ]", new Object[] { e.getMessage() }));
return result;
}
} else {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "[ {0} ] not called \n with a Session or Entity bean.", new Object[] { getClass() }));
return result;
}
}
Aggregations