Search in sources :

Example 1 with EjbBundleContext

use of com.sun.enterprise.deployment.annotation.context.EjbBundleContext 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 EjbBundleContext

use of com.sun.enterprise.deployment.annotation.context.EjbBundleContext 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 3 with EjbBundleContext

use of com.sun.enterprise.deployment.annotation.context.EjbBundleContext in project Payara by payara.

the class AbstractResourceHandler 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
 * @return
 * @throws AnnotationProcessorException
 */
@Override
public HandlerProcessingResult processAnnotation(AnnotationInfo ainfo) throws AnnotationProcessorException {
    AnnotatedElementHandler aeHandler = ainfo.getProcessingContext().getHandler();
    if (aeHandler instanceof EjbBundleContext) {
        EjbBundleContext ejbBundleContext = (EjbBundleContext) aeHandler;
        aeHandler = ejbBundleContext.createContextForEjb();
        if (aeHandler == null) {
            aeHandler = ejbBundleContext.createContextForEjbInterceptor();
        }
        // If it's still null and we're in an ejb-jar, use the EjbBundleContext.
        // This way we process dependencies on any classes (other than ejbs ,
        // interceptors , and their super-classes) that have annotations in case
        // we need the info for managed classes we wouldn't normally know about
        // (e.g. 299 classes).   In a .war, those are already processed during the
        // .war annotation scanning.
        EjbBundleDescriptor bundleDesc = ejbBundleContext.getDescriptor();
        RootDeploymentDescriptor enclosingBundle = bundleDesc.getModuleDescriptor().getDescriptor();
        boolean ejbJar = enclosingBundle instanceof EjbBundleDescriptor;
        if ((aeHandler == null) && ejbJar) {
            aeHandler = ejbBundleContext;
        }
    }
    if (aeHandler == null) {
        // not an ejb, interceptor in ejbBundle
        return getInvalidAnnotatedElementHandlerResult(ainfo.getProcessingContext().getHandler(), ainfo);
    }
    ResourceContainerContext[] rcContexts = null;
    if (aeHandler instanceof EjbsContext) {
        EjbsContext ejbsContext = (EjbsContext) aeHandler;
        rcContexts = (ResourceContainerContext[]) ejbsContext.getEjbContexts();
    } else if (aeHandler instanceof WebComponentsContext) {
        WebComponentsContext webCompsContext = (WebComponentsContext) aeHandler;
        rcContexts = (ResourceContainerContext[]) webCompsContext.getWebComponentContexts();
    } else if (aeHandler instanceof ResourceContainerContext) {
        rcContexts = new ResourceContainerContext[] { (ResourceContainerContext) aeHandler };
    } else {
        return getInvalidAnnotatedElementHandlerResult(aeHandler, ainfo);
    }
    return processAnnotation(ainfo, rcContexts);
}
Also used : EjbBundleContext(com.sun.enterprise.deployment.annotation.context.EjbBundleContext) ResourceContainerContext(com.sun.enterprise.deployment.annotation.context.ResourceContainerContext) WebComponentsContext(com.sun.enterprise.deployment.annotation.context.WebComponentsContext) EjbBundleDescriptor(com.sun.enterprise.deployment.EjbBundleDescriptor) RootDeploymentDescriptor(org.glassfish.deployment.common.RootDeploymentDescriptor) AnnotatedElementHandler(org.glassfish.apf.AnnotatedElementHandler) EjbsContext(com.sun.enterprise.deployment.annotation.context.EjbsContext)

Example 4 with EjbBundleContext

use of com.sun.enterprise.deployment.annotation.context.EjbBundleContext in project Payara by payara.

the class AbstractAttributeHandler 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.
 * This is a method in interface AnnotationHandler.
 *
 * @param ainfo the annotation information
 */
public HandlerProcessingResult processAnnotation(AnnotationInfo ainfo) throws AnnotationProcessorException {
    AnnotatedElement ae = ainfo.getAnnotatedElement();
    Annotation annotation = ainfo.getAnnotation();
    if (logger.isLoggable(Level.FINER)) {
        logger.finer("@process annotation " + annotation + " in " + ae);
    }
    AnnotatedElementHandler aeHandler = ainfo.getProcessingContext().getHandler();
    if (aeHandler instanceof EjbBundleContext) {
        EjbBundleContext ejbBundleContext = (EjbBundleContext) aeHandler;
        AnnotatedElementHandler aeh = ejbBundleContext.createContextForEjb();
        if (aeh != null) {
            aeHandler = aeh;
        } else {
            if (isDelegatee()) {
                aeHandler = ejbBundleContext.createContextForEjbInterceptor();
            }
            if (aeHandler == null) {
                return getInvalidAnnotatedElementHandlerResult(null, 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();
        }
    }
    EjbContext[] ejbContexts = null;
    EjbInterceptorContext ejbInterceptorContext = null;
    if (aeHandler instanceof EjbContext) {
        EjbContext ejbContext = (EjbContext) aeHandler;
        ejbContexts = new EjbContext[] { ejbContext };
    } else if (aeHandler instanceof EjbsContext) {
        ejbContexts = ((EjbsContext) aeHandler).getEjbContexts();
    } else if (isDelegatee() && aeHandler instanceof EjbInterceptorContext) {
        ejbInterceptorContext = (EjbInterceptorContext) aeHandler;
    } else {
        return getInvalidAnnotatedElementHandlerResult(aeHandler, ainfo);
    }
    HandlerProcessingResult procResult = null;
    if (ejbInterceptorContext != null) {
        procResult = processAnnotation(ainfo, ejbInterceptorContext);
    } else {
        procResult = processAnnotation(ainfo, ejbContexts);
    }
    if (logger.isLoggable(Level.FINER)) {
        logger.finer("New annotation for " + annotation);
    }
    return procResult;
}
Also used : EjbBundleContext(com.sun.enterprise.deployment.annotation.context.EjbBundleContext) ComponentContext(com.sun.enterprise.deployment.annotation.context.ComponentContext) EjbInterceptorContext(com.sun.enterprise.deployment.annotation.context.EjbInterceptorContext) EjbContext(com.sun.enterprise.deployment.annotation.context.EjbContext) HandlerProcessingResult(org.glassfish.apf.HandlerProcessingResult) AnnotatedElement(java.lang.reflect.AnnotatedElement) AnnotatedElementHandler(org.glassfish.apf.AnnotatedElementHandler) Annotation(java.lang.annotation.Annotation) EjbsContext(com.sun.enterprise.deployment.annotation.context.EjbsContext)

Example 5 with EjbBundleContext

use of com.sun.enterprise.deployment.annotation.context.EjbBundleContext in project Payara by payara.

the class AbstractEjbHandler 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.
 * This is a method in interface AnnotationHandler.
 *
 * @param ainfo the annotation information
 */
public HandlerProcessingResult processAnnotation(AnnotationInfo ainfo) throws AnnotationProcessorException {
    Class ejbClass = (Class) ainfo.getAnnotatedElement();
    Annotation annotation = ainfo.getAnnotation();
    if (logger.isLoggable(Level.FINER)) {
        logger.finer("@ process ejb annotation " + annotation + " in " + ejbClass);
    }
    AnnotatedElementHandler aeHandler = ainfo.getProcessingContext().getHandler();
    if (aeHandler != null && aeHandler instanceof EjbContext) {
        EjbContext context = (EjbContext) aeHandler;
        EjbDescriptor desc = (EjbDescriptor) context.getDescriptor();
        if (isValidEjbDescriptor(desc, annotation)) {
            return getDefaultProcessedResult();
        } else {
            log(Level.SEVERE, ainfo, localStrings.getLocalString("enterprise.deployment.annotation.handlers.notcompsuperclass", "The annotation symbol defined in super-class is not compatible with {0} ejb {1}.", new Object[] { desc.getType(), desc.getName() }));
            return getDefaultFailedResult();
        }
    } else if (aeHandler == null || !(aeHandler instanceof EjbBundleContext)) {
        return getInvalidAnnotatedElementHandlerResult(ainfo.getProcessingContext().getHandler(), ainfo);
    }
    EjbBundleContext ctx = (EjbBundleContext) aeHandler;
    if (logger.isLoggable(Level.FINE)) {
        logger.fine("My context is " + ctx);
    }
    String elementName = getAnnotatedName(annotation);
    if (elementName.length() == 0) {
        elementName = ejbClass.getSimpleName();
    } else {
        elementName = (String) TranslatedConfigView.getTranslatedValue(elementName);
    }
    EjbBundleDescriptorImpl currentBundle = (EjbBundleDescriptorImpl) ctx.getDescriptor();
    EjbDescriptor ejbDesc = null;
    try {
        ejbDesc = currentBundle.getEjbByName(elementName);
    } catch (IllegalArgumentException ex) {
    // getEjbByName throws IllegalArgumentException when no ejb is found
    }
    if (ejbDesc != null && !(ejbDesc instanceof DummyEjbDescriptor)) {
        // overriding rules applies
        if (logger.isLoggable(Level.FINE)) {
            logger.fine("Overriding rules apply for " + ejbClass.getName());
        }
        // don't allow ejb-jar.xml overwrite ejb type
        if (!isValidEjbDescriptor(ejbDesc, annotation)) {
            // this is an error
            log(Level.SEVERE, ainfo, localStrings.getLocalString("enterprise.deployment.annotation.handlers.wrongejbtype", "Wrong annotation symbol for ejb {0}", new Object[] { ejbDesc }));
            return getDefaultFailedResult();
        }
        // <ejb-class> is optional if a component-defining
        // annotation is used.  If present, <ejb-class> element
        // must match the class on which the component defining annotation
        // appears.
        String descriptorEjbClass = ejbDesc.getEjbClassName();
        if (descriptorEjbClass == null) {
            ejbDesc.setEjbClassName(ejbClass.getName());
            ejbDesc.applyDefaultClassToLifecycleMethods();
        } else if (!descriptorEjbClass.equals(ejbClass.getName())) {
            log(Level.SEVERE, ainfo, localStrings.getLocalString("enterprise.deployment.annotation.handlers.ejbclsmismatch", "", new Object[] { descriptorEjbClass, elementName, ejbClass.getName() }));
            return getDefaultFailedResult();
        }
    } else {
        if (logger.isLoggable(Level.FINE)) {
            logger.fine("Creating a new descriptor for " + ejbClass.getName());
        }
        EjbDescriptor dummyEjbDesc = ejbDesc;
        ejbDesc = createEjbDescriptor(elementName, ainfo);
        // the information from dummy ejb descriptor if applicable
        if (dummyEjbDesc != null) {
            currentBundle.removeEjb(dummyEjbDesc);
            ejbDesc.addEjbDescriptor(dummyEjbDesc);
            // reset ejbClassName on ejbDesc
            ejbDesc.setEjbClassName(ejbClass.getName());
        }
        // add the actual ejb descriptor to the ejb bundle
        currentBundle.addEjb(ejbDesc);
        if (logger.isLoggable(Level.FINE)) {
            logger.fine("New " + getAnnotationType().getName() + " bean " + elementName);
        }
    }
    // We need to include all ejbs of the same name in the annotation processing context
    // in order to handle the case that a bean class has both a component-defining
    // annotation and there are other ejb-jar.xml-defined beans with the same bean class.
    EjbDescriptor[] ejbDescs = currentBundle.getEjbByClassName(ejbClass.getName());
    HandlerProcessingResult procResult = null;
    for (EjbDescriptor next : ejbDescs) {
        procResult = setEjbDescriptorInfo(next, ainfo);
        doTimedObjectProcessing(ejbClass, next);
    }
    AnnotationContext annContext = null;
    if (ejbDescs.length == 1) {
        annContext = new EjbContext(ejbDesc, ejbClass);
    } else {
        annContext = new EjbsContext(ejbDescs, ejbClass);
    }
    // we push the new context on the stack...
    ctx.getProcessingContext().pushHandler(annContext);
    return procResult;
}
Also used : DummyEjbDescriptor(org.glassfish.ejb.deployment.descriptor.DummyEjbDescriptor) HandlerProcessingResult(org.glassfish.apf.HandlerProcessingResult) AnnotationContext(org.glassfish.apf.context.AnnotationContext) Annotation(java.lang.annotation.Annotation) DummyEjbDescriptor(org.glassfish.ejb.deployment.descriptor.DummyEjbDescriptor) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor) EjbsContext(com.sun.enterprise.deployment.annotation.context.EjbsContext) EjbBundleContext(com.sun.enterprise.deployment.annotation.context.EjbBundleContext) EjbContext(com.sun.enterprise.deployment.annotation.context.EjbContext) AnnotatedElementHandler(org.glassfish.apf.AnnotatedElementHandler) EjbBundleDescriptorImpl(org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)

Aggregations

EjbBundleContext (com.sun.enterprise.deployment.annotation.context.EjbBundleContext)5 AnnotatedElementHandler (org.glassfish.apf.AnnotatedElementHandler)5 EjbsContext (com.sun.enterprise.deployment.annotation.context.EjbsContext)3 Annotation (java.lang.annotation.Annotation)3 EjbContext (com.sun.enterprise.deployment.annotation.context.EjbContext)2 AnnotatedElement (java.lang.reflect.AnnotatedElement)2 HandlerProcessingResult (org.glassfish.apf.HandlerProcessingResult)2 EjbBundleDescriptorImpl (org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)2 EjbBundleDescriptor (com.sun.enterprise.deployment.EjbBundleDescriptor)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 WebBundleContext (com.sun.enterprise.deployment.annotation.context.WebBundleContext)1 WebComponentsContext (com.sun.enterprise.deployment.annotation.context.WebComponentsContext)1 ApplicationException (javax.ejb.ApplicationException)1 AnnotationContext (org.glassfish.apf.context.AnnotationContext)1 RootDeploymentDescriptor (org.glassfish.deployment.common.RootDeploymentDescriptor)1 DummyEjbDescriptor (org.glassfish.ejb.deployment.descriptor.DummyEjbDescriptor)1