Search in sources :

Example 16 with LifecycleCallbackDescriptor

use of com.sun.enterprise.deployment.LifecycleCallbackDescriptor in project Payara by payara.

the class AroundInvokeHandler method getAroundInvocationDescriptor.

protected LifecycleCallbackDescriptor getAroundInvocationDescriptor(AnnotationInfo ainfo) {
    Method m = (Method) ainfo.getAnnotatedElement();
    LifecycleCallbackDescriptor lccDesc = new LifecycleCallbackDescriptor();
    lccDesc.setLifecycleCallbackClass(m.getDeclaringClass().getName());
    lccDesc.setLifecycleCallbackMethod(m.getName());
    return lccDesc;
}
Also used : LifecycleCallbackDescriptor(com.sun.enterprise.deployment.LifecycleCallbackDescriptor) Method(java.lang.reflect.Method)

Example 17 with LifecycleCallbackDescriptor

use of com.sun.enterprise.deployment.LifecycleCallbackDescriptor 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));
        }
        if (m.getAnnotation(AroundTimeout.class) != null) {
            aroundTimeoutDescriptors.add(getLifecycleCallbackDescriptor(m));
        }
        if (m.getAnnotation(PostActivate.class) != null) {
            postActivateDescriptors.add(getLifecycleCallbackDescriptor(m));
        }
        if (m.getAnnotation(PrePassivate.class) != null) {
            prePassivateDescriptors.add(getLifecycleCallbackDescriptor(m));
        }
    }
    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 18 with LifecycleCallbackDescriptor

use of com.sun.enterprise.deployment.LifecycleCallbackDescriptor in project Payara by payara.

the class PrePassivateHandler method getPrePassivateDescriptor.

private LifecycleCallbackDescriptor getPrePassivateDescriptor(AnnotationInfo ainfo) {
    Method annotatedMethod = (Method) ainfo.getAnnotatedElement();
    LifecycleCallbackDescriptor prePassivate = new LifecycleCallbackDescriptor();
    prePassivate.setLifecycleCallbackClass(annotatedMethod.getDeclaringClass().getName());
    prePassivate.setLifecycleCallbackMethod(annotatedMethod.getName());
    return prePassivate;
}
Also used : LifecycleCallbackDescriptor(com.sun.enterprise.deployment.LifecycleCallbackDescriptor) Method(java.lang.reflect.Method)

Example 19 with LifecycleCallbackDescriptor

use of com.sun.enterprise.deployment.LifecycleCallbackDescriptor in project Payara by payara.

the class AppClientValidator method accept.

@Override
public void accept(ApplicationClientDescriptor appclientdescriptor) {
    bundleDescriptor = appclientdescriptor;
    application = appclientdescriptor.getApplication();
    // set the default lifecycle callback class
    for (LifecycleCallbackDescriptor next : appclientdescriptor.getPreDestroyDescriptors()) {
        next.setDefaultLifecycleCallbackClass(appclientdescriptor.getMainClassName());
    }
    for (LifecycleCallbackDescriptor next : appclientdescriptor.getPostConstructDescriptors()) {
        next.setDefaultLifecycleCallbackClass(appclientdescriptor.getMainClassName());
    }
}
Also used : LifecycleCallbackDescriptor(com.sun.enterprise.deployment.LifecycleCallbackDescriptor)

Example 20 with LifecycleCallbackDescriptor

use of com.sun.enterprise.deployment.LifecycleCallbackDescriptor in project Payara by payara.

the class PostConstructHandler method processAnnotation.

protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, ResourceContainerContext[] rcContexts) throws AnnotationProcessorException {
    Method annMethod = (Method) ainfo.getAnnotatedElement();
    validateAnnotatedLifecycleMethod(annMethod);
    String pcMethodName = annMethod.getName();
    String pcClassName = annMethod.getDeclaringClass().getName();
    for (ResourceContainerContext rcContext : rcContexts) {
        LifecycleCallbackDescriptor postConstructDesc = new LifecycleCallbackDescriptor();
        postConstructDesc.setLifecycleCallbackClass(pcClassName);
        postConstructDesc.setLifecycleCallbackMethod(pcMethodName);
        postConstructDesc.setMetadataSource(MetadataSource.ANNOTATION);
        // override by xml is handled in addPostConstructDescriptor
        rcContext.addPostConstructDescriptor(postConstructDesc);
    }
    return getDefaultProcessedResult();
}
Also used : LifecycleCallbackDescriptor(com.sun.enterprise.deployment.LifecycleCallbackDescriptor) ResourceContainerContext(com.sun.enterprise.deployment.annotation.context.ResourceContainerContext) Method(java.lang.reflect.Method)

Aggregations

LifecycleCallbackDescriptor (com.sun.enterprise.deployment.LifecycleCallbackDescriptor)38 Method (java.lang.reflect.Method)15 EjbInterceptor (com.sun.enterprise.deployment.EjbInterceptor)9 ArrayList (java.util.ArrayList)4 EJBException (javax.ejb.EJBException)4 InterceptorDescriptor (com.sun.enterprise.deployment.InterceptorDescriptor)3 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)3 EjbSessionDescriptor (org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)3 EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)2 ResourceContainerContext (com.sun.enterprise.deployment.annotation.context.ResourceContainerContext)2 Result (com.sun.enterprise.tools.verifier.Result)2 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)2 HashSet (java.util.HashSet)2 Descriptor (org.glassfish.deployment.common.Descriptor)2 EjbDescriptor (org.glassfish.ejb.deployment.descriptor.EjbDescriptor)2 EjbContext (com.sun.enterprise.deployment.annotation.context.EjbContext)1 EjbInterceptorContext (com.sun.enterprise.deployment.annotation.context.EjbInterceptorContext)1 Collection (java.util.Collection)1 LinkedList (java.util.LinkedList)1 Set (java.util.Set)1