1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.component.internal

File WikiComponentManager.java

 

Coverage histogram

../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

4
6
4
1
104
44
6
1
1.5
4
1.5

Classes

Class Line # Actions
WikiComponentManager 45 6 0% 6 1
0.928571492.9%
 

Contributing tests

This file is covered by 199 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.component.internal;
21   
22    import javax.inject.Inject;
23    import javax.inject.Named;
24    import javax.inject.Singleton;
25   
26    import org.xwiki.component.annotation.Component;
27    import org.xwiki.component.manager.ComponentManager;
28    import org.xwiki.component.phase.Initializable;
29    import org.xwiki.component.phase.InitializationException;
30    import org.xwiki.model.reference.EntityReference;
31    import org.xwiki.model.reference.WikiReference;
32    import org.xwiki.wiki.descriptor.WikiDescriptorManager;
33   
34    /**
35    * Proxy Component Manager that creates and queries individual Component Managers specific to the current wiki in the
36    * Execution Context. These Component Managers are created on the fly the first time a component is registered for the
37    * current wiki.
38    *
39    * @version $Id: 6d9e261406c61057ce92e2158cb7c17ed8e4be95 $
40    * @since 2.1RC1
41    */
42    @Component
43    @Named(WikiComponentManager.ID)
44    @Singleton
 
45    public class WikiComponentManager extends AbstractEntityComponentManager implements Initializable
46    {
47    /**
48    * The identifier of this {@link ComponentManager}.
49    */
50    public static final String ID = "wiki";
51   
52    /**
53    * The prefix of wiki namespace.
54    *
55    * @since 8.4RC1
56    */
57    public static final String NAMESPACE_PREFIX = ID + ':';
58   
59    @Inject
60    private WikiDescriptorManager wikis;
61   
62    /**
63    * The Component Manager to be used as parent when a component is not found in the current Component Manager.
64    */
65    @Inject
66    private ComponentManager rootComponentManager;
67   
 
68  2859537 toggle private String getCurrentWiki()
69    {
70  2859540 return this.wikis.getCurrentWikiId();
71    }
72   
 
73  2823203 toggle @Override
74    protected EntityReference getCurrentReference()
75    {
76  2823208 String currentWikiId = getCurrentWiki();
77   
78  2823200 return currentWikiId != null ? new WikiReference(currentWikiId) : null;
79    }
80   
81    /**
82    * {@inheritDoc}
83    * <p>
84    * Override default implementation with one much better for performances.
85    * </p>
86    *
87    * @see org.xwiki.component.internal.AbstractEntityComponentManager#getKey()
88    */
 
89  36349 toggle @Override
90    protected String getKey()
91    {
92  36352 String wiki = getCurrentWiki();
93   
94  36365 return wiki != null ? NAMESPACE_PREFIX + wiki : null;
95    }
96   
 
97  271 toggle @Override
98    public void initialize() throws InitializationException
99    {
100    // Set the parent to the Root Component Manager since if a component isn't found for a particular wiki
101    // we want to check if it's available in the Root Component Manager.
102  271 setInternalParent(this.rootComponentManager);
103    }
104    }