Search in sources :

Example 1 with InterceptorBindingDescriptor

use of org.glassfish.ejb.deployment.descriptor.InterceptorBindingDescriptor in project Payara by payara.

the class InterceptorsHandler method processAnnotation.

protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, EjbContext[] ejbContexts) throws AnnotationProcessorException {
    Interceptors interceptors = (Interceptors) ainfo.getAnnotation();
    EjbBundleDescriptorImpl ejbBundle = ((EjbDescriptor) ejbContexts[0].getDescriptor()).getEjbBundleDescriptor();
    // Process each of the interceptor classes.
    for (Class interceptor : interceptors.value()) {
        processInterceptorClass(interceptor, ejbBundle, ainfo);
    }
    for (EjbContext next : ejbContexts) {
        EjbDescriptor ejbDescriptor = (EjbDescriptor) next.getDescriptor();
        // Create binding information.
        InterceptorBindingDescriptor binding = new InterceptorBindingDescriptor();
        binding.setEjbName(ejbDescriptor.getName());
        for (Class interceptor : interceptors.value()) {
            binding.appendInterceptorClass(interceptor.getName());
        }
        if (ElementType.METHOD.equals(ainfo.getElementType())) {
            Method m = (Method) ainfo.getAnnotatedElement();
            MethodDescriptor md = new MethodDescriptor(m, MethodDescriptor.EJB_BEAN);
            binding.setBusinessMethod(md);
        } else if (ElementType.CONSTRUCTOR.equals(ainfo.getElementType())) {
            Constructor c = (Constructor) ainfo.getAnnotatedElement();
            Class cl = c.getDeclaringClass();
            Class[] ctorParamTypes = c.getParameterTypes();
            String[] parameterClassNames = (new MethodDescriptor()).getParameterClassNamesFor(null, ctorParamTypes);
            MethodDescriptor md = new MethodDescriptor(cl.getSimpleName(), null, parameterClassNames, MethodDescriptor.EJB_BEAN);
            binding.setBusinessMethod(md);
        }
        // All binding information processed from annotations should go
        // before the binding information processed from the descriptors.
        // Since descriptors are processed first, always place the binding
        // info at the front.  The binding information from the descriptor
        // is ordered, but there is no prescribed order in which the
        // annotations are processed, so all that matters is that it's
        // before the descriptor bindings and that the descriptor binding
        // order is preserved.
        ejbBundle.prependInterceptorBinding(binding);
    }
    return getDefaultProcessedResult();
}
Also used : Interceptors(javax.interceptor.Interceptors) EjbContext(com.sun.enterprise.deployment.annotation.context.EjbContext) InterceptorBindingDescriptor(org.glassfish.ejb.deployment.descriptor.InterceptorBindingDescriptor) Constructor(java.lang.reflect.Constructor) Method(java.lang.reflect.Method) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor) EjbBundleDescriptorImpl(org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)

Example 2 with InterceptorBindingDescriptor

use of org.glassfish.ejb.deployment.descriptor.InterceptorBindingDescriptor in project Payara by payara.

the class ExcludeClassInterceptorsHandler method processAnnotation.

protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, EjbContext[] ejbContexts) throws AnnotationProcessorException {
    EjbBundleDescriptorImpl ejbBundle = ((EjbDescriptor) ejbContexts[0].getDescriptor()).getEjbBundleDescriptor();
    for (EjbContext next : ejbContexts) {
        EjbDescriptor ejbDescriptor = (EjbDescriptor) next.getDescriptor();
        // Create binding information.
        InterceptorBindingDescriptor binding = new InterceptorBindingDescriptor();
        binding.setEjbName(ejbDescriptor.getName());
        binding.setExcludeClassInterceptors(true);
        // Annotation can be defined at a method level or constructor level.
        MethodDescriptor md = null;
        if (ElementType.METHOD.equals(ainfo.getElementType())) {
            Method m = (Method) ainfo.getAnnotatedElement();
            md = new MethodDescriptor(m, MethodDescriptor.EJB_BEAN);
        } else if (ElementType.CONSTRUCTOR.equals(ainfo.getElementType())) {
            Constructor c = (Constructor) ainfo.getAnnotatedElement();
            Class cl = c.getDeclaringClass();
            Class[] ctorParamTypes = c.getParameterTypes();
            String[] parameterClassNames = (new MethodDescriptor()).getParameterClassNamesFor(null, ctorParamTypes);
            md = new MethodDescriptor(cl.getSimpleName(), null, parameterClassNames, MethodDescriptor.EJB_BEAN);
        }
        // else throw Exception?
        binding.setBusinessMethod(md);
        ejbBundle.prependInterceptorBinding(binding);
    }
    return getDefaultProcessedResult();
}
Also used : EjbContext(com.sun.enterprise.deployment.annotation.context.EjbContext) InterceptorBindingDescriptor(org.glassfish.ejb.deployment.descriptor.InterceptorBindingDescriptor) Constructor(java.lang.reflect.Constructor) Method(java.lang.reflect.Method) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor) EjbBundleDescriptorImpl(org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)

Example 3 with InterceptorBindingDescriptor

use of org.glassfish.ejb.deployment.descriptor.InterceptorBindingDescriptor in project Payara by payara.

the class InterceptorBindingNode method endElement.

/**
 * receives notification of the end of an XML element by the Parser
 *
 * @param element the xml tag identification
 * @return true if this node is done processing the XML sub tree
 */
@Override
public boolean endElement(XMLElement element) {
    if (EjbTagNames.INTERCEPTOR_ORDER.equals(element.getQName())) {
        InterceptorBindingDescriptor desc = getDescriptor();
        desc.setIsTotalOrdering(true);
    } else if (EjbTagNames.METHOD_PARAMS.equals(element.getQName())) {
        // which means this method has no input parameter
        if (businessMethod.getParameterClassNames() == null) {
            businessMethod.setEmptyParameterClassNames();
        }
    } else if (EjbTagNames.METHOD.equals(element.getQName())) {
        InterceptorBindingDescriptor bindingDesc = getDescriptor();
        businessMethod.setEjbClassSymbol(MethodDescriptor.EJB_BEAN);
        bindingDesc.setBusinessMethod(businessMethod);
        if (needsOverloadResolution) {
            bindingDesc.setNeedsOverloadResolution(true);
        }
        businessMethod = null;
        needsOverloadResolution = false;
    }
    return super.endElement(element);
}
Also used : InterceptorBindingDescriptor(org.glassfish.ejb.deployment.descriptor.InterceptorBindingDescriptor)

Example 4 with InterceptorBindingDescriptor

use of org.glassfish.ejb.deployment.descriptor.InterceptorBindingDescriptor in project Payara by payara.

the class EjbBundleValidator method handleOverloadedInterceptorMethodBindings.

private void handleOverloadedInterceptorMethodBindings(EjbBundleDescriptorImpl bundleDesc) {
    List<InterceptorBindingDescriptor> origBindings = bundleDesc.getInterceptorBindings();
    if (origBindings.isEmpty()) {
        return;
    }
    ClassLoader cl = bundleDesc.getClassLoader();
    List<InterceptorBindingDescriptor> newBindings = new LinkedList<InterceptorBindingDescriptor>();
    for (InterceptorBindingDescriptor next : origBindings) {
        if (next.getNeedsOverloadResolution()) {
            MethodDescriptor overloadedMethodDesc = next.getBusinessMethod();
            String methodName = overloadedMethodDesc.getName();
            // For method-specific interceptors, there must be an ejb-name.
            String ejbName = next.getEjbName();
            EjbDescriptor ejbDesc = bundleDesc.getEjbByName(ejbName);
            Class ejbClass = null;
            try {
                ejbClass = cl.loadClass(ejbDesc.getEjbClassName());
            } catch (Exception e) {
                RuntimeException re = new RuntimeException("Error loading ejb class " + ejbDesc.getEjbClassName());
                re.initCause(e);
                throw re;
            }
            boolean isMethod = false;
            for (Method ejbClassMethod : ejbClass.getDeclaredMethods()) {
                if (ejbClassMethod.getName().equals(methodName)) {
                    isMethod = true;
                    InterceptorBindingDescriptor newInterceptorBinding = new InterceptorBindingDescriptor();
                    MethodDescriptor newMethodDesc = new MethodDescriptor(ejbClassMethod, MethodDescriptor.EJB_BEAN);
                    newInterceptorBinding.setEjbName(ejbName);
                    newInterceptorBinding.setBusinessMethod(newMethodDesc);
                    for (String interceptorClass : next.getInterceptorClasses()) {
                        newInterceptorBinding.appendInterceptorClass(interceptorClass);
                    }
                    newInterceptorBinding.setIsTotalOrdering(next.getIsTotalOrdering());
                    newInterceptorBinding.setExcludeDefaultInterceptors(next.getExcludeDefaultInterceptors());
                    newInterceptorBinding.setExcludeClassInterceptors(next.getExcludeClassInterceptors());
                    newBindings.add(newInterceptorBinding);
                }
            }
            // check if it's a constructor
            if (!isMethod && methodName.equals(ejbClass.getSimpleName())) {
                // Constructor - will resolve via implicit comparison
                newBindings.add(next);
                continue;
            }
        } else {
            newBindings.add(next);
        }
    }
    bundleDesc.setInterceptorBindings(newBindings);
}
Also used : InterceptorBindingDescriptor(org.glassfish.ejb.deployment.descriptor.InterceptorBindingDescriptor) Method(java.lang.reflect.Method) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) LinkedList(java.util.LinkedList) DummyEjbDescriptor(org.glassfish.ejb.deployment.descriptor.DummyEjbDescriptor) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor)

Example 5 with InterceptorBindingDescriptor

use of org.glassfish.ejb.deployment.descriptor.InterceptorBindingDescriptor in project Payara by payara.

the class InterceptorBindingTranslator method apply.

public TranslationResults apply(String ejbName) {
    if (isEmpty) {
        return new TranslationResults();
    }
    defaultInterceptorChain.clear();
    classInterceptorChain.clear();
    hasTotalClassLevelOrdering = false;
    totalClassLevelOrdering.clear();
    methodInterceptorsMap.clear();
    // Do a pass through default interceptor bindings.
    for (InterceptorBindingDescriptor binding : interceptorBindings) {
        if (binding.getBindingType() == BindingType.DEFAULT) {
            defaultInterceptorChain.addAll(binding.getInterceptorClasses());
        }
    }
    // Do a pass through Class level bindings.
    for (InterceptorBindingDescriptor binding : interceptorBindings) {
        if (binding.getBindingType() == BindingType.CLASS) {
            if (binding.getEjbName().equals(ejbName)) {
                processClassLevelBinding(binding);
            }
        }
    }
    // Now do method-level bindings.
    Map<MethodDescriptor, List<InterceptorBindingDescriptor>> methodBindings = new HashMap<MethodDescriptor, List<InterceptorBindingDescriptor>>();
    // bindings.
    for (InterceptorBindingDescriptor binding : interceptorBindings) {
        if ((binding.getEjbName().equals(ejbName)) && (binding.getBindingType() == BindingType.METHOD)) {
            MethodDescriptor method = binding.getBusinessMethod();
            List<InterceptorBindingDescriptor> methodBindingDescs = methodBindings.get(method);
            if (methodBindingDescs == null) {
                methodBindingDescs = new LinkedList<InterceptorBindingDescriptor>();
            }
            methodBindingDescs.add(binding);
            methodBindings.put(method, methodBindingDescs);
        }
    }
    for (Map.Entry<MethodDescriptor, List<InterceptorBindingDescriptor>> next : methodBindings.entrySet()) {
        processMethod(next.getKey(), next.getValue());
    }
    TranslationResults results = buildResults();
    return results;
}
Also used : HashMap(java.util.HashMap) InterceptorBindingDescriptor(org.glassfish.ejb.deployment.descriptor.InterceptorBindingDescriptor) List(java.util.List) LinkedList(java.util.LinkedList) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

InterceptorBindingDescriptor (org.glassfish.ejb.deployment.descriptor.InterceptorBindingDescriptor)7 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)5 Method (java.lang.reflect.Method)4 EjbDescriptor (org.glassfish.ejb.deployment.descriptor.EjbDescriptor)4 EjbContext (com.sun.enterprise.deployment.annotation.context.EjbContext)3 Constructor (java.lang.reflect.Constructor)3 LinkedList (java.util.LinkedList)3 EjbBundleDescriptorImpl (org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)3 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Interceptors (javax.interceptor.Interceptors)1 DummyEjbDescriptor (org.glassfish.ejb.deployment.descriptor.DummyEjbDescriptor)1