use of org.pentaho.chart.plugin.IChartPlugin in project pentaho-platform by pentaho.
the class ChartBeansSystemListener method initPlugins.
/**
* This methods looks in the chartbeans configuration file, and retrieves the prescribed list of chart plugins
* (renderers). For each defined renderer, the method then looks to the PluginManager to see if that renderer has been
* overridden. If it has, then the class defined in the PluginManager will be loaded IN PLACE OF the configuration
* file's class.
*
* @return list of available chart "plugin" (renderer) instances.
* @throws Exception
* if no chart plugins (renderers) are found.
*/
@SuppressWarnings("unchecked")
private List<IChartPlugin> initPlugins() throws Exception {
ArrayList<IChartPlugin> plugins = new ArrayList<IChartPlugin>();
HashMap<String, Object> pluginMap = new HashMap<String, Object>();
// $NON-NLS-1$
List<Element> nodes = PentahoSystem.getSystemSettings().getSystemSettings(configFile, "bean");
if (nodes == null || nodes.size() == 0) {
// $NON-NLS-1$
String msg = Messages.getInstance().getString("ChartBeansSystemListener.ERROR_0001_CONFIG_MISSING");
Logger.warn(ChartBeansSystemListener.class.getName(), msg);
throw new ChartSystemInitializationException(msg);
}
Element node;
String id;
Object plugin;
IPluginManager pluginManager = PentahoSystem.get(IPluginManager.class);
for (int i = 0; i < nodes.size(); i++) {
node = nodes.get(i);
// $NON-NLS-1$
id = node.attribute("id").getText();
// $NON-NLS-1$
pluginMap.put(id, node.attribute("class").getText());
// Now let's see if there is a plugin overriding this engine...
if ((null != pluginManager) && (pluginManager.isBeanRegistered(id))) {
try {
plugin = pluginManager.getBean(id);
pluginMap.put(id, plugin);
} catch (PluginBeanException e) {
Logger.warn(ChartBeansSystemListener.class.getName(), Messages.getInstance().getString("ChartBeansSystemListener.ERROR_0002_PLUGINMANAGER_BEAN_MISSING", // $NON-NLS-1$
id), e);
}
}
}
for (Object clazz : pluginMap.values()) {
try {
if (clazz instanceof String) {
plugins.add((IChartPlugin) Class.forName(clazz.toString()).newInstance());
} else {
plugins.add((IChartPlugin) clazz);
}
} catch (Exception ex) {
Logger.warn(ChartBeansSystemListener.class.getName(), Messages.getInstance().getString("ChartBeansSystemListener.ERROR_0003_CLASS_CREATION_PROBLEM") + clazz, // $NON-NLS-1$
ex);
}
}
return plugins;
}
Aggregations