// Add any dependencies based on @DependsOn/depends-on elements
JBossSessionBean31MetaData sessionBeanMetaData = (JBossSessionBean31MetaData) container.getMetaData();
String[] dependsOn = sessionBeanMetaData.getDependsOn();
if (dependsOn != null)
{
AbstractListMetaData containerDependencies = new AbstractListMetaData();
EjbLinkResolver ejbLinkResolver = new EjbLinkResolver();
for (String dependency : dependsOn)
{
// resolve the EJB through the ejb link in depends-on
JBossEnterpriseBeanMetaData dependencyBean = ejbLinkResolver.resolveEJB(dependency, unit);
if (dependencyBean == null)
{
throw new RuntimeException("Could not resolve bean for @DependsOn/depends-on with ejb-name: "
+ dependency + " while processing EJB named " + container.getEJBName());
}
if (isSingletonBean(dependencyBean) == false)
{
throw new RuntimeException("@DependsOn/depends-on can only refer to Singleton beans. "
+ dependencyBean.getEjbClass() + " is not a singleton bean");
}
// when a singleton bean depends on the other singleton bean, we add:
// 1) A dependency on the target EJB container. This we do by injecting the target EJB container
// into this container being installed. The injected target containers will then be used
// to instantiate the target @Depends bean (at the appropriate time)
// 2) A dependency on each of the exposed JNDI names of the target EJB (so that the
// target EJB can be accessed through JNDI within the dependent EJB)
// get the exposed JNDI names
List<String> jndiNames = this.getExposedJNDINames((JBossSessionBean31MetaData) dependencyBean);
for (String jndiName : jndiNames)
{
// add each jndi name as a dependency
// Note: The dependency resolution of a dependency with prefix JNDIKernelRegistryPlugin.JNDI_DEPENDENCY_PREFIX
// is handled by JNDIKernelRegistryPlugin, which does a JNDI lookup to see if the dependency is resolved.
// Effectively, none of the MC beans have to add the jndi name as an explicit supply. So when the
// corresponding jndi binder binds this jndi name to JNDI tree, the dependency will be marked as resolved
containerDependencyPolicy.addDependency(JNDIKernelRegistryPlugin.JNDI_DEPENDENCY_PREFIX + jndiName);
}
String dependencyBeanContainerName = dependencyBean.getContainerName();
// create a @Inject
AbstractInjectionValueMetaData containerDependencyInjection = new AbstractInjectionValueMetaData(dependencyBeanContainerName);
// add the @Inject to a list which will then be set on the container
containerDependencies.add(containerDependencyInjection);
}
// add the list of @Inject(s)
containerBMDBuilder.addPropertyMetaData("singletonDependsOn", containerDependencies);
}