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

File ContextComponentManager.java

 

Coverage histogram

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

Code metrics

2
8
6
1
107
60
7
0.88
1.33
6
1.17

Classes

Class Line # Actions
ContextComponentManager 45 8 0% 7 0
1.0100%
 

Contributing tests

This file is covered by 200 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.descriptor.ComponentDescriptor;
28    import org.xwiki.component.internal.multi.DelegateComponentManager;
29    import org.xwiki.component.manager.ComponentEventManager;
30    import org.xwiki.component.manager.ComponentManager;
31    import org.xwiki.component.manager.ComponentRepositoryException;
32    import org.xwiki.context.Execution;
33    import org.xwiki.model.namespace.UserNamespace;
34   
35    /**
36    * Chains Component Managers to perform lookups based on the current execution context (current user, current wiki,
37    * etc).
38    *
39    * @version $Id: d8102be97eb095b8d244f5863e3cd06d8252f089 $
40    * @since 2.1RC1
41    */
42    @Component
43    @Named("context")
44    @Singleton
 
45    public class ContextComponentManager extends DelegateComponentManager
46    {
47    /**
48    * The first Component Manager in the chain.
49    */
50    @Inject
51    @Named(UserNamespace.TYPE)
52    private ComponentManager userComponentManager;
53   
54    @Inject
55    private ComponentManager rootComponentManager;
56   
57    @Inject
58    private Execution execution;
59   
 
60  39402407 toggle @Override
61    public ComponentManager getComponentManager()
62    {
63    // If there is no context go directly to root CM
64  39412078 if (this.execution.getContext() == null) {
65  634824 return this.rootComponentManager;
66    } else {
67  38775201 return this.userComponentManager;
68    }
69    }
70   
71    // Make the Context Component Manager "read-only". Writes should be done against specific Component Managers.
72   
 
73  1 toggle @Override
74    public <T> void registerComponent(ComponentDescriptor<T> componentDescriptor, T componentInstance)
75    throws ComponentRepositoryException
76    {
77  1 throwException();
78    }
79   
 
80  2 toggle @Override
81    public <T> void registerComponent(ComponentDescriptor<T> componentDescriptor) throws ComponentRepositoryException
82    {
83  2 throwException();
84    }
85   
 
86  1 toggle @Override
87    public void setComponentEventManager(ComponentEventManager eventManager)
88    {
89  1 throwException();
90    }
91   
 
92  1 toggle @Override
93    public void setParent(ComponentManager parentComponentManager)
94    {
95  1 throwException();
96    }
97   
98    /**
99    * Exception to throw when trying to access a write method since this Component Manager is a chaining Component
100    * Manager and should only be used for read-only access.
101    */
 
102  5 toggle private void throwException()
103    {
104  5 throw new RuntimeException("The Context Component Manager should only be used for read access. Write "
105    + "operations should be done against specific Component Managers.");
106    }
107    }