/** * Returns the core component which is stored in JIRA's Dependency Injection container under the key that is the given class. * <p> * In practise, this is the same as {@link #getComponentOfType(Class)} except it will fail faster if the * given Class is not a known component key (it also has a shorter and more meaningful name). * <p> * Please note that this method only gets components from JIRA's core Pico Container. * That is, it retrieves core components and components declared in Plugins1 plugins, but not components declared in Plugins2 plugins. * * @param componentClass class to find a component instance by * @return the dependency injection component * @see #getComponentOfType(Class) */ public static <T> T getComponent(Class<T> componentClass) { return getWorker().getComponent(componentClass); }
/** * Returns the core component of the given Type (a Class or an Interface) which is stored in JIRA's * Dependency Injection container. * <p> * First it tries to find the component using the given Class as a key (like {@link #getComponent(Class)}), * however, if this fails then it will try to find a <em>unique</em> component that implements/extends the given Class. * This seems unlikely to be useful, but is included for now, for completeness and backward compatibility. * <p> * Please note that this method only gets components from JIRA's core Pico Container. * That is, it retrieves core components and components declared in Plugins1 plugins, but not components declared in Plugins2 plugins. * * @param componentClass class to find a component instance by * @return the dependency injection component * @see #getComponent(Class) */ public static <T> T getComponentOfType(Class<T> componentClass) { return getWorker().getComponentOfType(componentClass); }
/** * Retrieves and returns a public component from OSGi land via its class name. This method can be used to retrieve * a component provided via a plugins2 OSGi bundle. Please note that components returned via this method should * <strong>NEVER</strong> be cached (for example, by saving it in a static field) as they may be refreshed at * any time as a plugin is enabled/disabled or the componentManager is reinitialised (after an XML import). * <p/> * It is important to note that this only works for public components. That is components with {@code public="true"} * declared in their XML configuration. This means that they are available for other plugins to import. * <p/> * A example use case for this method is the dashboards plugin. In several areas in JIRA we may want to * render gadgets via the {@link com.atlassian.gadgets.view.GadgetViewFactory}. Whilst the interface for this * component is available in JIRA core, the implementation is provided by the dashboards OSGi bundle. This method * will allow us to access it. * * @param componentClass the class for which to find an OSGi component instance * @return the found component or <code>null</code> if it does not exist * @see #getComponentOfType(Class) */ public static <T> T getOSGiComponentInstanceOfType(Class<T> componentClass) { return getWorker().getOSGiComponentInstanceOfType(componentClass); }