Search in sources :

Example 6 with EjbJarDescription

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

the class SessionBeanComponentDescriptionFactory method processSessionBeans.

private void processSessionBeans(final DeploymentUnit deploymentUnit, final List<AnnotationInstance> sessionBeanAnnotations, final SessionBeanComponentDescription.SessionBeanType annotatedSessionBeanType) {
    final EjbJarDescription ejbJarDescription = getEjbJarDescription(deploymentUnit);
    final ServiceName deploymentUnitServiceName = deploymentUnit.getServiceName();
    PropertyReplacer propertyReplacer = EJBAnnotationPropertyReplacement.propertyReplacer(deploymentUnit);
    // process these session bean annotations and create component descriptions out of it
    for (final AnnotationInstance sessionBeanAnnotation : sessionBeanAnnotations) {
        final AnnotationTarget target = sessionBeanAnnotation.target();
        if (!(target instanceof ClassInfo)) {
            // Let's just WARN and move on. No need to throw an error
            EjbLogger.DEPLOYMENT_LOGGER.warn(EjbLogger.ROOT_LOGGER.annotationOnlyAllowedOnClass(sessionBeanAnnotation.name().toString(), target).getMessage());
            continue;
        }
        final ClassInfo sessionBeanClassInfo = (ClassInfo) target;
        // skip if it's not a valid class for session bean
        if (!assertSessionBeanClassValidity(sessionBeanClassInfo)) {
            continue;
        }
        final String ejbName = sessionBeanClassInfo.name().local();
        final AnnotationValue nameValue = sessionBeanAnnotation.value("name");
        final String beanName = (nameValue == null || nameValue.asString().isEmpty()) ? ejbName : propertyReplacer.replaceProperties(nameValue.asString());
        final SessionBeanMetaData beanMetaData = getEnterpriseBeanMetaData(deploymentUnit, beanName, SessionBeanMetaData.class);
        final SessionBeanComponentDescription.SessionBeanType sessionBeanType;
        final String beanClassName;
        if (beanMetaData != null) {
            beanClassName = override(sessionBeanClassInfo.name().toString(), beanMetaData.getEjbClass());
            sessionBeanType = override(annotatedSessionBeanType, descriptionOf(((SessionBeanMetaData) beanMetaData).getSessionType()));
        } else {
            beanClassName = sessionBeanClassInfo.name().toString();
            sessionBeanType = annotatedSessionBeanType;
        }
        final SessionBeanComponentDescription sessionBeanDescription;
        switch(sessionBeanType) {
            case STATELESS:
                sessionBeanDescription = new StatelessComponentDescription(beanName, beanClassName, ejbJarDescription, deploymentUnit, beanMetaData, defaultSlsbPoolAvailable);
                break;
            case STATEFUL:
                sessionBeanDescription = new StatefulComponentDescription(beanName, beanClassName, ejbJarDescription, deploymentUnit, beanMetaData);
                // If passivation is disabled for the SFSB, either via annotation or via DD, then setup the component
                // description appropriately
                final boolean passivationCapableAnnotationValue = sessionBeanAnnotation.value("passivationCapable") == null ? true : sessionBeanAnnotation.value("passivationCapable").asBoolean();
                final Boolean passivationCapableDeploymentDescriptorValue;
                if ((beanMetaData instanceof SessionBean32MetaData)) {
                    passivationCapableDeploymentDescriptorValue = ((SessionBean32MetaData) beanMetaData).isPassivationCapable();
                } else {
                    passivationCapableDeploymentDescriptorValue = null;
                }
                final boolean passivationApplicable = override(passivationCapableDeploymentDescriptorValue, passivationCapableAnnotationValue);
                ((StatefulComponentDescription) sessionBeanDescription).setPassivationApplicable(passivationApplicable);
                break;
            case SINGLETON:
                if (sessionBeanClassInfo.interfaceNames().contains(SESSION_BEAN_INTERFACE)) {
                    EjbLogger.ROOT_LOGGER.singletonCantImplementSessionBean(beanClassName);
                }
                sessionBeanDescription = new SingletonComponentDescription(beanName, beanClassName, ejbJarDescription, deploymentUnit, beanMetaData);
                break;
            default:
                throw EjbLogger.ROOT_LOGGER.unknownSessionBeanType(sessionBeanType.name());
        }
        addComponent(deploymentUnit, sessionBeanDescription);
        final AnnotationValue mappedNameValue = sessionBeanAnnotation.value("mappedName");
        if (mappedNameValue != null && !mappedNameValue.asString().isEmpty()) {
            EjbLogger.ROOT_LOGGER.mappedNameNotSupported(mappedNameValue != null ? mappedNameValue.asString() : "", ejbName);
        }
    }
    EjbDeploymentMarker.mark(deploymentUnit);
}
Also used : AnnotationTarget(org.jboss.jandex.AnnotationTarget) SessionBeanMetaData(org.jboss.metadata.ejb.spec.SessionBeanMetaData) ServiceName(org.jboss.msc.service.ServiceName) StatelessComponentDescription(org.jboss.as.ejb3.component.stateless.StatelessComponentDescription) StatefulComponentDescription(org.jboss.as.ejb3.component.stateful.StatefulComponentDescription) AnnotatedEJBComponentDescriptionDeploymentUnitProcessor.getEjbJarDescription(org.jboss.as.ejb3.deployment.processors.AnnotatedEJBComponentDescriptionDeploymentUnitProcessor.getEjbJarDescription) EjbJarDescription(org.jboss.as.ejb3.deployment.EjbJarDescription) SessionBean32MetaData(org.jboss.metadata.ejb.spec.SessionBean32MetaData) AnnotationValue(org.jboss.jandex.AnnotationValue) PropertyReplacer(org.jboss.metadata.property.PropertyReplacer) SingletonComponentDescription(org.jboss.as.ejb3.component.singleton.SingletonComponentDescription) SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription) AnnotationInstance(org.jboss.jandex.AnnotationInstance) ClassInfo(org.jboss.jandex.ClassInfo)

Example 7 with EjbJarDescription

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

the class EjbJarParsingDeploymentUnitProcessor method deploy.

/**
 * Finds an ejb-jar.xml (at WEB-INF of a .war or META-INF of a .jar) parses the file and creates
 * metadata out of it. The metadata is then attached to the deployment unit.
 *
 * @param deploymentPhase
 * @throws DeploymentUnitProcessingException
 */
@Override
public void deploy(DeploymentPhaseContext deploymentPhase) throws DeploymentUnitProcessingException {
    // get hold of the deployment unit.
    final DeploymentUnit deploymentUnit = deploymentPhase.getDeploymentUnit();
    // get the root of the deployment unit
    final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
    final EEApplicationClasses applicationClassesDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
    final EjbJarMetaData ejbJarMetaData;
    final EjbJarMetaData specMetaData = parseEjbJarXml(deploymentUnit);
    final EjbJarMetaData jbossMetaData = parseJBossEjb3Xml(deploymentUnit);
    if (specMetaData == null) {
        if (jbossMetaData == null)
            return;
        ejbJarMetaData = jbossMetaData;
    } else if (jbossMetaData == null) {
        ejbJarMetaData = specMetaData;
    } else {
        ejbJarMetaData = jbossMetaData.createMerged(specMetaData);
    }
    // Mark it as an EJB deployment
    EjbDeploymentMarker.mark(deploymentUnit);
    if (!deploymentUnit.hasAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_DESCRIPTION)) {
        final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
        final EjbJarDescription ejbModuleDescription = new EjbJarDescription(moduleDescription, deploymentUnit.getName().endsWith(".war"));
        deploymentUnit.putAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_DESCRIPTION, ejbModuleDescription);
    }
    // attach the EjbJarMetaData to the deployment unit
    deploymentUnit.putAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA, ejbJarMetaData);
    // if the jboss-ejb3.xml has a distinct-name configured then attach it to the deployment unit
    if (jbossMetaData != null && jbossMetaData.getDistinctName() != null) {
        deploymentUnit.putAttachment(org.jboss.as.ee.structure.Attachments.DISTINCT_NAME, jbossMetaData.getDistinctName());
    }
    if (ejbJarMetaData.getModuleName() != null) {
        eeModuleDescription.setModuleName(ejbJarMetaData.getModuleName());
    }
    if (ejbJarMetaData.isMetadataComplete()) {
        MetadataCompleteMarker.setMetadataComplete(deploymentUnit, true);
    }
    if (!ejbJarMetaData.isEJB3x()) {
        // EJB spec 20.5.1, we do not process annotations for older deployments
        MetadataCompleteMarker.setMetadataComplete(deploymentUnit, true);
    }
    if (ejbJarMetaData.getEnterpriseBeans() != null) {
        // check for entity beans
        StringBuilder beans = new StringBuilder();
        boolean error = false;
        for (AbstractEnterpriseBeanMetaData bean : ejbJarMetaData.getEnterpriseBeans()) {
            if (bean.getEjbType() == EjbType.ENTITY) {
                if (!error) {
                    error = true;
                } else {
                    beans.append(", ");
                }
                beans.append(bean.getEjbName());
            }
        }
        if (error) {
            throw EjbLogger.ROOT_LOGGER.entityBeansAreNotSupported(beans.toString());
        }
    }
}
Also used : AbstractEnterpriseBeanMetaData(org.jboss.metadata.ejb.spec.AbstractEnterpriseBeanMetaData) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) EEApplicationClasses(org.jboss.as.ee.component.EEApplicationClasses) EjbJarMetaData(org.jboss.metadata.ejb.spec.EjbJarMetaData) EjbJarDescription(org.jboss.as.ejb3.deployment.EjbJarDescription) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 8 with EjbJarDescription

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

the class MessageDrivenComponentDescriptionFactory method processMessageDrivenBeanMetaData.

private void processMessageDrivenBeanMetaData(final DeploymentUnit deploymentUnit, final MessageDrivenBeanMetaData mdb) throws DeploymentUnitProcessingException {
    final EjbJarDescription ejbJarDescription = getEjbJarDescription(deploymentUnit);
    final String beanName = mdb.getName();
    final String beanClassName = mdb.getEjbClass();
    String messageListenerInterface = mdb.getMessagingType();
    if (messageListenerInterface == null || messageListenerInterface.trim().isEmpty()) {
        // TODO: This isn't really correct to default to MessageListener
        messageListenerInterface = MessageListener.class.getName();
    }
    final Properties activationConfigProps = getActivationConfigProperties(mdb.getActivationConfig());
    final String defaultResourceAdapterName = this.getDefaultResourceAdapterName(deploymentUnit.getServiceRegistry());
    final MessageDrivenComponentDescription mdbComponentDescription = new MessageDrivenComponentDescription(beanName, beanClassName, ejbJarDescription, deploymentUnit, messageListenerInterface, activationConfigProps, defaultResourceAdapterName, mdb, defaultMdbPoolAvailable);
    mdbComponentDescription.setDeploymentDescriptorEnvironment(new DeploymentDescriptorEnvironment("java:comp/env/", mdb));
    addComponent(deploymentUnit, mdbComponentDescription);
}
Also used : MessageDrivenComponentDescription(org.jboss.as.ejb3.component.messagedriven.MessageDrivenComponentDescription) DeploymentDescriptorEnvironment(org.jboss.as.ee.component.DeploymentDescriptorEnvironment) AnnotatedEJBComponentDescriptionDeploymentUnitProcessor.getEjbJarDescription(org.jboss.as.ejb3.deployment.processors.AnnotatedEJBComponentDescriptionDeploymentUnitProcessor.getEjbJarDescription) EjbJarDescription(org.jboss.as.ejb3.deployment.EjbJarDescription) MessageListener(javax.jms.MessageListener) Properties(java.util.Properties)

Example 9 with EjbJarDescription

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

the class AnnotatedEJBComponentDescriptionDeploymentUnitProcessor method getEjbJarDescription.

protected static EjbJarDescription getEjbJarDescription(final DeploymentUnit deploymentUnit) {
    EjbJarDescription ejbJarDescription = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_DESCRIPTION);
    if (ejbJarDescription == null) {
        final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
        ejbJarDescription = new EjbJarDescription(moduleDescription, deploymentUnit.getName().endsWith(".war"));
        deploymentUnit.putAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_DESCRIPTION, ejbJarDescription);
    }
    return ejbJarDescription;
}
Also used : EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) EjbJarDescription(org.jboss.as.ejb3.deployment.EjbJarDescription)

Example 10 with EjbJarDescription

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

the class AnnotatedEJBComponentDescriptionDeploymentUnitProcessor method processDeploymentDescriptor.

private void processDeploymentDescriptor(final DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {
    // find the Jakarta Enterprise Beans jar metadata and start processing it
    final EjbJarMetaData ejbJarMetaData = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
    if (ejbJarMetaData == null) {
        return;
    }
    final SimpleSet<String> annotatedEJBs;
    if (appclient) {
        final List<ComponentDescription> additionalComponents = deploymentUnit.getAttachmentList(org.jboss.as.ee.component.Attachments.ADDITIONAL_RESOLVABLE_COMPONENTS);
        annotatedEJBs = new SimpleSet<String>() {

            @Override
            public boolean contains(Object o) {
                for (final ComponentDescription component : additionalComponents) {
                    if (component.getComponentName().equals(o)) {
                        return true;
                    }
                }
                return false;
            }
        };
    } else {
        final EjbJarDescription ejbJarDescription = getEjbJarDescription(deploymentUnit);
        annotatedEJBs = new SimpleSet<String>() {

            @Override
            public boolean contains(Object o) {
                return ejbJarDescription.hasComponent((String) o);
            }
        };
    }
    // process Jakarta Enterprise Beans
    final EnterpriseBeansMetaData ejbs = ejbJarMetaData.getEnterpriseBeans();
    if (ejbs != null && !ejbs.isEmpty()) {
        for (final EnterpriseBeanMetaData ejb : ejbs) {
            final String beanName = ejb.getName();
            // the important bit is to skip already processed Jakarta Enterprise Beans via annotations
            if (annotatedEJBs.contains(beanName)) {
                continue;
            }
            processBeanMetaData(deploymentUnit, ejb);
        }
    }
    EjbDeploymentMarker.mark(deploymentUnit);
}
Also used : ComponentDescription(org.jboss.as.ee.component.ComponentDescription) EnterpriseBeansMetaData(org.jboss.metadata.ejb.spec.EnterpriseBeansMetaData) EjbJarMetaData(org.jboss.metadata.ejb.spec.EjbJarMetaData) EjbJarDescription(org.jboss.as.ejb3.deployment.EjbJarDescription) EnterpriseBeanMetaData(org.jboss.metadata.ejb.spec.EnterpriseBeanMetaData)

Aggregations

EjbJarDescription (org.jboss.as.ejb3.deployment.EjbJarDescription)10 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)4 AnnotatedEJBComponentDescriptionDeploymentUnitProcessor.getEjbJarDescription (org.jboss.as.ejb3.deployment.processors.AnnotatedEJBComponentDescriptionDeploymentUnitProcessor.getEjbJarDescription)4 EjbJarMetaData (org.jboss.metadata.ejb.spec.EjbJarMetaData)4 Properties (java.util.Properties)2 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)2 DeploymentDescriptorEnvironment (org.jboss.as.ee.component.DeploymentDescriptorEnvironment)2 EEApplicationClasses (org.jboss.as.ee.component.EEApplicationClasses)2 MessageDrivenComponentDescription (org.jboss.as.ejb3.component.messagedriven.MessageDrivenComponentDescription)2 SessionBeanComponentDescription (org.jboss.as.ejb3.component.session.SessionBeanComponentDescription)2 SingletonComponentDescription (org.jboss.as.ejb3.component.singleton.SingletonComponentDescription)2 StatefulComponentDescription (org.jboss.as.ejb3.component.stateful.StatefulComponentDescription)2 StatelessComponentDescription (org.jboss.as.ejb3.component.stateless.StatelessComponentDescription)2 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)2 AnnotationInstance (org.jboss.jandex.AnnotationInstance)2 AnnotationTarget (org.jboss.jandex.AnnotationTarget)2 AnnotationValue (org.jboss.jandex.AnnotationValue)2 ClassInfo (org.jboss.jandex.ClassInfo)2 EnterpriseBeanMetaData (org.jboss.metadata.ejb.spec.EnterpriseBeanMetaData)2 EnterpriseBeansMetaData (org.jboss.metadata.ejb.spec.EnterpriseBeansMetaData)2