/** * Check the deployment annotation index for all classes with the @ManagedBean annotation. For * each class with the annotation, collect all the required information to create a managed bean * instance, and attach it to the context. * * @param phaseContext the deployment unit context * @throws DeploymentUnitProcessingException */ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION); final String applicationName = moduleDescription.getAppName(); final CompositeIndex compositeIndex = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX); if (compositeIndex == null) { return; } final List<AnnotationInstance> instances = compositeIndex.getAnnotations(MANAGED_BEAN_ANNOTATION_NAME); if (instances == null || instances.isEmpty()) { return; } for (AnnotationInstance instance : instances) { AnnotationTarget target = instance.target(); if (!(target instanceof ClassInfo)) { throw new DeploymentUnitProcessingException( "The ManagedBean annotation is only allowed at the class level: " + target); } final ClassInfo classInfo = (ClassInfo) target; final String beanClassName = classInfo.name().toString(); // Get the managed bean name from the annotation final AnnotationValue nameValue = instance.value(); final String beanName = nameValue == null || nameValue.asString().isEmpty() ? beanClassName : nameValue.asString(); final ManagedBeanComponentDescription componentDescription = new ManagedBeanComponentDescription( beanName, beanClassName, moduleDescription.getModuleName(), applicationName); final ServiceName baseName = deploymentUnit.getServiceName().append("component").append(beanName); // Add the view componentDescription.getViewClassNames().add(beanClassName); // Bind the view to its two JNDI locations // TODO - this should be a bit more elegant final BindingDescription moduleBinding = new BindingDescription(); moduleBinding.setAbsoluteBinding(true); moduleBinding.setBindingName("java:module/" + beanName); moduleBinding.setBindingType(beanClassName); moduleBinding.setReferenceSourceDescription( new ServiceBindingSourceDescription(baseName.append("VIEW").append(beanClassName))); componentDescription.getBindings().add(moduleBinding); final BindingDescription appBinding = new BindingDescription(); appBinding.setAbsoluteBinding(true); appBinding.setBindingName("java:app/" + moduleDescription.getModuleName() + "/" + beanName); appBinding.setBindingType(beanClassName); appBinding.setReferenceSourceDescription( new ServiceBindingSourceDescription(baseName.append("VIEW").append(beanClassName))); componentDescription.getBindings().add(appBinding); moduleDescription.addComponent(componentDescription); } }