use of org.glassfish.apf.HandlerProcessingResult in project Payara by payara.
the class MessageDrivenHandler 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 {
MessageDriven mdAn = (MessageDriven) ainfo.getAnnotation();
Class ejbClass = (Class) ainfo.getAnnotatedElement();
EjbMessageBeanDescriptor ejbMsgBeanDesc = (EjbMessageBeanDescriptor) ejbDesc;
HandlerProcessingResult procResult = setMessageListenerInterface(mdAn, ejbMsgBeanDesc, ejbClass, ainfo);
doDescriptionProcessing(mdAn.description(), ejbMsgBeanDesc);
doMappedNameProcessing(mdAn.mappedName(), ejbMsgBeanDesc);
for (ActivationConfigProperty acProp : mdAn.activationConfig()) {
EnvironmentProperty envProp = new EnvironmentProperty(acProp.propertyName(), TranslatedConfigView.expandValue(acProp.propertyValue()), "");
// xml override
switch(acProp.propertyName()) {
case "resourceAdapter":
ejbMsgBeanDesc.setResourceAdapterMid(envProp.getValue());
break;
case DescriptorConstants.MAX_POOL_SIZE:
initialiseBeanPoolDescriptor(ejbMsgBeanDesc);
ejbMsgBeanDesc.getIASEjbExtraDescriptors().getBeanPool().setMaxPoolSize(Integer.valueOf(envProp.getValue()));
break;
case DescriptorConstants.POOL_RESIZE_QTY:
initialiseBeanPoolDescriptor(ejbMsgBeanDesc);
ejbMsgBeanDesc.getIASEjbExtraDescriptors().getBeanPool().setPoolResizeQuantity(Integer.valueOf(envProp.getValue()));
break;
case DescriptorConstants.STEADY_POOL_SIZE:
initialiseBeanPoolDescriptor(ejbMsgBeanDesc);
ejbMsgBeanDesc.getIASEjbExtraDescriptors().getBeanPool().setSteadyPoolSize(Integer.valueOf(envProp.getValue()));
break;
case DescriptorConstants.MAX_WAIT_TIME:
initialiseBeanPoolDescriptor(ejbMsgBeanDesc);
ejbMsgBeanDesc.getIASEjbExtraDescriptors().getBeanPool().setMaxWaitTimeInMillis(Integer.valueOf(envProp.getValue()));
break;
case DescriptorConstants.POOL_IDLE_TIMEOUT:
initialiseBeanPoolDescriptor(ejbMsgBeanDesc);
ejbMsgBeanDesc.getIASEjbExtraDescriptors().getBeanPool().setPoolIdleTimeoutInSeconds(Integer.valueOf(envProp.getValue()));
break;
case "SingletonBeanPool":
NameValuePairDescriptor singletonProperty = new NameValuePairDescriptor();
singletonProperty.setName("singleton-bean-pool");
singletonProperty.setValue(envProp.getValue());
ejbMsgBeanDesc.getEjbBundleDescriptor().addEnterpriseBeansProperty(singletonProperty);
break;
default:
if (ejbMsgBeanDesc.getActivationConfigValue(envProp.getName()) == null) {
ejbMsgBeanDesc.putActivationConfigProperty(envProp);
}
break;
}
}
return procResult;
}
use of org.glassfish.apf.HandlerProcessingResult in project Payara by payara.
the class AbstractCommonAttributeHandler method processAnnotation.
/**
* Process a particular annotation which 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
*/
@Override
public HandlerProcessingResult processAnnotation(AnnotationInfo ainfo) throws AnnotationProcessorException {
AnnotatedElementHandler aeHandler = ainfo.getProcessingContext().getHandler();
if (aeHandler instanceof EjbBundleContext) {
EjbBundleContext ejbBundleContext = (EjbBundleContext) aeHandler;
aeHandler = ejbBundleContext.createContextForEjb();
} else if (aeHandler instanceof WebBundleContext) {
WebBundleContext webBundleContext = (WebBundleContext) aeHandler;
aeHandler = webBundleContext.createContextForWeb();
if (aeHandler == null) {
// no such web comp, use webBundleContext
aeHandler = ainfo.getProcessingContext().getHandler();
}
}
if (aeHandler == null) {
// no such ejb
return getInvalidAnnotatedElementHandlerResult(ainfo.getProcessingContext().getHandler(), ainfo);
}
if (!supportTypeInheritance() && ElementType.TYPE.equals(ainfo.getElementType()) && aeHandler instanceof ComponentContext) {
ComponentContext context = (ComponentContext) aeHandler;
Class clazz = (Class) ainfo.getAnnotatedElement();
if (!clazz.getName().equals(context.getComponentClassName())) {
if (logger.isLoggable(Level.WARNING)) {
log(Level.WARNING, ainfo, localStrings.getLocalString("enterprise.deployment.annotation.handlers.typeinhernotsupp", "The annotation symbol inheritance is not supported."));
}
return getDefaultProcessedResult();
}
}
HandlerProcessingResult procResult = null;
if (aeHandler instanceof EjbContext) {
procResult = processAnnotation(ainfo, new EjbContext[] { (EjbContext) aeHandler });
} else if (aeHandler instanceof EjbsContext) {
EjbsContext ejbsContext = (EjbsContext) aeHandler;
procResult = processAnnotation(ainfo, ejbsContext.getEjbContexts());
} else if (aeHandler instanceof WebComponentContext) {
procResult = processAnnotation(ainfo, new WebComponentContext[] { (WebComponentContext) aeHandler });
} else if (aeHandler instanceof WebComponentsContext) {
WebComponentsContext webCompsContext = (WebComponentsContext) aeHandler;
procResult = processAnnotation(ainfo, webCompsContext.getWebComponentContexts());
} else if (aeHandler instanceof WebBundleContext) {
WebBundleContext webBundleContext = (WebBundleContext) aeHandler;
procResult = processAnnotation(ainfo, webBundleContext);
} else {
return getInvalidAnnotatedElementHandlerResult(aeHandler, ainfo);
}
return procResult;
}
use of org.glassfish.apf.HandlerProcessingResult in project Payara by payara.
the class EJBsHandler method processAnnotation.
protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, ResourceContainerContext[] rcContexts) throws AnnotationProcessorException {
EJBs ejbsAnnotation = (EJBs) ainfo.getAnnotation();
EJB[] ejbAnnotations = ejbsAnnotation.value();
if (ejbAnnotations.length == 0) {
String localizedMsg = localStrings.getLocalString("enterprise.deployment.annotation.handlers.emptyEJBs", "No @EJB elements in @EJBs on " + ainfo.getAnnotatedElement(), new Object[] { ejbsAnnotation, ainfo.getAnnotatedElement() });
logger.log(Level.WARNING, localizedMsg);
}
List<HandlerProcessingResult> results = new ArrayList<HandlerProcessingResult>();
for (EJB ejb : ejbAnnotations) {
results.add(processEJB(ainfo, rcContexts, ejb));
}
return getOverallProcessingResult(results);
}
use of org.glassfish.apf.HandlerProcessingResult in project Payara by payara.
the class AnnotationProcessorImpl method processAnnotations.
private HandlerProcessingResult processAnnotations(ProcessingContext ctx, ElementType type, AnnotatedElement element) throws AnnotationProcessorException {
AnnotatedElementHandler handler = ctx.getHandler();
logStart(handler, type, element);
HandlerProcessingResult result = processAnnotations(ctx, element);
logEnd(handler, type, element);
dumpProcessingResult(result);
return result;
}
use of org.glassfish.apf.HandlerProcessingResult in project Payara by payara.
the class AnnotationProcessorImpl method process.
private void process(ProcessingContext ctx, AnnotationInfo element, HandlerProcessingResultImpl result) throws AnnotationProcessorException {
Annotation annotation = element.getAnnotation();
if (AnnotationUtils.shouldLog("annotation")) {
logger.log(Level.FINER, "Annotation : {0} delegate = {1}", new Object[] { annotation.annotationType().getName(), delegate });
}
result.addResult(annotation.annotationType(), ResultType.UNPROCESSED);
// we ignore all java.* annotations
Package annPackage = annotation.annotationType().getPackage();
if (annPackage != null && annPackage.getName().startsWith("java.lang"))
return;
List<AnnotationHandler> annotationHandlers = handlers.get(annotation.annotationType().getName());
if (annotationHandlers != null) {
for (AnnotationHandler handler : annotationHandlers) {
// here we need to be careful, we are ready to invoke a handler
// to process a particular annotation type. However, this handler
// may have defined a list of annotations that should be processed
// (if present on the annotated element) before itself.
// do this check and process those annotations first.
Class<? extends Annotation>[] dependencies = handler.getTypeDependencies();
if (dependencies != null) {
AnnotatedElement ae = element.getAnnotatedElement();
for (Class<? extends Annotation> annotationType : dependencies) {
Annotation depAnnotation = ae.getAnnotation(annotationType);
if (depAnnotation != null) {
ResultType resultType = result.processedAnnotations().get(annotationType);
if (resultType == null || resultType == ResultType.UNPROCESSED) {
// annotation is present, process it.
AnnotationInfo info = new AnnotationInfo(ctx, ae, depAnnotation, getTopElementType());
process(ctx, info, result);
}
}
}
}
// at this point, all annotation that I declared depending on
// are processed
HandlerProcessingResult processingResult = null;
try {
processingResult = handler.processAnnotation(element);
} catch (AnnotationProcessorException ape) {
// I am logging this exception
log(Level.SEVERE, ape.getLocator(), ape.getMessage());
// errors.
if (ape.isFatal()) {
throw ape;
}
if (++errorCount > 100) {
throw new AnnotationProcessorException(AnnotationUtils.getLocalString("enterprise.deployment.annotation.toomanyerror", "Too many errors, annotation processing abandoned."));
}
processingResult = HandlerProcessingResultImpl.getDefaultResult(annotation.annotationType(), ResultType.FAILED);
} catch (Throwable e) {
AnnotationProcessorException ape = new AnnotationProcessorException(e.getMessage(), element);
ape.initCause(e);
throw ape;
}
result.addAll(processingResult);
}
} else {
if (delegate != null) {
delegate.process(ctx, element, result);
} else {
ctx.getErrorHandler().fine(new AnnotationProcessorException("No handler defined for " + annotation.annotationType()));
}
}
}
Aggregations