JIRA 4.0 : PicoContainer and JIRA
This page last changed on Nov 16, 2005 by jnolen.
PicocontainerJIRA uses Picocontainer as a central object factory. Picocontainer is responsible for instantiating objects and resolving their constructor dependencies. This greatly simplifies code, in that any Picocontainer-instantiated object (eg. a Webwork action) can obtain an instance of another (eg. a Manager class) simply by requesting one in its constructor. PicoContainer will ensure each object required in the constructor is passed in (aka dependency injection). Eg. the ViewIssue action: ViewIssue.java public class ViewIssue extends AbstractViewIssue { .... public ViewIssue(RepositoryManager repositoryManager, PermissionManager permissionManager, TrackbackManager trackbackManager, ThumbnailManager thumbnailManager, SubTaskManager subTaskManager, IssueLinkManager issueLinkManager, IssueLinkTypeManager issueLinkTypeManager, VoteManager voteManager, WatcherManager watcherManager, PluginManager pluginManager) { super(issueLinkManager, subTaskManager); this.trackbackManager = trackbackManager; this.thumbnailManager = thumbnailManager; this.issueLinkTypeManager = issueLinkTypeManager; this.pluginManager = pluginManager; this.pagerManager = new PagerManager(ActionContext.getSession()); this.repositoryManager = repositoryManager; this.permissionManager = permissionManager; this.voteManager = voteManager; this.watcherManager = watcherManager; } .... } Non-managed classesClasses not managed by Picocontainer (eg. workflow conditions / functions, Services and Listeners, or JSP scriptlets) can still get pico-instantiated objects statically using static methods of ManagerFactory or ComponentManager.getInstance(). For example: ComponentManager.getInstance().getProjectManager(); ComponentManager.getInstance().getIssueFactory(); ManagerFactory.getCustomFieldManager(); //or ManagerFactory.getApplicationProperties(); Using ComponentManager.getInstance() is prefered as ManagerFactory will become obsolete. However, if a method that you are after does not exist on the ComponentManager, use ManagerFactory. Register new Picocontainer-managed classesPicocontainer-managed classes need to be registered with Picocontainer. This happens automatically for Webwork actions, but other classes need to be registered manually. This is done in ComponentManager's registerComponents() method: ComponentManager.java private void registerComponents() { .... internalContainer.registerComponentInstance(CoreFactory.getActionDispatcher()); internalContainer.registerComponentInstance(CoreFactory.getGenericDelegator()); internalContainer.registerComponentInstance(CoreFactory.getAssociationManager()); internalContainer.registerComponentInstance(MailFactory.getServerManager()); internalContainer.registerComponentInstance(UserManager.getInstance()); internalContainer.registerComponentInstance(SearchProviderFactory.getDefaultProvider()); ..... internalContainer.registerComponentImplementation(IssueUpdater.class, DefaultIssueUpdater.class); internalContainer.registerComponentImplementation(IssueEventDispatcher.class); internalContainer.registerComponentImplementation(ChangeLogUtils.class); internalContainer.registerComponentImplementation(QueryCreator.class); internalContainer.registerComponentImplementation(ReleaseNoteManager.class); internalContainer.registerComponentImplementation(ApplicationProperties.class, ApplicationPropertiesImpl.class); internalContainer.registerComponentImplementation(VelocityManager.class, JiraVelocityManager.class); internalContainer.registerComponentImplementation(ConstantsManager.class, DefaultConstantsManager.class); internalContainer.registerComponentImplementation(PermissionSchemeManager.class, DefaultPermissionSchemeManager.class); internalContainer.registerComponentImplementation(CacheManager.class, DefaultCacheManager.class); internalContainer.registerComponentImplementation(TrackbackManager.class, TrackbackManagerImpl.class); internalContainer.registerComponentImplementation(WatcherManager.class, DefaultWatcherManager.class); internalContainer.registerComponentImplementation(EntityUtils.class); internalContainer.registerComponentImplementation(AttachmentManager.class, DefaultAttachmentManager.class); internalContainer.registerComponentImplementation(FieldManager.class, DefaultFieldManager.class); ..... } |
![]() |
Document generated by Confluence on Oct 06, 2009 00:31 |