Examples of OsgiServiceFactoryBean


Examples of org.eclipse.gemini.blueprint.service.exporter.support.OsgiServiceFactoryBean

  private void registerOsgiService(final String beanName, final OsgiService service) {
    final Class<?> type = applicationContext.getType(beanName);
    final Class<?>[] interfaces = getInterfaces(type, service);
        try {
            logger.debug("Registering bean {} as OSGi service using interfaces {}.", beanName, Arrays.asList(interfaces));
            final OsgiServiceFactoryBean factoryBean = new OsgiServiceFactoryBean();
            factoryBean.setServiceProperties(getServiceProperties(service));
            factoryBean.setInterfaces(interfaces);
            factoryBean.setBeanFactory(applicationContext);
            factoryBean.setTargetBeanName(beanName);
            factoryBean.setBundleContext(bundleContext);
            factoryBean.afterPropertiesSet();
        } catch (final Exception e) {
            logger.warn("Error registering bean '{}' as OSGi service.", beanName, e);
        }
    }
View Full Code Here

Examples of org.springframework.osgi.service.exporter.support.OsgiServiceFactoryBean

                            BeanDefinitionRegistry registry = (BeanDefinitionRegistry) bFactory;
                            BeanDefinition def = BeanDefinitionBuilder.genericBeanDefinition(className).getBeanDefinition();
                            registry.registerBeanDefinition(getComponentName(), def);

                            // register the bean as service in the OSGI-Registry
                            osgiFactoryBean = new OsgiServiceFactoryBean();
                            osgiFactoryBean.setTargetBeanName(getComponentName());
                            osgiFactoryBean.setBeanFactory(bFactory);
                            osgiFactoryBean.setBundleContext(b.getBundleContext());
                            osgiFactoryBean.setInterfaces(new Class[] { clazz });
                            osgiFactoryBean.afterPropertiesSet();
View Full Code Here

Examples of org.springframework.osgi.service.exporter.support.OsgiServiceFactoryBean

  private void registerService(String pid, Object bean) {
    // add properties
    Dictionary props = new Hashtable(2);
    props.put(Constants.SERVICE_PID, pid);

    OsgiServiceFactoryBean exporter = createExporter(pid, bean);
    serviceExporters.put(pid, exporter);
    try {
      serviceRegistrations.add(exporter.getObject());
    }
    catch (Exception ex) {
      throw new BeanCreationException("Cannot publish bean for pid " + pid, ex);
    }
  }
View Full Code Here

Examples of org.springframework.osgi.service.exporter.support.OsgiServiceFactoryBean

      throw new BeanCreationException("Cannot publish bean for pid " + pid, ex);
    }
  }

  private OsgiServiceFactoryBean createExporter(String beanName, Object bean) {
    OsgiServiceFactoryBean exporter = new OsgiServiceFactoryBean();
    exporter.setAutoExport(autoExport);
    exporter.setBeanClassLoader(classLoader);
    exporter.setBeanName(beanName);
    exporter.setBundleContext(bundleContext);
    exporter.setContextClassLoader(ccl);
    exporter.setInterfaces(interfaces);
    exporter.setListeners(listeners);
    exporter.setTarget(bean);

    try {
      exporter.afterPropertiesSet();
    }
    catch (Exception ex) {
      throw new BeanCreationException("Cannot publish bean for pid " + beanName, ex);
    }
    return exporter;
View Full Code Here

Examples of org.springframework.osgi.service.exporter.support.OsgiServiceFactoryBean

      }
    }
  }

  private void unregisterService(String pid) {
    OsgiServiceFactoryBean exporterFactory = (OsgiServiceFactoryBean) serviceExporters.remove(pid);

    if (exporterFactory != null) {

      Object registration = null;
      try {
        registration = exporterFactory.getObject();
      }
      catch (Exception ex) {
        // log the exception and continue
        log.error("Could not retrieve registration for pid " + pid, ex);
      }

      if (log.isTraceEnabled()) {
        log.trace("Unpublishing bean for pid " + pid + " w/ registration " + registration);
      }
      // remove service registration
      serviceRegistrations.remove(registration);

      exporterFactory.destroy();
    }
  }
View Full Code Here

Examples of org.springframework.osgi.service.exporter.support.OsgiServiceFactoryBean

  }

  public void testSimpleService() throws Exception {
    Object bean = appContext.getBean("&inlineReference");
    assertSame(OsgiServiceFactoryBean.class, bean.getClass());
    OsgiServiceFactoryBean exporter = (OsgiServiceFactoryBean) bean;

    assertTrue(Arrays.equals(new Class[] { Serializable.class }, getInterfaces(exporter)));
    assertEquals("string", getTargetBeanName(exporter));
    assertEquals(appContext.getBean("string"), getTarget(exporter));
View Full Code Here

Examples of org.springframework.osgi.service.exporter.support.OsgiServiceFactoryBean

    assertSame(appContext.getBean("string"), getServiceAtIndex(0));
  }

  public void testBiggerService() throws Exception {
    OsgiServiceFactoryBean exporter = (OsgiServiceFactoryBean) appContext.getBean("&manyOptions");

    assertTrue(Arrays.equals(new Class[] { Serializable.class, CharSequence.class }, getInterfaces(exporter)));
    Properties prop = new Properties();
    prop.setProperty("foo", "bar");
    prop.setProperty("white", "horse");
    assertEquals(prop, exporter.getServiceProperties());

    // Should be wrapped with a TCCL setting proxy
    System.out.println(getServiceAtIndex(1));
    assertNotSame(appContext.getBean("string"), getServiceAtIndex(1));
View Full Code Here

Examples of org.springframework.osgi.service.exporter.support.OsgiServiceFactoryBean

    assertEquals("string", getTargetBeanName(exporter));
    assertEquals(appContext.getBean("string"), getTarget(exporter));
  }

  public void testNestedService() throws Exception {
    OsgiServiceFactoryBean exporter = (OsgiServiceFactoryBean) appContext.getBean("&nestedService");
    assertTrue(Arrays.equals(new Class[] { Object.class }, getInterfaces(exporter)));

    Object service = getServiceAtIndex(2);
    assertSame(HashMap.class, service.getClass());
View Full Code Here

Examples of org.springframework.osgi.service.exporter.support.OsgiServiceFactoryBean

    assertTrue(bean instanceof ServiceRegistration);
    assertNotSame("registration not wrapped to provide exporting listener notification", registration, bean);
  }

  public void testServiceProperties() throws Exception {
    OsgiServiceFactoryBean exporter = (OsgiServiceFactoryBean) appContext.getBean("&serviceProperties");
    Map properties = exporter.getServiceProperties();
    assertEquals(2, properties.size());
    assertTrue(properties.get("string") instanceof String);
    assertTrue(properties.get("int") instanceof Integer);

    assertNull(getTargetBeanName(exporter));
View Full Code Here

Examples of org.springframework.osgi.service.exporter.support.OsgiServiceFactoryBean

    assertNotNull(getTarget(exporter));

  }

  public void testListeners() throws Exception {
    OsgiServiceFactoryBean exporter = (OsgiServiceFactoryBean) appContext.getBean("&exporterWithListener");
    OsgiServiceRegistrationListener[] listeners = getListeners(exporter);
    assertEquals(2, listeners.length);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.