Search in sources :

Example 31 with LifecycleCallbackDescriptor

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

the class EjbSessionDescriptor method addPrePassivateDescriptor.

public void addPrePassivateDescriptor(LifecycleCallbackDescriptor prePassivateDesc) {
    String className = prePassivateDesc.getLifecycleCallbackClass();
    boolean found = false;
    for (LifecycleCallbackDescriptor next : getPrePassivateDescriptors()) {
        if (next.getLifecycleCallbackClass().equals(className)) {
            found = true;
            break;
        }
    }
    if (!found) {
        getPrePassivateDescriptors().add(prePassivateDesc);
    }
}
Also used : LifecycleCallbackDescriptor(com.sun.enterprise.deployment.LifecycleCallbackDescriptor)

Example 32 with LifecycleCallbackDescriptor

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

the class CallbackMethodException method check.

public Result check(EjbDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    ClassLoader cl = getVerifierContext().getClassLoader();
    Set<LifecycleCallbackDescriptor> callbackDescs = new HashSet<LifecycleCallbackDescriptor>();
    for (EjbInterceptor interceptor : descriptor.getInterceptorClasses()) {
        callbackDescs.addAll(interceptor.getPostConstructDescriptors());
        callbackDescs.addAll(interceptor.getPreDestroyDescriptors());
        callbackDescs.addAll(interceptor.getCallbackDescriptors(LifecycleCallbackDescriptor.CallbackType.PRE_PASSIVATE));
        callbackDescs.addAll(interceptor.getCallbackDescriptors(LifecycleCallbackDescriptor.CallbackType.POST_ACTIVATE));
    }
    if (descriptor.hasPostConstructMethod())
        callbackDescs.addAll(descriptor.getPostConstructDescriptors());
    if (descriptor.hasPreDestroyMethod())
        callbackDescs.addAll(descriptor.getPreDestroyDescriptors());
    // session descriptor has two extra interceptor methods.
    if (descriptor instanceof EjbSessionDescriptor) {
        EjbSessionDescriptor ejbSessionDescriptor = ((EjbSessionDescriptor) descriptor);
        if (ejbSessionDescriptor.hasPostActivateMethod())
            callbackDescs.addAll(ejbSessionDescriptor.getPostActivateDescriptors());
        if (ejbSessionDescriptor.hasPrePassivateMethod())
            callbackDescs.addAll(ejbSessionDescriptor.getPrePassivateDescriptors());
    }
    for (LifecycleCallbackDescriptor callbackDesc : callbackDescs) {
        try {
            Method method = callbackDesc.getLifecycleCallbackMethodObject(cl);
            Class[] excepClasses = method.getExceptionTypes();
            for (Class exception : excepClasses) {
                if (!(RuntimeException.class.isAssignableFrom(exception) || java.rmi.RemoteException.class.isAssignableFrom(exception))) {
                    addErrorDetails(result, compName);
                    result.failed(smh.getLocalString(getClass().getName() + ".failed", "Method [ {0} ] throws an application exception.", new Object[] { method }));
                }
            }
        }// will be caught in other tests
         catch (Exception e) {
        }
    }
    if (result.getStatus() != Result.FAILED) {
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "Valid Callback methods."));
    }
    return result;
}
Also used : EjbInterceptor(com.sun.enterprise.deployment.EjbInterceptor) Method(java.lang.reflect.Method) Result(com.sun.enterprise.tools.verifier.Result) LifecycleCallbackDescriptor(com.sun.enterprise.deployment.LifecycleCallbackDescriptor) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) HashSet(java.util.HashSet)

Example 33 with LifecycleCallbackDescriptor

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

the class CallbacksOnBeanClass method check.

public Result check(EjbDescriptor descriptor) {
    result = getInitializedResult();
    compName = getVerifierContext().getComponentNameConstructor();
    Set<EjbInterceptor> interceptors = descriptor.getInterceptorClasses();
    for (EjbInterceptor interceptor : interceptors) {
        if (interceptor.hasCallbackDescriptor(LifecycleCallbackDescriptor.CallbackType.POST_ACTIVATE)) {
            Set<LifecycleCallbackDescriptor> callBackDescs = interceptor.getCallbackDescriptors(LifecycleCallbackDescriptor.CallbackType.POST_ACTIVATE);
            reportError(callBackDescs, "ejbActivate", interceptor.getInterceptorClassName());
        }
        if (interceptor.hasCallbackDescriptor(LifecycleCallbackDescriptor.CallbackType.PRE_PASSIVATE)) {
            Set<LifecycleCallbackDescriptor> callBackDescs = interceptor.getCallbackDescriptors(LifecycleCallbackDescriptor.CallbackType.PRE_PASSIVATE);
            reportError(callBackDescs, "ejbPassivate", interceptor.getInterceptorClassName());
        }
        if (interceptor.hasCallbackDescriptor(LifecycleCallbackDescriptor.CallbackType.POST_CONSTRUCT)) {
            Set<LifecycleCallbackDescriptor> callBackDescs = interceptor.getCallbackDescriptors(LifecycleCallbackDescriptor.CallbackType.POST_CONSTRUCT);
            reportError(callBackDescs, "ejbCreate", interceptor.getInterceptorClassName());
        }
        if (interceptor.hasCallbackDescriptor(LifecycleCallbackDescriptor.CallbackType.PRE_DESTROY)) {
            Set<LifecycleCallbackDescriptor> callBackDescs = interceptor.getCallbackDescriptors(LifecycleCallbackDescriptor.CallbackType.PRE_DESTROY);
            reportError(callBackDescs, "ejbRemove", interceptor.getInterceptorClassName());
        }
    }
    if (result.getStatus() != Result.FAILED) {
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "Valid lifecycle callback method(s)"));
    }
    return result;
}
Also used : LifecycleCallbackDescriptor(com.sun.enterprise.deployment.LifecycleCallbackDescriptor) EjbInterceptor(com.sun.enterprise.deployment.EjbInterceptor)

Example 34 with LifecycleCallbackDescriptor

use of com.sun.enterprise.deployment.LifecycleCallbackDescriptor 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 35 with LifecycleCallbackDescriptor

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

the class BeanCallbackInterceptor method createCallbackInterceptors.

private List<CallbackInterceptor> createCallbackInterceptors(CallbackType eventType, InterceptorDescriptor inter, ClassLoader classLoaderToUse) throws Exception {
    List<CallbackInterceptor> callbackList = new ArrayList<CallbackInterceptor>();
    List<LifecycleCallbackDescriptor> orderedCallbackMethods = inter.getOrderedCallbackDescriptors(eventType, classLoaderToUse);
    String className = inter.getInterceptorClassName();
    for (LifecycleCallbackDescriptor callbackDesc : orderedCallbackMethods) {
        Method method = null;
        try {
            method = callbackDesc.getLifecycleCallbackMethodObject(classLoaderToUse);
        } catch (Exception e) {
            throw new IllegalStateException("No callback method of name " + callbackDesc.getLifecycleCallbackMethod() + " found on class " + className, e);
        }
        CallbackInterceptor interceptor = null;
        if (inter.getFromBeanClass()) {
            interceptor = new BeanCallbackInterceptor(method);
        } else {
            Integer bigInt = instanceIndexMap.get(className);
            int index = (bigInt == null) ? -1 : bigInt;
            if (index == -1) {
                throw new IllegalStateException(getInternalErrorString(className));
            }
            interceptor = new CallbackInterceptor(index, method);
        }
        callbackList.add(interceptor);
    }
    return callbackList;
}
Also used : LifecycleCallbackDescriptor(com.sun.enterprise.deployment.LifecycleCallbackDescriptor) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) EJBException(javax.ejb.EJBException)

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