Search in sources :

Example 1 with CallbackType

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

the class BeanCallbackInterceptor method initEjbCallbackIndices.

private void initEjbCallbackIndices() throws ClassNotFoundException, Exception {
    int size = CallbackType.values().length;
    ArrayList[] callbacks = new ArrayList[size];
    boolean scanFor2xLifecycleMethods = true;
    int numPostConstructFrameworkCallbacks = 0;
    for (CallbackType eventType : CallbackType.values()) {
        int index = eventType.ordinal();
        callbacks[index] = new ArrayList<CallbackInterceptor>();
        boolean scanForCallbacks = true;
        if (!(ejbDesc instanceof EjbSessionDescriptor)) {
            if ((eventType == CallbackType.PRE_PASSIVATE) || (eventType == CallbackType.POST_ACTIVATE)) {
                scanForCallbacks = false;
            }
        }
        if (scanForCallbacks) {
            // Make sure any framework interceptors are first
            for (InterceptorDescriptor callback : frameworkInterceptors) {
                if (callback.hasCallbackDescriptor(eventType)) {
                    Class interceptorClass = callback.getInterceptorClass();
                    ClassLoader classLoaderToUse = (interceptorClass != null) ? interceptorClass.getClassLoader() : loader;
                    List<CallbackInterceptor> inters = createCallbackInterceptors(eventType, callback, classLoaderToUse);
                    for (CallbackInterceptor inter : inters) {
                        callbacks[index].add(inter);
                        if (eventType == CallbackType.POST_CONSTRUCT) {
                            numPostConstructFrameworkCallbacks++;
                        }
                    }
                }
            }
            List<EjbInterceptor> callbackList = ejbDesc.getCallbackInterceptors(eventType);
            // to scan for the old 2.x style lifecycle methods
            if (callbackList.size() > 0) {
                scanFor2xLifecycleMethods = false;
            }
            for (EjbInterceptor callback : callbackList) {
                List<CallbackInterceptor> inters = createCallbackInterceptors(eventType, callback);
                for (CallbackInterceptor inter : inters) {
                    callbacks[index].add(inter);
                }
            }
        }
    }
    if (scanFor2xLifecycleMethods) {
        load2xLifecycleMethods(callbacks);
    }
    // The next set of lines are to handle the case where
    // the app doesn't have a @PostConstruct or it
    // doesn't implement the EntrerpriseBean interface
    // In this case we scan for ejbCreate() for MDBs and SLSBs
    boolean lookForEjbCreateMethod = container.scanForEjbCreateMethod();
    if (lookForEjbCreateMethod) {
        loadOnlyEjbCreateMethod(callbacks, numPostConstructFrameworkCallbacks);
    }
    callbackChain = new CallbackChainImpl[size];
    for (CallbackType eventType : CallbackType.values()) {
        int index = eventType.ordinal();
        CallbackInterceptor[] interceptors = (CallbackInterceptor[]) callbacks[index].toArray(new CallbackInterceptor[callbacks[index].size()]);
        callbackChain[index] = new CallbackChainImpl(interceptors);
    }
}
Also used : ArrayList(java.util.ArrayList) EjbInterceptor(com.sun.enterprise.deployment.EjbInterceptor) InterceptorDescriptor(com.sun.enterprise.deployment.InterceptorDescriptor) CallbackType(com.sun.enterprise.deployment.LifecycleCallbackDescriptor.CallbackType) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)

Aggregations

EjbInterceptor (com.sun.enterprise.deployment.EjbInterceptor)1 InterceptorDescriptor (com.sun.enterprise.deployment.InterceptorDescriptor)1 CallbackType (com.sun.enterprise.deployment.LifecycleCallbackDescriptor.CallbackType)1 ArrayList (java.util.ArrayList)1 EjbSessionDescriptor (org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)1