ConnectorRegistry registry = new ConnectorRegistry();
registry.loadMetadata(cl);
String[] mbeans = registry.findManagedBeans();
MBeanServer server = MBeanServerFactory.newMBeanServer(DOMAIN_CONNECTOR);
for (int i = 0; i < mbeans.length; i++) {
ManagedBean managed = registry.findManagedBean(mbeans[i]);
String clsName = managed.getType();
String domain = managed.getDomain();
if (domain == null) {
domain = DOMAIN_CONNECTOR;
}
Class cls = Class.forName(clsName, true, cl);
Object objMBean = null;
// Use the factory method when it is defined.
Method[] methods = cls.getMethods();
for (Method method : methods) {
if (method.getName().equals(FACTORY_METHOD) &&
Modifier.isStatic(method.getModifiers())) {
objMBean = method.invoke(null);
logger.log(Level.INFO, "Create MBean using factory method.");
break;
}
}
if (objMBean == null) {
objMBean = cls.newInstance();
}
// Call the initialize method if the MBean extends ConnectorSupport class
if (objMBean instanceof ConnectorSupport) {
Method method = cls.getMethod("initialize", new Class[] {Map.class});
Map props = config.getParamValues();
method.invoke(objMBean, new Object[] {props});
}
ModelMBean mm = managed.createMBean(objMBean);
String beanObjName = domain + ":name=" + mbeans[i];
server.registerMBean(mm, new ObjectName(beanObjName));
}
registry.setMBeanServer(server);
entries.put(appId, registry);
return registry;