return;
List<BeanMetaDataFactory> beanFactories = deployment.getBeanFactories();
// Get the KernelDeployment ManagedObject
ManagedObject deploymentMO = managedObjects.get(KernelDeployment.class.getName());
if(deploymentMO == null)
{
// Check for the KernelDeployment impl name
deploymentMO = managedObjects.get(AbstractKernelDeployment.class.getName());
if(deploymentMO == null)
{
// Should not happen?
deploymentMO = mof.createManagedObject(deployment.getClass());
}
else
{
// Put the MO under the attachment interface name
managedObjects.remove(AbstractKernelDeployment.class.getName());
}
managedObjects.put(KernelDeployment.class.getName(), deploymentMO);
}
if(deploymentMO instanceof MutableManagedObject)
((MutableManagedObject) deploymentMO).setName(KernelDeployment.class.getName());
if(deploymentMO instanceof ManagedObjectImpl)
((ManagedObjectImpl) deploymentMO).setAttachmentName(KernelDeployment.class.getName());
MetaData metaData = unit.getMetaData();
// Update the beanFactories value to a list of BeanMetaDataFactory with BeanMetaDatas
ManagedProperty beanFactoriesMP = deploymentMO.getProperty("beanFactories");
List<GenericValue> tmpBFs = new ArrayList<GenericValue>();
CollectionMetaType beansFactoryType = new CollectionMetaType(BeanMetaDataFactory.class.getName(), AbstractManagedObjectFactory.MANAGED_OBJECT_META_TYPE);
if(beanFactories != null)
{
List<GenericValue> tmpBeans = new ArrayList<GenericValue>();
CollectionMetaType beansType = new CollectionMetaType(BeanMetaDataFactory.class.getName(), AbstractManagedObjectFactory.MANAGED_OBJECT_META_TYPE);
for(BeanMetaDataFactory bmdf : beanFactories)
{
ManagedObject bmdfMO = mof.initManagedObject(bmdf, metaData);
if(bmdfMO == null)
{
// Create a container managed object
bmdfMO = createFactoryManagedObject(bmdf, deploymentMO, metaData);
}
if((bmdfMO instanceof MutableManagedObject) == false)
{
// Just go with the default ManagedObject
GenericValueSupport gv = new GenericValueSupport(AbstractManagedObjectFactory.MANAGED_OBJECT_META_TYPE, bmdfMO);
tmpBFs.add(gv);
continue;
}
MutableManagedObject bmdfMMO = (MutableManagedObject) bmdfMO;
bmdfMMO.setParent(deploymentMO);
Map<String, ManagedProperty> oldProps = bmdfMMO.getProperties();
ManagedProperty beansMPCheck = oldProps.get("beans");
// If there already is a beans property assume it's correct
if(beansMPCheck != null)
{
// Need to map
continue;
}
Map<String, ManagedProperty> newProps = new HashMap<String, ManagedProperty>(oldProps);
// Create a beans ManagedProperty, a list of BeanMetaData ManagedObjects
Fields fields = getFields("beans", beansType);
ManagedPropertyImpl beansMP = new ManagedPropertyImpl(bmdfMO, fields);
newProps.put("beans", beansMP);
// Create a ManagedObject for each of the beans BeanMetaData
List<BeanMetaData> beans = bmdf.getBeans();
if(beans != null)
{
for(BeanMetaData bmd : beans)
{
DeploymentUnit compUnit = unit.getComponent(bmd.getName());
if(compUnit == null)
{
log.debug("Failed to find component for bean: "+bmd.getName());
continue;
}
MetaData compMetaData = compUnit.getMetaData();
GenericValue gv = getManagedObjectValue(bmd, compMetaData, bmdfMO);
if(gv != null)
{
// The component managed objects need to be in the root map
ManagedObject compMO = (ManagedObject) gv.getValue();
// Use the ManagedObject name if it's not the same as the attachmentName
String managedObjectName = compUnit.getName();
if(compMO != null && compMO.getAttachmentName() != null)
{
managedObjectName = compMO.getAttachmentName().equals(compMO.getName()) ?
compUnit.getName() : compMO.getName();
}
// Add the managed object
managedObjects.put(managedObjectName, compMO);
// Add the bean MO to the beans list
tmpBeans.add(gv);