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

File DefaultScriptServiceManager.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

2
7
1
1
75
35
3
0.43
7
1
3

Classes

Class Line # Actions
DefaultScriptServiceManager 41 7 0% 3 1
0.990%
 

Contributing tests

No tests hitting this source file were found.

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.script.internal.service;
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.slf4j.Logger;
28    import org.xwiki.component.annotation.Component;
29    import org.xwiki.component.manager.ComponentManager;
30    import org.xwiki.script.service.ScriptService;
31    import org.xwiki.script.service.ScriptServiceManager;
32   
33    /**
34    * Locate Script Services by name dynamically at runtime by looking them up agains the Component Manager.
35    *
36    * @version $Id: 8723715e20d8e34766f6a503e54a9e52209dccb2 $
37    * @since 2.3M1
38    */
39    @Component
40    @Singleton
 
41    public class DefaultScriptServiceManager implements ScriptServiceManager
42    {
43    /**
44    * Used to locate Script Services dynamically. Note that since the lookup is done dynamically new Script Services
45    * can be added on the fly in the classloader and they'll be found (after they've been registered against the
46    * component manager obviously).
47    */
48    @Inject
49    @Named("context")
50    private Provider<ComponentManager> componentManager;
51   
52    /**
53    * The logger to log.
54    */
55    @Inject
56    private Logger logger;
57   
 
58  423800 toggle @Override
59    public ScriptService get(String serviceName)
60    {
61  423797 ScriptService scriptService = null;
62   
63  423791 if (this.componentManager.get().hasComponent(ScriptService.class, serviceName)) {
64  414894 try {
65  414895 scriptService = this.componentManager.get().getInstance(ScriptService.class, serviceName);
66    } catch (Exception e) {
67  0 this.logger.error("Failed to lookup script service for role hint [{}]", serviceName, e);
68    }
69    } else {
70  8898 this.logger.debug("No script service registered for role hint [{}]", serviceName);
71    }
72   
73  423800 return scriptService;
74    }
75    }