{
BeanMetaDataBuilder containerBMDBuilder = BeanMetaDataBuilder.createBuilder(containerMCBeanName, container
.getClass().getName());
containerBMDBuilder.setConstructorValue(container);
DependencyPolicy containerDependencyPolicy = container.getDependencyPolicy();
// Add dependency on switchboard
Barrier switchBoard = unit.getAttachment(Barrier.class);
// the container cannot function without an SwitchBoard Barrier
if (switchBoard == null)
{
throw new RuntimeException("No SwitchBoard Barrier found for bean: " + container.getEjbName() + " in unit: " + unit);
}
// add dependency on START (and not INSTALLED) state of Switchboard, since the container only requires a fully populated ENC context,
// but doesn't require a invokable context. An invokable context is only needed by Injector.
containerBMDBuilder.addDemand(switchBoard.getId(), ControllerState.CREATE, ControllerState.START, null);
logger.debug("Added dependency on switchboard " + switchBoard.getId() + " for container " + container.getName());
InjectionManager injectionManager = unit.getAttachment(InjectionManager.class);
// the container cannot function without an InjectionManager
if (injectionManager == null)
{
throw new RuntimeException("No InjectionManager found for bean: " + container.getEjbName() + " in unit: " + unit);
}
// set the InjectionManager on the container
container.setInjectionManager(injectionManager);
// add EEInjector to InjectionManager
this.setupInjectors(unit, container, injectionManager, switchBoard);
// Process @DependsOn/depends-on
// 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