Register Service Factory Demo

The Register Service Factory demo is a simple bundle which registers the Time Service from the Register Service demo via a service factory which provides different service objects for different bundles.

Demo Components

The JAR of the Register Service Factory demo is regservicefactory.jar in demo/bundles.

The demo source files are in the demo/framework/basics/regservice directory of the Framework Professional Edition Package .

In case you have changed something in the source of the demo, use the mkrsf script to recompile and repack the demo.

Starting the Demo

Using an Install Script

The Register Service Factory demo is included in the demo/framework/basics/install.txt install script. For more information about installing demos via install scripts, refer to General Rules for Demos.

Activating All Necessary Components

Inside the Demo

The Register Service Factory demo registers the Time Service from the Register Service demo. The components that are specific for this demo are in the demo.basics.registerservice.impl.service.factory package.

When the demo is started, the start method of the activator is called. The activator registers the Time Service passing itself as the service factory for this service to the framework. The Time Service is registered with service property TimeService.TIME_ZONE equal to the local time zone.

    Hashtable props = new Hashtable();
    props.put(TimeService.TIME_ZONE, TimeZone.getDefault()); 
    servReg = bc.registerService(TimeService.class.getName(), this, props);
Listing 1: Registering a service via a service factory.

In the getService method inherited from ServiceFactory, RegisterServiceFactory returns a new instance of TimeServiceFactory, which is associated with the ID of the requesting bundle.

  public Object getService(Bundle bundle, ServiceRegistration servReg) {
    return new TimeServiceFactory(bundle.getBundleId());
  }
Listing 2: Implementing a service factory.

Basic Demos