Class ProviderRegistryImpl
- java.lang.Object
-
- org.apache.geronimo.osgi.registry.ProviderRegistryImpl
-
- All Implemented Interfaces:
ProviderRegistry
public class ProviderRegistryImpl extends java.lang.Object implements ProviderRegistry
The implementation of the provider registry used to store the bundle registrations.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
ProviderRegistryImpl.BundleProviderLoader
Holder class for located services information.private class
ProviderRegistryImpl.BundleResources
private class
ProviderRegistryImpl.SPIRegistry
Holder class for information about a given collection of id to provider mappings.
-
Field Summary
Fields Modifier and Type Field Description private Activator
activator
static java.lang.String
EXPORT_PROVIDER_HEADER
static java.lang.String
OPT_IN_HEADER
private ProviderRegistryImpl.SPIRegistry
providers
private ProviderRegistryImpl.SPIRegistry
serviceProviders
-
Constructor Summary
Constructors Constructor Description ProviderRegistryImpl(Activator activator)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
addBundle(org.osgi.framework.Bundle bundle)
Add a bundle to the provider registry.java.lang.Object
getService(java.lang.String providerId)
Locate and instantiate an instance of a service provider defined in the META-INF/services directory of tracked bundles.java.lang.Class<?>
getServiceClass(java.lang.String providerId)
Locate and return the class for a service provider defined in the META-INF/services directory of tracked bundles.java.util.List<java.lang.Class<?>>
getServiceClasses(java.lang.String providerId)
Locate all services that match a given provider id and return the implementation classesjava.util.List<java.lang.Object>
getServices(java.lang.String providerId)
Locate all services that match a given provider id and create instances.java.lang.Class<?>
locate(java.lang.String providerId)
Locate a class by its provider id indicator.java.util.List<java.lang.Class<?>>
locateAll(java.lang.String providerId)
Locate all class files that match a given provider id.private void
log(int level, java.lang.String message)
private void
log(int level, java.lang.String message, java.lang.Throwable th)
protected void
registerProvider(ProviderRegistryImpl.BundleProviderLoader provider)
Register an individual provivider item by its provider identifier.protected void
registerService(ProviderRegistryImpl.BundleProviderLoader provider)
Register an individual provivider item by its provider identifier.void
removeBundle(org.osgi.framework.Bundle bundle, java.lang.Object obj)
Remove a bundle from the registry.protected void
unregisterProvider(ProviderRegistryImpl.BundleProviderLoader provider)
Removed a provider registration for a named provider id.protected void
unregisterService(ProviderRegistryImpl.BundleProviderLoader provider)
Removed a provider registration for a named provider id.
-
-
-
Field Detail
-
OPT_IN_HEADER
public static final java.lang.String OPT_IN_HEADER
- See Also:
- Constant Field Values
-
EXPORT_PROVIDER_HEADER
public static final java.lang.String EXPORT_PROVIDER_HEADER
- See Also:
- Constant Field Values
-
providers
private ProviderRegistryImpl.SPIRegistry providers
-
serviceProviders
private ProviderRegistryImpl.SPIRegistry serviceProviders
-
activator
private Activator activator
-
-
Constructor Detail
-
ProviderRegistryImpl
public ProviderRegistryImpl(Activator activator)
-
-
Method Detail
-
addBundle
public java.lang.Object addBundle(org.osgi.framework.Bundle bundle)
Add a bundle to the provider registry. This searches for services information in the OSGI-INF/providers directory of the bundle and registers this information in a provider registry. Bundles that need to locate class instances can use the provider registry to locate classes that might reside in other bundles.- Parameters:
bundle
- The source bundle.- Returns:
- A map of the located registrations. Returns null if this bundle does not contain any providers.
-
removeBundle
public void removeBundle(org.osgi.framework.Bundle bundle, java.lang.Object obj)
Remove a bundle from the registry.- Parameters:
bundle
- The target bundle.
-
registerProvider
protected void registerProvider(ProviderRegistryImpl.BundleProviderLoader provider)
Register an individual provivider item by its provider identifier.- Parameters:
id
- The provider id.provider
- The loader used to resolve the provider class.
-
unregisterProvider
protected void unregisterProvider(ProviderRegistryImpl.BundleProviderLoader provider)
Removed a provider registration for a named provider id.- Parameters:
id
- The target idprovider
- The provider registration instance
-
registerService
protected void registerService(ProviderRegistryImpl.BundleProviderLoader provider)
Register an individual provivider item by its provider identifier.- Parameters:
id
- The provider id.provider
- The loader used to resolve the provider class.
-
unregisterService
protected void unregisterService(ProviderRegistryImpl.BundleProviderLoader provider)
Removed a provider registration for a named provider id.- Parameters:
id
- The target idprovider
- The provider registration instance
-
locate
public java.lang.Class<?> locate(java.lang.String providerId)
Locate a class by its provider id indicator. .- Specified by:
locate
in interfaceProviderRegistry
- Parameters:
providerId
- The provider id (generally, a fully qualified class name).- Returns:
- The Class corresponding to this provider id. Returns null if this is not registered or the indicated class can't be loaded.
-
locateAll
public java.util.List<java.lang.Class<?>> locateAll(java.lang.String providerId)
Locate all class files that match a given provider id.- Specified by:
locateAll
in interfaceProviderRegistry
- Parameters:
providerId
- The target provider identifier.- Returns:
- A List containing the class objects corresponding to the provider identifier. Returns an empty list if no matching classes can be located.
-
getService
public java.lang.Object getService(java.lang.String providerId) throws java.lang.Exception
Locate and instantiate an instance of a service provider defined in the META-INF/services directory of tracked bundles.- Specified by:
getService
in interfaceProviderRegistry
- Parameters:
providerId
- The name of the target interface class.- Returns:
- The service instance. Returns null if no service defintions can be located.
- Throws:
java.lang.Exception
- Any classloading or other exceptions thrown during the process of creating this service instance.
-
getServices
public java.util.List<java.lang.Object> getServices(java.lang.String providerId)
Locate all services that match a given provider id and create instances.- Specified by:
getServices
in interfaceProviderRegistry
- Parameters:
providerId
- The target provider identifier.- Returns:
- A List containing the instances corresponding to the provider identifier. Returns an empty list if no matching classes can be located or created
-
getServiceClasses
public java.util.List<java.lang.Class<?>> getServiceClasses(java.lang.String providerId)
Locate all services that match a given provider id and return the implementation classes- Specified by:
getServiceClasses
in interfaceProviderRegistry
- Parameters:
providerId
- The target provider identifier.- Returns:
- A List containing the classes corresponding to the provider identifier. Returns an empty list if no matching classes can be located.
-
getServiceClass
public java.lang.Class<?> getServiceClass(java.lang.String providerId) throws java.lang.ClassNotFoundException
Locate and return the class for a service provider defined in the META-INF/services directory of tracked bundles.- Specified by:
getServiceClass
in interfaceProviderRegistry
- Parameters:
providerId
- The name of the target interface class.- Returns:
- The provider class. Returns null if no service defintions can be located.
- Throws:
java.lang.Exception
- Any classloading or other exceptions thrown during the process of loading this service provider class.java.lang.ClassNotFoundException
-
log
private void log(int level, java.lang.String message)
-
log
private void log(int level, java.lang.String message, java.lang.Throwable th)
-
-