Search in sources :

Example 1 with AnnotatedElementHandler

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();
}
Also used : ApplicationException(javax.ejb.ApplicationException) EjbBundleContext(com.sun.enterprise.deployment.annotation.context.EjbBundleContext) EjbApplicationExceptionInfo(org.glassfish.ejb.deployment.descriptor.EjbApplicationExceptionInfo) AnnotatedElement(java.lang.reflect.AnnotatedElement) AnnotatedElementHandler(org.glassfish.apf.AnnotatedElementHandler) Annotation(java.lang.annotation.Annotation) EjbBundleDescriptorImpl(org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)

Example 2 with AnnotatedElementHandler

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;
}
Also used : HandlerProcessingResult(org.glassfish.apf.HandlerProcessingResult) AnnotatedElementHandler(org.glassfish.apf.AnnotatedElementHandler)

Example 3 with AnnotatedElementHandler

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;
}
Also used : Scanner(org.glassfish.apf.Scanner) Field(java.lang.reflect.Field) Constructor(java.lang.reflect.Constructor) ComponentInfo(org.glassfish.apf.ComponentInfo) Method(java.lang.reflect.Method) AnnotationProcessorException(org.glassfish.apf.AnnotationProcessorException) AnnotatedElementHandler(org.glassfish.apf.AnnotatedElementHandler)

Example 4 with AnnotatedElementHandler

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;
}
Also used : AppClientContext(com.sun.enterprise.deployment.annotation.context.AppClientContext) EjbBundleContext(com.sun.enterprise.deployment.annotation.context.EjbBundleContext) WebBundleContext(com.sun.enterprise.deployment.annotation.context.WebBundleContext) RarBundleContext(com.sun.enterprise.deployment.annotation.context.RarBundleContext) AnnotatedElementHandler(org.glassfish.apf.AnnotatedElementHandler)

Example 5 with AnnotatedElementHandler

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;
}
Also used : HandlerProcessingResult(org.glassfish.apf.HandlerProcessingResult) AnnotatedElementHandler(org.glassfish.apf.AnnotatedElementHandler)

Aggregations

AnnotatedElementHandler (org.glassfish.apf.AnnotatedElementHandler)13 EjbBundleContext (com.sun.enterprise.deployment.annotation.context.EjbBundleContext)5 HandlerProcessingResult (org.glassfish.apf.HandlerProcessingResult)5 EjbsContext (com.sun.enterprise.deployment.annotation.context.EjbsContext)3 WebBundleContext (com.sun.enterprise.deployment.annotation.context.WebBundleContext)3 Annotation (java.lang.annotation.Annotation)3 AnnotatedElement (java.lang.reflect.AnnotatedElement)3 EjbContext (com.sun.enterprise.deployment.annotation.context.EjbContext)2 WebComponentContext (com.sun.enterprise.deployment.annotation.context.WebComponentContext)2 WebComponentsContext (com.sun.enterprise.deployment.annotation.context.WebComponentsContext)2 EjbBundleDescriptorImpl (org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)2 EjbBundleDescriptor (com.sun.enterprise.deployment.EjbBundleDescriptor)1 WebComponentDescriptor (com.sun.enterprise.deployment.WebComponentDescriptor)1 AppClientContext (com.sun.enterprise.deployment.annotation.context.AppClientContext)1 ComponentContext (com.sun.enterprise.deployment.annotation.context.ComponentContext)1 EjbInterceptorContext (com.sun.enterprise.deployment.annotation.context.EjbInterceptorContext)1 RarBundleContext (com.sun.enterprise.deployment.annotation.context.RarBundleContext)1 ResourceContainerContext (com.sun.enterprise.deployment.annotation.context.ResourceContainerContext)1 Constructor (java.lang.reflect.Constructor)1 Field (java.lang.reflect.Field)1