public void install(String name, DependencyPolicy dependencies,
DeploymentUnit unit, Object service)
{
// Look for the kernel deployment
KernelDeployment deployment = null;
if(unit != null)
{
deployment = (KernelDeployment) unit.getAttachment(KernelDeployment.class.getName());
if(deployment == null)
{
AbstractKernelDeployment akd = new AbstractKernelDeployment();
akd.setBeanFactories(new ArrayList<BeanMetaDataFactory>());
deployment = akd;
String kdname = unit.getShortName();
deployment.setName(kdname);
unit.addAttachment(KernelDeployment.class.getName(), deployment);
log.info("Created KernelDeployment for: "+unit.getShortName());
}
}
// Create the metadata for the bean to install
AbstractBeanMetaData bean = new AbstractBeanMetaData(name, service.getClass().getName());
bean.setConstructor(new AlreadyInstantiated(service));
MCDependencyPolicy policy = (MCDependencyPolicy) dependencies;
bean.setDepends(policy.getDependencies());
bean.setDemands(policy.getDemands());
bean.setSupplies(policy.getSupplies());
log.info("installing bean: " + name);
log.info(" with dependencies:");
for (Object obj : policy.getDependencies())
{
Object msgObject = obj;
if (obj instanceof AbstractDemandMetaData)
{
msgObject = ((AbstractDemandMetaData)obj).getDemand();
}
log.info("\t" + msgObject);
}
log.info(" and demands:");
for(DemandMetaData dmd : policy.getDemands())
{
log.info("\t" + dmd.getDemand() + "; Required: " + dmd.getWhenRequired().getStateString());
}
log.info(" and supplies:");
for(SupplyMetaData smd : policy.getSupplies())
{
log.info("\t" + smd.getSupply());
}
if(service instanceof EJBContainer)
{
EJBContainer container = EJBContainer.class.cast(service);
// TODO: use an informer
JavaEEModule module = container.getModule();
String moduleName = stripSuffix(module.getName());
JavaEEApplication app = module.getApplication();
String appName = app != null ? stripSuffix(app.getName()) : null;
String scopedBeanName = "application=" + (appName != null ? appName : moduleName) + ",module=" + moduleName + ",component=" + container.getEjbName();
String encFactoryBeanName = "jboss.ejb3:" + scopedBeanName + ",service=EjbEncFactory";
// create an EjbEncFactory for this container
{
BeanMetaDataBuilder builder = BeanMetaDataBuilderFactory.createBuilder(encFactoryBeanName, NamingComponentEjbEncFactory.class.getName());
String componentBeanName = "jboss.naming:" + scopedBeanName;
builder.addConstructorParameter(JavaEEComponent.class.getName(), new AbstractInjectionValueMetaData(componentBeanName));
// TODO: is deployment always available at this stage?
deployment.getBeanFactories().add(builder.getBeanMetaDataFactory());
}
// modify the container bean meta data to inject the EjbEncFactory
BeanMetaDataBuilder builder = BeanMetaDataBuilderFactory.createBuilder(bean);
//builder.addPropertyMetaData("namingComponent", new AbstractInjectionValueMetaData("java:comp"));
builder.addPropertyMetaData("ejbEncFactory", new AbstractInjectionValueMetaData(encFactoryBeanName));
// Add the BeanInstantiator injection into EJBContainer
// TODO: (Jaikiran) Terrible hack! Use JavaEEComponentInformer to get the app name.
// But for now, due to lack of time for 6.0.0.CR1 release, let's just use this hack
if (appName == null)
{
appName = moduleName;
}
String beanInstantiatorMcName = BeanInstantiatorRegistration.getInstantiatorRegistrationName(appName, moduleName, container.getEjbName());
builder.addPropertyMetaData("beanInstantiator", new AbstractInjectionValueMetaData(beanInstantiatorMcName));
// ahem
if(service instanceof StatelessContainer)
{
((StatelessContainer) service).setBusinessObjectFactory(new EJB31StatelessBusinessObjectFactory());
}
if(service instanceof StatefulContainer)
((StatefulContainer) service).setBusinessObjectFactory(new EJB31StatefulBusinessObjectFactory(kernel));
}
if(unit != null)
{
// Just add the mc bean metadata to the unit
deployment.getBeanFactories().add(bean);
log.info("Added bean("+name+") to KernelDeployment of: "+unit.getShortName());
}
else
{
// Install directly into the kernel