Registers the specified service object with the specified properties under the specified class names into the Framework. A {@code ServiceRegistration} object is returned. The{@code ServiceRegistration} object is for the private use of the bundleregistering the service and should not be shared with other bundles. The registering bundle is defined to be the context bundle. Other bundles can locate the service by using one of the {@link #getServiceReferences(Class,String)}, {@link #getServiceReferences(String,String)}, {@link #getServiceReference(Class)} or{@link #getServiceReference(String)} methods.
A bundle can register a service object that implements the {@link ServiceFactory} interface to have more flexibility in providingservice objects to other bundles.
The following steps are required to register a service:
- If {@code service} does not implement {@code ServiceFactory}, an {@code IllegalArgumentException} is thrown if {@code service} is not an{@code instanceof} all the specified class names.
- The Framework adds the following service properties to the service properties from the specified {@code Dictionary} (which may be{@code null}):
- A property named {@link Constants#SERVICE_ID} identifying theregistration number of the service
- A property named {@link Constants#OBJECTCLASS} containing all thespecified classes.
- A property named {@link Constants#SERVICE_SCOPE} identifying thescope of the service.
- A property named {@link Constants#SERVICE_BUNDLEID} identifying thethe context bundle.
Properties with these names in the specified {@code Dictionary} will beignored. - The service is added to the Framework service registry and may now be used by other bundles.
- A service event of type {@link ServiceEvent#REGISTERED} is fired.
- A {@code ServiceRegistration} object for this registration isreturned.
@param clazzes The class names under which the service can be located.The class names in this array will be stored in the service's properties under the key {@link Constants#OBJECTCLASS}.
@param service The service object or an object implementing{@code ServiceFactory}.
@param properties The properties for this service. The keys in theproperties object must all be {@code String} objects. See{@link Constants} for a list of standard service property keys.Changes should not be made to this object after calling this method. To update the service's properties the {@link ServiceRegistration#setProperties(Dictionary)} method mustbe called. The set of properties may be {@code null} if theservice has no properties.
@return A {@code ServiceRegistration} object for use by the bundleregistering the service to update the service's properties or to unregister the service.
@throws IllegalArgumentException If one of the following is true:
- {@code service} is {@code null}.
- {@code service} doesnot implement {@code ServiceFactory} and is not an instance ofall the specified classes.
- {@code properties} containscase variants of the same key name.
@throws SecurityException If the caller does not have the{@code ServicePermission} to register the service for all thenamed classes and the Java Runtime Environment supports permissions.
@throws IllegalStateException If this BundleContext is no longer valid.
@see ServiceRegistration
@see PrototypeServiceFactory
@see ServiceFactory