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);
}
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());
}
}
}
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);
}
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;
}
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);
}
Aggregations