Search in sources :

Example 1 with EjbInterceptor

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

the class InterceptorMethodTest method check.

public Result check(EjbDescriptor descriptor) {
    result = getInitializedResult();
    compName = getVerifierContext().getComponentNameConstructor();
    testInterceptorMethods(descriptor.getAroundInvokeDescriptors(), "AroundInvoke", true);
    testInterceptorMethods(descriptor.getPreDestroyDescriptors(), "PreDestroy", true);
    testInterceptorMethods(descriptor.getPostConstructDescriptors(), "PostConstruct", true);
    if (descriptor instanceof EjbSessionDescriptor) {
        EjbSessionDescriptor sessionDescriptor = (EjbSessionDescriptor) descriptor;
        testInterceptorMethods(sessionDescriptor.getPrePassivateDescriptors(), "PrePassivate", true);
        testInterceptorMethods(sessionDescriptor.getPostActivateDescriptors(), "PostActivate", true);
    }
    descriptor.getInterceptorClasses();
    for (EjbInterceptor interceptor : descriptor.getInterceptorClasses()) {
        testInterceptorMethods(interceptor.getAroundInvokeDescriptors(), "AroundInvoke", false);
        testInterceptorMethods(interceptor.getPreDestroyDescriptors(), "PreDestroy", false);
        testInterceptorMethods(interceptor.getPostConstructDescriptors(), "PostConstruct", false);
        testInterceptorMethods(interceptor.getCallbackDescriptors(LifecycleCallbackDescriptor.CallbackType.PRE_PASSIVATE), "PrePassivate", false);
        testInterceptorMethods(interceptor.getCallbackDescriptors(LifecycleCallbackDescriptor.CallbackType.POST_ACTIVATE), "PostActivate", false);
    }
    if (result.getStatus() != Result.FAILED) {
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.ejb30.InterceptorMethodTest.passed", "Valid Interceptor methods."));
    }
    return result;
}
Also used : EjbInterceptor(com.sun.enterprise.deployment.EjbInterceptor) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)

Example 2 with EjbInterceptor

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

the class EjbBundleNode method writeDescriptor.

@Override
public Node writeDescriptor(Node parent, EjbBundleDescriptorImpl ejbDesc) {
    Node jarNode = super.writeDescriptor(parent, ejbDesc);
    Node entrepriseBeansNode = appendChild(jarNode, EjbTagNames.EJBS);
    for (EjbDescriptor ejb : ejbDesc.getEjbs()) {
        if (EjbSessionDescriptor.TYPE.equals(ejb.getType())) {
            EjbSessionNode subNode = new EjbSessionNode();
            subNode.writeDescriptor(entrepriseBeansNode, EjbTagNames.SESSION, (EjbSessionDescriptor) ejb);
        } else if (EjbEntityDescriptor.TYPE.equals(ejb.getType())) {
            EjbEntityNode subNode = new EjbEntityNode();
            subNode.writeDescriptor(entrepriseBeansNode, EjbTagNames.ENTITY, (EjbEntityDescriptor) ejb);
        } else if (EjbMessageBeanDescriptor.TYPE.equals(ejb.getType())) {
            MessageDrivenBeanNode subNode = new MessageDrivenBeanNode();
            subNode.writeDescriptor(entrepriseBeansNode, EjbTagNames.MESSAGE_DRIVEN, (EjbMessageBeanDescriptor) ejb);
        } else {
            throw new IllegalStateException("Unknown ejb type " + ejb.getType());
        }
    }
    if (ejbDesc.hasInterceptors()) {
        Node interceptorsNode = appendChild(jarNode, EjbTagNames.INTERCEPTORS);
        EjbInterceptorNode interceptorNode = new EjbInterceptorNode();
        for (EjbInterceptor next : ejbDesc.getInterceptors()) {
            interceptorNode.writeDescriptor(interceptorsNode, EjbTagNames.INTERCEPTOR, next);
        }
    }
    // relationships*
    if (ejbDesc.hasRelationships()) {
        (new RelationshipsNode()).writeDescriptor(jarNode, EjbTagNames.RELATIONSHIPS, ejbDesc);
    }
    // assembly-descriptor
    writeAssemblyDescriptor(jarNode, ejbDesc);
    appendTextChild(jarNode, EjbTagNames.EJB_CLIENT_JAR, ejbDesc.getEjbClientJarUri());
    return jarNode;
}
Also used : GFEjbBundleRuntimeNode(org.glassfish.ejb.deployment.node.runtime.GFEjbBundleRuntimeNode) EjbBundleRuntimeNode(org.glassfish.ejb.deployment.node.runtime.EjbBundleRuntimeNode) Node(org.w3c.dom.Node) EjbInterceptor(com.sun.enterprise.deployment.EjbInterceptor)

Example 3 with EjbInterceptor

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

the class EjbBundleValidator method getAllPrePassivatePostActivateCallbackInfo.

private String getAllPrePassivatePostActivateCallbackInfo(EjbSessionDescriptor sessionDesc) {
    List<LifecycleCallbackDescriptor> descriptors = new ArrayList<LifecycleCallbackDescriptor>();
    descriptors.addAll(sessionDesc.getPrePassivateDescriptors());
    descriptors.addAll(sessionDesc.getPostActivateDescriptors());
    for (EjbInterceptor interceptor : sessionDesc.getInterceptorClasses()) {
        descriptors.addAll(interceptor.getCallbackDescriptors(LifecycleCallbackDescriptor.CallbackType.PRE_PASSIVATE));
        descriptors.addAll(interceptor.getCallbackDescriptors(LifecycleCallbackDescriptor.CallbackType.POST_ACTIVATE));
    }
    StringBuilder result = new StringBuilder();
    for (LifecycleCallbackDescriptor each : descriptors) {
        result.append(each.getLifecycleCallbackClass());
        result.append(".");
        result.append(each.getLifecycleCallbackMethod());
        result.append(", ");
    }
    if (result.length() > 2) {
        return result.substring(0, result.length() - 2);
    } else {
        return result.toString();
    }
}
Also used : LifecycleCallbackDescriptor(com.sun.enterprise.deployment.LifecycleCallbackDescriptor) ArrayList(java.util.ArrayList) EjbInterceptor(com.sun.enterprise.deployment.EjbInterceptor)

Example 4 with EjbInterceptor

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

the class InterceptorBindingTranslator method buildResults.

private TranslationResults buildResults() {
    TranslationResults results = new TranslationResults();
    if (hasTotalClassLevelOrdering) {
        for (String next : totalClassLevelOrdering) {
            EjbInterceptor interceptor = ejbBundle.getInterceptorByClassName(next);
            results.allInterceptorClasses.add(interceptor);
            results.classInterceptorChain.add(interceptor);
        }
    } else {
        for (String next : defaultInterceptorChain) {
            EjbInterceptor interceptor = ejbBundle.getInterceptorByClassName(next);
            results.allInterceptorClasses.add(interceptor);
            results.classInterceptorChain.add(interceptor);
        }
        for (String next : classInterceptorChain) {
            EjbInterceptor interceptor = ejbBundle.getInterceptorByClassName(next);
            results.allInterceptorClasses.add(interceptor);
            results.classInterceptorChain.add(interceptor);
        }
    }
    for (MethodDescriptor nextMethod : methodInterceptorsMap.keySet()) {
        List<String> interceptorClassChain = (List<String>) methodInterceptorsMap.get(nextMethod);
        List<EjbInterceptor> interceptorChain = new LinkedList<EjbInterceptor>();
        for (String nextClass : interceptorClassChain) {
            EjbInterceptor interceptor = ejbBundle.getInterceptorByClassName(nextClass);
            results.allInterceptorClasses.add(interceptor);
            interceptorChain.add(interceptor);
        }
        results.methodInterceptorsMap.put(nextMethod, interceptorChain);
    }
    return results;
}
Also used : EjbInterceptor(com.sun.enterprise.deployment.EjbInterceptor) List(java.util.List) LinkedList(java.util.LinkedList) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) LinkedList(java.util.LinkedList)

Example 5 with EjbInterceptor

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