1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.component.internal.multi

File DefaultComponentManagerManager.java

 

Coverage histogram

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

Code metrics

4
14
2
1
97
45
6
0.43
7
2
3

Classes

Class Line # Actions
DefaultComponentManagerManager 41 14 0% 6 0
1.0100%
 

Contributing tests

This file is covered by 166 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.multi;
21   
22    import java.util.Map;
23    import java.util.concurrent.ConcurrentHashMap;
24   
25    import javax.inject.Inject;
26    import javax.inject.Singleton;
27   
28    import org.xwiki.component.annotation.Component;
29    import org.xwiki.component.manager.ComponentLookupException;
30    import org.xwiki.component.manager.ComponentManager;
31    import org.xwiki.component.namespace.NamespaceUtils;
32   
33    /**
34    * Default implementation of {@link ComponentManagerManager}.
35    *
36    * @version $Id: 2354c510ff74d1f65c5bf0aea258cb8dc84b3914 $
37    * @since 3.3M2
38    */
39    @Component
40    @Singleton
 
41    public class DefaultComponentManagerManager implements ComponentManagerManager
42    {
43    /**
44    * The Factory to use to create Component Managers whenever a component is registered for a key that doesn't already
45    * exist.
46    */
47    @Inject
48    private ComponentManagerFactory defaultComponentManagerFactory;
49   
50    /**
51    * The root component manager.
52    */
53    @Inject
54    private ComponentManager rootComponentManager;
55   
56    /**
57    * Holds Component Managers based on identifiers.
58    */
59    private Map<String, ComponentManager> componentManagers = new ConcurrentHashMap<>();
60   
 
61  1351382 toggle @Override
62    public ComponentManager getComponentManager(String namespace, boolean create)
63    {
64  1351449 ComponentManager componentManager;
65  1351484 if (namespace == null) {
66  247 componentManager = this.rootComponentManager;
67    } else {
68  1351263 componentManager = this.componentManagers.get(namespace);
69  1351287 if (componentManager == null && create) {
70  123 componentManager = createComponentManager(namespace);
71  123 this.componentManagers.put(namespace, componentManager);
72    }
73    }
74   
75  1351584 return componentManager;
76    }
77   
78    /**
79    * Create a new {@link ComponentManager} for the provided id.
80    *
81    * @param namespace the identifier of the component manager
82    * @return a new {@link ComponentManager} instance
83    */
 
84  123 toggle private ComponentManager createComponentManager(String namespace)
85    {
86  123 String prefix = NamespaceUtils.getPrefix(namespace);
87   
88  123 ComponentManagerFactory componentManagerFactory;
89  123 try {
90  123 componentManagerFactory = this.rootComponentManager.getInstance(ComponentManagerFactory.class, prefix);
91    } catch (ComponentLookupException e) {
92  72 componentManagerFactory = this.defaultComponentManagerFactory;
93    }
94   
95  123 return componentManagerFactory.createComponentManager(namespace, this.rootComponentManager);
96    }
97    }