Class ComponentContainer
java.lang.Object
com.atlassian.jira.component.pico.ComponentContainer
Wraps a Pico container and a Spring container, adding various convenience methods and awareness of OSGi.
The components contained herein could be any combination of:
- core Jira components (published to OSGi or not), and
- Plugins 1 components.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionComponentContainer
(org.picocontainer.MutablePicoContainer picoContainer, OsgiServiceRegistry osgiServiceRegistry, ComponentContainer.ContainerLevel level, org.springframework.context.ConfigurableApplicationContext springContainer) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
component
(OsgiServiceScope scope, org.picocontainer.ComponentAdapter componentAdapter) Adds the given component adapter to this container, with the given scope.<T> T
getComponent
(Class<T> componentClass) Returns the component with the given class as its key or type.org.picocontainer.ComponentAdapter
getComponentAdapter
(Class<?> key) Returns the component adapter with the given key.<T> T
getComponentInstance
(Class<T> key) Returns the component whose key is the given class.<T> T
getComponentInstanceOfType
(Class<T> keyOrType) Retrieves and returns a component which is an instance of given class.<T> List<T>
getComponents
(Class<T> type) Returns any components of the given type.com.atlassian.plugin.osgi.hostcomponents.HostComponentProvider
getLevel()
Returns the level of this container.<T> void
implementation
(OsgiServiceScope scope, Class<? super T> key, Class<T> implementation) <T> void
implementation
(OsgiServiceScope scope, Class<? super T> key, Class<T> implementation, boolean trackBundle) <T> void
implementation
(OsgiServiceScope scope, Class<? super T> key, Class<T> implementation, Object... parametersOrKeys) Registers the given component using the given keys to look up its constructor parameters.<T> void
implementation
(OsgiServiceScope scope, Class<? super T> key, Class<T> implementation, org.picocontainer.Parameter[] parameters) Registers the given component by explicitly providing its constructor arguments.<T> void
implementationBasedOnAppProperty
(OsgiServiceScope scope, Class<T> interfaceClass, Class<? extends T> enabledClass, Class<? extends T> disabledClass, String appPropertiesKey) Registers one of two possible implementations of a given interface, based on the boolean value of the given application property.<T> void
implementationViaNoArgConstructor
(OsgiServiceScope scope, Class<T> key, Class<? extends T> implementation) Registers a component via its no-arg constructor, to work around PICO-201.<T,
S extends T>
voidinstance
(OsgiServiceScope scope, Class<T> key, S instance) Adds the given component to this container.void
internalInstance
(Object instance) Adds the given internal component (not published to OSGi), using the object's class as the key.void
internalInstance
(String key, Object instance) Adds the given internal component (not published to OSGi), using the given key.void
internalInstanceOf
(Class<?> componentClass) Adds an internal (non-OSGi) instance of the given class to this container.<T> T
loadComponent
(Class<T> componentClass, Collection<Object> dependencies) Instantiates a component from its class and dependent classes/instances, found in this container and/or among the given dependencies.static <T> T
loadComponent
(Class<T> componentClass, Collection<Object> dependencies, ComponentContainer existingContainer) Instantiates a component from its class and dependent classes/instances.<T> void
provideViaFactory
(Class<T> serviceInterface, Class<? extends org.osgi.framework.ServiceFactory<T>> osgiFactoryClass) Registers an OSGiServiceFactory
for the given type of service.void
refresh()
Refreshes this container; allows components to be looked up.void
registerComponent
(Class<?> interfaceClass, Class<?> componentClass) Adds the given component to this container.void
setLevel
(ComponentContainer.ContainerLevel newLevel) Sets the level of this container.
-
Constructor Details
-
ComponentContainer
public ComponentContainer(org.picocontainer.MutablePicoContainer picoContainer, OsgiServiceRegistry osgiServiceRegistry, ComponentContainer.ContainerLevel level, org.springframework.context.ConfigurableApplicationContext springContainer) Constructor.- Parameters:
picoContainer
- the parent Pico containerosgiServiceRegistry
- the registry of components to publish to OSGilevel
- the level of this containerspringContainer
- the child Spring container
-
-
Method Details
-
loadComponent
@Nullable public static <T> T loadComponent(Class<T> componentClass, Collection<Object> dependencies, @Nullable ComponentContainer existingContainer) Instantiates a component from its class and dependent classes/instances.- Type Parameters:
T
- the type of component- Parameters:
componentClass
- the class of component to instantiatedependencies
- the component's dependencies (classes and/or instances)existingContainer
- the existing container, if any- Returns:
- the component, or null if the component class is the
Void
class - Since:
- 8.0
-
refresh
public void refresh()Refreshes this container; allows components to be looked up. Call this after registering all Pico components.- Since:
- 9.11
-
loadComponent
Instantiates a component from its class and dependent classes/instances, found in this container and/or among the given dependencies.- Type Parameters:
T
- the type of component- Parameters:
componentClass
- the class of component to instantiatedependencies
- the component's dependencies (classes and/or instances)- Returns:
- the component, or null if the component class is the
Void
class - Since:
- 8.0
-
registerComponent
Adds the given component to this container.- Parameters:
interfaceClass
- the implemented interface, if any (e.g. none in plugins 1)componentClass
- the implementation class
-
implementationBasedOnAppProperty
public <T> void implementationBasedOnAppProperty(OsgiServiceScope scope, Class<T> interfaceClass, Class<? extends T> enabledClass, Class<? extends T> disabledClass, String appPropertiesKey) Registers one of two possible implementations of a given interface, based on the boolean value of the given application property. The instances of the two implementation classes must each be provided separately to this call, e.g. viainternalInstanceOf(java.lang.Class)
.- Type Parameters:
T
- the component type- Parameters:
scope
- the scope of the componentinterfaceClass
- the implemented interfaceenabledClass
- the implementation if the property is setdisabledClass
- the implementation if the property is not setappPropertiesKey
- the key of the property to check- Since:
- 8.0
-
getComponents
Returns any components of the given type.- Type Parameters:
T
- the component type- Parameters:
type
- the component type- Returns:
- see above
- Since:
- 8.0
- See Also:
-
PicoContainer.getComponents(Class)
-
getComponentAdapter
Returns the component adapter with the given key.- Parameters:
key
- the key to look up- Returns:
- see
PicoContainer.getComponentAdapter(Object)
-
getComponentInstance
Returns the component whose key is the given class.- Type Parameters:
T
- the type of key- Parameters:
key
- the component key, typically an interface or implementation- Returns:
null
if there is no component with that key
-
getComponentInstanceOfType
Retrieves and returns a component which is an instance of given class. This is the same as callinggetComponentInstance(Class)
, except that if the given Class is not a known key, it will try to find a unique component that implements or extends that Class.- Parameters:
keyOrType
- the key or class of component to find- Returns:
- the found component, or
null
if it doesn't exist
-
getHostComponentProvider
public com.atlassian.plugin.osgi.hostcomponents.HostComponentProvider getHostComponentProvider() -
internalInstance
Adds the given internal component (not published to OSGi), using the object's class as the key.- Parameters:
instance
- the instance to add
-
internalInstance
Adds the given internal component (not published to OSGi), using the given key.- Parameters:
key
- the key under which to add the componentinstance
- the component instance to add
-
instance
Adds the given component to this container.- Type Parameters:
T
- the interface being implementedS
- the class that implements it- Parameters:
scope
- the visibility of the component to OSGikey
- the component's key in the container, usually the interface being implementedinstance
- the component instance to add
-
internalInstanceOf
Adds an internal (non-OSGi) instance of the given class to this container.- Parameters:
componentClass
- the class that implements the component
-
implementation
public <T> void implementation(OsgiServiceScope scope, Class<? super T> key, Class<T> implementation) -
implementation
public <T> void implementation(OsgiServiceScope scope, Class<? super T> key, Class<T> implementation, boolean trackBundle) -
implementation
public <T> void implementation(OsgiServiceScope scope, Class<? super T> key, Class<T> implementation, Object... parametersOrKeys) Registers the given component using the given keys to look up its constructor parameters. Any of the given keys that are already aParameter
are used as-is rather than being used for lookup.- Parameters:
scope
- the visibility of the component to OSGikey
- the interface that the component implementsimplementation
- the component's implementation classparametersOrKeys
- the component's constructor parameters (or the keys thereof, in any combination)- See Also:
-
implementation
public <T> void implementation(OsgiServiceScope scope, Class<? super T> key, Class<T> implementation, org.picocontainer.Parameter[] parameters) Registers the given component by explicitly providing its constructor arguments.- Type Parameters:
T
- the type of the implementation class- Parameters:
scope
- the visibility of the component to OSGikey
- the interface that the component implementsimplementation
- the component's implementation classparameters
- the component's constructor arguments- See Also:
-
MutablePicoContainer.addComponent(java.lang.Object, java.lang.Object, org.picocontainer.Parameter...)
-
implementationViaNoArgConstructor
public <T> void implementationViaNoArgConstructor(OsgiServiceScope scope, Class<T> key, Class<? extends T> implementation) Registers a component via its no-arg constructor, to work around PICO-201.- Type Parameters:
T
- the type of component- Parameters:
scope
- the scope of the componentkey
- the component key (usually the interface being implemented)implementation
- the class that implements the component; must have a no-arg constructor
-
provideViaFactory
public <T> void provideViaFactory(Class<T> serviceInterface, Class<? extends org.osgi.framework.ServiceFactory<T>> osgiFactoryClass) Registers an OSGiServiceFactory
for the given type of service.There are two ways to provide a service to OSGi: via a singleton object that implements the service interface, or via a
ServiceFactory
that creates a separate instance of the service for each calling bundle. This method does the latter.- Type Parameters:
T
- the interface of the service being provided- Parameters:
serviceInterface
- the interface of the OSGi serviceosgiFactoryClass
- the service factory class. The factory implementation will be created and injected by the Pico container, but will not be registered in the container.
-
component
Adds the given component adapter to this container, with the given scope.- Parameters:
scope
- the scope of the componentcomponentAdapter
- the adapter to add
-
getLevel
Returns the level of this container.- Returns:
- see above
- Since:
- 8.0
-
setLevel
Sets the level of this container.- Parameters:
newLevel
- the level to set- Since:
- 8.0
-
getComponent
Returns the component with the given class as its key or type.- Type Parameters:
T
- the component type- Parameters:
componentClass
- the key or type to look up- Returns:
- null if it can't be found
- Since:
- 8.0
- See Also:
-
PicoContainer.getComponent(Class)
-