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

File ContextComponentManagerProvider.java

 

Coverage histogram

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

Code metrics

0
6
1
1
75
33
2
0.33
6
1
2

Classes

Class Line # Actions
ContextComponentManagerProvider 43 6 0% 2 0
1.0100%
 

Contributing tests

This file is covered by 1513 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.Provider;
25    import javax.inject.Singleton;
26   
27    import org.apache.commons.lang3.exception.ExceptionUtils;
28    import org.slf4j.Logger;
29    import org.xwiki.component.annotation.Component;
30    import org.xwiki.component.manager.ComponentLookupException;
31    import org.xwiki.component.manager.ComponentManager;
32   
33    /**
34    * Provide the {@link ComponentManager} associated to the current context. Return the root {@link ComponentManager} if
35    * no context oriented {@link ComponentManager} can be found.
36    *
37    * @version $Id: 369678276a82184361517a457a231e95a772f024 $
38    * @since 4.1.4
39    */
40    @Component
41    @Named("context")
42    @Singleton
 
43    public class ContextComponentManagerProvider implements Provider<ComponentManager>
44    {
45    @Inject
46    private Logger logger;
47   
48    /**
49    * The root {@link ComponentManager} used to lookup the context {@link ComponentManager} and as a fallback if none
50    * is provided.
51    */
52    @Inject
53    private ComponentManager rootComponentManager;
54   
 
55  1306878 toggle @Override
56    public ComponentManager get()
57    {
58  1306878 ComponentManager componentManagerToUse;
59   
60    // Look for the Context Component Manager so that Macros can be registered for a specific user, for a
61    // specific wiki, etc. If it's not found use the Root Component Manager. This allows the Rendering module
62    // to work outside of XWiki when there's no notion of Execution Context and Wiki Model for example.
63  1306877 try {
64  1306876 componentManagerToUse = this.rootComponentManager.getInstance(ComponentManager.class, "context");
65    } catch (ComponentLookupException e) {
66    // This means the Context CM doesn't exist, use the Root CM.
67  42349 componentManagerToUse = this.rootComponentManager;
68  42349 this.logger.debug("Failed to find the [context] Component Manager. Cause: [{}]. Using the Root Component "
69    + "Manager", ExceptionUtils.getRootCauseMessage(e));
70    }
71   
72  1306885 return componentManagerToUse;
73    }
74   
75    }