Search in sources :

Example 31 with MethodDescriptor

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

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

the class LockHandler 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();
    Class classAn = (Class) ainfo.getAnnotatedElement();
    Lock lockAnn = (Lock) ainfo.getAnnotation();
    // 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.
    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 (!matchesExistingReadOrWriteLockMethod(m, ejbDesc)) {
            MethodDescriptor newMethodDesc = new MethodDescriptor(m);
            if (lockAnn.value() == LockType.WRITE) {
                ejbDesc.addWriteLockMethod(newMethodDesc);
            } else {
                ejbDesc.addReadLockMethod(newMethodDesc);
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) Lock(javax.ejb.Lock)

Example 33 with MethodDescriptor

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

the class EjbDescriptor method addMethodLevelChain.

@Override
public void addMethodLevelChain(List<EjbInterceptor> chain, Method m, boolean aroundInvoke) {
    if (chain.size() == 0) {
        return;
    }
    MethodDescriptor methodDesc = new MethodDescriptor(m);
    List<EjbInterceptor> existingChain = null;
    for (MethodDescriptor next : methodInterceptorsMap.keySet()) {
        if (next.implies(methodDesc)) {
            existingChain = methodInterceptorsMap.get(methodDesc);
            break;
        }
    }
    if (existingChain != null) {
        existingChain.addAll(chain);
    } else {
        List<EjbInterceptor> newChain = new LinkedList<>();
        for (EjbInterceptor interceptor : interceptorChain) {
            boolean include = aroundInvoke ? interceptor.hasAroundInvokeDescriptor() : interceptor.hasAroundTimeoutDescriptor();
            if (include) {
                newChain.add(interceptor);
            }
        }
        newChain.addAll(chain);
        methodInterceptorsMap.put(methodDesc, newChain);
    }
}
Also used : MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor)

Example 34 with MethodDescriptor

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

the class EjbDescriptor method getMethodPermissions.

private Set<MethodPermission> getMethodPermissions(MethodDescriptor methodDescriptor) {
    Set<MethodPermission> methodPermissionsForMethod = new HashSet<>();
    for (Iterator<MethodPermission> e = this.getPermissionedMethodsByPermission().keySet().iterator(); e.hasNext(); ) {
        MethodPermission nextPermission = e.next();
        Set<MethodDescriptor> permissionedMethods = this.getPermissionedMethodsByPermission().get(nextPermission);
        for (Iterator<MethodDescriptor> itr = permissionedMethods.iterator(); itr.hasNext(); ) {
            MethodDescriptor md = itr.next();
            if (md.equals(methodDescriptor)) {
                methodPermissionsForMethod.add(nextPermission);
            }
        }
    }
    return methodPermissionsForMethod;
}
Also used : MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor)

Example 35 with MethodDescriptor

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

the class EjbDescriptor method setMethodContainerTransactions.

/**
 * Sets the container transactions for all the method descriptors of this ejb. The Hashtable is keyed by method
 * descriptor and the values are the corresponding container transaction objects.. Throws an Illegal argument if this
 * ejb has transaction type BEAN_TRANSACTION_TYPE.
 *
 * @param methodContainerTransactions
 */
public void setMethodContainerTransactions(Hashtable<MethodDescriptor, ContainerTransaction> methodContainerTransactions) {
    if (methodContainerTransactions != null) {
        for (Enumeration<MethodDescriptor> e = methodContainerTransactions.keys(); e.hasMoreElements(); ) {
            MethodDescriptor methodDescriptor = e.nextElement();
            ContainerTransaction containerTransaction = methodContainerTransactions.get(methodDescriptor);
            setContainerTransactionFor(methodDescriptor, containerTransaction);
        }
    }
}
Also used : 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