Map<String, Annotation> moAnns = bmdMO.getAnnotations();
ManagementObject mo = (ManagementObject) moAnns.get(ManagementObject.class.getName());
// Reset the name to the bean name rather than the attachment name
if(bmdMO instanceof MutableManagedObject)
{
MutableManagedObject mmo = (MutableManagedObject) bmdMO;
// Reset the name to the bean name if its the attachment name
if(mmo.getName().equals(mmo.getAttachmentName()))
mmo.setName(bmd.getName());
mmo.setParent(kdMO);
// Add an alias property
Set<Object> bmdAliases = bmd.getAliases();
Map<String, ManagedProperty> oldProps = mmo.getProperties();
Map<String, ManagedProperty> newProps = new HashMap<String, ManagedProperty>(oldProps);
if(bmdAliases != null && bmdAliases.size() > 0)
{
ArrayMetaType aliasType = new ArrayMetaType(SimpleMetaType.STRING, false);
DefaultFieldsImpl fields = getFields("alias", aliasType);
fields.setDescription("Aliases of the bean");
String[] aliases = new String[bmdAliases.size()];
Iterator<?> i = bmdAliases.iterator();
for(int n = 0; i.hasNext(); n++)
{
aliases[n] = i.next().toString();
}
ArrayValueSupport value = new ArrayValueSupport(aliasType, aliases);
fields.setValue(value);
ManagedPropertyImpl aliasesMP = new ManagedPropertyImpl(bmdMO, fields);
newProps.put("alias", aliasesMP);
}
// Add a state property
DefaultFieldsImpl stateFields = getFields("state", ControllerStateMetaType.TYPE);
stateFields.setViewUse(new ViewUse[]{ViewUse.STATISTIC});
EnumValue stateValue = getState(bmd.getName(), kernel);
stateFields.setValue(stateValue);
stateFields.setDescription("The bean controller state");
ManagedPropertyImpl stateMP = new ManagedPropertyImpl(mmo, stateFields);
newProps.put("state", stateMP);
// Update the properties
mmo.setProperties(newProps);
}
log.debug("Created ManagedObject: "+bmdMO+" for bean: "+bmd.getName());
kdMOs.put(bmd.getName(), bmdMO);
}
// Create the ManagedDeployment
ManagedDeployment md = mgtDeploymentCreator.build(deploymentUnit, kdMOs, null);
if(firstDeployment == null)
firstDeployment = md;
// Create the ManagedComponents
for(ManagedObject bmdMO : kdMOs.values())
{
if(bmdMO.getAttachmentName().equals(KernelDeployment.class.getName()))
continue;
ComponentType type = KnownComponentTypes.MCBean.Any.getType();
Map<String, Annotation> moAnns = bmdMO.getAnnotations();
ManagementComponent mc = (ManagementComponent) moAnns.get(ManagementComponent.class.getName());
if(mc != null)
{
type = new ComponentType(mc.type(), mc.subtype());
}
ManagedComponentImpl comp = new ManagedComponentImpl(type, md, bmdMO);
md.addComponent(bmdMO.getName(), comp);
log.debug("Created ManagedComponent("+comp.getName()+") of type: "
+type
+" for MO: "+bmdMO.getName()
+", componentName: "+bmdMO.getComponentName());
}
if(md != null)
bootstrapMDs.put(kd.getName(), md);
}
// Add other Server managed objects
if(firstDeployment != null)
{
ComponentType type = new ComponentType("MCBean", "MCServer");
ManagedObject serverMO = mof.initManagedObject(mcserver, null);
if (serverMO.getOperations() != null && serverMO.getOperations().size() == 0)
{
ManagedOperationImpl shutdown = new ManagedOperationImpl("Shutdown the server", "shutdown");
if(serverMO instanceof MutableManagedObject)
{
HashSet<ManagedOperation> ops = new HashSet<ManagedOperation>();
ops.add(shutdown);
MutableManagedObject mmo = MutableManagedObject.class.cast(serverMO);
mmo.setOperations(ops);
}
}
ManagedComponentImpl serverComp = new ManagedComponentImpl(type, firstDeployment, serverMO);
firstDeployment.addComponent("MCServer", serverComp);
try