use of org.glassfish.apf.AnnotationProcessorException in project Payara by payara.
the class AsynchronousHandler method setAsynchronous.
/**
* Designate a method as asynchronous in the deployment descriptor
* @param methodIntf null if processed on bean class / superclass. Otherwise,
* set to the remote/local client view of the associated interface
* @throws AnnotationProcessorException
*/
private void setAsynchronous(Method m0, EjbDescriptor ejbDesc, String methodIntf) throws AnnotationProcessorException {
if (!ejbDesc.getType().equals(EjbSessionDescriptor.TYPE)) {
throw new AnnotationProcessorException("Invalid asynchronous method " + m0 + "@Asynchronous is only permitted for session beans");
}
EjbSessionDescriptor sessionDesc = (EjbSessionDescriptor) ejbDesc;
MethodDescriptor methodDesc = (methodIntf == null) ? new MethodDescriptor(m0) : new MethodDescriptor(m0, methodIntf);
if (logger.isLoggable(Level.FINE)) {
logger.fine("Adding asynchronous method " + methodDesc);
}
// There is no way to "turn off" the asynchronous designation in the
// deployment descriptor, so we don't need to do any override checks
// here. Just always add any async methods.
sessionDesc.addAsynchronousMethod(methodDesc);
}
use of org.glassfish.apf.AnnotationProcessorException in project Payara by payara.
the class ConcurrencyManagementHandler method processAnnotation.
protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, EjbContext[] ejbContexts) throws AnnotationProcessorException {
ConcurrencyManagement cmAn = (ConcurrencyManagement) ainfo.getAnnotation();
ConcurrencyManagementType cmType = cmAn.value();
for (EjbContext ejbContext : ejbContexts) {
EjbDescriptor ejbDesc = ejbContext.getDescriptor();
if (ejbDesc instanceof EjbSessionDescriptor) {
EjbSessionDescriptor.ConcurrencyManagementType descCMType;
switch(cmType) {
case CONTAINER:
descCMType = EjbSessionDescriptor.ConcurrencyManagementType.Container;
break;
case BEAN:
descCMType = EjbSessionDescriptor.ConcurrencyManagementType.Bean;
break;
default:
throw new AnnotationProcessorException("Unsupported concurrency management " + "type = " + cmType);
}
EjbSessionDescriptor sDesc = (EjbSessionDescriptor) ejbDesc;
// Set value on descriptor unless it has been set by .xml
sDesc.setConcurrencyManagementTypeIfNotSet(descCMType);
}
}
return getDefaultProcessedResult();
}
use of org.glassfish.apf.AnnotationProcessorException in project Payara by payara.
the class EJBHandler method processEJB.
/**
* Process a particular annotation whose type is the same as the
* one returned by @see getAnnotationType(). All information
* pertinent to the annotation and its context is encapsulated
* in the passed AnnotationInfo instance.
*
* @param ainfo the annotation information
* @param rcContexts an array of ResourceContainerContext
* @param ejbAn
* @return HandlerProcessingResult
*/
protected HandlerProcessingResult processEJB(AnnotationInfo ainfo, ResourceContainerContext[] rcContexts, EJB ejbAn) throws AnnotationProcessorException {
EjbReferenceDescriptor[] ejbRefs = null;
String defaultLogicalName = null;
Class defaultBeanInterface = null;
InjectionTarget target = null;
if (ElementType.FIELD.equals(ainfo.getElementType())) {
Field f = (Field) ainfo.getAnnotatedElement();
String targetClassName = f.getDeclaringClass().getName();
defaultLogicalName = targetClassName + "/" + f.getName();
defaultBeanInterface = f.getType();
target = new InjectionTarget();
target.setClassName(targetClassName);
target.setFieldName(f.getName());
target.setMetadataSource(MetadataSource.ANNOTATION);
} else if (ElementType.METHOD.equals(ainfo.getElementType())) {
Method m = (Method) ainfo.getAnnotatedElement();
String targetClassName = m.getDeclaringClass().getName();
validateInjectionMethod(m, ainfo);
// Derive javabean property name.
String propertyName = getInjectionMethodPropertyName(m, ainfo);
defaultLogicalName = targetClassName + "/" + propertyName;
defaultBeanInterface = m.getParameterTypes()[0];
target = new InjectionTarget();
target.setClassName(targetClassName);
target.setMethodName(m.getName());
target.setMetadataSource(MetadataSource.ANNOTATION);
} else if (ElementType.TYPE.equals(ainfo.getElementType())) {
// if either of them not set, fail fast. See issue 17284
if (ejbAn.name().equals("") || ejbAn.beanInterface() == Object.class) {
Class c = (Class) ainfo.getAnnotatedElement();
AnnotationProcessorException fatalException = new AnnotationProcessorException(localStrings.getLocalString("enterprise.deployment.annotation.handlers.invalidtypelevelejb", "Invalid TYPE-level @EJB with name() = [{0}] and " + "beanInterface = [{1}] in {2}. Each TYPE-level @EJB " + "must specify both name() and beanInterface().", new Object[] { ejbAn.name(), ejbAn.beanInterface(), c }), ainfo);
fatalException.setFatal(true);
throw fatalException;
}
} else {
// can't happen
return getDefaultFailedResult();
}
// NOTE that default value is Object.class, not null
Class beanInterface = (ejbAn.beanInterface() == Object.class) ? defaultBeanInterface : ejbAn.beanInterface();
String logicalName = ejbAn.name().equals("") ? defaultLogicalName : ejbAn.name();
ejbRefs = getEjbReferenceDescriptors(logicalName, rcContexts);
for (EjbReferenceDescriptor ejbRef : ejbRefs) {
if (target != null)
ejbRef.addInjectionTarget(target);
if (// a new one
!ok(ejbRef.getName()))
ejbRef.setName(logicalName);
// merge type information
setEjbType(ejbRef, beanInterface);
// merge description
if (!ok(ejbRef.getDescription()) && ok(ejbAn.description()))
ejbRef.setDescription(ejbAn.description());
// merge lookup-name and mapped-name
if (!ejbRef.hasLookupName() && ok(ejbAn.lookup()))
ejbRef.setLookupName(ejbAn.lookup());
if (!ok(ejbRef.getMappedName()) && ok(ejbAn.mappedName()))
ejbRef.setMappedName(ejbAn.mappedName());
// merge beanName/linkName
if (!ok(ejbRef.getLinkName()) && ok(ejbAn.beanName()))
ejbRef.setLinkName(ejbAn.beanName());
}
return getDefaultProcessedResult();
}
use of org.glassfish.apf.AnnotationProcessorException 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();
}
Aggregations