コード例 #1
0
  @Test
  public void testSetPropertiesAfterStop() throws Exception {
    Bundle bundle = installBundle(getBundleArchiveA());
    try {
      bundle.start();
      BundleContext bundleContext = bundle.getBundleContext();
      assertNotNull(bundleContext);

      ServiceRegistration registration =
          bundleContext.registerService(BundleContext.class.getName(), bundleContext, null);
      assertNotNull(registration);

      bundle.stop();

      try {
        registration.setProperties(new Hashtable<String, Object>());
        fail("Should not be here!");
      } catch (IllegalStateException t) {
        // expected
      }
      assertNoServiceEvent();
    } finally {
      bundle.uninstall();
    }
  }
コード例 #2
0
 public void updated(Dictionary<String, ?> config) throws ConfigurationException {
   if (config != null) {
     Integer filterPriority = (Integer) config.get(FILTER_PRIORITY);
     String applicationName = (String) config.get(APPLICATION_NAME);
     setPriority(filterPriority);
     setApplicationName(applicationName);
   }
   synchronized (this) {
     filterFactoryServiceRegistration.setProperties(config);
   }
 }
コード例 #3
0
  @Test
  public void testModifyServiceProperties() throws Exception {
    Bundle bundle = installBundle(getBundleArchiveA());
    try {
      bundle.start();
      BundleContext context = bundle.getBundleContext();
      assertNotNull(context);
      assertNoServiceEvent();

      String filter = "(&(objectClass=org.osgi.framework.BundleContext)(foo=bar))";
      context.addServiceListener(this, filter);

      Hashtable<String, Object> props = new Hashtable<String, Object>();
      props.put("foo", "bar");
      ServiceRegistration sreg =
          context.registerService(BundleContext.class.getName(), context, props);
      ServiceReference sref = sreg.getReference();

      assertServiceEvent(ServiceEvent.REGISTERED, sref);

      props.put("xxx", "yyy");
      sreg.setProperties(props);
      assertServiceEvent(ServiceEvent.MODIFIED, sref);

      props.put("foo", "notbar");
      sreg.setProperties(props);
      assertServiceEvent(ServiceEvent.MODIFIED_ENDMATCH, sref);

      props.put("foo", "bar");
      sreg.setProperties(props);
      assertServiceEvent(ServiceEvent.MODIFIED, sref);

      sreg.unregister();
      assertServiceEvent(ServiceEvent.UNREGISTERING, sref);
    } finally {
      bundle.uninstall();
    }
  }
コード例 #4
0
  private BundleContext assertServiceLifecycle(
      Bundle bundle, Dictionary<String, Object> properties, boolean events) throws Exception {
    assertNoServiceEvent();

    BundleContext bundleContext = bundle.getBundleContext();
    ServiceRegistration registration =
        bundleContext.registerService(BundleContext.class.getName(), bundleContext, properties);
    ServiceReference reference = registration.getReference();

    if (events) assertServiceEvent(ServiceEvent.REGISTERED, reference);
    else assertNoServiceEvent();

    registration.setProperties(properties);
    if (events) assertServiceEvent(ServiceEvent.MODIFIED, reference);
    else assertNoServiceEvent();

    registration.unregister();
    if (events) assertServiceEvent(ServiceEvent.UNREGISTERING, reference);
    else assertNoServiceEvent();

    registration =
        bundleContext.registerService(BundleContext.class.getName(), bundleContext, properties);
    reference = registration.getReference();
    if (events) assertServiceEvent(ServiceEvent.REGISTERED, reference);
    else assertNoServiceEvent();

    bundle.stop();
    if (events) assertServiceEvent(ServiceEvent.UNREGISTERING, reference);
    else assertNoServiceEvent();

    try {
      bundleContext.addServiceListener(this);
      fail("Should not be here!");
    } catch (IllegalStateException t) {
      // expected
    }

    bundle.start();
    bundleContext = bundle.getBundleContext();
    assertNotNull(bundleContext);

    return bundleContext;
  }
コード例 #5
0
 /**
  * update the properties of the remote service.
  *
  * @param properties a set of property key/value pairs to be updated.
  * @see
  *     org.eclipse.ecf.remoteservice.IRemoteServiceRegistration#setProperties(java.util.Dictionary)
  */
 public void setProperties(final Dictionary properties) {
   reg.setProperties(properties);
 }
コード例 #6
0
  @Test
  public void testSetProperties() throws Exception {
    Bundle bundle = installBundle(getBundleArchiveA());
    try {
      bundle.start();
      BundleContext bundleContext = bundle.getBundleContext();
      assertNotNull(bundleContext);

      String propertyA = "org.jboss.osgi.test.PropertyA";
      String propertyALower = "org.jboss.osgi.test.propertya";

      Hashtable<String, Object> properties = new Hashtable<String, Object>();
      properties.put(propertyA, "testA");
      ServiceRegistration registration =
          bundleContext.registerService(BundleContext.class.getName(), bundleContext, properties);
      assertNotNull(registration);
      ServiceReference reference = registration.getReference();
      assertNotNull(reference);
      assertEquals("testA", reference.getProperty(propertyA));
      assertEquals("testA", reference.getProperty(propertyALower));

      Object serviceID = reference.getProperty(Constants.SERVICE_ID);
      Object objectClass = reference.getProperty(Constants.OBJECTCLASS);

      assertAllReferences(bundleContext, null, "(" + propertyA + "=testA)", reference);
      assertAllReferences(bundleContext, null, "(" + propertyALower + "=testA)", reference);
      assertAllReferences(
          bundleContext, null, "(" + Constants.SERVICE_ID + "=" + serviceID + ")", reference);

      bundleContext.addServiceListener(this);

      properties = new Hashtable<String, Object>();
      properties.put(propertyA, "testAChanged");
      registration.setProperties(properties);
      assertServiceEvent(ServiceEvent.MODIFIED, reference);
      assertEquals("testAChanged", reference.getProperty(propertyA));
      assertNoAllReferences(bundleContext, null, "(" + propertyA + "=testA)");
      assertNoAllReferences(bundleContext, null, "(" + propertyALower + "=testA)");
      assertAllReferences(bundleContext, null, "(" + propertyA + "=testAChanged)", reference);
      assertAllReferences(bundleContext, null, "(" + propertyALower + "=testAChanged)", reference);

      registration.setProperties(null);
      assertServiceEvent(ServiceEvent.MODIFIED, reference);
      assertNull(reference.getProperty(propertyA));
      assertNoAllReferences(bundleContext, null, "(" + propertyA + "=testA)");
      assertNoAllReferences(bundleContext, null, "(" + propertyALower + "=testA)");
      assertNoAllReferences(bundleContext, null, "(" + propertyA + "=testAChanged)");
      assertNoAllReferences(bundleContext, null, "(" + propertyALower + "=testAChanged)");

      properties = new Hashtable<String, Object>();
      properties.put(propertyA, "testA2");
      properties.put(Constants.SERVICE_ID, "rubbish1");
      properties.put(Constants.OBJECTCLASS, "rubbish2");
      registration.setProperties(properties);
      assertServiceEvent(ServiceEvent.MODIFIED, reference);
      assertEquals("testA2", reference.getProperty(propertyA));
      assertEquals("testA2", reference.getProperty(propertyALower));
      assertEquals(serviceID, reference.getProperty(Constants.SERVICE_ID));
      assertEquals(serviceID, reference.getProperty(Constants.SERVICE_ID.toLowerCase()));
      assertEquals(objectClass, reference.getProperty(Constants.OBJECTCLASS));
      assertEquals(objectClass, reference.getProperty(Constants.OBJECTCLASS.toLowerCase()));

      try {
        assertNoAllReferences(bundleContext, null, "(" + Constants.SERVICE_ID + "=rubbish1)");
        fail("NumberFormatException expected");
      } catch (NumberFormatException ex) {
        // expected
      }

      assertAllReferences(
          bundleContext, null, "(" + Constants.SERVICE_ID + "=" + serviceID + ")", reference);

      properties = new Hashtable<String, Object>();
      properties.put("a", "1");
      properties.put("A", "2");
      try {
        registration.setProperties(properties);
        fail("Should not be here!");
      } catch (IllegalArgumentException t) {
        // expected
      }
      assertNoServiceEvent();

      registration.unregister();
      assertServiceEvent(ServiceEvent.UNREGISTERING, reference);

      try {
        registration.setProperties(new Hashtable<String, Object>());
        fail("Should not be here!");
      } catch (IllegalStateException t) {
        // expected
      }
      assertNoServiceEvent();
    } finally {
      bundle.uninstall();
    }
  }
コード例 #7
0
 public void setProperties(Dictionary properties) {
   delegate.setProperties(properties);
 }