public class ProviderLocator extends Object
Modifier and Type | Method and Description |
---|---|
static void |
destroy()
Cleanup resources on bundle shutdown.
|
static Object |
getService(String iface,
Class<?> contextClass,
ClassLoader loader)
Get a single service instance that matches an interface
definition.
|
static Class<?> |
getServiceClass(String iface,
Class<?> contextClass,
ClassLoader loader)
Locate a service class that matches an interface
definition.
|
static List<Class<?>> |
getServiceClasses(String iface,
Class<?> contextClass,
ClassLoader loader)
Get a list of service class implementations that match
an interface name.
|
static List<Object> |
getServices(String iface,
Class<?> contextClass,
ClassLoader loader)
Get a list of services that match a given interface
name.
|
static void |
init(org.osgi.framework.BundleContext c)
initialize the tracker statics for this bundle
|
static Class<?> |
loadClass(String className)
Utility class for locating a class with OSGi registry
support.
|
static Class<?> |
loadClass(String className,
Class<?> contextClass)
Utility class for locating a class with OSGi registry
support.
|
static Class<?> |
loadClass(String className,
Class<?> contextClass,
ClassLoader loader)
Standardized utility method for performing class lookups
with support for OSGi registry lookups.
|
static Class<?> |
locate(String providerId)
Locate a class by its provider id indicator.
|
static List<Class<?>> |
locateAll(String providerId)
Locate all class files that match a given factory id.
|
static String |
lookupByJREPropertyFile(String path,
String property)
Perform a service class discovery by looking for a
property in a target properties file located in the
java.home directory.
|
public static void init(org.osgi.framework.BundleContext c)
c
- The starup BundleContext.public static void destroy()
public static Class<?> locate(String providerId)
providerId
- The provider id (generally, a fully qualified class name).public static List<Class<?>> locateAll(String providerId)
providerId
- The target provider identifier.public static Class<?> loadClass(String className) throws ClassNotFoundException
className
- The name of the target class.ClassNotFoundException
- Thrown if the class cannot be located.public static Class<?> loadClass(String className, Class<?> contextClass) throws ClassNotFoundException
className
- The name of the target class.ClassNotFoundException
- Thrown if the class cannot be located.public static Class<?> loadClass(String className, Class<?> contextClass, ClassLoader loader) throws ClassNotFoundException
className
- The name of the target class.loader
- An optional class loader.ClassNotFoundException
- Thrown if the class cannot be loaded.public static Object getService(String iface, Class<?> contextClass, ClassLoader loader) throws Exception
iface
- The name of the required interface.contextClass
- The class requesting the lookup (used for class resolution).loader
- A class loader to use for searching for service definitions
and loading classes.Exception
- Thrown for any classloading or exceptions thrown
trying to instantiate a service instance.public static Class<?> getServiceClass(String iface, Class<?> contextClass, ClassLoader loader) throws ClassNotFoundException
iface
- The name of the required interface.contextClass
- The class requesting the lookup (used for class resolution).loader
- A class loader to use for searching for service definitions
and loading classes.Exception
- Thrown for any classloading exceptions thrown
trying to load the class.ClassNotFoundException
public static List<Object> getServices(String iface, Class<?> contextClass, ClassLoader loader) throws Exception
iface
- The name of the required interface.contextClass
- The class requesting the lookup (used for class resolution).loader
- A class loader to use for searching for service definitions
and loading classes.Exception
- Thrown for any classloading or exceptions thrown
trying to instantiate a service instance.public static List<Class<?>> getServiceClasses(String iface, Class<?> contextClass, ClassLoader loader) throws Exception
iface
- The name of the required interface.contextClass
- The class requesting the lookup (used for class resolution).loader
- A class loader to use for searching for service definitions
and loading classes.Exception
- Thrown for any classloading exceptions thrown
trying to load a provider class.public static String lookupByJREPropertyFile(String path, String property) throws IOException
path
- The relative path to the desired properties file.property
- The name of the required property.IOException
Copyright © 2014. All Rights Reserved.