}
final EEApplicationDescription applicationDescription = deploymentUnit.getAttachment(Attachments.EE_APPLICATION_DESCRIPTION);
final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT);
final SingletonComponentDescription singletonComponentDescription = componentDescriptionType.cast(componentDescription);
final List<AnnotationInstance> dependsOnAnnotations = annotationsOnBean.get(DotName.createSimple(DependsOn.class
.getName()));
if (dependsOnAnnotations == null || dependsOnAnnotations.isEmpty()) {
return;
}
validate(annotationsOnBean, dependsOnAnnotations, singletonComponentDescription.getEJBName());
final AnnotationInstance dependsOnAnnotation = dependsOnAnnotations.get(0);
// Add the dependencies
final String[] annotationValues = dependsOnAnnotation.value().asStringArray();
for (String annotationValue : annotationValues) {
final Set<ComponentDescription> components = applicationDescription.getComponents(annotationValue, deploymentRoot.getRoot());
if (components.isEmpty()) {
throw new DeploymentUnitProcessingException("Could not find EJB " + annotationValue + " referenced by @DependsOn annotation in " + componentDescription.getComponentClassName());
} else if (components.size() != 1) {
throw new DeploymentUnitProcessingException("More than one EJB called" + annotationValue + " referenced by @DependsOn annotation in " + componentDescription.getComponentClassName() + " Components: " + components);
}
final ComponentDescription component = components.iterator().next();
final ServiceName serviceName = createServiceName(component);
singletonComponentDescription.getDependsOn().add(serviceName);
componentDescription.addDependency(createServiceName(component),
DependencyType.REQUIRED);
}
logger.info(singletonComponentDescription.getEJBName() + " bean has @DependsOn");
componentDescription.getConfigurators().add(new ComponentConfigurator() {
@Override
public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
configuration.getStartDependencies().add(new DependencyConfigurator<ComponentStartService>() {
@Override
public void configureDependency(final ServiceBuilder<?> serviceBuilder, ComponentStartService service) throws DeploymentUnitProcessingException {
for(ServiceName dep : singletonComponentDescription.getDependsOn()) {
serviceBuilder.addDependency(dep);
}
}
});
}