Class ProviderLocator

java.lang.Object
org.apache.tomee.jakartaee.api.locator.ProviderLocator

public class ProviderLocator
extends Object
  • Method Details

    • loadClass

      public static Class<?> loadClass​(String className) throws ClassNotFoundException
      Utility class for locating a class with OSGi registry support. Uses the thread context classloader as part of the search order.
      Parameters:
      className - The name of the target class.
      Returns:
      The loaded class.
      Throws:
      ClassNotFoundException - Thrown if the class cannot be located.
    • loadClass

      public static Class<?> loadClass​(String className, Class<?> contextClass) throws ClassNotFoundException
      Utility class for locating a class with OSGi registry support. Uses the thread context classloader as part of the search order.
      Parameters:
      className - The name of the target class.
      contextClass - The context class to retrive the classloader.
      Returns:
      The loaded class.
      Throws:
      ClassNotFoundException - Thrown if the class cannot be located.
    • loadClass

      public static Class<?> loadClass​(String className, Class<?> contextClass, ClassLoader loader) throws ClassNotFoundException
      Standardized utility method for performing class lookups with support for OSGi registry lookups.
      Parameters:
      className - The name of the target class.
      contextClass - The context class to retrive the classloader.
      loader - An optional class loader.
      Returns:
      The loaded class
      Throws:
      ClassNotFoundException - Thrown if the class cannot be loaded.
    • getService

      public static Object getService​(String iface, Class<?> contextClass, ClassLoader loader) throws Exception
      Get a single service instance that matches an interface definition.
      Parameters:
      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.
      Returns:
      The service instance, or null if no matching services can be found.
      Throws:
      Exception - Thrown for any classloading or exceptions thrown trying to instantiate a service instance.
    • getServiceClass

      public static Class<?> getServiceClass​(String iface, Class<?> contextClass, ClassLoader loader) throws ClassNotFoundException
      Locate a service class that matches an interface definition.
      Parameters:
      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.
      Returns:
      The located class, or null if no matching services can be found.
      Throws:
      ClassNotFoundException - Thrown for any classloading exceptions thrown trying to load the class.
    • getServices

      public static List<Object> getServices​(String iface, Class<?> contextClass, ClassLoader loader) throws Exception
      Get a list of services that match a given interface name. This searches both the current class path and the global repository for matches.
      Parameters:
      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.
      Returns:
      A list of matching services. Returns an empty list if there are no matches.
      Throws:
      Exception - Thrown for any classloading or exceptions thrown trying to instantiate a service instance.
    • getServiceClasses

      public static List<Class<?>> getServiceClasses​(String iface, Class<?> contextClass, ClassLoader loader) throws Exception
      Get a list of service class implementations that match an interface name. This searches both the current class path and the global repository for matches.
      Parameters:
      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.
      Returns:
      A list of matching provider classes. Returns an empty list if there are no matches.
      Throws:
      Exception - Thrown for any classloading exceptions thrown trying to load a provider class.
    • lookupByJREPropertyFile

      public static String lookupByJREPropertyFile​(String path, String property) throws IOException
      Perform a service class discovery by looking for a property in a target properties file located in the java.home directory.
      Parameters:
      path - The relative path to the desired properties file.
      property - The name of the required property.
      Returns:
      The value of the named property within the properties file. Returns null if the property doesn't exist or the properties file doesn't exist.
      Throws:
      IOException