Search in sources :

Example 56 with MethodDescriptor

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

Example 57 with MethodDescriptor

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

the class AccessTimeoutHandler method postProcessAnnotation.

/**
 * Set the default value (from class type annotation) on all
 * methods that don't have a value.
 */
public void postProcessAnnotation(AnnotationInfo ainfo, EjbContext ejbContext) throws AnnotationProcessorException {
    EjbSessionDescriptor ejbDesc = (EjbSessionDescriptor) ejbContext.getDescriptor();
    // At this point, all method-level specific annotations have been processed.
    // For non-private methods, find the ones from the EjbContext's
    // component definition view that are declared on this class.  This will correctly
    // eliminate any overridden methods and provide the most-derived version of each.
    // Use the Class's declared methods list to get the private methods.
    Class classAn = (Class) ainfo.getAnnotatedElement();
    AccessTimeout timeoutAnn = (AccessTimeout) ainfo.getAnnotation();
    List<Method> toProcess = new ArrayList<Method>();
    for (Method m : ejbContext.getComponentDefinitionMethods()) {
        if (classAn.equals(m.getDeclaringClass())) {
            toProcess.add(m);
        }
    }
    for (Method m : classAn.getDeclaredMethods()) {
        if (Modifier.isPrivate(m.getModifiers())) {
            toProcess.add(m);
        }
    }
    for (Method m : toProcess) {
        // descriptor, set it.
        if (!matchesExistingAccessTimeoutMethod(m, ejbDesc)) {
            MethodDescriptor newMethodDesc = new MethodDescriptor(m);
            ejbDesc.addAccessTimeoutMethod(newMethodDesc, timeoutAnn.value(), timeoutAnn.unit());
        }
    }
}
Also used : AccessTimeout(javax.ejb.AccessTimeout) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor)

Example 58 with MethodDescriptor

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

the class AsynchronousHandler method setAsynchronous.

/**
 * Designate a method as asynchronous in the deployment descriptor
 * @param methodIntf  null if processed on bean class / superclass.  Otherwise,
 *                    set to the remote/local client view of the associated interface
 * @throws AnnotationProcessorException
 */
private void setAsynchronous(Method m0, EjbDescriptor ejbDesc, String methodIntf) throws AnnotationProcessorException {
    if (!ejbDesc.getType().equals(EjbSessionDescriptor.TYPE)) {
        throw new AnnotationProcessorException("Invalid asynchronous method " + m0 + "@Asynchronous is only permitted for session beans");
    }
    EjbSessionDescriptor sessionDesc = (EjbSessionDescriptor) ejbDesc;
    MethodDescriptor methodDesc = (methodIntf == null) ? new MethodDescriptor(m0) : new MethodDescriptor(m0, methodIntf);
    if (logger.isLoggable(Level.FINE)) {
        logger.fine("Adding asynchronous method " + methodDesc);
    }
    // There is no way to "turn off" the asynchronous designation in the
    // deployment descriptor, so we don't need to do any override checks
    // here.  Just always add any async methods.
    sessionDesc.addAsynchronousMethod(methodDesc);
}
Also used : AnnotationProcessorException(org.glassfish.apf.AnnotationProcessorException) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor)

Example 59 with MethodDescriptor

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

the class ExcludeDefaultInterceptorsHandler 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.setExcludeDefaultInterceptors(true);
        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);
        }
        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 60 with MethodDescriptor

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

the class InitHandler method addInitMethod.

private void addInitMethod(EjbSessionDescriptor descriptor, Method beanMethod, String adaptedCreateMethodName, boolean local) throws Exception {
    String homeIntfName = local ? descriptor.getLocalHomeClassName() : descriptor.getHomeClassName();
    ClassLoader cl = descriptor.getEjbBundleDescriptor().getClassLoader();
    Class homeIntf = cl.loadClass(homeIntfName);
    Method createMethod = null;
    if ((adaptedCreateMethodName == null) || (adaptedCreateMethodName.equals(""))) {
        // signature.
        for (Method next : homeIntf.getMethods()) {
            if (next.getName().startsWith("create") && TypeUtil.sameParamTypes(next, beanMethod)) {
                createMethod = next;
                break;
            }
        }
        if (createMethod == null) {
            throw new NoSuchMethodException("No matching adapted home " + "method found for @Init " + " method " + beanMethod);
        }
    } else {
        createMethod = homeIntf.getMethod(adaptedCreateMethodName, beanMethod.getParameterTypes());
    }
    MethodDescriptor beanMethodDescriptor = new MethodDescriptor(beanMethod, MethodDescriptor.EJB_BEAN);
    MethodDescriptor createMethodDescriptor = new MethodDescriptor(createMethod, (local ? MethodDescriptor.EJB_HOME : MethodDescriptor.EJB_LOCALHOME));
    EjbInitInfo initInfo = new EjbInitInfo();
    initInfo.setBeanMethod(beanMethodDescriptor);
    initInfo.setCreateMethod(createMethodDescriptor);
    descriptor.addInitMethod(initInfo);
}
Also used : Method(java.lang.reflect.Method) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) EjbInitInfo(org.glassfish.ejb.deployment.descriptor.EjbInitInfo)

Aggregations

MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)97 Method (java.lang.reflect.Method)37 Iterator (java.util.Iterator)25 EjbSessionDescriptor (org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)23 Set (java.util.Set)18 ContainerTransaction (org.glassfish.ejb.deployment.descriptor.ContainerTransaction)17 Enumeration (java.util.Enumeration)16 ArrayList (java.util.ArrayList)12 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)11 MethodPermission (com.sun.enterprise.deployment.MethodPermission)10 EjbContext (com.sun.enterprise.deployment.annotation.context.EjbContext)10 EjbDescriptor (org.glassfish.ejb.deployment.descriptor.EjbDescriptor)10 Result (com.sun.enterprise.tools.verifier.Result)9 HashSet (java.util.HashSet)9 Vector (java.util.Vector)7 EjbEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor)7 MethodNode (com.sun.enterprise.deployment.node.MethodNode)6 Collection (java.util.Collection)6 HashMap (java.util.HashMap)6 ScheduledTimerDescriptor (org.glassfish.ejb.deployment.descriptor.ScheduledTimerDescriptor)6