Search in sources :

Example 31 with EjbInterceptor

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

the class EjbServicesImpl method makeInterceptorChain.

private List<EjbInterceptor> makeInterceptorChain(InterceptionType interceptionType, List<Interceptor<?>> lifecycleList, com.sun.enterprise.deployment.EjbDescriptor ejbDesc) {
    List<EjbInterceptor> ejbInterceptorList = new LinkedList<EjbInterceptor>();
    if (lifecycleList == null) {
        return ejbInterceptorList;
    }
    for (Interceptor<?> next : lifecycleList) {
        EjbInterceptor ejbInt = makeEjbInterceptor(next, ejbDesc.getEjbBundleDescriptor());
        Class<?> interceptorClass = next.getBeanClass();
        while (interceptorClass != null && !interceptorClass.equals(Object.class)) {
            String methodName = getInterceptorMethod(interceptorClass, getInterceptorAnnotationType(interceptionType));
            if (methodName != null) {
                LifecycleCallbackDescriptor lifecycleDesc = new LifecycleCallbackDescriptor();
                lifecycleDesc.setLifecycleCallbackClass(interceptorClass.getName());
                lifecycleDesc.setLifecycleCallbackMethod(methodName);
                switch(interceptionType) {
                    case POST_CONSTRUCT:
                        ejbInt.addPostConstructDescriptor(lifecycleDesc);
                        break;
                    case PRE_DESTROY:
                        ejbInt.addPreDestroyDescriptor(lifecycleDesc);
                        break;
                    case PRE_PASSIVATE:
                        ejbInt.addPrePassivateDescriptor(lifecycleDesc);
                        break;
                    case POST_ACTIVATE:
                        ejbInt.addPostActivateDescriptor(lifecycleDesc);
                        break;
                    case AROUND_INVOKE:
                        lifecycleDesc.setRequiresInvocationContextArgument(true);
                        ejbInt.addAroundInvokeDescriptor(lifecycleDesc);
                        break;
                    case AROUND_TIMEOUT:
                        lifecycleDesc.setRequiresInvocationContextArgument(true);
                        ejbInt.addAroundTimeoutDescriptor(lifecycleDesc);
                        break;
                    case AROUND_CONSTRUCT:
                        ejbInt.addAroundConstructDescriptor(lifecycleDesc);
                        break;
                    default:
                        throw new IllegalArgumentException("Invalid lifecycle interception type " + interceptionType);
                }
            }
            interceptorClass = interceptorClass.getSuperclass();
        }
        ejbInterceptorList.add(ejbInt);
    }
    return ejbInterceptorList;
}
Also used : LifecycleCallbackDescriptor(com.sun.enterprise.deployment.LifecycleCallbackDescriptor) EjbInterceptor(com.sun.enterprise.deployment.EjbInterceptor) LinkedList(java.util.LinkedList)

Example 32 with EjbInterceptor

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

the class BeanCallbackInterceptor method getAroundTimeoutChain.

public InterceptorManager.InterceptorChain getAroundTimeoutChain(MethodDescriptor mDesc, Method beanMethod) {
    ArrayList<AroundInvokeInterceptor> interceptors = new ArrayList<AroundInvokeInterceptor>();
    for (InterceptorDescriptor interceptor : frameworkInterceptors) {
        Set<LifecycleCallbackDescriptor> aroundTimeoutDescs = interceptor.getAroundTimeoutDescriptors();
        if (aroundTimeoutDescs.isEmpty()) {
            continue;
        }
        List<LifecycleCallbackDescriptor> orderedAIInterceptors = null;
        Class interceptorClass = interceptor.getInterceptorClass();
        ClassLoader classLoaderToUse = (interceptorClass != null) ? interceptorClass.getClassLoader() : loader;
        try {
            orderedAIInterceptors = interceptor.getOrderedAroundTimeoutDescriptors(classLoaderToUse);
        } catch (Exception e) {
            throw new IllegalStateException("No AroundTimeoutIntercetpors found " + " on class " + interceptor.getInterceptorClassName(), e);
        }
        addAroundInvokeInterceptors(interceptors, interceptor, orderedAIInterceptors, interceptor.getInterceptorClassName(), classLoaderToUse);
    }
    List<EjbInterceptor> list = (ejbDesc != null) ? ejbDesc.getAroundTimeoutInterceptors(mDesc) : new LinkedList<EjbInterceptor>();
    for (EjbInterceptor interceptor : list) {
        String className = interceptor.getInterceptorClassName();
        Set<LifecycleCallbackDescriptor> aroundTimeoutDescs = interceptor.getAroundTimeoutDescriptors();
        if (aroundTimeoutDescs.isEmpty()) {
            continue;
        }
        List<LifecycleCallbackDescriptor> orderedATInterceptors;
        try {
            orderedATInterceptors = interceptor.getOrderedAroundTimeoutDescriptors(loader);
        } catch (Exception e) {
            throw new IllegalStateException("No AroundTimeoutIntercetpors found " + " on class " + className, e);
        }
        addAroundInvokeInterceptors(interceptors, interceptor, orderedATInterceptors, className, loader);
    }
    AroundInvokeInterceptor[] inter = interceptors.toArray(new AroundInvokeInterceptor[interceptors.size()]);
    return new AroundInvokeChainImpl(inter);
}
Also used : ArrayList(java.util.ArrayList) EjbInterceptor(com.sun.enterprise.deployment.EjbInterceptor) EJBException(javax.ejb.EJBException) InterceptorDescriptor(com.sun.enterprise.deployment.InterceptorDescriptor) LifecycleCallbackDescriptor(com.sun.enterprise.deployment.LifecycleCallbackDescriptor)

Example 33 with EjbInterceptor

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

the class EjbContainerServicesImpl method isEjbManagedObject.

public boolean isEjbManagedObject(Object desc, Class c) {
    String className = c.getName();
    EjbDescriptor ejbDesc = (EjbDescriptor) desc;
    Set<String> ejbManagedObjectClassNames = new HashSet<String>();
    ejbManagedObjectClassNames.add(ejbDesc.getEjbClassName());
    for (EjbInterceptor next : ejbDesc.getInterceptorClasses()) {
        if (!next.isCDIInterceptor()) {
            ejbManagedObjectClassNames.add(next.getInterceptorClassName());
        }
    }
    Set<String> serializableClassNames = new HashSet<String>();
    for (String next : ejbManagedObjectClassNames) {
        // Add the serializable sub-class version of each name as well
        serializableClassNames.add(EJBUtils.getGeneratedSerializableClassName(next));
    }
    boolean isEjbManagedObject = ejbManagedObjectClassNames.contains(className) || serializableClassNames.contains(className);
    return isEjbManagedObject;
}
Also used : EjbInterceptor(com.sun.enterprise.deployment.EjbInterceptor) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor) HashSet(java.util.HashSet)

Example 34 with EjbInterceptor

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

the class LifecycleCallbackNode method getDescriptor.

@Override
public LifecycleCallbackDescriptor getDescriptor() {
    if (descriptor == null) {
        descriptor = new LifecycleCallbackDescriptor();
        Descriptor parentDesc = (Descriptor) getParentNode().getDescriptor();
        if (parentDesc instanceof EjbDescriptor) {
            EjbDescriptor ejbDesc = (EjbDescriptor) parentDesc;
            descriptor.setDefaultLifecycleCallbackClass(ejbDesc.getEjbClassName());
        } else if (parentDesc instanceof EjbInterceptor) {
            EjbInterceptor ejbInterceptor = (EjbInterceptor) parentDesc;
            descriptor.setDefaultLifecycleCallbackClass(ejbInterceptor.getInterceptorClassName());
        }
    // we set the default lifecycle callback class for appclient
    // later in validate since the appclient Main class is not
    // available at this point
    }
    return descriptor;
}
Also used : LifecycleCallbackDescriptor(com.sun.enterprise.deployment.LifecycleCallbackDescriptor) LifecycleCallbackDescriptor(com.sun.enterprise.deployment.LifecycleCallbackDescriptor) Descriptor(org.glassfish.deployment.common.Descriptor) EjbDescriptor(com.sun.enterprise.deployment.EjbDescriptor) EjbInterceptor(com.sun.enterprise.deployment.EjbInterceptor) EjbDescriptor(com.sun.enterprise.deployment.EjbDescriptor)

Aggregations

EjbInterceptor (com.sun.enterprise.deployment.EjbInterceptor)34 LifecycleCallbackDescriptor (com.sun.enterprise.deployment.LifecycleCallbackDescriptor)9 LinkedList (java.util.LinkedList)6 Method (java.lang.reflect.Method)5 HashSet (java.util.HashSet)5 EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)3 InterceptorDescriptor (com.sun.enterprise.deployment.InterceptorDescriptor)3 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)3 Result (com.sun.enterprise.tools.verifier.Result)3 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)3 ArrayList (java.util.ArrayList)3 EjbSessionDescriptor (org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)3 Descriptor (org.glassfish.deployment.common.Descriptor)2 Node (org.w3c.dom.Node)2 JCDIService (com.sun.enterprise.container.common.spi.JCDIService)1 BundleDescriptor (com.sun.enterprise.deployment.BundleDescriptor)1 EjbBundleDescriptor (com.sun.enterprise.deployment.EjbBundleDescriptor)1 EjbMessageBeanDescriptor (com.sun.enterprise.deployment.EjbMessageBeanDescriptor)1 EntityManagerFactoryReferenceDescriptor (com.sun.enterprise.deployment.EntityManagerFactoryReferenceDescriptor)1 EntityManagerReferenceDescriptor (com.sun.enterprise.deployment.EntityManagerReferenceDescriptor)1