use of org.glassfish.apf.AnnotatedElementHandler in project Payara by payara.
the class ApplicationExceptionHandler method processAnnotation.
public HandlerProcessingResult processAnnotation(AnnotationInfo ainfo) throws AnnotationProcessorException {
AnnotatedElement ae = ainfo.getAnnotatedElement();
Annotation annotation = ainfo.getAnnotation();
AnnotatedElementHandler aeHandler = ainfo.getProcessingContext().getHandler();
if (aeHandler instanceof EjbBundleContext) {
EjbBundleContext ejbBundleContext = (EjbBundleContext) aeHandler;
EjbBundleDescriptorImpl ejbBundle = (EjbBundleDescriptorImpl) ejbBundleContext.getDescriptor();
ApplicationException appExcAnn = (ApplicationException) annotation;
EjbApplicationExceptionInfo appExcInfo = new EjbApplicationExceptionInfo();
Class annotatedClass = (Class) ae;
appExcInfo.setExceptionClassName(annotatedClass.getName());
appExcInfo.setRollback(appExcAnn.rollback());
appExcInfo.setInherited(appExcAnn.inherited());
// in ejb-jar.xml
if (!ejbBundle.getApplicationExceptions().containsKey(annotatedClass.getName())) {
ejbBundle.addApplicationException(appExcInfo);
}
}
return getDefaultProcessedResult();
}
use of org.glassfish.apf.AnnotatedElementHandler 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.AnnotatedElementHandler in project Payara by payara.
the class AnnotationProcessorImpl method process.
private ProcessingResult process(ProcessingContext ctx, Class c) throws AnnotationProcessorException {
Scanner scanner = ctx.getProcessingInput();
ProcessingResultImpl result = new ProcessingResultImpl();
// let's see first if this package is new to us and annotated.
Package classPackage = c.getPackage();
if (classPackage != null && visitedPackages.add(classPackage)) {
// new package
result.add(classPackage, processAnnotations(ctx, ElementType.PACKAGE, classPackage));
}
ComponentInfo info = null;
try {
info = scanner.getComponentInfo(c);
} catch (NoClassDefFoundError err) {
// issue 456: allow verifier to report this issue
AnnotationProcessorException ape = new AnnotationProcessorException(AnnotationUtils.getLocalString("enterprise.deployment.annotation.classnotfounderror", "Class [ {0} ] not found. Error while loading [ {1} ]", new Object[] { err.getMessage(), c }));
ctx.getErrorHandler().error(ape);
// annotation processing
return result;
}
// process the class itself.
AnnotatedElementHandler handler = ctx.getHandler();
logStart(handler, ElementType.TYPE, c);
result.add(c, processAnnotations(ctx, c));
// now dive into the fields.
for (Field field : info.getFields()) {
result.add(field, processAnnotations(ctx, ElementType.FIELD, field));
}
// constructors...
for (Constructor constructor : info.getConstructors()) {
logStart(ctx.getHandler(), ElementType.CONSTRUCTOR, constructor);
result.add(constructor, processAnnotations(ctx, constructor));
// parameters
processParameters(ctx, constructor.getParameterAnnotations());
logEnd(ctx.getHandler(), ElementType.CONSTRUCTOR, constructor);
}
// methods...
for (Method method : info.getMethods()) {
logStart(ctx.getHandler(), ElementType.METHOD, method);
result.add(method, processAnnotations(ctx, method));
// parameters
processParameters(ctx, method.getParameterAnnotations());
logEnd(ctx.getHandler(), ElementType.METHOD, method);
}
// Because of annotation inheritance, we need to to travel to
// the superclasses to ensure that annotations defined at the
// TYPE level are processed at this component level.
// Note : so far, I am ignoring the implemented interfaces
Class currentClass = c.getSuperclass();
while (currentClass != null && !currentClass.equals(Object.class)) {
// the trick is to add the results for this class, not
// for the ones they are defined in...
result.add(c, processAnnotations(ctx, currentClass));
currentClass = currentClass.getSuperclass();
}
// end of class processing, we need to get the top handler
// since it may have changed during the annotation processing
logEnd(ctx.getHandler(), ElementType.TYPE, c);
return result;
}
use of org.glassfish.apf.AnnotatedElementHandler in project Payara by payara.
the class AnnotatedElementHandlerFactory method createAnnotatedElementHandler.
public static AnnotatedElementHandler createAnnotatedElementHandler(RootDeploymentDescriptor bundleDesc) {
AnnotatedElementHandler aeHandler = null;
if (bundleDesc instanceof EjbBundleDescriptor) {
EjbBundleDescriptor ejbBundleDesc = (EjbBundleDescriptor) bundleDesc;
aeHandler = new EjbBundleContext(ejbBundleDesc);
} else if (bundleDesc instanceof ApplicationClientDescriptor) {
ApplicationClientDescriptor appClientDesc = (ApplicationClientDescriptor) bundleDesc;
aeHandler = new AppClientContext(appClientDesc);
} else if (bundleDesc instanceof WebBundleDescriptor) {
WebBundleDescriptor webBundleDesc = (WebBundleDescriptor) bundleDesc;
aeHandler = new WebBundleContext(webBundleDesc);
} else if (bundleDesc instanceof ConnectorDescriptor) {
ConnectorDescriptor connectorDesc = (ConnectorDescriptor) bundleDesc;
aeHandler = new RarBundleContext(connectorDesc);
}
return aeHandler;
}
use of org.glassfish.apf.AnnotatedElementHandler 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
*/
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;
}
Aggregations