Package com.atlassian.sal.api.component
Class ComponentLocator
java.lang.Object
com.atlassian.sal.api.component.ComponentLocator
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected StringconvertClassToName(Class iface) Converts the interface name into a String keystatic <T> TgetComponent(Class<T> iface) Gets a component by its interface.static <T> TgetComponent(Class<T> iface, String componentKey) Gets a component by its interface and its Id.protected abstract <T> TgetComponentInternal(Class<T> iface) Gets the requested component, to be overridden for each applicationprotected abstract <T> TgetComponentInternal(Class<T> iface, String componentKey) Gets the requested component, to be overridden for each applicationstatic <T> Collection<T>getComponents(Class<T> iface) Gets a components by interface.static <T> Optional<T>getComponentSafely(Class<T> iface) Get a component by it's interface safely.protected abstract <T> Collection<T>getComponentsInternal(Class<T> iface) static booleanstatic voidSets the component locator to use.
-
Constructor Details
-
ComponentLocator
public ComponentLocator()
-
-
Method Details
-
setComponentLocator
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
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
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
Gets a component by its interface and its Id.- Parameters:
iface- The interface to find an implementation forcomponentKey- id of the component- Returns:
- The implementation
-
getComponentInternal
Gets the requested component, to be overridden for each application- Parameters:
iface- The interface to lookup- Returns:
- The implementation
-
getComponentInternal
Gets the requested component, to be overridden for each application- Parameters:
iface- The interface to lookupcomponentKey- key of the component- Returns:
- The implementation
-
getComponents
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
-
convertClassToName
Converts the interface name into a String key- Parameters:
iface- The interface to convert- Returns:
- The String key to use to find the implementation
-