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.
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.
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.
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.
RegisterServiceFactory - the bundle activator of the demo.
It is also the service factory of the demo - it implements org.osgi.framework.ServiceFactory.TimeServiceFactory - the class of the Time Service - it extends
the demo.basics.registerservice.service.TimeService abstract
class, which is discussed in the description of the Register Service demo.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); |
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());
} |