Search in sources :

Example 6 with AnnotationProcessorException

use of org.glassfish.apf.AnnotationProcessorException in project Payara by payara.

the class AsynchronousHandler method setAsynchronous.

/**
 * Designate a method as asynchronous in the deployment descriptor
 * @param methodIntf  null if processed on bean class / superclass.  Otherwise,
 *                    set to the remote/local client view of the associated interface
 * @throws AnnotationProcessorException
 */
private void setAsynchronous(Method m0, EjbDescriptor ejbDesc, String methodIntf) throws AnnotationProcessorException {
    if (!ejbDesc.getType().equals(EjbSessionDescriptor.TYPE)) {
        throw new AnnotationProcessorException("Invalid asynchronous method " + m0 + "@Asynchronous is only permitted for session beans");
    }
    EjbSessionDescriptor sessionDesc = (EjbSessionDescriptor) ejbDesc;
    MethodDescriptor methodDesc = (methodIntf == null) ? new MethodDescriptor(m0) : new MethodDescriptor(m0, methodIntf);
    if (logger.isLoggable(Level.FINE)) {
        logger.fine("Adding asynchronous method " + methodDesc);
    }
    // There is no way to "turn off" the asynchronous designation in the
    // deployment descriptor, so we don't need to do any override checks
    // here.  Just always add any async methods.
    sessionDesc.addAsynchronousMethod(methodDesc);
}
Also used : AnnotationProcessorException(org.glassfish.apf.AnnotationProcessorException) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor)

Example 7 with AnnotationProcessorException

use of org.glassfish.apf.AnnotationProcessorException in project Payara by payara.

the class ConcurrencyManagementHandler method processAnnotation.

protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, EjbContext[] ejbContexts) throws AnnotationProcessorException {
    ConcurrencyManagement cmAn = (ConcurrencyManagement) ainfo.getAnnotation();
    ConcurrencyManagementType cmType = cmAn.value();
    for (EjbContext ejbContext : ejbContexts) {
        EjbDescriptor ejbDesc = ejbContext.getDescriptor();
        if (ejbDesc instanceof EjbSessionDescriptor) {
            EjbSessionDescriptor.ConcurrencyManagementType descCMType;
            switch(cmType) {
                case CONTAINER:
                    descCMType = EjbSessionDescriptor.ConcurrencyManagementType.Container;
                    break;
                case BEAN:
                    descCMType = EjbSessionDescriptor.ConcurrencyManagementType.Bean;
                    break;
                default:
                    throw new AnnotationProcessorException("Unsupported concurrency management " + "type = " + cmType);
            }
            EjbSessionDescriptor sDesc = (EjbSessionDescriptor) ejbDesc;
            // Set value on descriptor unless it has been set by .xml
            sDesc.setConcurrencyManagementTypeIfNotSet(descCMType);
        }
    }
    return getDefaultProcessedResult();
}
Also used : ConcurrencyManagement(javax.ejb.ConcurrencyManagement) ConcurrencyManagementType(javax.ejb.ConcurrencyManagementType) EjbContext(com.sun.enterprise.deployment.annotation.context.EjbContext) AnnotationProcessorException(org.glassfish.apf.AnnotationProcessorException) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) EjbDescriptor(com.sun.enterprise.deployment.EjbDescriptor)

Example 8 with AnnotationProcessorException

use of org.glassfish.apf.AnnotationProcessorException in project Payara by payara.

the class EJBHandler method processEJB.

/**
 * Process a particular annotation whose type is the same as the
 * one returned by @see getAnnotationType(). All information
 * pertinent to the annotation and its context is encapsulated
 * in the passed AnnotationInfo instance.
 *
 * @param ainfo the annotation information
 * @param rcContexts an array of ResourceContainerContext
 * @param ejbAn
 * @return HandlerProcessingResult
 */
protected HandlerProcessingResult processEJB(AnnotationInfo ainfo, ResourceContainerContext[] rcContexts, EJB ejbAn) throws AnnotationProcessorException {
    EjbReferenceDescriptor[] ejbRefs = null;
    String defaultLogicalName = null;
    Class defaultBeanInterface = null;
    InjectionTarget target = null;
    if (ElementType.FIELD.equals(ainfo.getElementType())) {
        Field f = (Field) ainfo.getAnnotatedElement();
        String targetClassName = f.getDeclaringClass().getName();
        defaultLogicalName = targetClassName + "/" + f.getName();
        defaultBeanInterface = f.getType();
        target = new InjectionTarget();
        target.setClassName(targetClassName);
        target.setFieldName(f.getName());
        target.setMetadataSource(MetadataSource.ANNOTATION);
    } else if (ElementType.METHOD.equals(ainfo.getElementType())) {
        Method m = (Method) ainfo.getAnnotatedElement();
        String targetClassName = m.getDeclaringClass().getName();
        validateInjectionMethod(m, ainfo);
        // Derive javabean property name.
        String propertyName = getInjectionMethodPropertyName(m, ainfo);
        defaultLogicalName = targetClassName + "/" + propertyName;
        defaultBeanInterface = m.getParameterTypes()[0];
        target = new InjectionTarget();
        target.setClassName(targetClassName);
        target.setMethodName(m.getName());
        target.setMetadataSource(MetadataSource.ANNOTATION);
    } else if (ElementType.TYPE.equals(ainfo.getElementType())) {
        // if either of them not set, fail fast.  See issue 17284
        if (ejbAn.name().equals("") || ejbAn.beanInterface() == Object.class) {
            Class c = (Class) ainfo.getAnnotatedElement();
            AnnotationProcessorException fatalException = new AnnotationProcessorException(localStrings.getLocalString("enterprise.deployment.annotation.handlers.invalidtypelevelejb", "Invalid TYPE-level @EJB with name() = [{0}] and " + "beanInterface = [{1}] in {2}.  Each TYPE-level @EJB " + "must specify both name() and beanInterface().", new Object[] { ejbAn.name(), ejbAn.beanInterface(), c }), ainfo);
            fatalException.setFatal(true);
            throw fatalException;
        }
    } else {
        // can't happen
        return getDefaultFailedResult();
    }
    // NOTE that default value is Object.class, not null
    Class beanInterface = (ejbAn.beanInterface() == Object.class) ? defaultBeanInterface : ejbAn.beanInterface();
    String logicalName = ejbAn.name().equals("") ? defaultLogicalName : ejbAn.name();
    ejbRefs = getEjbReferenceDescriptors(logicalName, rcContexts);
    for (EjbReferenceDescriptor ejbRef : ejbRefs) {
        if (target != null)
            ejbRef.addInjectionTarget(target);
        if (// a new one
        !ok(ejbRef.getName()))
            ejbRef.setName(logicalName);
        // merge type information
        setEjbType(ejbRef, beanInterface);
        // merge description
        if (!ok(ejbRef.getDescription()) && ok(ejbAn.description()))
            ejbRef.setDescription(ejbAn.description());
        // merge lookup-name and mapped-name
        if (!ejbRef.hasLookupName() && ok(ejbAn.lookup()))
            ejbRef.setLookupName(ejbAn.lookup());
        if (!ok(ejbRef.getMappedName()) && ok(ejbAn.mappedName()))
            ejbRef.setMappedName(ejbAn.mappedName());
        // merge beanName/linkName
        if (!ok(ejbRef.getLinkName()) && ok(ejbAn.beanName()))
            ejbRef.setLinkName(ejbAn.beanName());
    }
    return getDefaultProcessedResult();
}
Also used : Field(java.lang.reflect.Field) EjbReferenceDescriptor(com.sun.enterprise.deployment.EjbReferenceDescriptor) InjectionTarget(com.sun.enterprise.deployment.InjectionTarget) Method(java.lang.reflect.Method) AnnotationProcessorException(org.glassfish.apf.AnnotationProcessorException)

Example 9 with AnnotationProcessorException

use of org.glassfish.apf.AnnotationProcessorException 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)

Aggregations

AnnotationProcessorException (org.glassfish.apf.AnnotationProcessorException)9 Method (java.lang.reflect.Method)4 EjbSessionDescriptor (org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)4 EjbContext (com.sun.enterprise.deployment.annotation.context.EjbContext)3 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)2 Field (java.lang.reflect.Field)2 Set (java.util.Set)2 AnnotationInfo (org.glassfish.apf.AnnotationInfo)2 ConfigPropertyHandler (com.sun.enterprise.connectors.deployment.annotation.handlers.ConfigPropertyHandler)1 EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)1 EjbReferenceDescriptor (com.sun.enterprise.deployment.EjbReferenceDescriptor)1 InjectionTarget (com.sun.enterprise.deployment.InjectionTarget)1 LifecycleCallbackDescriptor (com.sun.enterprise.deployment.LifecycleCallbackDescriptor)1 Annotation (java.lang.annotation.Annotation)1 AnnotatedElement (java.lang.reflect.AnnotatedElement)1 Constructor (java.lang.reflect.Constructor)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ConcurrencyManagement (javax.ejb.ConcurrencyManagement)1 ConcurrencyManagementType (javax.ejb.ConcurrencyManagementType)1