Search in sources :

Example 36 with MethodDescriptor

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

the class EjbDescriptor method getConstructorInterceptors.

/**
 * Return bean constructor for AroundConstruct interceptors
 */
private List<EjbInterceptor> getConstructorInterceptors(ClassLoader classLoader) {
    List<EjbInterceptor> callbackInterceptors = null;
    String shortClassName = ejbClassName;
    int i = ejbClassName.lastIndexOf('.');
    if (i > -1) {
        shortClassName = ejbClassName.substring(i + 1);
    }
    JCDIService jcdiService = (sl == null) ? null : sl.getService(JCDIService.class);
    if (jcdiService != null && jcdiService.isJCDIEnabled(getEjbBundleDescriptor())) {
        try {
            Class<?> beanClass = classLoader.loadClass(getEjbClassName());
            Constructor<?>[] ctors = beanClass.getDeclaredConstructors();
            String[] parameterClassNames = null;
            MethodDescriptor dummy = new MethodDescriptor();
            for (Constructor<?> ctor : ctors) {
                if (ctor.getAnnotation(Inject.class) != null) {
                    // @Inject constructor
                    Class<?>[] ctorParamTypes = ctor.getParameterTypes();
                    parameterClassNames = dummy.getParameterClassNamesFor(null, ctorParamTypes);
                    callbackInterceptors = getClassOrMethodInterceptors(new MethodDescriptor(shortClassName, null, parameterClassNames, MethodDescriptor.EJB_BEAN));
                    break;
                }
            }
        } catch (Throwable t) {
            _logger.log(Level.SEVERE, "enterprise.deployment.backend.methodClassLoadFailure", new Object[] { this.getEjbClassName() });
            throw new RuntimeException(t);
        }
    }
    if (callbackInterceptors == null) {
        // non-CDI or no @Inject constructor - use no-arg constructor
        callbackInterceptors = getClassOrMethodInterceptors(new MethodDescriptor(shortClassName, null, new String[0], MethodDescriptor.EJB_BEAN));
    }
    return callbackInterceptors;
}
Also used : Inject(javax.inject.Inject) JCDIService(com.sun.enterprise.container.common.spi.JCDIService) Constructor(java.lang.reflect.Constructor) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor)

Example 37 with MethodDescriptor

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

the class EjbDescriptor method getContainerTransaction.

/**
 * returns a ContainerTransaction if all the transactional methods on the ejb descriptor have the same transaction type
 * else return null
 *
 * @return
 */
public ContainerTransaction getContainerTransaction() {
    Vector<MethodDescriptor> transactionalMethods = new Vector<>(getTransactionMethodDescriptors());
    MethodDescriptor md = transactionalMethods.firstElement();
    if (md != null) {
        ContainerTransaction first = getContainerTransactionFor(md);
        for (Enumeration<MethodDescriptor> e = transactionalMethods.elements(); e.hasMoreElements(); ) {
            MethodDescriptor next = e.nextElement();
            ContainerTransaction nextCt = this.getContainerTransactionFor(next);
            if (nextCt != null && !nextCt.equals(first)) {
                return null;
            }
        }
        return first;
    }
    return null;
}
Also used : MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor)

Example 38 with MethodDescriptor

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

the class EjbDescriptor method convertMethodContainerTransactionsOfStyle.

private void convertMethodContainerTransactionsOfStyle(int requestedStyleForConversion, Hashtable<MethodDescriptor, ContainerTransaction> convertedMethods) {
    Collection<MethodDescriptor> transactionMethods = this.getTransactionMethodDescriptors();
    Hashtable<MethodDescriptor, ContainerTransaction> transactions = getMethodContainerTransactions();
    for (Enumeration<MethodDescriptor> e = transactions.keys(); e.hasMoreElements(); ) {
        MethodDescriptor md = e.nextElement();
        if (md.getStyle() == requestedStyleForConversion) {
            ContainerTransaction ct = getMethodContainerTransactions().get(md);
            for (Enumeration<MethodDescriptor> mds = md.doStyleConversion(this, transactionMethods).elements(); mds.hasMoreElements(); ) {
                MethodDescriptor next = mds.nextElement();
                convertedMethods.put(next, new ContainerTransaction(ct));
            }
        }
    }
}
Also used : MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor)

Example 39 with MethodDescriptor

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

the class TransactionAttributeHandler 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 {
    EjbDescriptor ejbDesc = (EjbDescriptor) ejbContext.getDescriptor();
    TransactionAttribute taAn = (TransactionAttribute) ainfo.getAnnotation();
    ContainerTransaction containerTransaction = getContainerTransaction(taAn.value());
    Class classAn = (Class) ainfo.getAnnotatedElement();
    Set txBusMethods = ejbDesc.getTxBusinessMethodDescriptors();
    for (Object mdObj : txBusMethods) {
        MethodDescriptor md = (MethodDescriptor) mdObj;
        // override by xml
        if (classAn.equals(ejbContext.getDeclaringClass(md)) && ejbDesc.getContainerTransactionFor(md) == null) {
            ejbDesc.setContainerTransactionFor(md, containerTransaction);
        }
    }
}
Also used : Set(java.util.Set) TransactionAttribute(javax.ejb.TransactionAttribute) ContainerTransaction(org.glassfish.ejb.deployment.descriptor.ContainerTransaction) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor)

Example 40 with MethodDescriptor

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

the class AccessTimeoutHandler method matchesExistingAccessTimeoutMethod.

private boolean matchesExistingAccessTimeoutMethod(Method methodToMatch, EjbSessionDescriptor desc) {
    List<MethodDescriptor> timeoutMethods = desc.getAccessTimeoutMethods();
    boolean match = false;
    for (MethodDescriptor next : timeoutMethods) {
        Method m = next.getMethod(desc);
        if ((m.getDeclaringClass().equals(methodToMatch.getDeclaringClass())) && TypeUtil.sameMethodSignature(m, methodToMatch)) {
            match = true;
            break;
        }
    }
    return match;
}
Also used : Method(java.lang.reflect.Method) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor)

Aggregations

MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)108 Method (java.lang.reflect.Method)42 EjbSessionDescriptor (org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)26 Iterator (java.util.Iterator)21 ContainerTransaction (org.glassfish.ejb.deployment.descriptor.ContainerTransaction)17 Enumeration (java.util.Enumeration)14 Set (java.util.Set)14 ArrayList (java.util.ArrayList)13 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)11 EjbDescriptor (org.glassfish.ejb.deployment.descriptor.EjbDescriptor)11 EjbContext (com.sun.enterprise.deployment.annotation.context.EjbContext)10 Result (com.sun.enterprise.tools.verifier.Result)9 MethodPermission (com.sun.enterprise.deployment.MethodPermission)8 MethodNode (com.sun.enterprise.deployment.node.MethodNode)7 EjbEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor)7 Node (org.w3c.dom.Node)7 List (java.util.List)6 ScheduledTimerDescriptor (org.glassfish.ejb.deployment.descriptor.ScheduledTimerDescriptor)6 DeploymentDescriptorNode (com.sun.enterprise.deployment.node.DeploymentDescriptorNode)5 HashMap (java.util.HashMap)5