com.atlassian.sal.api.component
Class ComponentLocator

java.lang.Object
  extended by 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 Summary
ComponentLocator()
           
 
Method Summary
protected  String convertClassToName(Class iface)
          Converts the interface name into a String key
static
<T> T
getComponent(Class<T> iface)
          Gets a component by its interface.
static
<T> T
getComponent(Class<T> iface, String componentKey)
          Gets a component by its interface and its Id.
protected abstract
<T> T
getComponentInternal(Class<T> iface)
          Gets the requested component, to be overridden for each application
protected abstract
<T> T
getComponentInternal(Class<T> iface, String componentKey)
          Gets the requested component, to be overridden for each application
static
<T> Collection<T>
getComponents(Class<T> iface)
          Gets a components by interface.
protected abstract
<T> Collection<T>
getComponentsInternal(Class<T> iface)
           
static boolean isInitialized()
           
static void setComponentLocator(ComponentLocator loc)
          Sets the component locator to use.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ComponentLocator

public ComponentLocator()
Method Detail

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

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


Copyright © 2010 Atlassian. All Rights Reserved.