Class ComponentLocator

java.lang.Object
com.atlassian.sal.api.component.ComponentLocator

public abstract class ComponentLocator extends Object
Unified interface to access components via their interface. Calling getComponent(Class) will work the same in any application, regardless of underlying dependency injection system used.
Since:
2.0
  • Constructor Details

    • ComponentLocator

      public ComponentLocator()
  • Method Details

    • setComponentLocator

      public static void setComponentLocator(ComponentLocator loc)
      Sets the component locator to use. Should only be called once.
      Parameters:
      loc - The implementation to use
    • isInitialized

      public static boolean isInitialized()
      Returns:
      True if intialized with a locator subclass
    • getComponent

      public static <T> T getComponent(Class<T> iface)
      Gets a component by its interface. Applications that don't support interface-based components will need to convert the interface name into a String
      Parameters:
      iface - The interface to find an implementation for
      Returns:
      The implementation
    • getComponentSafely

      public static <T> Optional<T> getComponentSafely(Class<T> iface)
      Get a component by it's interface safely. If there is any issue with fetching the interface then this method will return Optional.empty().
      Parameters:
      iface - The interface to find an implementation for
      Returns:
      The implementation
    • getComponent

      public static <T> T getComponent(Class<T> iface, String componentKey)
      Gets a component by its interface and its Id.
      Parameters:
      iface - The interface to find an implementation for
      componentKey - id of the component
      Returns:
      The implementation
    • getComponentInternal

      protected abstract <T> T getComponentInternal(Class<T> iface)
      Gets the requested component, to be overridden for each application
      Parameters:
      iface - The interface to lookup
      Returns:
      The implementation
    • getComponentInternal

      protected abstract <T> T getComponentInternal(Class<T> iface, String componentKey)
      Gets the requested component, to be overridden for each application
      Parameters:
      iface - The interface to lookup
      componentKey - key of the component
      Returns:
      The implementation
    • getComponents

      public static <T> Collection<T> getComponents(Class<T> iface)
      Gets a components by interface. Applications that don't support interface-based components will need to covert the interface name into a String
      Parameters:
      iface - The interface to find an implementation for
      Returns:
      The implementation
    • getComponentsInternal

      protected abstract <T> Collection<T> getComponentsInternal(Class<T> iface)
    • convertClassToName

      protected String convertClassToName(Class iface)
      Converts the interface name into a String key
      Parameters:
      iface - The interface to convert
      Returns:
      The String key to use to find the implementation