Search in sources :

Example 21 with EjbContext

use of com.sun.enterprise.deployment.annotation.context.EjbContext 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 22 with EjbContext

use of com.sun.enterprise.deployment.annotation.context.EjbContext 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 23 with EjbContext

use of com.sun.enterprise.deployment.annotation.context.EjbContext in project Payara by payara.

the class TransactionManagementHandler method processAnnotation.

protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, EjbContext[] ejbContexts) throws AnnotationProcessorException {
    TransactionManagement tmAn = (TransactionManagement) ainfo.getAnnotation();
    String tmType = TransactionManagementType.CONTAINER.equals(tmAn.value()) ? EjbDescriptor.CONTAINER_TRANSACTION_TYPE : EjbDescriptor.BEAN_TRANSACTION_TYPE;
    for (EjbContext ejbContext : ejbContexts) {
        EjbDescriptor ejbDesc = (EjbDescriptor) ejbContext.getDescriptor();
        // override by xml
        if (ejbDesc.getTransactionType() == null) {
            ejbDesc.setTransactionType(tmType);
        }
    }
    return getDefaultProcessedResult();
}
Also used : EjbContext(com.sun.enterprise.deployment.annotation.context.EjbContext) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor) TransactionManagement(javax.ejb.TransactionManagement)

Example 24 with EjbContext

use of com.sun.enterprise.deployment.annotation.context.EjbContext in project Payara by payara.

the class AbstractAttributeHandler method processAnnotation.

/**
 * Process a particular annotation which 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.
 * This is a method in interface AnnotationHandler.
 *
 * @param ainfo the annotation information
 */
public HandlerProcessingResult processAnnotation(AnnotationInfo ainfo) throws AnnotationProcessorException {
    AnnotatedElement ae = ainfo.getAnnotatedElement();
    Annotation annotation = ainfo.getAnnotation();
    if (logger.isLoggable(Level.FINER)) {
        logger.finer("@process annotation " + annotation + " in " + ae);
    }
    AnnotatedElementHandler aeHandler = ainfo.getProcessingContext().getHandler();
    if (aeHandler instanceof EjbBundleContext) {
        EjbBundleContext ejbBundleContext = (EjbBundleContext) aeHandler;
        AnnotatedElementHandler aeh = ejbBundleContext.createContextForEjb();
        if (aeh != null) {
            aeHandler = aeh;
        } else {
            if (isDelegatee()) {
                aeHandler = ejbBundleContext.createContextForEjbInterceptor();
            }
            if (aeHandler == null) {
                return getInvalidAnnotatedElementHandlerResult(null, ainfo);
            }
        }
    }
    if (!supportTypeInheritance() && ElementType.TYPE.equals(ainfo.getElementType()) && aeHandler instanceof ComponentContext) {
        ComponentContext context = (ComponentContext) aeHandler;
        Class clazz = (Class) ainfo.getAnnotatedElement();
        if (!clazz.getName().equals(context.getComponentClassName())) {
            if (logger.isLoggable(Level.WARNING)) {
                log(Level.WARNING, ainfo, localStrings.getLocalString("enterprise.deployment.annotation.handlers.typeinhernotsupp", "The annotation symbol inheritance is not supported."));
            }
            return getDefaultProcessedResult();
        }
    }
    EjbContext[] ejbContexts = null;
    EjbInterceptorContext ejbInterceptorContext = null;
    if (aeHandler instanceof EjbContext) {
        EjbContext ejbContext = (EjbContext) aeHandler;
        ejbContexts = new EjbContext[] { ejbContext };
    } else if (aeHandler instanceof EjbsContext) {
        ejbContexts = ((EjbsContext) aeHandler).getEjbContexts();
    } else if (isDelegatee() && aeHandler instanceof EjbInterceptorContext) {
        ejbInterceptorContext = (EjbInterceptorContext) aeHandler;
    } else {
        return getInvalidAnnotatedElementHandlerResult(aeHandler, ainfo);
    }
    HandlerProcessingResult procResult = null;
    if (ejbInterceptorContext != null) {
        procResult = processAnnotation(ainfo, ejbInterceptorContext);
    } else {
        procResult = processAnnotation(ainfo, ejbContexts);
    }
    if (logger.isLoggable(Level.FINER)) {
        logger.finer("New annotation for " + annotation);
    }
    return procResult;
}
Also used : EjbBundleContext(com.sun.enterprise.deployment.annotation.context.EjbBundleContext) ComponentContext(com.sun.enterprise.deployment.annotation.context.ComponentContext) EjbInterceptorContext(com.sun.enterprise.deployment.annotation.context.EjbInterceptorContext) EjbContext(com.sun.enterprise.deployment.annotation.context.EjbContext) HandlerProcessingResult(org.glassfish.apf.HandlerProcessingResult) AnnotatedElement(java.lang.reflect.AnnotatedElement) AnnotatedElementHandler(org.glassfish.apf.AnnotatedElementHandler) Annotation(java.lang.annotation.Annotation) EjbsContext(com.sun.enterprise.deployment.annotation.context.EjbsContext)

Example 25 with EjbContext

use of com.sun.enterprise.deployment.annotation.context.EjbContext in project Payara by payara.

the class AbstractEjbHandler method processAnnotation.

/**
 * Process a particular annotation which 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.
 * This is a method in interface AnnotationHandler.
 *
 * @param ainfo the annotation information
 */
public HandlerProcessingResult processAnnotation(AnnotationInfo ainfo) throws AnnotationProcessorException {
    Class ejbClass = (Class) ainfo.getAnnotatedElement();
    Annotation annotation = ainfo.getAnnotation();
    if (logger.isLoggable(Level.FINER)) {
        logger.finer("@ process ejb annotation " + annotation + " in " + ejbClass);
    }
    AnnotatedElementHandler aeHandler = ainfo.getProcessingContext().getHandler();
    if (aeHandler != null && aeHandler instanceof EjbContext) {
        EjbContext context = (EjbContext) aeHandler;
        EjbDescriptor desc = (EjbDescriptor) context.getDescriptor();
        if (isValidEjbDescriptor(desc, annotation)) {
            return getDefaultProcessedResult();
        } else {
            log(Level.SEVERE, ainfo, localStrings.getLocalString("enterprise.deployment.annotation.handlers.notcompsuperclass", "The annotation symbol defined in super-class is not compatible with {0} ejb {1}.", new Object[] { desc.getType(), desc.getName() }));
            return getDefaultFailedResult();
        }
    } else if (aeHandler == null || !(aeHandler instanceof EjbBundleContext)) {
        return getInvalidAnnotatedElementHandlerResult(ainfo.getProcessingContext().getHandler(), ainfo);
    }
    EjbBundleContext ctx = (EjbBundleContext) aeHandler;
    if (logger.isLoggable(Level.FINE)) {
        logger.fine("My context is " + ctx);
    }
    String elementName = getAnnotatedName(annotation);
    if (elementName.length() == 0) {
        elementName = ejbClass.getSimpleName();
    } else {
        elementName = (String) TranslatedConfigView.getTranslatedValue(elementName);
    }
    EjbBundleDescriptorImpl currentBundle = (EjbBundleDescriptorImpl) ctx.getDescriptor();
    EjbDescriptor ejbDesc = null;
    try {
        ejbDesc = currentBundle.getEjbByName(elementName);
    } catch (IllegalArgumentException ex) {
    // getEjbByName throws IllegalArgumentException when no ejb is found
    }
    if (ejbDesc != null && !(ejbDesc instanceof DummyEjbDescriptor)) {
        // overriding rules applies
        if (logger.isLoggable(Level.FINE)) {
            logger.fine("Overriding rules apply for " + ejbClass.getName());
        }
        // don't allow ejb-jar.xml overwrite ejb type
        if (!isValidEjbDescriptor(ejbDesc, annotation)) {
            // this is an error
            log(Level.SEVERE, ainfo, localStrings.getLocalString("enterprise.deployment.annotation.handlers.wrongejbtype", "Wrong annotation symbol for ejb {0}", new Object[] { ejbDesc }));
            return getDefaultFailedResult();
        }
        // <ejb-class> is optional if a component-defining
        // annotation is used.  If present, <ejb-class> element
        // must match the class on which the component defining annotation
        // appears.
        String descriptorEjbClass = ejbDesc.getEjbClassName();
        if (descriptorEjbClass == null) {
            ejbDesc.setEjbClassName(ejbClass.getName());
            ejbDesc.applyDefaultClassToLifecycleMethods();
        } else if (!descriptorEjbClass.equals(ejbClass.getName())) {
            log(Level.SEVERE, ainfo, localStrings.getLocalString("enterprise.deployment.annotation.handlers.ejbclsmismatch", "", new Object[] { descriptorEjbClass, elementName, ejbClass.getName() }));
            return getDefaultFailedResult();
        }
    } else {
        if (logger.isLoggable(Level.FINE)) {
            logger.fine("Creating a new descriptor for " + ejbClass.getName());
        }
        EjbDescriptor dummyEjbDesc = ejbDesc;
        ejbDesc = createEjbDescriptor(elementName, ainfo);
        // the information from dummy ejb descriptor if applicable
        if (dummyEjbDesc != null) {
            currentBundle.removeEjb(dummyEjbDesc);
            ejbDesc.addEjbDescriptor(dummyEjbDesc);
            // reset ejbClassName on ejbDesc
            ejbDesc.setEjbClassName(ejbClass.getName());
        }
        // add the actual ejb descriptor to the ejb bundle
        currentBundle.addEjb(ejbDesc);
        if (logger.isLoggable(Level.FINE)) {
            logger.fine("New " + getAnnotationType().getName() + " bean " + elementName);
        }
    }
    // We need to include all ejbs of the same name in the annotation processing context
    // in order to handle the case that a bean class has both a component-defining
    // annotation and there are other ejb-jar.xml-defined beans with the same bean class.
    EjbDescriptor[] ejbDescs = currentBundle.getEjbByClassName(ejbClass.getName());
    HandlerProcessingResult procResult = null;
    for (EjbDescriptor next : ejbDescs) {
        procResult = setEjbDescriptorInfo(next, ainfo);
        doTimedObjectProcessing(ejbClass, next);
    }
    AnnotationContext annContext = null;
    if (ejbDescs.length == 1) {
        annContext = new EjbContext(ejbDesc, ejbClass);
    } else {
        annContext = new EjbsContext(ejbDescs, ejbClass);
    }
    // we push the new context on the stack...
    ctx.getProcessingContext().pushHandler(annContext);
    return procResult;
}
Also used : DummyEjbDescriptor(org.glassfish.ejb.deployment.descriptor.DummyEjbDescriptor) HandlerProcessingResult(org.glassfish.apf.HandlerProcessingResult) AnnotationContext(org.glassfish.apf.context.AnnotationContext) Annotation(java.lang.annotation.Annotation) DummyEjbDescriptor(org.glassfish.ejb.deployment.descriptor.DummyEjbDescriptor) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor) EjbsContext(com.sun.enterprise.deployment.annotation.context.EjbsContext) EjbBundleContext(com.sun.enterprise.deployment.annotation.context.EjbBundleContext) EjbContext(com.sun.enterprise.deployment.annotation.context.EjbContext) AnnotatedElementHandler(org.glassfish.apf.AnnotatedElementHandler) EjbBundleDescriptorImpl(org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)

Aggregations

EjbContext (com.sun.enterprise.deployment.annotation.context.EjbContext)26 Method (java.lang.reflect.Method)12 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)10 EjbDescriptor (org.glassfish.ejb.deployment.descriptor.EjbDescriptor)10 EjbSessionDescriptor (org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)10 EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)4 EjbsContext (com.sun.enterprise.deployment.annotation.context.EjbsContext)4 EjbBundleDescriptorImpl (org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)4 Role (org.glassfish.security.common.Role)4 AnnotatedElement (java.lang.reflect.AnnotatedElement)3 Constructor (java.lang.reflect.Constructor)3 AnnotationProcessorException (org.glassfish.apf.AnnotationProcessorException)3 InterceptorBindingDescriptor (org.glassfish.ejb.deployment.descriptor.InterceptorBindingDescriptor)3 RunAsIdentityDescriptor (com.sun.enterprise.deployment.RunAsIdentityDescriptor)2 EjbBundleContext (com.sun.enterprise.deployment.annotation.context.EjbBundleContext)2 WebBundleContext (com.sun.enterprise.deployment.annotation.context.WebBundleContext)2 WebComponentContext (com.sun.enterprise.deployment.annotation.context.WebComponentContext)2 Annotation (java.lang.annotation.Annotation)2 DeclareRoles (javax.annotation.security.DeclareRoles)2 RunAs (javax.annotation.security.RunAs)2