Search in sources :

Example 61 with MethodDescriptor

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

the class LockHandler method matchesExistingReadOrWriteLockMethod.

private boolean matchesExistingReadOrWriteLockMethod(Method methodToMatch, EjbSessionDescriptor desc) {
    List<MethodDescriptor> lockMethods = desc.getReadAndWriteLockMethods();
    boolean match = false;
    for (MethodDescriptor next : lockMethods) {
        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)

Example 62 with MethodDescriptor

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

Example 63 with MethodDescriptor

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

the class ScheduleHandler method processSchedule.

protected HandlerProcessingResult processSchedule(Schedule sch, AnnotationInfo ainfo, EjbContext[] ejbContexts) throws AnnotationProcessorException {
    for (EjbContext ejbContext : ejbContexts) {
        EjbDescriptor ejbDesc = (EjbDescriptor) ejbContext.getDescriptor();
        if (ElementType.METHOD.equals(ainfo.getElementType())) {
            Method annMethod = (Method) ainfo.getAnnotatedElement();
            // .xml-defined timer method overrides @Schedule
            if (!ejbDesc.hasScheduledTimerMethodFromDD(annMethod)) {
                ScheduledTimerDescriptor sd = new ScheduledTimerDescriptor();
                sd.setSecond(sch.second());
                sd.setMinute(sch.minute());
                sd.setHour(sch.hour());
                sd.setDayOfMonth(sch.dayOfMonth());
                sd.setMonth(sch.month());
                sd.setDayOfWeek(sch.dayOfWeek());
                sd.setYear(sch.year());
                sd.setTimezone(sch.timezone());
                sd.setPersistent(sch.persistent());
                sd.setInfo(sch.info());
                sd.setTimeoutMethod(new MethodDescriptor(annMethod));
                ejbDesc.addScheduledTimerDescriptor(sd);
                if (logger.isLoggable(Level.FINE)) {
                    logger.fine("@@@ Found Schedule on " + annMethod);
                    logger.fine("@@@ TimerConfig : " + ((sd.getInfo() != null && !sd.getInfo().equals("")) ? sd.getInfo() : null) + " # " + sd.getPersistent());
                }
            }
        }
    }
    return getDefaultProcessedResult();
}
Also used : ScheduledTimerDescriptor(org.glassfish.ejb.deployment.descriptor.ScheduledTimerDescriptor) EjbContext(com.sun.enterprise.deployment.annotation.context.EjbContext) Method(java.lang.reflect.Method) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor)

Example 64 with MethodDescriptor

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

the class TransactionAttributeHandler method processAnnotation.

protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, EjbContext[] ejbContexts) throws AnnotationProcessorException {
    TransactionAttribute taAn = (TransactionAttribute) ainfo.getAnnotation();
    for (EjbContext ejbContext : ejbContexts) {
        EjbDescriptor ejbDesc = (EjbDescriptor) ejbContext.getDescriptor();
        ContainerTransaction containerTransaction = getContainerTransaction(taAn.value());
        if (ElementType.TYPE.equals(ainfo.getElementType())) {
            ejbContext.addPostProcessInfo(ainfo, this);
        } else {
            Method annMethod = (Method) ainfo.getAnnotatedElement();
            Set txBusMethods = ejbDesc.getTxBusinessMethodDescriptors();
            for (Object next : txBusMethods) {
                MethodDescriptor nextDesc = (MethodDescriptor) next;
                Method m = nextDesc.getMethod(ejbDesc);
                if (TypeUtil.sameMethodSignature(m, annMethod) && ejbDesc.getContainerTransactionFor(nextDesc) == null) {
                    // override by xml
                    ejbDesc.setContainerTransactionFor(nextDesc, containerTransaction);
                }
            }
            if (ejbDesc instanceof EjbSessionDescriptor) {
                EjbSessionDescriptor sd = (EjbSessionDescriptor) ejbDesc;
                if (sd.isStateful() || sd.isSingleton()) {
                    ClassLoader loader = ejbDesc.getEjbBundleDescriptor().getClassLoader();
                    Set<LifecycleCallbackDescriptor> lcds = ejbDesc.getLifecycleCallbackDescriptors();
                    for (LifecycleCallbackDescriptor lcd : lcds) {
                        if (lcd.getLifecycleCallbackClass().equals(ejbDesc.getEjbClassName()) && lcd.getLifecycleCallbackMethod().equals(annMethod.getName())) {
                            try {
                                Method m = lcd.getLifecycleCallbackMethodObject(loader);
                                MethodDescriptor md = new MethodDescriptor(m, MethodDescriptor.LIFECYCLE_CALLBACK);
                                if (TypeUtil.sameMethodSignature(m, annMethod) && ejbDesc.getContainerTransactionFor(md) == null) {
                                    // stateful lifecycle callback txn attr type EJB spec
                                    if (sd.isStateful() && containerTransaction != null) {
                                        String txAttr = containerTransaction.getTransactionAttribute();
                                        if (txAttr != null && !txAttr.equals(ContainerTransaction.REQUIRES_NEW) && !txAttr.equals(ContainerTransaction.NOT_SUPPORTED)) {
                                            logger.log(Level.WARNING, localStrings.getLocalString("enterprise.deployment.annotation.handlers.sfsblifecycletxnattrtypewarn", "Stateful session bean {0} lifecycle callback method {1} has transaction " + "attribute {2} with container-managed transaction demarcation. " + "The transaction attribute should be either REQUIRES_NEW or NOT_SUPPORTED", new Object[] { (sd.getName() == null ? "" : sd.getName()), m.getName(), txAttr }));
                                        }
                                    }
                                    // override by xml
                                    ejbDesc.setContainerTransactionFor(md, containerTransaction);
                                    if (logger.isLoggable(Level.FINE)) {
                                        logger.log(Level.FINE, "Found matching callback method {0}<>{1} : {2}", new Object[] { ejbDesc.getEjbClassName(), md, containerTransaction });
                                    }
                                }
                            } catch (Exception e) {
                                if (logger.isLoggable(Level.FINE)) {
                                    logger.log(Level.FINE, "Transaction attribute for a lifecycle callback annotation processing error", e);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return getDefaultProcessedResult();
}
Also used : Set(java.util.Set) TransactionAttribute(javax.ejb.TransactionAttribute) Method(java.lang.reflect.Method) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor) AnnotationProcessorException(org.glassfish.apf.AnnotationProcessorException) LifecycleCallbackDescriptor(com.sun.enterprise.deployment.LifecycleCallbackDescriptor) EjbContext(com.sun.enterprise.deployment.annotation.context.EjbContext) ContainerTransaction(org.glassfish.ejb.deployment.descriptor.ContainerTransaction) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)

Example 65 with MethodDescriptor

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

the class EjbDescriptor method doMethodDescriptorConversions.

void doMethodDescriptorConversions() throws Exception {
    // container transactions first
    Hashtable transactions = this.getMethodContainerTransactions();
    // _logger.log(Level.FINE,"Pre conversion = " + transactions);
    Hashtable convertedTransactions = new Hashtable();
    Collection transactionMethods = this.getTransactionMethodDescriptors();
    for (Enumeration e = transactions.keys(); e.hasMoreElements(); ) {
        MethodDescriptor md = (MethodDescriptor) e.nextElement();
        ContainerTransaction ct = (ContainerTransaction) transactions.get(md);
        for (Enumeration mds = md.doStyleConversion(this, transactionMethods).elements(); mds.hasMoreElements(); ) {
            MethodDescriptor next = (MethodDescriptor) mds.nextElement();
            convertedTransactions.put(next, new ContainerTransaction(ct));
        }
    }
    // _logger.log(Level.FINE,"Post conversion = " + convertedTransactions);
    setMethodContainerTransactions(convertedTransactions);
    convertMethodPermissions();
}
Also used : Enumeration(java.util.Enumeration) Hashtable(java.util.Hashtable) Collection(java.util.Collection) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor)

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