Search in sources :

Example 16 with MethodDescriptor

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

the class EjbDescriptorImpl method getRemoveMethods.

/**
 * Get the remove methods of the EJB
 *
 * @return An iterator over the remove methods
 */
@Override
public Collection<Method> getRemoveMethods() {
    Set<Method> removeMethods = new HashSet<Method>();
    if (ejbDesc.getType().equals(EjbSessionDescriptor.TYPE)) {
        EjbSessionDescriptor sessionDesc = (EjbSessionDescriptor) ejbDesc;
        if (sessionDesc.isStateful() && sessionDesc.hasRemoveMethods()) {
            for (MethodDescriptor mDesc : sessionDesc.getRemoveMethodDescriptors()) {
                Method m = mDesc.getMethod(ejbDesc);
                if (m == null) {
                    throw new IllegalStateException("Can't resolve remove method " + mDesc + " For EJB " + sessionDesc.getName());
                }
                removeMethods.add(m);
            }
        }
    }
    return removeMethods;
}
Also used : Method(java.lang.reflect.Method) EjbSessionDescriptor(com.sun.enterprise.deployment.EjbSessionDescriptor) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) HashSet(java.util.HashSet)

Example 17 with MethodDescriptor

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

the class SafeProperties method setInterceptorChain.

private void setInterceptorChain(InvocationInfo info) {
    if (info.aroundMethod != null) {
        if (info.isEjbTimeout) {
            MethodDescriptor md = new MethodDescriptor(info.aroundMethod, MethodDescriptor.TIMER_METHOD);
            info.interceptorChain = interceptorManager.getAroundTimeoutChain(md, info.aroundMethod);
        } else {
            MethodDescriptor md = new MethodDescriptor(info.aroundMethod, MethodDescriptor.EJB_BEAN);
            info.interceptorChain = interceptorManager.getAroundInvokeChain(md, info.aroundMethod);
        }
    }
}
Also used : MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor)

Example 18 with MethodDescriptor

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

the class SafeProperties method setConcurrencyInvInfo.

private void setConcurrencyInvInfo(Method invInfoMethod, String methodIntf, InvocationInfo invInfo) {
    MethodLockInfo lockInfo = null;
    // Set READ/WRITE lock info.  Only applies to singleton beans.
    if (isSingleton) {
        EjbSessionDescriptor singletonDesc = (EjbSessionDescriptor) ejbDescriptor;
        List<MethodDescriptor> readLockMethods = singletonDesc.getReadLockMethods();
        List<MethodDescriptor> writeLockMethods = singletonDesc.getWriteLockMethods();
        DistributedLockType distLockType = singletonDesc.isClustered() ? singletonDesc.getClusteredLockType() : DistributedLockType.LOCK_NONE;
        for (MethodDescriptor readLockMethodDesc : readLockMethods) {
            Method readLockMethod = readLockMethodDesc.getMethod(singletonDesc);
            if (implMethodMatchesInvInfoMethod(invInfoMethod, methodIntf, readLockMethod)) {
                lockInfo = new MethodLockInfo();
                switch(distLockType) {
                    case INHERIT:
                        {
                            _logger.log(Level.WARNING, "Distributed Read Lock for Method {0} Upgraded to Read/Write", readLockMethod.getName());
                            lockInfo.setLockType(LockType.WRITE, true);
                            break;
                        }
                    case LOCK_NONE:
                        {
                            lockInfo.setLockType(LockType.READ, false);
                        }
                }
                break;
            }
        }
        if (lockInfo == null) {
            for (MethodDescriptor writeLockMethodDesc : writeLockMethods) {
                Method writeLockMethod = writeLockMethodDesc.getMethod(singletonDesc);
                if (implMethodMatchesInvInfoMethod(invInfoMethod, methodIntf, writeLockMethod)) {
                    lockInfo = new MethodLockInfo();
                    lockInfo.setLockType(LockType.WRITE, distLockType != DistributedLockType.LOCK_NONE);
                    break;
                }
            }
        }
    }
    // Set AccessTimeout info
    if (isSingleton || isStatefulSession) {
        EjbSessionDescriptor sessionDesc = (EjbSessionDescriptor) ejbDescriptor;
        List<EjbSessionDescriptor.AccessTimeoutHolder> accessTimeoutInfo = sessionDesc.getAccessTimeoutInfo();
        for (EjbSessionDescriptor.AccessTimeoutHolder accessTimeoutHolder : accessTimeoutInfo) {
            MethodDescriptor accessTimeoutMethodDesc = accessTimeoutHolder.method;
            Method accessTimeoutMethod = accessTimeoutMethodDesc.getMethod(sessionDesc);
            if (implMethodMatchesInvInfoMethod(invInfoMethod, methodIntf, accessTimeoutMethod)) {
                if (lockInfo == null) {
                    lockInfo = new MethodLockInfo();
                }
                lockInfo.setTimeout(accessTimeoutHolder.value, accessTimeoutHolder.unit);
                break;
            }
        }
    }
    if (lockInfo != null) {
        invInfo.methodLockInfo = lockInfo;
    }
}
Also used : DistributedLockType(fish.payara.cluster.DistributedLockType) Method(java.lang.reflect.Method) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) MethodLockInfo(com.sun.ejb.MethodLockInfo)

Example 19 with MethodDescriptor

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

the class SafeProperties method addInvocationInfo.

private InvocationInfo addInvocationInfo(Method method, String methodIntf, Class originalIntf, boolean isEjbTimeout, boolean optionalLocalBusView) throws EJBException {
    MethodDescriptor md = new MethodDescriptor(method, methodIntf);
    boolean flushEnabled = findFlushEnabledAttr(md);
    int txAttr = containerTransactionManager.findTxAttr(md);
    InvocationInfo info = createInvocationInfo(method, txAttr, flushEnabled, methodIntf, originalIntf);
    boolean isHomeIntf = methodIntf.equals(MethodDescriptor.EJB_HOME) || methodIntf.equals(MethodDescriptor.EJB_LOCALHOME);
    if (!isHomeIntf) {
        Method beanMethod = null;
        if (!isEjbTimeout) {
            try {
                beanMethod = getEJBClass().getMethod(method.getName(), method.getParameterTypes());
            } catch (NoSuchMethodException nsmEx) {
            // TODO
            }
        } else {
            // For a timeout it is the method
            beanMethod = method;
        }
        if (beanMethod != null) {
            // Can't set AroundInvoke/AroundTimeout chains here, but set up some
            // state on info object so it can be done right after InterceptorManager
            // is initialized.
            info.aroundMethod = beanMethod;
            info.isEjbTimeout = isEjbTimeout;
        }
        // Asynchronous method initialization
        if (isEligibleForAsync(originalIntf, methodIntf)) {
            Method targetMethod = optionalLocalBusView ? beanMethod : method;
            boolean isAsync = ((EjbSessionDescriptor) ejbDescriptor).isAsynchronousMethod(targetMethod);
            if (isAsync) {
                // Check return type
                if (optionalLocalBusView && beanMethod != null) {
                    boolean beanMethodReturnTypeVoid = beanMethod.getReturnType().equals(Void.TYPE);
                    boolean beanMethodReturnTypeFuture = beanMethod.getReturnType().equals(Future.class);
                    if (!beanMethodReturnTypeVoid && !beanMethodReturnTypeFuture) {
                        throw new RuntimeException("Invalid no-interface view asynchronous method '" + beanMethod + "' for bean " + ejbDescriptor.getName() + ". Async method exposed through no-interface view must " + " have return type void or java.lang.concurrent.Future<V>");
                    }
                } else {
                    // Use actual interface method instead of method from generated interface
                    Method intfMethod = null;
                    try {
                        intfMethod = originalIntf.getMethod(method.getName(), method.getParameterTypes());
                    } catch (NoSuchMethodException nsmEx) {
                        throw new RuntimeException("No matching async intf method for method '" + beanMethod + "' on bean " + ejbDescriptor.getName());
                    }
                    if (beanMethod == null) {
                        throw new RuntimeException("No matching bean class method for async method '" + intfMethod + "' on bean " + ejbDescriptor.getName());
                    }
                    boolean beanMethodReturnTypeVoid = beanMethod.getReturnType().equals(Void.TYPE);
                    boolean beanMethodReturnTypeFuture = beanMethod.getReturnType().equals(Future.class);
                    boolean intfMethodReturnTypeVoid = intfMethod.getReturnType().equals(Void.TYPE);
                    boolean intfMethodReturnTypeFuture = intfMethod.getReturnType().equals(Future.class);
                    boolean bothVoid = intfMethodReturnTypeVoid && beanMethodReturnTypeVoid;
                    boolean bothFuture = intfMethodReturnTypeFuture && beanMethodReturnTypeFuture;
                    if (!bothVoid && !bothFuture) {
                        throw new RuntimeException(// 
                        "Invalid asynchronous bean class / interface " + "method signatures for bean " + // 
                        ejbDescriptor.getName() + ". beanMethod = '" + beanMethod + "' , interface method = '" + intfMethod + "'");
                    }
                }
                info.setIsAsynchronous(true);
            }
        }
    }
    if (methodIntf.equals(MethodDescriptor.EJB_WEB_SERVICE)) {
        webServiceInvocationInfoMap.put(method, info);
    } else {
        invocationInfoMap.put(method, info);
    }
    return info;
}
Also used : InvocationInfo(com.sun.ejb.InvocationInfo) Method(java.lang.reflect.Method) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) WebServiceEndpoint(com.sun.enterprise.deployment.WebServiceEndpoint)

Example 20 with MethodDescriptor

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

the class Generator method getSecurityAttribute.

protected String getSecurityAttribute(EjbDescriptor dd, Method m) {
    // The SEC_* strings returned MUST match the SEC_* constants in
    // com.sun.ejb.Container.
    MethodDescriptor thisMethodDesc = new MethodDescriptor(m, ejbClassSymbol);
    Set unchecked = dd.getUncheckedMethodDescriptors();
    if (unchecked != null) {
        Iterator i = unchecked.iterator();
        while (i.hasNext()) {
            MethodDescriptor md = (MethodDescriptor) i.next();
            if (thisMethodDesc.equals(md))
                return "SEC_UNCHECKED";
        }
    }
    Set excluded = dd.getExcludedMethodDescriptors();
    if (excluded != null) {
        Iterator i = excluded.iterator();
        while (i.hasNext()) {
            MethodDescriptor md = (MethodDescriptor) i.next();
            if (thisMethodDesc.equals(md))
                return "SEC_EXCLUDED";
        }
    }
    return "SEC_CHECKED";
}
Also used : Set(java.util.Set) Iterator(java.util.Iterator) 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