Search in sources :

Example 1 with SessionBean32MetaData

use of org.jboss.metadata.ejb.spec.SessionBean32MetaData in project wildfly by wildfly.

the class SessionBeanComponentDescriptionFactory method processSessionBeanMetaData.

private void processSessionBeanMetaData(final DeploymentUnit deploymentUnit, final SessionBeanMetaData sessionBean) throws DeploymentUnitProcessingException {
    final EjbJarDescription ejbJarDescription = getEjbJarDescription(deploymentUnit);
    final CompositeIndex compositeIndex = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.COMPOSITE_ANNOTATION_INDEX);
    final String beanName = sessionBean.getName();
    SessionType sessionType = sessionBean.getSessionType();
    if (sessionType == null && sessionBean instanceof GenericBeanMetaData) {
        final GenericBeanMetaData bean = (GenericBeanMetaData) sessionBean;
        if (bean.getEjbType() == EjbType.SESSION) {
            sessionType = determineSessionType(sessionBean.getEjbClass(), compositeIndex);
            if (sessionType == null) {
                throw EjbLogger.ROOT_LOGGER.sessionTypeNotSpecified(beanName);
            }
        } else {
            //it is not a session bean, so we ignore it
            return;
        }
    } else if (sessionType == null) {
        sessionType = determineSessionType(sessionBean.getEjbClass(), compositeIndex);
        if (sessionType == null) {
            throw EjbLogger.ROOT_LOGGER.sessionTypeNotSpecified(beanName);
        }
    }
    final String beanClassName = sessionBean.getEjbClass();
    final SessionBeanComponentDescription sessionBeanDescription;
    switch(sessionType) {
        case Stateless:
            sessionBeanDescription = new StatelessComponentDescription(beanName, beanClassName, ejbJarDescription, deploymentUnit.getServiceName(), sessionBean);
            break;
        case Stateful:
            sessionBeanDescription = new StatefulComponentDescription(beanName, beanClassName, ejbJarDescription, deploymentUnit.getServiceName(), sessionBean);
            if (sessionBean instanceof SessionBean32MetaData && ((SessionBean32MetaData) sessionBean).isPassivationCapable() != null) {
                ((StatefulComponentDescription) sessionBeanDescription).setPassivationApplicable(((SessionBean32MetaData) sessionBean).isPassivationCapable());
            }
            break;
        case Singleton:
            sessionBeanDescription = new SingletonComponentDescription(beanName, beanClassName, ejbJarDescription, deploymentUnit.getServiceName(), sessionBean);
            break;
        default:
            throw EjbLogger.ROOT_LOGGER.unknownSessionBeanType(sessionType.name());
    }
    addComponent(deploymentUnit, sessionBeanDescription);
}
Also used : SessionType(org.jboss.metadata.ejb.spec.SessionType) StatelessComponentDescription(org.jboss.as.ejb3.component.stateless.StatelessComponentDescription) StatefulComponentDescription(org.jboss.as.ejb3.component.stateful.StatefulComponentDescription) EjbJarDescription(org.jboss.as.ejb3.deployment.EjbJarDescription) AbstractDeploymentUnitProcessor.getEjbJarDescription(org.jboss.as.ejb3.deployment.processors.AbstractDeploymentUnitProcessor.getEjbJarDescription) SessionBean32MetaData(org.jboss.metadata.ejb.spec.SessionBean32MetaData) CompositeIndex(org.jboss.as.server.deployment.annotation.CompositeIndex) GenericBeanMetaData(org.jboss.metadata.ejb.spec.GenericBeanMetaData) SingletonComponentDescription(org.jboss.as.ejb3.component.singleton.SingletonComponentDescription) SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription)

Example 2 with SessionBean32MetaData

use of org.jboss.metadata.ejb.spec.SessionBean32MetaData 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, deploymentUnitServiceName, beanMetaData);
                break;
            case STATEFUL:
                sessionBeanDescription = new StatefulComponentDescription(beanName, beanClassName, ejbJarDescription, deploymentUnitServiceName, 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:
                sessionBeanDescription = new SingletonComponentDescription(beanName, beanClassName, ejbJarDescription, deploymentUnitServiceName, beanMetaData);
                break;
            default:
                throw EjbLogger.ROOT_LOGGER.unknownSessionBeanType(sessionBeanType.name());
        }
        addComponent(deploymentUnit, sessionBeanDescription);
    }
    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) EjbJarDescription(org.jboss.as.ejb3.deployment.EjbJarDescription) AbstractDeploymentUnitProcessor.getEjbJarDescription(org.jboss.as.ejb3.deployment.processors.AbstractDeploymentUnitProcessor.getEjbJarDescription) 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)

Aggregations

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 EjbJarDescription (org.jboss.as.ejb3.deployment.EjbJarDescription)2 AbstractDeploymentUnitProcessor.getEjbJarDescription (org.jboss.as.ejb3.deployment.processors.AbstractDeploymentUnitProcessor.getEjbJarDescription)2 SessionBean32MetaData (org.jboss.metadata.ejb.spec.SessionBean32MetaData)2 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 GenericBeanMetaData (org.jboss.metadata.ejb.spec.GenericBeanMetaData)1 SessionBeanMetaData (org.jboss.metadata.ejb.spec.SessionBeanMetaData)1 SessionType (org.jboss.metadata.ejb.spec.SessionType)1 PropertyReplacer (org.jboss.metadata.property.PropertyReplacer)1 ServiceName (org.jboss.msc.service.ServiceName)1