use of org.pentaho.platform.api.engine.PluginBeanDefinition in project pentaho-platform by pentaho.
the class DefaultPluginManager method initializeBeanFactory.
/**
* Initializes a bean factory for serving up instance of plugin classes.
*
* @return an instance of the factory that allows callers to continue to define more beans on it programmatically
*/
protected void initializeBeanFactory(final IPlatformPlugin plugin, final ClassLoader loader) throws PlatformPluginRegistrationException {
if (!(loader instanceof PluginClassLoader)) {
logger.warn("Can't determine plugin dir to load spring file because classloader is not of type PluginClassLoader. " + // $NON-NLS-1$
"This is since we are probably in a unit test");
// $NON-NLS-1$
return;
}
//
// Get the native factory (the factory that comes preconfigured via either Spring bean files or via JUnit test
//
BeanFactory nativeBeanFactory = getNativeBeanFactory(plugin, loader);
//
// Now create the definable factory for accepting old style bean definitions from IPluginProvider
//
GenericApplicationContext beanFactory = null;
if (nativeBeanFactory != null && nativeBeanFactory instanceof GenericApplicationContext) {
beanFactory = (GenericApplicationContext) nativeBeanFactory;
} else {
beanFactory = new GenericApplicationContext();
beanFactory.setClassLoader(loader);
beanFactory.getBeanFactory().setBeanClassLoader(loader);
if (nativeBeanFactory != null) {
beanFactory.getBeanFactory().setParentBeanFactory(nativeBeanFactory);
}
}
beanFactory.addBeanFactoryPostProcessor(new PentahoBeanScopeValidatorPostProcessor());
beanFactoryMap.put(plugin.getId(), beanFactory);
// been made available to the plugin manager
for (PluginBeanDefinition def : plugin.getBeans()) {
// register by classname if id is null
def.setBeanId((def.getBeanId() == null) ? def.getClassname() : def.getBeanId());
assertUnique(plugin.getId(), def.getBeanId());
// defining plugin beans the old way through the plugin provider ifc supports only prototype scope
BeanDefinition beanDef = BeanDefinitionBuilder.rootBeanDefinition(def.getClassname()).setScope(BeanDefinition.SCOPE_PROTOTYPE).getBeanDefinition();
beanFactory.registerBeanDefinition(def.getBeanId(), beanDef);
}
StandaloneSpringPentahoObjectFactory pentahoFactory = new StandaloneSpringPentahoObjectFactory("Plugin Factory ( " + plugin.getId() + " )");
pentahoFactory.init(null, beanFactory);
}
use of org.pentaho.platform.api.engine.PluginBeanDefinition in project pentaho-platform by pentaho.
the class PentahoSystemPluginManager method createBeanFactory.
private GenericApplicationContext createBeanFactory(IPlatformPlugin plugin, ClassLoader classloader) throws PlatformPluginRegistrationException {
if (!(classloader instanceof PluginClassLoader)) {
throw new PlatformPluginRegistrationException("Can't determine plugin dir to load spring file because classloader is not of type PluginClassLoader. " + "This is since we are probably in a unit test");
}
//
// Get the native factory (the factory that comes preconfigured via either Spring bean files or via JUnit test
//
BeanFactory nativeBeanFactory = getNativeBeanFactory(plugin, classloader);
//
// Now create the definable factory for accepting old style bean definitions from IPluginProvider
//
GenericApplicationContext beanFactory = null;
if (nativeBeanFactory != null && nativeBeanFactory instanceof GenericApplicationContext) {
beanFactory = (GenericApplicationContext) nativeBeanFactory;
} else {
beanFactory = new GenericApplicationContext();
beanFactory.setClassLoader(classloader);
beanFactory.getBeanFactory().setBeanClassLoader(classloader);
if (nativeBeanFactory != null) {
beanFactory.getBeanFactory().setParentBeanFactory(nativeBeanFactory);
}
}
beanFactory.addBeanFactoryPostProcessor(new PentahoBeanScopeValidatorPostProcessor());
// been made available to the plugin manager
for (PluginBeanDefinition def : plugin.getBeans()) {
// register by classname if id is null
def.setBeanId((def.getBeanId() == null) ? def.getClassname() : def.getBeanId());
try {
assertUnique(beanFactory, plugin.getId(), def.getBeanId());
} catch (PlatformPluginRegistrationException e) {
logger.error(MessageFormat.format("Unable to register plugin bean, a bean by the id {0} is already defined in plugin: {1}", def.getBeanId(), plugin.getId()));
continue;
}
// defining plugin beans the old way through the plugin provider ifc supports only prototype scope
BeanDefinition beanDef = BeanDefinitionBuilder.rootBeanDefinition(def.getClassname()).setScope(BeanDefinition.SCOPE_PROTOTYPE).getBeanDefinition();
beanFactory.registerBeanDefinition(def.getBeanId(), beanDef);
}
return beanFactory;
}
use of org.pentaho.platform.api.engine.PluginBeanDefinition in project pentaho-platform by pentaho.
the class SystemPathPluginProviderIT method testLoadBeanDefinition.
@SuppressWarnings("deprecation")
@Test
public void testLoadBeanDefinition() throws PlatformPluginRegistrationException {
microPlatform.init();
List<IPlatformPlugin> plugins = provider.getPlugins(new StandaloneSession());
IPlatformPlugin plugin = (IPlatformPlugin) CollectionUtils.find(plugins, new PluginNameMatcherPredicate("Plugin 1"));
assertNotNull("Plugin 1 should have been found", plugin);
Collection<PluginBeanDefinition> beans = plugin.getBeans();
assertEquals("FooComponent was not loaded", 1, CollectionUtils.countMatches(beans, new Predicate() {
public boolean evaluate(Object object) {
PluginBeanDefinition bean = (PluginBeanDefinition) object;
return bean.getBeanId().equals("FooComponent") && bean.getClassname().equals("org.pentaho.test.platform.plugin.pluginmgr.FooComponent");
}
}));
assertEquals("genericBean was not loaded", 1, CollectionUtils.countMatches(beans, new Predicate() {
public boolean evaluate(Object object) {
PluginBeanDefinition bean = (PluginBeanDefinition) object;
return bean.getBeanId().equals("genericBean") && bean.getClassname().equals("java.lang.Object");
}
}));
}
Aggregations