use of org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor in project Payara by payara.
the class SingletonHandler method createEjbDescriptor.
/**
* Create a new EjbDescriptor for a given elementName and AnnotationInfo.
* @param elementName
* @param ainfo
* @return a new EjbDescriptor
*/
protected EjbDescriptor createEjbDescriptor(String elementName, AnnotationInfo ainfo) throws AnnotationProcessorException {
AnnotatedElement ae = ainfo.getAnnotatedElement();
Class ejbClass = (Class) ae;
EjbSessionDescriptor newDescriptor = new EjbSessionDescriptor();
newDescriptor.setName(elementName);
newDescriptor.setEjbClassName(ejbClass.getName());
newDescriptor.setSessionType(EjbSessionDescriptor.SINGLETON);
doSingletonSpecificProcessing(newDescriptor, ejbClass);
return newDescriptor;
}
use of org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor in project Payara by payara.
the class SingletonHandler method setEjbDescriptorInfo.
/**
* Set Annotation information to Descriptor.
* This method will also be invoked for an existing descriptor with
* annotation as user may not specific a complete xml.
* @param ejbDesc
* @param ainfo
* @return HandlerProcessingResult
*/
protected HandlerProcessingResult setEjbDescriptorInfo(EjbDescriptor ejbDesc, AnnotationInfo ainfo) throws AnnotationProcessorException {
EjbSessionDescriptor ejbSingletonDescriptor = (EjbSessionDescriptor) ejbDesc;
Class ejbClass = (Class) ainfo.getAnnotatedElement();
Singleton singleton = (Singleton) ainfo.getAnnotation();
// set session bean type in case it wasn't set in a sparse ejb-jar.xml.
if (!ejbSingletonDescriptor.isSessionTypeSet()) {
ejbSingletonDescriptor.setSessionType(EjbSessionDescriptor.SINGLETON);
}
doDescriptionProcessing(singleton.description(), ejbDesc);
doMappedNameProcessing(singleton.mappedName(), ejbDesc);
doSingletonSpecificProcessing(ejbSingletonDescriptor, ejbClass);
return setBusinessAndHomeInterfaces(ejbDesc, ainfo);
}
use of org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor in project Payara by payara.
the class StatefulHandler method createEjbDescriptor.
/**
* Create a new EjbDescriptor for a given elementName and AnnotationInfo.
* @param elementName
* @param ainfo
* @return a new EjbDescriptor
*/
protected EjbDescriptor createEjbDescriptor(String elementName, AnnotationInfo ainfo) throws AnnotationProcessorException {
AnnotatedElement ae = ainfo.getAnnotatedElement();
Class ejbClass = (Class) ae;
EjbSessionDescriptor newDescriptor = new EjbSessionDescriptor();
newDescriptor.setName(elementName);
newDescriptor.setEjbClassName(ejbClass.getName());
newDescriptor.setSessionType(EjbSessionDescriptor.STATEFUL);
return newDescriptor;
}
use of org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor in project Payara by payara.
the class TransactionAttributeHandler method processAnnotation.
protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, EjbContext[] ejbContexts) throws AnnotationProcessorException {
TransactionAttribute taAn = (TransactionAttribute) ainfo.getAnnotation();
for (EjbContext ejbContext : ejbContexts) {
EjbDescriptor ejbDesc = (EjbDescriptor) ejbContext.getDescriptor();
ContainerTransaction containerTransaction = getContainerTransaction(taAn.value());
if (ElementType.TYPE.equals(ainfo.getElementType())) {
ejbContext.addPostProcessInfo(ainfo, this);
} else {
Method annMethod = (Method) ainfo.getAnnotatedElement();
Set txBusMethods = ejbDesc.getTxBusinessMethodDescriptors();
for (Object next : txBusMethods) {
MethodDescriptor nextDesc = (MethodDescriptor) next;
Method m = nextDesc.getMethod(ejbDesc);
if (TypeUtil.sameMethodSignature(m, annMethod) && ejbDesc.getContainerTransactionFor(nextDesc) == null) {
// override by xml
ejbDesc.setContainerTransactionFor(nextDesc, containerTransaction);
}
}
if (ejbDesc instanceof EjbSessionDescriptor) {
EjbSessionDescriptor sd = (EjbSessionDescriptor) ejbDesc;
if (sd.isStateful() || sd.isSingleton()) {
ClassLoader loader = ejbDesc.getEjbBundleDescriptor().getClassLoader();
Set<LifecycleCallbackDescriptor> lcds = ejbDesc.getLifecycleCallbackDescriptors();
for (LifecycleCallbackDescriptor lcd : lcds) {
if (lcd.getLifecycleCallbackClass().equals(ejbDesc.getEjbClassName()) && lcd.getLifecycleCallbackMethod().equals(annMethod.getName())) {
try {
Method m = lcd.getLifecycleCallbackMethodObject(loader);
MethodDescriptor md = new MethodDescriptor(m, MethodDescriptor.LIFECYCLE_CALLBACK);
if (TypeUtil.sameMethodSignature(m, annMethod) && ejbDesc.getContainerTransactionFor(md) == null) {
// stateful lifecycle callback txn attr type EJB spec
if (sd.isStateful() && containerTransaction != null) {
String txAttr = containerTransaction.getTransactionAttribute();
if (txAttr != null && !txAttr.equals(ContainerTransaction.REQUIRES_NEW) && !txAttr.equals(ContainerTransaction.NOT_SUPPORTED)) {
logger.log(Level.WARNING, localStrings.getLocalString("enterprise.deployment.annotation.handlers.sfsblifecycletxnattrtypewarn", "Stateful session bean {0} lifecycle callback method {1} has transaction " + "attribute {2} with container-managed transaction demarcation. " + "The transaction attribute should be either REQUIRES_NEW or NOT_SUPPORTED", new Object[] { (sd.getName() == null ? "" : sd.getName()), m.getName(), txAttr }));
}
}
// override by xml
ejbDesc.setContainerTransactionFor(md, containerTransaction);
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, "Found matching callback method {0}<>{1} : {2}", new Object[] { ejbDesc.getEjbClassName(), md, containerTransaction });
}
}
} catch (Exception e) {
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, "Transaction attribute for a lifecycle callback annotation processing error", e);
}
}
}
}
}
}
}
}
return getDefaultProcessedResult();
}
use of org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor in project Payara by payara.
the class HomeInterfaceCreateMethodExceptionRemote method check.
/**
* Session beans home interface create method throws RemoteException test.
*
* The following are the requirements for the enterprise Bean's home interface
* signature:
*
* An Session Bean's home interface defines zero or more create(...) methods.
*
* The throws clause must include java.rmi.RemoteException.
*
* @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) {
boolean oneFailed = false;
boolean foundAtLeastOneRemote = false;
// methods which must throw java.rmi.RemoteException
if (descriptor.getHomeClassName() == null || "".equals(descriptor.getHomeClassName())) {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addNaDetails(smh.getLocalString(getClass().getName() + ".notApplicable1", "No Remote Home Interface for this ejb", new Object[] {}));
return result;
}
try {
VerifierTestContext context = getVerifierContext();
ClassLoader jcl = context.getClassLoader();
Class c = Class.forName(descriptor.getHomeClassName(), false, getVerifierContext().getClassLoader());
Method[] methods = c.getDeclaredMethods();
Class[] methodExceptionTypes;
boolean throwsRemoteException = false;
for (int i = 0; i < methods.length; i++) {
// clear these from last time thru loop
throwsRemoteException = false;
if (methods[i].getName().startsWith("create")) {
// is failed
if (!foundAtLeastOneRemote) {
foundAtLeastOneRemote = true;
}
methodExceptionTypes = methods[i].getExceptionTypes();
// methods must also throw java.rmi.RemoteException
if (EjbUtils.isValidRemoteException(methodExceptionTypes)) {
throwsRemoteException = true;
}
// method
if (throwsRemoteException) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".debug1", "For Home Interface [ {0} ] Method [ {1} ]", new Object[] { c.getName(), methods[i].getName() }));
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "The create method which must throw java.rmi.RemoteException was found."));
} else if (!throwsRemoteException) {
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} ] Method [ {1} ]", new Object[] { c.getName(), methods[i].getName() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: A create method was found, but did not throw java.rmi.RemoteException."));
}
// end of reporting for this particular 'create' method
}
// if the home interface found a "create" method
}
// for all the methods within the home interface class, loop
} 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 within bean [ {1} ]", new Object[] { descriptor.getHomeClassName(), descriptor.getName() }));
}
if (!foundAtLeastOneRemote) {
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[] { descriptor.getHomeClassName() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed1", "No create method was found in [ {0} ]", new Object[] { descriptor.getHomeClassName() }));
result.setStatus(result.FAILED);
} else {
if (oneFailed) {
result.setStatus(result.FAILED);
} else {
result.setStatus(result.PASSED);
}
}
return result;
} else {
result.addErrorDetails(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(), "Session", "Entity" }));
return result;
}
}
Aggregations