@ParametersAreNonnullByDefault public class ComponentContainer extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
ComponentContainer.ContainerLevel
The possible levels of a
ComponentContainer. |
| Constructor and Description |
|---|
ComponentContainer(org.picocontainer.MutablePicoContainer picoContainer,
OsgiServiceRegistry osgiServiceRegistry,
ComponentContainer.ContainerLevel level)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
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 |
getHostComponentProvider() |
ComponentContainer.ContainerLevel |
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> |
instance(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 OSGi
ServiceFactory for the given type of service. |
void |
registerComponent(Class<?> interfaceClass,
Class<?> componentClass)
Adds the given component to the underlying Pico container.
|
void |
setLevel(ComponentContainer.ContainerLevel newLevel)
Sets the level of this container.
|
public ComponentContainer(org.picocontainer.MutablePicoContainer picoContainer,
OsgiServiceRegistry osgiServiceRegistry,
ComponentContainer.ContainerLevel level)
picoContainer - the wrapped Pico containerosgiServiceRegistry - the registry of components to publish to OSGilevel - the level of this container@Nullable public static <T> T loadComponent(Class<T> componentClass, Collection<Object> dependencies, @Nullable ComponentContainer existingContainer)
T - the type of componentcomponentClass - the class of component to instantiatedependencies - the component's dependencies (classes and/or instances)existingContainer - the existing container, if anyVoid classpublic <T> T loadComponent(Class<T> componentClass, Collection<Object> dependencies)
T - the type of componentcomponentClass - the class of component to instantiatedependencies - the component's dependencies (classes and/or instances)Void classpublic void registerComponent(@Nullable Class<?> interfaceClass, Class<?> componentClass)
interfaceClass - the implemented interface, if any (e.g. none in plugins 1)componentClass - the implementation classpublic <T> void implementationBasedOnAppProperty(OsgiServiceScope scope, Class<T> interfaceClass, Class<? extends T> enabledClass, Class<? extends T> disabledClass, String appPropertiesKey)
internalInstanceOf(java.lang.Class).T - the component typescope - 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 checkpublic <T> List<T> getComponents(Class<T> type)
T - the component typetype - the component typePicoContainer.getComponents(Class)@Nullable public org.picocontainer.ComponentAdapter getComponentAdapter(Class<?> key)
key - the key to look upPicoContainer.getComponentAdapter(Object)@Nullable public <T> T getComponentInstance(Class<T> key)
T - the type of keykey - the component key, typically an interface or implementationnull if there is no component with that key@Nullable public <T> T getComponentInstanceOfType(Class<T> keyOrType)
getComponentInstance(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.keyOrType - the key or class of component to findnull if it doesn't existpublic com.atlassian.plugin.osgi.hostcomponents.HostComponentProvider getHostComponentProvider()
public void internalInstance(Object instance)
instance - the instance to addpublic void internalInstance(String key, Object instance)
key - the key under which to add the componentinstance - the component instance to addpublic <T,S extends T> void instance(OsgiServiceScope scope, Class<T> key, S instance)
T - the interface being implementedS - the class that implements itscope - the visibility of the component to OSGikey - the component's key in the container, usually the interface being implementedinstance - the component instance to addpublic void internalInstanceOf(Class<?> componentClass)
componentClass - the class that implements the componentpublic <T> void implementation(OsgiServiceScope scope, Class<? super T> key, Class<T> implementation)
public <T> void implementation(OsgiServiceScope scope, Class<? super T> key, Class<T> implementation, boolean trackBundle)
public <T> void implementation(OsgiServiceScope scope, Class<? super T> key, Class<T> implementation, Object... parametersOrKeys)
Parameter are used as-is rather than being used for lookup.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)implementation(OsgiServiceScope, Class, Class, Parameter[])public <T> void implementation(OsgiServiceScope scope, Class<? super T> key, Class<T> implementation, org.picocontainer.Parameter[] parameters)
T - the type of the implementation classscope - the visibility of the component to OSGikey - the interface that the component implementsimplementation - the component's implementation classparameters - the component's constructor argumentsMutablePicoContainer.addComponent(java.lang.Object, java.lang.Object, org.picocontainer.Parameter...)public <T> void implementationViaNoArgConstructor(OsgiServiceScope scope, Class<T> key, Class<? extends T> implementation)
T - the type of componentscope - 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 constructorpublic <T> void provideViaFactory(Class<T> serviceInterface, Class<? extends org.osgi.framework.ServiceFactory<T>> osgiFactoryClass)
ServiceFactory 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.
T - the interface of the service being providedserviceInterface - 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.public void component(OsgiServiceScope scope, org.picocontainer.ComponentAdapter componentAdapter)
scope - the scope of the componentcomponentAdapter - the adapter to add@Nonnull public ComponentContainer.ContainerLevel getLevel()
public void setLevel(ComponentContainer.ContainerLevel newLevel)
newLevel - the level to set@Nullable public <T> T getComponent(Class<T> componentClass)
T - the component typecomponentClass - the key or type to look upPicoContainer.getComponent(Class)Copyright © 2002-2023 Atlassian. All Rights Reserved.