1. Project Clover database Tue Dec 20 2016 21:24:09 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
106
59
7
0.88
1.33
6
1.17

Classes

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

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