Search in sources :

Example 1 with EjbInterceptorContext

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

the class InterceptorsHandler method processInterceptorClass.

private void processInterceptorClass(Class interceptorClass, EjbBundleDescriptorImpl ejbBundle, AnnotationInfo ainfo) throws AnnotationProcessorException {
    Set<LifecycleCallbackDescriptor> aroundInvokeDescriptors = new HashSet<LifecycleCallbackDescriptor>();
    Set<LifecycleCallbackDescriptor> aroundTimeoutDescriptors = new HashSet<LifecycleCallbackDescriptor>();
    Set<LifecycleCallbackDescriptor> postActivateDescriptors = new HashSet<LifecycleCallbackDescriptor>();
    Set<LifecycleCallbackDescriptor> prePassivateDescriptors = new HashSet<LifecycleCallbackDescriptor>();
    ComponentDefinition cdef = new ComponentDefinition(interceptorClass);
    for (Method m : cdef.getMethods()) {
        if (m.getAnnotation(AroundInvoke.class) != null) {
            aroundInvokeDescriptors.add(getLifecycleCallbackDescriptor(m, true));
        }
        if (m.getAnnotation(AroundTimeout.class) != null) {
            aroundTimeoutDescriptors.add(getLifecycleCallbackDescriptor(m, true));
        }
        if (m.getAnnotation(PostActivate.class) != null) {
            postActivateDescriptors.add(getLifecycleCallbackDescriptor(m, false));
        }
        if (m.getAnnotation(PrePassivate.class) != null) {
            prePassivateDescriptors.add(getLifecycleCallbackDescriptor(m, false));
        }
    }
    EjbInterceptor interceptor = ejbBundle.getInterceptorByClassName(interceptorClass.getName());
    if (interceptor == null) {
        interceptor = new EjbInterceptor();
        interceptor.setInterceptorClassName(interceptorClass.getName());
        // Add interceptor to the set of all interceptors in the ejb-jar
        ejbBundle.addInterceptor(interceptor);
    }
    if (aroundInvokeDescriptors.size() > 0) {
        interceptor.addAroundInvokeDescriptors(aroundInvokeDescriptors);
    }
    if (aroundTimeoutDescriptors.size() > 0) {
        interceptor.addAroundTimeoutDescriptors(aroundTimeoutDescriptors);
    }
    if (postActivateDescriptors.size() > 0) {
        interceptor.addCallbackDescriptors(CallbackType.POST_ACTIVATE, postActivateDescriptors);
    }
    if (prePassivateDescriptors.size() > 0) {
        interceptor.addCallbackDescriptors(CallbackType.PRE_PASSIVATE, prePassivateDescriptors);
    }
    // process resource related annotations
    EjbInterceptorContext ejbInterceptorContext = new EjbInterceptorContext(interceptor);
    ProcessingContext procContext = ainfo.getProcessingContext();
    procContext.pushHandler(ejbInterceptorContext);
    procContext.getProcessor().process(procContext, new Class[] { interceptorClass });
    return;
}
Also used : PostActivate(javax.ejb.PostActivate) ProcessingContext(org.glassfish.apf.ProcessingContext) LifecycleCallbackDescriptor(com.sun.enterprise.deployment.LifecycleCallbackDescriptor) PrePassivate(javax.ejb.PrePassivate) EjbInterceptorContext(com.sun.enterprise.deployment.annotation.context.EjbInterceptorContext) EjbInterceptor(com.sun.enterprise.deployment.EjbInterceptor) Method(java.lang.reflect.Method) AroundTimeout(javax.interceptor.AroundTimeout) AroundInvoke(javax.interceptor.AroundInvoke) HashSet(java.util.HashSet) ComponentDefinition(org.glassfish.apf.impl.ComponentDefinition)

Example 2 with EjbInterceptorContext

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

Aggregations

EjbInterceptorContext (com.sun.enterprise.deployment.annotation.context.EjbInterceptorContext)2 EjbInterceptor (com.sun.enterprise.deployment.EjbInterceptor)1 LifecycleCallbackDescriptor (com.sun.enterprise.deployment.LifecycleCallbackDescriptor)1 ComponentContext (com.sun.enterprise.deployment.annotation.context.ComponentContext)1 EjbBundleContext (com.sun.enterprise.deployment.annotation.context.EjbBundleContext)1 EjbContext (com.sun.enterprise.deployment.annotation.context.EjbContext)1 EjbsContext (com.sun.enterprise.deployment.annotation.context.EjbsContext)1 Annotation (java.lang.annotation.Annotation)1 AnnotatedElement (java.lang.reflect.AnnotatedElement)1 Method (java.lang.reflect.Method)1 HashSet (java.util.HashSet)1 PostActivate (javax.ejb.PostActivate)1 PrePassivate (javax.ejb.PrePassivate)1 AroundInvoke (javax.interceptor.AroundInvoke)1 AroundTimeout (javax.interceptor.AroundTimeout)1 AnnotatedElementHandler (org.glassfish.apf.AnnotatedElementHandler)1 HandlerProcessingResult (org.glassfish.apf.HandlerProcessingResult)1 ProcessingContext (org.glassfish.apf.ProcessingContext)1 ComponentDefinition (org.glassfish.apf.impl.ComponentDefinition)1