public final class OsgiRegistry
extends java.lang.Object
implements org.osgi.framework.SynchronousBundleListener
ServiceFinder
class,
an instance of OsgiRegistry is created and associated with given
OSGi BundleContext. META-INF/services entries are then being accessed
via the OSGi Bundle API as direct ClassLoader#getResource() method invocation
does not work in this case within OSGi.Modifier and Type | Class and Description |
---|---|
private static class |
OsgiRegistry.BundleSpiProvidersLoader |
private class |
OsgiRegistry.OsgiServiceFinder |
Modifier and Type | Field and Description |
---|---|
private org.osgi.framework.BundleContext |
bundleContext |
private java.util.Map<java.lang.String,org.osgi.framework.Bundle> |
classToBundleMapping |
private static java.lang.String |
CoreBundleSymbolicNAME |
private java.util.Map<java.lang.Long,java.util.Map<java.lang.String,java.util.concurrent.Callable<java.util.List<java.lang.Class<?>>>>> |
factories |
private static OsgiRegistry |
instance |
private java.util.concurrent.locks.ReadWriteLock |
lock |
private static java.util.logging.Logger |
LOGGER |
private static java.lang.String |
WEB_INF_CLASSES |
Modifier | Constructor and Description |
---|---|
private |
OsgiRegistry(org.osgi.framework.BundleContext bundleContext)
Creates a new OsgiRegistry instance bound to a particular OSGi runtime.
|
Modifier and Type | Method and Description |
---|---|
void |
bundleChanged(org.osgi.framework.BundleEvent event) |
static java.lang.String |
bundleEntryPathToClassName(java.lang.String packagePath,
java.lang.String bundleEntryPath)
Translates bundle entry path as returned from
Bundle.findEntries(String, String, boolean) to
fully qualified class name that resides in given package path (directly or indirectly in its subpackages). |
java.lang.Class<?> |
classForNameWithException(java.lang.String className)
Get the Class from the class name.
|
private static java.util.Enumeration<java.net.URL> |
findEntries(org.osgi.framework.Bundle bundle,
java.lang.String path,
java.lang.String fileNamePattern,
boolean recursive) |
static OsgiRegistry |
getInstance()
Returns an
OsgiRegistry instance. |
java.util.Enumeration<java.net.URL> |
getPackageResources(java.lang.String packagePath,
java.lang.ClassLoader classLoader,
boolean recursive)
Get URLs of resources from a given package.
|
java.util.ResourceBundle |
getResourceBundle(java.lang.String bundleName)
Tries to load resource bundle via OSGi means.
|
(package private) void |
hookUp()
Will hook up this instance with the OSGi runtime.
|
static boolean |
isPackageLevelEntry(java.lang.String packagePath,
java.lang.String entryPath)
Returns whether the given entry path is located directly in the provided package path.
|
private static java.lang.Class<?> |
loadClass(org.osgi.framework.Bundle bundle,
java.lang.String className) |
private java.util.List<java.lang.Class<?>> |
locateAllProviders(java.lang.String serviceName) |
static java.lang.String |
normalizedPackagePath(java.lang.String packagePath)
Normalized package returns path that does not start with '/' character and ends with '/' character.
|
private void |
register(org.osgi.framework.Bundle bundle) |
private void |
registerExistingBundles() |
private void |
setOSGiServiceFinderIteratorProvider() |
private static final java.lang.String WEB_INF_CLASSES
private static final java.lang.String CoreBundleSymbolicNAME
private static final java.util.logging.Logger LOGGER
private final org.osgi.framework.BundleContext bundleContext
private final java.util.Map<java.lang.Long,java.util.Map<java.lang.String,java.util.concurrent.Callable<java.util.List<java.lang.Class<?>>>>> factories
private final java.util.concurrent.locks.ReadWriteLock lock
private static OsgiRegistry instance
private final java.util.Map<java.lang.String,org.osgi.framework.Bundle> classToBundleMapping
private OsgiRegistry(org.osgi.framework.BundleContext bundleContext)
BundleContext
.bundleContext
- must be a non-null instance of a BundleContextpublic static OsgiRegistry getInstance()
OsgiRegistry
instance. Call this method only if sure that the application is running in OSGi
environment, otherwise a call to this method can lead to an ClassNotFoundException
.OsgiRegistry
instance.public void bundleChanged(org.osgi.framework.BundleEvent event)
bundleChanged
in interface org.osgi.framework.BundleListener
public static java.lang.String bundleEntryPathToClassName(java.lang.String packagePath, java.lang.String bundleEntryPath)
Bundle.findEntries(String, String, boolean)
to
fully qualified class name that resides in given package path (directly or indirectly in its subpackages).packagePath
- The package path where the class is located (even recursively)bundleEntryPath
- The bundle path to translate.public static boolean isPackageLevelEntry(java.lang.String packagePath, java.lang.String entryPath)
false
is returned.packagePath
- Package path which the entry is compared toentryPath
- Entry pathpublic static java.lang.String normalizedPackagePath(java.lang.String packagePath)
packagePath
- package path to normalize.public java.util.Enumeration<java.net.URL> getPackageResources(java.lang.String packagePath, java.lang.ClassLoader classLoader, boolean recursive)
packagePath
- package.classLoader
- resource class loader.recursive
- whether the given package path should be scanned recursively by OSGipublic java.lang.Class<?> classForNameWithException(java.lang.String className) throws java.lang.ClassNotFoundException
The context class loader will be utilized if accessible and non-null. Otherwise the defining class loader of this class will be utilized.
className
- the class name.java.lang.ClassNotFoundException
- if the class cannot be found.public java.util.ResourceBundle getResourceBundle(java.lang.String bundleName)
bundleName
- name of the resource bundle to loadvoid hookUp()
private void registerExistingBundles()
private void setOSGiServiceFinderIteratorProvider()
private void register(org.osgi.framework.Bundle bundle)
private java.util.List<java.lang.Class<?>> locateAllProviders(java.lang.String serviceName)
private static java.lang.Class<?> loadClass(org.osgi.framework.Bundle bundle, java.lang.String className) throws java.lang.ClassNotFoundException
java.lang.ClassNotFoundException
private static java.util.Enumeration<java.net.URL> findEntries(org.osgi.framework.Bundle bundle, java.lang.String path, java.lang.String fileNamePattern, boolean recursive)