use of org.pentaho.platform.api.engine.IPentahoObjectRegistration in project pentaho-platform by pentaho.
the class PentahoSystemPluginManager method registerContentTypes.
protected void registerContentTypes(IPlatformPlugin plugin, ClassLoader loader, GenericApplicationContext beanFactory) throws PlatformPluginRegistrationException {
// index content types and define any file meta providersIContentGeneratorInfo
for (IContentInfo info : plugin.getContentInfos()) {
final HashMap<String, Object> attributes = new HashMap<String, Object>();
attributes.put(PLUGIN_ID, plugin.getId());
attributes.put("extension", info.getExtension());
IPentahoObjectRegistration handle = PentahoSystem.registerReference(new SingletonPentahoObjectReference.Builder<IContentInfo>(IContentInfo.class).object(info).attributes(attributes).build(), IContentInfo.class);
registerReference(plugin.getId(), handle);
}
}
use of org.pentaho.platform.api.engine.IPentahoObjectRegistration in project pentaho-platform by pentaho.
the class PentahoSystemPluginManager method registerPerspectives.
private void registerPerspectives(IPlatformPlugin plugin, ClassLoader loader) {
for (IPluginPerspective pluginPerspective : plugin.getPluginPerspectives()) {
// PentahoSystem.get( IPluginPerspectiveManager.class ).addPluginPerspective( pluginPerspective );
final IPentahoObjectRegistration referenceHandle = PentahoSystem.registerReference(new SingletonPentahoObjectReference.Builder<IPluginPerspective>(IPluginPerspective.class).object(pluginPerspective).attributes(Collections.<String, Object>singletonMap(PLUGIN_ID, plugin.getId())).build(), IPluginPerspective.class);
registerReference(plugin.getId(), referenceHandle);
}
}
use of org.pentaho.platform.api.engine.IPentahoObjectRegistration in project pentaho-platform by pentaho.
the class OSGIRuntimeObjectFactoryTest method testObjectDefined.
@Test
public void testObjectDefined() throws Exception {
assertFalse(objectFactory.objectDefined(String.class));
SingletonPentahoObjectReference<String> ref = new SingletonPentahoObjectReference<String>(String.class, "Testing", Collections.<String, Object>singletonMap("foo", "bar"), 10);
IPentahoObjectRegistration iPentahoObjectRegistration = objectFactory.registerReference(ref, String.class);
String s = objectFactory.get(String.class, null);
assertEquals("Testing", s);
assertTrue(objectFactory.objectDefined(String.class));
ServiceRegistration registration = mock(ServiceRegistration.class);
ServiceRegistration registration2 = mock(ServiceRegistration.class);
ServiceReference mockRef = mock(ServiceReference.class);
when(bundleContext.registerService(eq(String.class.getName()), anyObject(), any(Dictionary.class))).thenReturn(registration);
when(bundleContext.registerService(eq(IPentahoObjectReference.class.getName()), anyObject(), any(Dictionary.class))).thenReturn(registration2);
objectFactory.setBundleContext(bundleContext);
when(bundleContext.getServiceReference(String.class)).thenReturn(mockRef);
assertTrue(objectFactory.objectDefined(String.class));
iPentahoObjectRegistration.remove();
verify(registration, times(1)).unregister();
}
use of org.pentaho.platform.api.engine.IPentahoObjectRegistration in project pentaho-platform by pentaho.
the class RuntimeObjectFactoryTest method testDeregistration.
@Test
public void testDeregistration() throws Exception {
PentahoSystem.clearObjectFactory();
final IPentahoObjectRegistration handle = PentahoSystem.registerObject("Testing");
assertEquals("Testing", PentahoSystem.get(String.class));
handle.remove();
assertNull(PentahoSystem.get(String.class));
}
use of org.pentaho.platform.api.engine.IPentahoObjectRegistration in project pentaho-platform by pentaho.
the class PublishedBeanRegistry method registerFactory.
public static void registerFactory(ApplicationContext applicationContext) {
Object markerBean = null;
try {
// The marker may not be present if there are no published beans from this factory.
markerBean = applicationContext.getBean(Const.FACTORY_MARKER);
} catch (NoSuchBeanDefinitionException ignored) {
// ignore
}
if (markerBean == null) {
// applicationContext
return;
}
factoryMarkerCache.put(applicationContext, markerBean);
final ConfigurableApplicationContext listableBeanFactory = (ConfigurableApplicationContext) applicationContext;
List<IPentahoObjectRegistration> registrationList = new ArrayList<>();
handleRegistry.put(listableBeanFactory, registrationList);
Map<Class<?>, List<String>> classListMap = classToBeanMap.get(markerBean);
for (Map.Entry<Class<?>, List<String>> classListEntry : classListMap.entrySet()) {
Class<?> clazz = classListEntry.getKey();
for (String beanName : classListEntry.getValue()) {
IPentahoObjectRegistration iPentahoObjectRegistration = PentahoSystem.registerReference(new SpringPentahoObjectReference(listableBeanFactory, beanName, clazz, null, listableBeanFactory.getBeanFactory().getBeanDefinition(beanName)));
registrationList.add(iPentahoObjectRegistration);
}
}
listableBeanFactory.addApplicationListener(new ApplicationListener() {
@Override
public void onApplicationEvent(ApplicationEvent applicationEvent) {
if (applicationEvent instanceof ContextClosedEvent) {
for (IPentahoObjectRegistration iPentahoObjectRegistration : handleRegistry.get(listableBeanFactory)) {
iPentahoObjectRegistration.remove();
}
}
}
});
}
Aggregations