Search in sources :

Example 1 with ApplicationExceptionDescriptions

use of org.jboss.as.ejb3.deployment.ApplicationExceptionDescriptions in project wildfly by wildfly.

the class ApplicationExceptionMergingProcessor method deploy.

@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (!EjbDeploymentMarker.isEjbDeployment(deploymentUnit)) {
        return;
    }
    final List<DeploymentUnit> accessibleSubDeployments = deploymentUnit.getAttachment(Attachments.ACCESSIBLE_SUB_DEPLOYMENTS);
    final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
    final ApplicationExceptions applicationExceptions = new ApplicationExceptions();
    for (DeploymentUnit unit : accessibleSubDeployments) {
        //we want to get the details for classes from all sub deployments we have access to
        final ApplicationExceptionDescriptions exceptionDescriptions = unit.getAttachment(EjbDeploymentAttachmentKeys.APPLICATION_EXCEPTION_DESCRIPTIONS);
        if (exceptionDescriptions != null) {
            for (Map.Entry<String, org.jboss.as.ejb3.tx.ApplicationExceptionDetails> exception : exceptionDescriptions.getApplicationExceptions().entrySet()) {
                try {
                    final Class<?> index = ClassLoadingUtils.loadClass(exception.getKey(), module);
                    applicationExceptions.addApplicationException(index, exception.getValue());
                } catch (ClassNotFoundException e) {
                    ROOT_LOGGER.debug("Could not load application exception class", e);
                }
            }
        }
    }
    //now add the exceptions from the assembly descriptor
    EjbJarMetaData ejbJarMetaData = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
    if (ejbJarMetaData != null) {
        // process assembly-descriptor stuff
        AssemblyDescriptorMetaData assemblyDescriptor = ejbJarMetaData.getAssemblyDescriptor();
        if (assemblyDescriptor != null) {
            // process application-exception(s)
            ApplicationExceptionsMetaData ddAppExceptions = assemblyDescriptor.getApplicationExceptions();
            if (ddAppExceptions != null && !ddAppExceptions.isEmpty()) {
                for (ApplicationExceptionMetaData applicationException : ddAppExceptions) {
                    String exceptionClassName = applicationException.getExceptionClass();
                    try {
                        final Class<?> index = ClassLoadingUtils.loadClass(exceptionClassName, module);
                        boolean rollback = applicationException.isRollback();
                        // by default inherited is true
                        boolean inherited = applicationException.isInherited() == null ? true : applicationException.isInherited();
                        // add the application exception to the ejb jar description
                        applicationExceptions.addApplicationException(index, new ApplicationExceptionDetails(exceptionClassName, inherited, rollback));
                    } catch (ClassNotFoundException e) {
                        throw EjbLogger.ROOT_LOGGER.failToLoadAppExceptionClassInEjbJarXml(exceptionClassName, e);
                    }
                }
            }
        }
    }
    deploymentUnit.putAttachment(EjbDeploymentAttachmentKeys.APPLICATION_EXCEPTION_DETAILS, applicationExceptions);
}
Also used : ApplicationExceptions(org.jboss.as.ejb3.deployment.ApplicationExceptions) ApplicationExceptionDetails(org.jboss.as.ejb3.tx.ApplicationExceptionDetails) EjbJarMetaData(org.jboss.metadata.ejb.spec.EjbJarMetaData) ApplicationExceptionDescriptions(org.jboss.as.ejb3.deployment.ApplicationExceptionDescriptions) ApplicationExceptionsMetaData(org.jboss.metadata.ejb.spec.ApplicationExceptionsMetaData) AssemblyDescriptorMetaData(org.jboss.metadata.ejb.spec.AssemblyDescriptorMetaData) ApplicationExceptionMetaData(org.jboss.metadata.ejb.spec.ApplicationExceptionMetaData) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) Map(java.util.Map)

Example 2 with ApplicationExceptionDescriptions

use of org.jboss.as.ejb3.deployment.ApplicationExceptionDescriptions in project wildfly by wildfly.

the class ApplicationExceptionAnnotationProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (MetadataCompleteMarker.isMetadataComplete(deploymentUnit)) {
        return;
    }
    final CompositeIndex compositeIndex = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
    if (compositeIndex == null) {
        return;
    }
    List<AnnotationInstance> applicationExceptionAnnotations = compositeIndex.getAnnotations(DotName.createSimple(ApplicationException.class.getName()));
    if (applicationExceptionAnnotations == null || applicationExceptionAnnotations.isEmpty()) {
        return;
    }
    ApplicationExceptionDescriptions descriptions = new ApplicationExceptionDescriptions();
    deploymentUnit.putAttachment(EjbDeploymentAttachmentKeys.APPLICATION_EXCEPTION_DESCRIPTIONS, descriptions);
    for (AnnotationInstance annotationInstance : applicationExceptionAnnotations) {
        AnnotationTarget target = annotationInstance.target();
        if (!(target instanceof ClassInfo)) {
            throw EjbLogger.ROOT_LOGGER.annotationOnlyAllowedOnClass(ApplicationException.class.getName(), target);
        }
        String exceptionClassName = ((ClassInfo) target).name().toString();
        boolean rollback = false;
        AnnotationValue rollBackAnnValue = annotationInstance.value("rollback");
        if (rollBackAnnValue != null) {
            rollback = rollBackAnnValue.asBoolean();
        }
        // default "inherited" is true
        boolean inherited = true;
        AnnotationValue inheritedAnnValue = annotationInstance.value("inherited");
        if (inheritedAnnValue != null) {
            inherited = inheritedAnnValue.asBoolean();
        }
        descriptions.addApplicationException(exceptionClassName, rollback, inherited);
    }
}
Also used : AnnotationTarget(org.jboss.jandex.AnnotationTarget) ApplicationException(javax.ejb.ApplicationException) ApplicationExceptionDescriptions(org.jboss.as.ejb3.deployment.ApplicationExceptionDescriptions) CompositeIndex(org.jboss.as.server.deployment.annotation.CompositeIndex) AnnotationValue(org.jboss.jandex.AnnotationValue) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) AnnotationInstance(org.jboss.jandex.AnnotationInstance) ClassInfo(org.jboss.jandex.ClassInfo)

Aggregations

ApplicationExceptionDescriptions (org.jboss.as.ejb3.deployment.ApplicationExceptionDescriptions)2 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)2 Map (java.util.Map)1 ApplicationException (javax.ejb.ApplicationException)1 ApplicationExceptions (org.jboss.as.ejb3.deployment.ApplicationExceptions)1 ApplicationExceptionDetails (org.jboss.as.ejb3.tx.ApplicationExceptionDetails)1 CompositeIndex (org.jboss.as.server.deployment.annotation.CompositeIndex)1 AnnotationInstance (org.jboss.jandex.AnnotationInstance)1 AnnotationTarget (org.jboss.jandex.AnnotationTarget)1 AnnotationValue (org.jboss.jandex.AnnotationValue)1 ClassInfo (org.jboss.jandex.ClassInfo)1 ApplicationExceptionMetaData (org.jboss.metadata.ejb.spec.ApplicationExceptionMetaData)1 ApplicationExceptionsMetaData (org.jboss.metadata.ejb.spec.ApplicationExceptionsMetaData)1 AssemblyDescriptorMetaData (org.jboss.metadata.ejb.spec.AssemblyDescriptorMetaData)1 EjbJarMetaData (org.jboss.metadata.ejb.spec.EjbJarMetaData)1 Module (org.jboss.modules.Module)1