Search in sources :

Example 1 with HandlerProcessingResult

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

the class MessageDrivenHandler method setEjbDescriptorInfo.

/**
 * Set Annotation information to Descriptor.
 * This method will also be invoked for an existing descriptor with
 * annotation as user may not specific a complete xml.
 * @param ejbDesc
 * @param ainfo
 * @return HandlerProcessingResult
 */
protected HandlerProcessingResult setEjbDescriptorInfo(EjbDescriptor ejbDesc, AnnotationInfo ainfo) throws AnnotationProcessorException {
    MessageDriven mdAn = (MessageDriven) ainfo.getAnnotation();
    Class ejbClass = (Class) ainfo.getAnnotatedElement();
    EjbMessageBeanDescriptor ejbMsgBeanDesc = (EjbMessageBeanDescriptor) ejbDesc;
    HandlerProcessingResult procResult = setMessageListenerInterface(mdAn, ejbMsgBeanDesc, ejbClass, ainfo);
    doDescriptionProcessing(mdAn.description(), ejbMsgBeanDesc);
    doMappedNameProcessing(mdAn.mappedName(), ejbMsgBeanDesc);
    for (ActivationConfigProperty acProp : mdAn.activationConfig()) {
        EnvironmentProperty envProp = new EnvironmentProperty(acProp.propertyName(), TranslatedConfigView.expandValue(acProp.propertyValue()), "");
        // xml override
        switch(acProp.propertyName()) {
            case "resourceAdapter":
                ejbMsgBeanDesc.setResourceAdapterMid(envProp.getValue());
                break;
            case DescriptorConstants.MAX_POOL_SIZE:
                initialiseBeanPoolDescriptor(ejbMsgBeanDesc);
                ejbMsgBeanDesc.getIASEjbExtraDescriptors().getBeanPool().setMaxPoolSize(Integer.valueOf(envProp.getValue()));
                break;
            case DescriptorConstants.POOL_RESIZE_QTY:
                initialiseBeanPoolDescriptor(ejbMsgBeanDesc);
                ejbMsgBeanDesc.getIASEjbExtraDescriptors().getBeanPool().setPoolResizeQuantity(Integer.valueOf(envProp.getValue()));
                break;
            case DescriptorConstants.STEADY_POOL_SIZE:
                initialiseBeanPoolDescriptor(ejbMsgBeanDesc);
                ejbMsgBeanDesc.getIASEjbExtraDescriptors().getBeanPool().setSteadyPoolSize(Integer.valueOf(envProp.getValue()));
                break;
            case DescriptorConstants.MAX_WAIT_TIME:
                initialiseBeanPoolDescriptor(ejbMsgBeanDesc);
                ejbMsgBeanDesc.getIASEjbExtraDescriptors().getBeanPool().setMaxWaitTimeInMillis(Integer.valueOf(envProp.getValue()));
                break;
            case DescriptorConstants.POOL_IDLE_TIMEOUT:
                initialiseBeanPoolDescriptor(ejbMsgBeanDesc);
                ejbMsgBeanDesc.getIASEjbExtraDescriptors().getBeanPool().setPoolIdleTimeoutInSeconds(Integer.valueOf(envProp.getValue()));
                break;
            case "SingletonBeanPool":
                NameValuePairDescriptor singletonProperty = new NameValuePairDescriptor();
                singletonProperty.setName("singleton-bean-pool");
                singletonProperty.setValue(envProp.getValue());
                ejbMsgBeanDesc.getEjbBundleDescriptor().addEnterpriseBeansProperty(singletonProperty);
                break;
            default:
                if (ejbMsgBeanDesc.getActivationConfigValue(envProp.getName()) == null) {
                    ejbMsgBeanDesc.putActivationConfigProperty(envProp);
                }
                break;
        }
    }
    return procResult;
}
Also used : ActivationConfigProperty(javax.ejb.ActivationConfigProperty) EjbMessageBeanDescriptor(org.glassfish.ejb.deployment.descriptor.EjbMessageBeanDescriptor) NameValuePairDescriptor(com.sun.enterprise.deployment.NameValuePairDescriptor) HandlerProcessingResult(org.glassfish.apf.HandlerProcessingResult) EnvironmentProperty(com.sun.enterprise.deployment.EnvironmentProperty) MessageDriven(javax.ejb.MessageDriven)

Example 2 with HandlerProcessingResult

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

the class AbstractCommonAttributeHandler 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.
 *
 * @param ainfo the annotation information
 */
@Override
public HandlerProcessingResult processAnnotation(AnnotationInfo ainfo) throws AnnotationProcessorException {
    AnnotatedElementHandler aeHandler = ainfo.getProcessingContext().getHandler();
    if (aeHandler instanceof EjbBundleContext) {
        EjbBundleContext ejbBundleContext = (EjbBundleContext) aeHandler;
        aeHandler = ejbBundleContext.createContextForEjb();
    } else if (aeHandler instanceof WebBundleContext) {
        WebBundleContext webBundleContext = (WebBundleContext) aeHandler;
        aeHandler = webBundleContext.createContextForWeb();
        if (aeHandler == null) {
            // no such web comp, use webBundleContext
            aeHandler = ainfo.getProcessingContext().getHandler();
        }
    }
    if (aeHandler == null) {
        // no such ejb
        return getInvalidAnnotatedElementHandlerResult(ainfo.getProcessingContext().getHandler(), 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();
        }
    }
    HandlerProcessingResult procResult = null;
    if (aeHandler instanceof EjbContext) {
        procResult = processAnnotation(ainfo, new EjbContext[] { (EjbContext) aeHandler });
    } else if (aeHandler instanceof EjbsContext) {
        EjbsContext ejbsContext = (EjbsContext) aeHandler;
        procResult = processAnnotation(ainfo, ejbsContext.getEjbContexts());
    } else if (aeHandler instanceof WebComponentContext) {
        procResult = processAnnotation(ainfo, new WebComponentContext[] { (WebComponentContext) aeHandler });
    } else if (aeHandler instanceof WebComponentsContext) {
        WebComponentsContext webCompsContext = (WebComponentsContext) aeHandler;
        procResult = processAnnotation(ainfo, webCompsContext.getWebComponentContexts());
    } else if (aeHandler instanceof WebBundleContext) {
        WebBundleContext webBundleContext = (WebBundleContext) aeHandler;
        procResult = processAnnotation(ainfo, webBundleContext);
    } else {
        return getInvalidAnnotatedElementHandlerResult(aeHandler, ainfo);
    }
    return procResult;
}
Also used : HandlerProcessingResult(org.glassfish.apf.HandlerProcessingResult) AnnotatedElementHandler(org.glassfish.apf.AnnotatedElementHandler)

Example 3 with HandlerProcessingResult

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

the class EJBsHandler method processAnnotation.

protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, ResourceContainerContext[] rcContexts) throws AnnotationProcessorException {
    EJBs ejbsAnnotation = (EJBs) ainfo.getAnnotation();
    EJB[] ejbAnnotations = ejbsAnnotation.value();
    if (ejbAnnotations.length == 0) {
        String localizedMsg = localStrings.getLocalString("enterprise.deployment.annotation.handlers.emptyEJBs", "No @EJB elements in @EJBs on " + ainfo.getAnnotatedElement(), new Object[] { ejbsAnnotation, ainfo.getAnnotatedElement() });
        logger.log(Level.WARNING, localizedMsg);
    }
    List<HandlerProcessingResult> results = new ArrayList<HandlerProcessingResult>();
    for (EJB ejb : ejbAnnotations) {
        results.add(processEJB(ainfo, rcContexts, ejb));
    }
    return getOverallProcessingResult(results);
}
Also used : EJBs(javax.ejb.EJBs) HandlerProcessingResult(org.glassfish.apf.HandlerProcessingResult) ArrayList(java.util.ArrayList) EJB(javax.ejb.EJB)

Example 4 with HandlerProcessingResult

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

the class AnnotationProcessorImpl method processAnnotations.

private HandlerProcessingResult processAnnotations(ProcessingContext ctx, ElementType type, AnnotatedElement element) throws AnnotationProcessorException {
    AnnotatedElementHandler handler = ctx.getHandler();
    logStart(handler, type, element);
    HandlerProcessingResult result = processAnnotations(ctx, element);
    logEnd(handler, type, element);
    dumpProcessingResult(result);
    return result;
}
Also used : HandlerProcessingResult(org.glassfish.apf.HandlerProcessingResult) AnnotatedElementHandler(org.glassfish.apf.AnnotatedElementHandler)

Example 5 with HandlerProcessingResult

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

the class AnnotationProcessorImpl method process.

private void process(ProcessingContext ctx, AnnotationInfo element, HandlerProcessingResultImpl result) throws AnnotationProcessorException {
    Annotation annotation = element.getAnnotation();
    if (AnnotationUtils.shouldLog("annotation")) {
        logger.log(Level.FINER, "Annotation : {0} delegate = {1}", new Object[] { annotation.annotationType().getName(), delegate });
    }
    result.addResult(annotation.annotationType(), ResultType.UNPROCESSED);
    // we ignore all java.* annotations
    Package annPackage = annotation.annotationType().getPackage();
    if (annPackage != null && annPackage.getName().startsWith("java.lang"))
        return;
    List<AnnotationHandler> annotationHandlers = handlers.get(annotation.annotationType().getName());
    if (annotationHandlers != null) {
        for (AnnotationHandler handler : annotationHandlers) {
            // here we need to be careful, we are ready to invoke a handler
            // to process a particular annotation type. However, this handler
            // may have defined a list of annotations that should be processed
            // (if present on the annotated element) before itself.
            // do this check and process those annotations first.
            Class<? extends Annotation>[] dependencies = handler.getTypeDependencies();
            if (dependencies != null) {
                AnnotatedElement ae = element.getAnnotatedElement();
                for (Class<? extends Annotation> annotationType : dependencies) {
                    Annotation depAnnotation = ae.getAnnotation(annotationType);
                    if (depAnnotation != null) {
                        ResultType resultType = result.processedAnnotations().get(annotationType);
                        if (resultType == null || resultType == ResultType.UNPROCESSED) {
                            // annotation is present, process it.
                            AnnotationInfo info = new AnnotationInfo(ctx, ae, depAnnotation, getTopElementType());
                            process(ctx, info, result);
                        }
                    }
                }
            }
            // at this point, all annotation that I declared depending on
            // are processed
            HandlerProcessingResult processingResult = null;
            try {
                processingResult = handler.processAnnotation(element);
            } catch (AnnotationProcessorException ape) {
                // I am logging this exception
                log(Level.SEVERE, ape.getLocator(), ape.getMessage());
                // errors.
                if (ape.isFatal()) {
                    throw ape;
                }
                if (++errorCount > 100) {
                    throw new AnnotationProcessorException(AnnotationUtils.getLocalString("enterprise.deployment.annotation.toomanyerror", "Too many errors, annotation processing abandoned."));
                }
                processingResult = HandlerProcessingResultImpl.getDefaultResult(annotation.annotationType(), ResultType.FAILED);
            } catch (Throwable e) {
                AnnotationProcessorException ape = new AnnotationProcessorException(e.getMessage(), element);
                ape.initCause(e);
                throw ape;
            }
            result.addAll(processingResult);
        }
    } else {
        if (delegate != null) {
            delegate.process(ctx, element, result);
        } else {
            ctx.getErrorHandler().fine(new AnnotationProcessorException("No handler defined for " + annotation.annotationType()));
        }
    }
}
Also used : HandlerProcessingResult(org.glassfish.apf.HandlerProcessingResult) AnnotatedElement(java.lang.reflect.AnnotatedElement) ResultType(org.glassfish.apf.ResultType) Annotation(java.lang.annotation.Annotation) AnnotationHandler(org.glassfish.apf.AnnotationHandler) AnnotationProcessorException(org.glassfish.apf.AnnotationProcessorException) AnnotationInfo(org.glassfish.apf.AnnotationInfo)

Aggregations

HandlerProcessingResult (org.glassfish.apf.HandlerProcessingResult)13 ArrayList (java.util.ArrayList)6 AnnotatedElementHandler (org.glassfish.apf.AnnotatedElementHandler)5 Annotation (java.lang.annotation.Annotation)3 EjbBundleContext (com.sun.enterprise.deployment.annotation.context.EjbBundleContext)2 EjbContext (com.sun.enterprise.deployment.annotation.context.EjbContext)2 EjbsContext (com.sun.enterprise.deployment.annotation.context.EjbsContext)2 AnnotatedElement (java.lang.reflect.AnnotatedElement)2 EnvironmentProperty (com.sun.enterprise.deployment.EnvironmentProperty)1 NameValuePairDescriptor (com.sun.enterprise.deployment.NameValuePairDescriptor)1 ComponentContext (com.sun.enterprise.deployment.annotation.context.ComponentContext)1 EjbInterceptorContext (com.sun.enterprise.deployment.annotation.context.EjbInterceptorContext)1 WebBundleContext (com.sun.enterprise.deployment.annotation.context.WebBundleContext)1 WebComponentContext (com.sun.enterprise.deployment.annotation.context.WebComponentContext)1 WebComponentsContext (com.sun.enterprise.deployment.annotation.context.WebComponentsContext)1 ApplicationState (fish.payara.nucleus.hotdeploy.ApplicationState)1 Resource (javax.annotation.Resource)1 Resources (javax.annotation.Resources)1 ActivationConfigProperty (javax.ejb.ActivationConfigProperty)1 EJB (javax.ejb.EJB)1