1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.internal.render

File OldRenderingProvider.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart8.png
54% of files have more coverage

Code metrics

2
12
6
1
117
76
9
0.75
2
6
1.5

Classes

Class Line # Actions
OldRenderingProvider 50 12 0% 9 4
0.880%
 

Contributing tests

This file is covered by 2 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 com.xpn.xwiki.internal.render;
21   
22    import java.util.Arrays;
23    import java.util.List;
24   
25    import javax.inject.Inject;
26    import javax.inject.Named;
27    import javax.inject.Provider;
28    import javax.inject.Singleton;
29   
30    import org.slf4j.Logger;
31    import org.xwiki.component.annotation.Component;
32    import org.xwiki.component.descriptor.ComponentDescriptor;
33    import org.xwiki.component.event.ComponentDescriptorAddedEvent;
34    import org.xwiki.component.manager.ComponentLookupException;
35    import org.xwiki.component.manager.ComponentManager;
36    import org.xwiki.component.phase.Initializable;
37    import org.xwiki.component.phase.InitializationException;
38    import org.xwiki.observation.EventListener;
39    import org.xwiki.observation.ObservationManager;
40    import org.xwiki.observation.event.Event;
41   
42    /**
43    * Dynamic provider for the default implementation of {@link OldRendering}.
44    *
45    * @version $Id: 30d628593b6c203282191e361fcd8f4d0f98ec50 $
46    * @since 7.1M1
47    */
48    @Component
49    @Singleton
 
50    public class OldRenderingProvider implements Provider<OldRendering>, Initializable
51    {
52    private static final List<Event> LISTENER_EVENTS = Arrays.<Event>asList(new ComponentDescriptorAddedEvent(
53    OldRendering.class));
54   
55    @Inject
56    private ObservationManager observation;
57   
58    @Inject
59    @Named("context")
60    private Provider<ComponentManager> componentManagerProvider;
61   
62    // Not injecting it directly since it triggers a lot of dependencies.
63    // Also we want to possibly find it in extensions
64    private OldRendering oldRendering;
65   
66    @Inject
67    private Logger logger;
68   
 
69  89 toggle @Override
70    public void initialize() throws InitializationException
71    {
72  89 this.observation.addListener(new EventListener()
73    {
 
74  0 toggle @Override
75    public void onEvent(Event event, Object componentManager, Object descriptor)
76    {
77  0 onNewOldRendering((ComponentDescriptor<OldRendering>) descriptor, (ComponentManager) componentManager);
78    }
79   
 
80  352 toggle @Override
81    public String getName()
82    {
83  352 return "OldRenderingListener";
84    }
85   
 
86  88 toggle @Override
87    public List<Event> getEvents()
88    {
89  88 return LISTENER_EVENTS;
90    }
91    });
92    }
93   
 
94  1 toggle void onNewOldRendering(ComponentDescriptor<OldRendering> descriptor, ComponentManager componentManager)
95    {
96  1 try {
97  1 this.oldRendering = componentManager.getInstance(OldRendering.class);
98    } catch (ComponentLookupException e) {
99  0 this.logger.error("Failed to lookup component [{}]", descriptor, e);
100    }
101    }
102   
 
103  3864 toggle @Override
104    public OldRendering get()
105    {
106  3864 if (this.oldRendering == null) {
107  62 try {
108  62 this.oldRendering = this.componentManagerProvider.get().getInstance(OldRendering.class);
109    } catch (ComponentLookupException e) {
110  0 throw new RuntimeException("Failed to get lookup default implementation of [" + OldRendering.class
111    + "]", e);
112    }
113    }
114   
115  3864 return this.oldRendering;
116    }
117    }