use of org.glassfish.ejb.deployment.descriptor.EjbDescriptor in project Payara by payara.
the class CmpFields method runIndividualCmpFieldTest.
/**
* run an individual verifier test of a declated cmp field of the class
*
* @param entity the descriptor for the entity bean containing the cmp-field
* @param f the descriptor for the declared cmp field
* @param c the class owning the cmp field
* @parma r the result object to use to put the test results in
*
* @return true if the test passed
*/
protected boolean runIndividualCmpFieldTest(Descriptor entity, Descriptor persistentField, Class c, Result result) {
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
String cmpFieldName = persistentField.getName();
String getMethodName = "get" + Character.toUpperCase(cmpFieldName.charAt(0)) + cmpFieldName.substring(1);
Method getMethod = getMethod(c, getMethodName, null);
Class fieldType;
if (getMethod != null) {
boolean run = false;
// get the return type for the setMethod
fieldType = getMethod.getReturnType();
EjbBundleDescriptorImpl bundle = ((EjbDescriptor) entity).getEjbBundleDescriptor();
if (!RmiIIOPUtils.isValidRmiIDLPrimitiveType(fieldType) && !EjbUtils.isValidSerializableType(fieldType)) {
// it must be a reference to a bean's home or local interface
if (!isValidInterface(fieldType, bundle.getEjbs(), MethodDescriptor.EJB_REMOTE, result)) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error : Invalid type assigned for container managed field [ {0} ] in bean [ {1} ]", new Object[] { ((Descriptor) persistentField).getName(), entity.getName() }));
return false;
}
if (!isValidInterface(fieldType, bundle.getEjbs(), MethodDescriptor.EJB_LOCAL, result)) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error : Invalid type assigned for container managed field [ {0} ] in bean [ {1} ]", new Object[] { ((Descriptor) persistentField).getName(), entity.getName() }));
return false;
}
}
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "Valid type assigned for container managed field [ {0} ] in bean [ {1} ]", new Object[] { ((Descriptor) persistentField).getName(), entity.getName() }));
run = true;
return run;
} else {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CMPTest.isAccessorDeclared.failed2", "Error : Cannot find accessor [ {0} ] method for [ {1} ] field ", new Object[] { getMethodName, persistentField.getName() }));
}
return false;
}
use of org.glassfish.ejb.deployment.descriptor.EjbDescriptor in project Payara by payara.
the class CmrFields method isValidInterface.
private boolean isValidInterface(Class fieldType, Set<EjbDescriptor> entities) {
String component = "";
if (entities == null)
return false;
// only local interface can be a valid interface
Iterator<EjbDescriptor> iterator = entities.iterator();
while (iterator.hasNext()) {
EjbDescriptor entity = iterator.next();
if (fieldType.getName().equals(entity.getLocalClassName()))
return true;
}
return false;
}
use of org.glassfish.ejb.deployment.descriptor.EjbDescriptor in project Payara by payara.
the class EjbNameMethodElement method check.
/**
* The ejb-name element within the method element must be the name of one
* of the enterprise beans declared in the deployment descriptor.
*
* @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();
// get ejb's methods
// DOL doesn't save "ejb-name" element inside of method element
// so i can't seem to get at raw representation of XML data needed
// for this test,
// <ejb-name> within <method> element is the name of the ejb
// descriptor where you got the method descriptor from,
// so you can't trip negative assertion and test should always pass
// once plugged into new DOL, where access to raw XML is
// available, then this test can be properly modified,
// then i would use DOL similar to this:
// Set methods = descriptor.getMethodDescriptors();
// for (Iterator itr = methods.iterator(); itr.hasNext();) {
// MethodDescriptor methodDescriptor = (MethodDescriptor) itr.next();
boolean found = false;
for (Iterator itr2 = descriptor.getEjbBundleDescriptor().getEjbs().iterator(); itr2.hasNext(); ) {
EjbDescriptor ejbDescriptor = (EjbDescriptor) itr2.next();
logger.log(Level.FINE, getClass().getName() + ".debug1", new Object[] { ejbDescriptor.getName() });
// descriptor where you got the method descriptor from
if (descriptor.getName().equals(ejbDescriptor.getName())) {
found = true;
if (result.getStatus() != Result.FAILED) {
result.setStatus(Result.PASSED);
// for now, pass in details string via addGoodDetails
// until DOL raw data issue gets resolved
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "[ {0} ] is valid and contained within jar.", new Object[] { descriptor.getName() }));
}
}
}
if (!found) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: [ {0} ] is not the name of one of the EJB's within jar.", new Object[] { descriptor.getName() }));
// (methodDescriptor.getName() pending DOL update
}
// }
return result;
}
use of org.glassfish.ejb.deployment.descriptor.EjbDescriptor in project Payara by payara.
the class EjbRefTypeElement method check.
// Logger to log messages
/**
* The ejb-ref-type element must be one of the following:
* Entity
* Session
*
* @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();
boolean failed = false;
// Session
if (!descriptor.getEjbReferenceDescriptors().isEmpty()) {
for (Iterator itr = descriptor.getEjbReferenceDescriptors().iterator(); itr.hasNext(); ) {
EjbReferenceDescriptor nextEjbReference = (EjbReferenceDescriptor) itr.next();
// Need to use XPath, because if DOL sees an inconsistent
// ref-type, it gives a warning and changes the type
// String ejbRefTypeStr = nextEjbReference.getType();
String refStr = (nextEjbReference.isLocal()) ? "ejb-local-ref" : "ejb-ref";
String beanType = (descriptor.getType()).toLowerCase();
String xpathQuery = null;
if (getVerifierContext().getDocument().getDoctype() != null) {
xpathQuery = "/ejb-jar/enterprise-beans/" + beanType + "[ejb-name=\"" + descriptor.getName() + "\"]/" + refStr + "[ejb-ref-name=\"" + nextEjbReference.getName() + "\"]/ejb-ref-type";
} else {
String prefix = XpathPrefixResolver.fakeXPrefix;
xpathQuery = prefix + ":" + "ejb-jar/" + prefix + ":" + "enterprise-beans/" + prefix + ":" + beanType + "[" + prefix + ":ejb-name=\"" + descriptor.getName() + "\"]/" + prefix + ":" + refStr + "[" + prefix + ":ejb-ref-name=\"" + nextEjbReference.getName() + "\"]/" + prefix + ":" + "ejb-ref-type";
}
String ejbRefTypeStr = getXPathValueForNonRuntime(xpathQuery);
EjbDescriptor rdesc = (EjbDescriptor) nextEjbReference.getEjbDescriptor();
// XPath queries seem to fail for XSD Descriptors
if (ejbRefTypeStr == null) {
ejbRefTypeStr = nextEjbReference.getType();
}
if (!((ejbRefTypeStr.equals(EjbSessionDescriptor.TYPE)) || (ejbRefTypeStr.equals(EjbEntityDescriptor.TYPE)))) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: ejb-ref-type [ {0} ] within \n bean [ {1} ] is not valid. \n Must be [ {2} ] or [ {3} ]", new Object[] { ejbRefTypeStr, descriptor.getName(), EjbEntityDescriptor.TYPE, EjbSessionDescriptor.TYPE }));
failed = true;
} else if (rdesc != null) {
String actualRefType = rdesc.getType();
if (!ejbRefTypeStr.equals(actualRefType)) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed2", "Error: ejb-ref-type [ {0} ] was specifed for ejb-ref [ {1} ], within bean [ {2} ], when it should have been [ {3} ].", new Object[] { ejbRefTypeStr, nextEjbReference.getName(), descriptor.getName(), actualRefType }));
failed = true;
}
}
}
} else {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "There are no ejb references to other beans within this bean [ {0} ]", new Object[] { descriptor.getName() }));
return result;
}
if (failed) {
result.setStatus(Result.FAILED);
} else {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed", "All ejb-ref-type elements are valid. They are all [ {0} ] or [ {1} ] within this bean [ {2} ]", new Object[] { EjbEntityDescriptor.TYPE, EjbSessionDescriptor.TYPE, descriptor.getName() }));
}
return result;
}
use of org.glassfish.ejb.deployment.descriptor.EjbDescriptor in project Payara by payara.
the class BeanMethodCalculatorImpl method getTransactionalMethodsFor.
/**
* @return a collection of MethodDescriptor for all the methods of my
* ejb which are elligible to have a particular transaction setting.
*/
public Collection getTransactionalMethodsFor(com.sun.enterprise.deployment.EjbDescriptor desc, ClassLoader loader) throws ClassNotFoundException, NoSuchMethodException {
EjbDescriptor ejbDescriptor = (EjbDescriptor) desc;
// only set if desc is a stateful session bean. NOTE that
// !statefulSessionBean does not imply stateless session bean
boolean statefulSessionBean = false;
Vector methods = new Vector();
if (ejbDescriptor instanceof EjbSessionDescriptor) {
statefulSessionBean = ((EjbSessionDescriptor) ejbDescriptor).isStateful();
boolean singletonSessionBean = ((EjbSessionDescriptor) ejbDescriptor).isSingleton();
// Session Beans
if (ejbDescriptor.isRemoteInterfacesSupported()) {
Collection disallowedMethods = extractDisallowedMethodsFor(javax.ejb.EJBObject.class, sessionBeanMethodsDisallowed);
Collection potentials = getTransactionMethodsFor(loader, ejbDescriptor.getRemoteClassName(), disallowedMethods);
transformAndAdd(potentials, MethodDescriptor.EJB_REMOTE, methods);
}
if (ejbDescriptor.isRemoteBusinessInterfacesSupported()) {
for (String intfName : ejbDescriptor.getRemoteBusinessClassNames()) {
Class businessIntf = loader.loadClass(intfName);
Method[] busIntfMethods = businessIntf.getMethods();
for (Method next : busIntfMethods) {
methods.add(new MethodDescriptor(next, MethodDescriptor.EJB_REMOTE));
}
}
}
if (ejbDescriptor.isLocalInterfacesSupported()) {
Collection disallowedMethods = extractDisallowedMethodsFor(javax.ejb.EJBLocalObject.class, sessionLocalBeanMethodsDisallowed);
Collection potentials = getTransactionMethodsFor(loader, ejbDescriptor.getLocalClassName(), disallowedMethods);
transformAndAdd(potentials, MethodDescriptor.EJB_LOCAL, methods);
}
if (ejbDescriptor.isLocalBusinessInterfacesSupported()) {
for (String intfName : ejbDescriptor.getLocalBusinessClassNames()) {
Class businessIntf = loader.loadClass(intfName);
Method[] busIntfMethods = businessIntf.getMethods();
for (Method next : busIntfMethods) {
methods.add(new MethodDescriptor(next, MethodDescriptor.EJB_LOCAL));
}
}
}
if (ejbDescriptor.isLocalBean()) {
String intfName = ejbDescriptor.getEjbClassName();
Class businessIntf = loader.loadClass(intfName);
Method[] busIntfMethods = businessIntf.getMethods();
for (Method next : busIntfMethods) {
methods.add(new MethodDescriptor(next, MethodDescriptor.EJB_LOCAL));
}
}
if (ejbDescriptor.hasWebServiceEndpointInterface()) {
Class webServiceClass = loader.loadClass(ejbDescriptor.getWebServiceEndpointInterfaceName());
Method[] webMethods = webServiceClass.getMethods();
for (int i = 0; i < webMethods.length; i++) {
methods.add(new MethodDescriptor(webMethods[i], MethodDescriptor.EJB_WEB_SERVICE));
}
}
// SFSB and Singleton can have lifecycle callbacks transactional
if (statefulSessionBean || singletonSessionBean) {
Set<LifecycleCallbackDescriptor> lcds = ejbDescriptor.getLifecycleCallbackDescriptors();
for (LifecycleCallbackDescriptor lcd : lcds) {
try {
Method m = lcd.getLifecycleCallbackMethodObject(loader);
MethodDescriptor md = new MethodDescriptor(m, MethodDescriptor.LIFECYCLE_CALLBACK);
methods.add(md);
} catch (Exception e) {
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "Lifecycle callback processing error", e);
}
}
}
}
} else {
// entity beans local interfaces
String homeIntf = ejbDescriptor.getHomeClassName();
if (homeIntf != null) {
Class home = loader.loadClass(homeIntf);
Collection potentials = getTransactionMethodsFor(javax.ejb.EJBHome.class, home);
transformAndAdd(potentials, MethodDescriptor.EJB_HOME, methods);
String remoteIntf = ejbDescriptor.getRemoteClassName();
Class remote = loader.loadClass(remoteIntf);
potentials = getTransactionMethodsFor(javax.ejb.EJBObject.class, remote);
transformAndAdd(potentials, MethodDescriptor.EJB_REMOTE, methods);
}
// enity beans remote interfaces
String localHomeIntf = ejbDescriptor.getLocalHomeClassName();
if (localHomeIntf != null) {
Class home = loader.loadClass(localHomeIntf);
Collection potentials = getTransactionMethodsFor(javax.ejb.EJBLocalHome.class, home);
transformAndAdd(potentials, MethodDescriptor.EJB_LOCALHOME, methods);
String remoteIntf = ejbDescriptor.getLocalClassName();
Class remote = loader.loadClass(remoteIntf);
potentials = getTransactionMethodsFor(javax.ejb.EJBLocalObject.class, remote);
transformAndAdd(potentials, MethodDescriptor.EJB_LOCAL, methods);
}
}
if (!statefulSessionBean) {
if (ejbDescriptor.isTimedObject()) {
if (ejbDescriptor.getEjbTimeoutMethod() != null) {
methods.add(ejbDescriptor.getEjbTimeoutMethod());
}
for (ScheduledTimerDescriptor schd : ejbDescriptor.getScheduledTimerDescriptors()) {
methods.add(schd.getTimeoutMethod());
}
}
}
return methods;
}
Aggregations