public final class OsgiRegistry extends 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 | Method and Description |
---|---|
void |
bundleChanged(org.osgi.framework.BundleEvent event) |
static String |
bundleEntryPathToClassName(String packagePath,
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). |
Class<?> |
classForNameWithException(String className)
Get the Class from the class name.
|
static OsgiRegistry |
getInstance()
Returns an
OsgiRegistry instance. |
Enumeration<URL> |
getPackageResources(String packagePath,
ClassLoader classLoader,
boolean recursive)
Get URLs of resources from a given package.
|
ResourceBundle |
getResourceBundle(String bundleName)
Tries to load resource bundle via OSGi means.
|
static boolean |
isPackageLevelEntry(String packagePath,
String entryPath)
Returns whether the given entry path is located directly in the provided package path.
|
static String |
normalizedPackagePath(String packagePath)
Normalized package returns path that does not start with '/' character and ends with '/' character.
|
public 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 String bundleEntryPathToClassName(String packagePath, 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(String packagePath, String entryPath)
false
is returned.packagePath
- Package path which the entry is compared toentryPath
- Entry pathpublic static String normalizedPackagePath(String packagePath)
packagePath
- package path to normalize.public Enumeration<URL> getPackageResources(String packagePath, ClassLoader classLoader, boolean recursive)
packagePath
- package.classLoader
- resource class loader.recursive
- whether the given package path should be scanned recursively by OSGipublic Class<?> classForNameWithException(String className) throws 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.ClassNotFoundException
- if the class cannot be found.public ResourceBundle getResourceBundle(String bundleName)
bundleName
- name of the resource bundle to loadCopyright © 2007-2024, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.