1. Project Clover database Tue Dec 20 2016 21:24:09 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 175 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  179381 toggle @Override
62    public ComponentManager getComponentManager(String namespace, boolean create)
63    {
64  179373 ComponentManager componentManager;
65  179367 if (namespace == null) {
66  74 componentManager = this.rootComponentManager;
67    } else {
68  179297 componentManager = this.componentManagers.get(namespace);
69  179297 if (componentManager == null && create) {
70  102 componentManager = createComponentManager(namespace);
71  102 this.componentManagers.put(namespace, componentManager);
72    }
73    }
74   
75  179360 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  102 toggle private ComponentManager createComponentManager(String namespace)
85    {
86  102 String prefix = NamespaceUtils.getPrefix(namespace);
87   
88  102 ComponentManagerFactory componentManagerFactory;
89  102 try {
90  102 componentManagerFactory = this.rootComponentManager.getInstance(ComponentManagerFactory.class, prefix);
91    } catch (ComponentLookupException e) {
92  55 componentManagerFactory = this.defaultComponentManagerFactory;
93    }
94   
95  102 return componentManagerFactory.createComponentManager(namespace, this.rootComponentManager);
96    }
97    }