System.out.println("Creating MBeans ...");
// Create the MBean for the top-level Server object
String domain = server.getDefaultDomain();
ManagedBean managed = registry.findManagedBean("StandardServer");
ModelMBean mm = managed.createMBean(tree);
mm.addAttributeChangeNotificationListener(demo, "shutdown", tree);
mm.addAttributeChangeNotificationListener(demo, "port", tree);
server.registerMBean(mm, createName(domain, tree));
// Create the MBean for each associated Service and friendes
Service services[] = tree.findServices();
for (int i = 0; i < services.length; i++) {
// The MBean for the Service itself
managed = registry.findManagedBean("StandardService");
mm = managed.createMBean(services[i]);
mm.addAttributeChangeNotificationListener(demo, "name",
services[i]);
server.registerMBean(mm, createName(domain, services[i]));
// The MBean for the corresponding Engine
managed = registry.findManagedBean("StandardEngine");
Engine container = (Engine) services[i].getContainer();
mm = managed.createMBean(container);
mm.addAttributeChangeNotificationListener(demo, "name",
container);
server.registerMBean(mm, createName(domain, container));
// The MBeans for the corresponding Connectors
managed = registry.findManagedBean("HttpConnector");
Connector connectors[] = services[i].findConnectors();
for (int j = 0; j < connectors.length; j++) {
mm = managed.createMBean(connectors[j]);
mm.addAttributeChangeNotificationListener(demo, "port",
connectors[j]);
server.registerMBean
(mm, createName(domain, connectors[j]));
}