1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
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 |
|
@link |
44 |
|
|
45 |
|
@version |
46 |
|
@since |
47 |
|
|
48 |
|
@Component |
49 |
|
@Singleton |
|
|
| 80% |
Uncovered Elements: 4 (20) |
Complexity: 9 |
Complexity Density: 0.75 |
|
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 |
|
|
63 |
|
|
64 |
|
private OldRendering oldRendering; |
65 |
|
|
66 |
|
@Inject |
67 |
|
private Logger logger; |
68 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
69 |
89 |
@Override... |
70 |
|
public void initialize() throws InitializationException |
71 |
|
{ |
72 |
89 |
this.observation.addListener(new EventListener() |
73 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
74 |
0 |
@Override... |
75 |
|
public void onEvent(Event event, Object componentManager, Object descriptor) |
76 |
|
{ |
77 |
0 |
onNewOldRendering((ComponentDescriptor<OldRendering>) descriptor, (ComponentManager) componentManager); |
78 |
|
} |
79 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
80 |
352 |
@Override... |
81 |
|
public String getName() |
82 |
|
{ |
83 |
352 |
return "OldRenderingListener"; |
84 |
|
} |
85 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
86 |
88 |
@Override... |
87 |
|
public List<Event> getEvents() |
88 |
|
{ |
89 |
88 |
return LISTENER_EVENTS; |
90 |
|
} |
91 |
|
}); |
92 |
|
} |
93 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
94 |
1 |
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 |
|
|
|
|
| 85.7% |
Uncovered Elements: 1 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
103 |
3864 |
@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 |
|
} |