Search in sources :

Example 1 with Remove

use of javax.ejb.Remove in project tomee by apache.

the class CdiEjbBean method findRemove.

private List<Method> findRemove(final Class<?> beanClass, final Class<?> beanInterface) {
    final List<Method> toReturn = new ArrayList<>();
    // Get all the public methods of the bean class and super class
    final Method[] methods = beanClass.getMethods();
    // Search for methods annotated with @Remove
    for (final Method method : methods) {
        final Remove annotation = method.getAnnotation(Remove.class);
        if (annotation != null) {
            // Get the corresponding method into the bean interface
            final Method interfaceMethod;
            try {
                interfaceMethod = beanInterface.getMethod(method.getName(), method.getParameterTypes());
                toReturn.add(interfaceMethod);
            } catch (final SecurityException e) {
                e.printStackTrace();
            } catch (final NoSuchMethodException e) {
            // The method can not be into the interface in which case we
            // don't wonder of
            }
        }
    }
    return toReturn;
}
Also used : ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) AnnotatedMethod(javax.enterprise.inject.spi.AnnotatedMethod) Remove(javax.ejb.Remove)

Example 2 with Remove

use of javax.ejb.Remove in project Payara by payara.

the class RemoveHandler method processAnnotation.

protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, EjbContext[] ejbContexts) throws AnnotationProcessorException {
    Remove remove = (Remove) ainfo.getAnnotation();
    for (EjbContext next : ejbContexts) {
        EjbSessionDescriptor sessionDescriptor = (EjbSessionDescriptor) next.getDescriptor();
        Method m = (Method) ainfo.getAnnotatedElement();
        MethodDescriptor removeMethod = new MethodDescriptor(m, MethodDescriptor.EJB_BEAN);
        EjbRemovalInfo removalInfo = sessionDescriptor.getRemovalInfo(removeMethod);
        if (removalInfo == null) {
            // if this element is not defined in xml
            // use all information from annotation
            removalInfo = new EjbRemovalInfo();
            removalInfo.setRemoveMethod(removeMethod);
            removalInfo.setRetainIfException(remove.retainIfException());
            sessionDescriptor.addRemoveMethod(removalInfo);
        } else {
            // is not defined in xml
            if (!removalInfo.isRetainIfExceptionSet()) {
                removalInfo.setRetainIfException(remove.retainIfException());
            }
        }
    }
    return getDefaultProcessedResult();
}
Also used : EjbContext(com.sun.enterprise.deployment.annotation.context.EjbContext) EjbRemovalInfo(org.glassfish.ejb.deployment.descriptor.EjbRemovalInfo) Remove(javax.ejb.Remove) Method(java.lang.reflect.Method) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor)

Aggregations

Method (java.lang.reflect.Method)2 Remove (javax.ejb.Remove)2 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)1 EjbContext (com.sun.enterprise.deployment.annotation.context.EjbContext)1 ArrayList (java.util.ArrayList)1 AnnotatedMethod (javax.enterprise.inject.spi.AnnotatedMethod)1 EjbRemovalInfo (org.glassfish.ejb.deployment.descriptor.EjbRemovalInfo)1 EjbSessionDescriptor (org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)1