use of org.pentaho.platform.api.engine.IObjectCreator in project pentaho-platform by pentaho.
the class PentahoSystemPluginManager method registerContentGenerators.
private void registerContentGenerators(IPlatformPlugin plugin, ClassLoader loader, final GenericApplicationContext beanFactory) throws PlatformPluginRegistrationException {
// register the content generators
for (final IContentGeneratorInfo cgInfo : plugin.getContentGenerators()) {
// define the bean in the factory
BeanDefinition beanDef = BeanDefinitionBuilder.rootBeanDefinition(cgInfo.getClassname()).setScope(BeanDefinition.SCOPE_PROTOTYPE).getBeanDefinition();
// register bean with alias of content generator id (old way)
beanFactory.registerBeanDefinition(cgInfo.getId(), beanDef);
// register bean with alias of type (with default perspective) as well (new way)
beanFactory.registerAlias(cgInfo.getId(), cgInfo.getType());
PluginMessageLogger.add(Messages.getInstance().getString("PluginManager.USER_CONTENT_GENERATOR_REGISTERED", cgInfo.getId(), plugin.getId()));
final HashMap<String, Object> attributes = new HashMap<String, Object>();
attributes.put(PLUGIN_ID, plugin.getId());
attributes.put(CONTENT_TYPE, cgInfo.getType());
final IPentahoObjectRegistration referenceHandle = PentahoSystem.registerReference(new PrototypePentahoObjectReference.Builder<IContentGenerator>(IContentGenerator.class).creator(new IObjectCreator<IContentGenerator>() {
@Override
public IContentGenerator create(IPentahoSession session) {
return (IContentGenerator) beanFactory.getBean(cgInfo.getId());
}
}).attributes(attributes).build(), IContentGenerator.class);
registerReference(plugin.getId(), referenceHandle);
}
// The remaining operations require a beanFactory
if (beanFactory == null) {
return;
}
String[] names = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(beanFactory.getBeanFactory(), IContentGenerator.class);
ArrayList<String> ids = new ArrayList<String>();
for (String beanName : names) {
ids.add(beanName);
Collections.addAll(ids, beanFactory.getAliases(beanName));
}
for (final String beanName : ids) {
final HashMap<String, Object> attributes = new HashMap<String, Object>();
attributes.put(PLUGIN_ID, plugin.getId());
attributes.put(CONTENT_TYPE, beanName);
final IPentahoObjectRegistration referenceHandle = PentahoSystem.registerReference(new PrototypePentahoObjectReference.Builder<IContentGenerator>(IContentGenerator.class).creator(new IObjectCreator<IContentGenerator>() {
@Override
public IContentGenerator create(IPentahoSession session) {
return (IContentGenerator) beanFactory.getBean(beanName);
}
}).attributes(attributes).build(), IContentGenerator.class);
registerReference(plugin.getId(), referenceHandle);
}
}
use of org.pentaho.platform.api.engine.IObjectCreator in project pentaho-platform by pentaho.
the class PrototypePentahoObjectReferenceTest method testReference.
@Test
public void testReference() throws Exception {
PrototypePentahoObjectReference<UUID> sessionRef = new PrototypePentahoObjectReference.Builder<UUID>(UUID.class).creator(new IObjectCreator<UUID>() {
@Override
public UUID create(IPentahoSession session) {
return UUID.randomUUID();
}
}).build();
IPentahoSession s1 = new StandaloneSession("joe");
IPentahoSession s2 = new StandaloneSession("admin");
PentahoSessionHolder.setSession(s1);
UUID s1Uuid = sessionRef.getObject();
PentahoSessionHolder.setSession(s2);
UUID s2Uuid = sessionRef.getObject();
assertNotSame(s1Uuid, s2Uuid);
PentahoSessionHolder.setSession(s1);
UUID s1UuidAgain = sessionRef.getObject();
assertNotSame(s1Uuid, s1UuidAgain);
}
use of org.pentaho.platform.api.engine.IObjectCreator in project pentaho-platform by pentaho.
the class SessionBoundPentahoObjectReferenceTest method testReference.
@Test
public void testReference() throws Exception {
SessionBoundPentahoObjectReference<UUID> sessionRef = new SessionBoundPentahoObjectReference.Builder<UUID>(UUID.class).creator(new IObjectCreator<UUID>() {
@Override
public UUID create(IPentahoSession session) {
return UUID.randomUUID();
}
}).build();
IPentahoSession s1 = new StandaloneSession("joe");
IPentahoSession s2 = new StandaloneSession("admin");
PentahoSessionHolder.setSession(s1);
UUID s1Uuid = sessionRef.getObject();
PentahoSessionHolder.setSession(s2);
UUID s2Uuid = sessionRef.getObject();
assertNotSame(s1Uuid, s2Uuid);
PentahoSessionHolder.setSession(s1);
UUID s1UuidAgain = sessionRef.getObject();
assertSame(s1Uuid, s1UuidAgain);
}
Aggregations