Search in sources :

Example 6 with IPentahoObjectRegistration

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);
    }
}
Also used : IContentInfo(org.pentaho.platform.api.engine.IContentInfo) HashMap(java.util.HashMap) BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) IPentahoObjectRegistration(org.pentaho.platform.api.engine.IPentahoObjectRegistration)

Example 7 with IPentahoObjectRegistration

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);
    }
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) IPentahoObjectRegistration(org.pentaho.platform.api.engine.IPentahoObjectRegistration) IPluginPerspective(org.pentaho.platform.api.engine.perspective.pojo.IPluginPerspective)

Example 8 with IPentahoObjectRegistration

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();
}
Also used : Dictionary(java.util.Dictionary) SingletonPentahoObjectReference(org.pentaho.platform.engine.core.system.objfac.references.SingletonPentahoObjectReference) IPentahoObjectRegistration(org.pentaho.platform.api.engine.IPentahoObjectRegistration) ServiceRegistration(org.osgi.framework.ServiceRegistration) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 9 with IPentahoObjectRegistration

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));
}
Also used : IPentahoObjectRegistration(org.pentaho.platform.api.engine.IPentahoObjectRegistration) Test(org.junit.Test)

Example 10 with IPentahoObjectRegistration

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();
                }
            }
        }
    });
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ArrayList(java.util.ArrayList) ApplicationEvent(org.springframework.context.ApplicationEvent) ApplicationListener(org.springframework.context.ApplicationListener) ArrayList(java.util.ArrayList) List(java.util.List) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) IPentahoObjectRegistration(org.pentaho.platform.api.engine.IPentahoObjectRegistration) Map(java.util.Map) WeakHashMap(java.util.WeakHashMap) ContextClosedEvent(org.springframework.context.event.ContextClosedEvent)

Aggregations

IPentahoObjectRegistration (org.pentaho.platform.api.engine.IPentahoObjectRegistration)10 SingletonPentahoObjectReference (org.pentaho.platform.engine.core.system.objfac.references.SingletonPentahoObjectReference)4 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)2 Test (org.junit.Test)2 ServiceRegistration (org.osgi.framework.ServiceRegistration)2 IPlatformPlugin (org.pentaho.platform.api.engine.IPlatformPlugin)2 StandaloneSpringPentahoObjectFactory (org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)2 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)2 IOException (java.io.IOException)1 Dictionary (java.util.Dictionary)1 Hashtable (java.util.Hashtable)1 List (java.util.List)1 WeakHashMap (java.util.WeakHashMap)1 Bundle (org.osgi.framework.Bundle)1 ServiceFactory (org.osgi.framework.ServiceFactory)1 ServiceReference (org.osgi.framework.ServiceReference)1 IContentGenerator (org.pentaho.platform.api.engine.IContentGenerator)1