1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.component.script; |
21 |
|
|
22 |
|
import java.lang.reflect.Type; |
23 |
|
|
24 |
|
import javax.inject.Inject; |
25 |
|
import javax.inject.Named; |
26 |
|
import javax.inject.Provider; |
27 |
|
import javax.inject.Singleton; |
28 |
|
|
29 |
|
import org.xwiki.bridge.DocumentAccessBridge; |
30 |
|
import org.xwiki.component.annotation.Component; |
31 |
|
import org.xwiki.component.internal.multi.ComponentManagerManager; |
32 |
|
import org.xwiki.component.manager.ComponentLookupException; |
33 |
|
import org.xwiki.component.manager.ComponentManager; |
34 |
|
import org.xwiki.context.Execution; |
35 |
|
import org.xwiki.script.service.ScriptService; |
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
@version |
41 |
|
@since |
42 |
|
|
43 |
|
@Component |
44 |
|
@Named("component") |
45 |
|
@Singleton |
|
|
| 100% |
Uncovered Elements: 0 (38) |
Complexity: 15 |
Complexity Density: 0.75 |
|
46 |
|
public class ComponentScriptService implements ScriptService |
47 |
|
{ |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
private static final String ERROR_KEY = "scriptservice.component.error"; |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
@Inject |
58 |
|
@Named("context") |
59 |
|
private Provider<ComponentManager> contextComponentManagerProvider; |
60 |
|
|
61 |
|
@Inject |
62 |
|
@Named("context/root") |
63 |
|
@Deprecated |
64 |
|
private Provider<ComponentManager> contextrootComponentManagerProvider; |
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
@Inject |
70 |
|
private ComponentManagerManager componentManagerManager; |
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
@Inject |
76 |
|
private DocumentAccessBridge bridge; |
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
@Inject |
82 |
|
private Execution execution; |
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
@return |
88 |
|
@deprecated@link |
89 |
|
@link |
90 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
91 |
2 |
@Deprecated... |
92 |
|
public ComponentManager getComponentManager() |
93 |
|
{ |
94 |
2 |
return this.bridge.hasProgrammingRights() ? this.contextrootComponentManagerProvider.get() : null; |
95 |
|
} |
96 |
|
|
97 |
|
|
98 |
|
@return |
99 |
|
@since |
100 |
|
@since |
101 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
102 |
99 |
public ComponentManager getContextComponentManager()... |
103 |
|
{ |
104 |
99 |
return this.bridge.hasProgrammingRights() ? this.contextComponentManagerProvider.get() : null; |
105 |
|
} |
106 |
|
|
107 |
|
|
108 |
|
@return |
109 |
|
@since |
110 |
|
@since |
111 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
112 |
2 |
public ComponentManager getRootComponentManager()... |
113 |
|
{ |
114 |
2 |
return getComponentManager(null); |
115 |
|
} |
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
@param@link |
128 |
|
@return |
129 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
130 |
4 |
public ComponentManager getComponentManager(String namespace)... |
131 |
|
{ |
132 |
4 |
return this.bridge.hasProgrammingRights() ? this.componentManagerManager.getComponentManager(namespace, false) |
133 |
|
: null; |
134 |
|
} |
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
@param |
141 |
|
@param |
142 |
|
@return |
143 |
|
@since |
144 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 3 |
Complexity Density: 0.43 |
|
145 |
94 |
public <T> T getInstance(Type roleType)... |
146 |
|
{ |
147 |
94 |
T result = null; |
148 |
94 |
ComponentManager cm = getContextComponentManager(); |
149 |
94 |
if (cm != null) { |
150 |
93 |
try { |
151 |
93 |
result = cm.getInstance(roleType); |
152 |
|
} catch (ComponentLookupException e) { |
153 |
1 |
setError(e); |
154 |
|
} |
155 |
|
} |
156 |
94 |
return result; |
157 |
|
} |
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
|
162 |
|
|
163 |
|
@param |
164 |
|
@param |
165 |
|
@param |
166 |
|
|
167 |
|
@return |
168 |
|
@since |
169 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 3 |
Complexity Density: 0.43 |
|
170 |
3 |
public <T> T getInstance(Type roleType, String roleHint)... |
171 |
|
{ |
172 |
3 |
T result = null; |
173 |
3 |
ComponentManager cm = getContextComponentManager(); |
174 |
3 |
if (cm != null) { |
175 |
2 |
try { |
176 |
2 |
result = cm.getInstance(roleType, roleHint); |
177 |
|
} catch (ComponentLookupException e) { |
178 |
1 |
setError(e); |
179 |
|
} |
180 |
|
} |
181 |
3 |
return result; |
182 |
|
} |
183 |
|
|
184 |
|
|
185 |
|
|
186 |
|
|
187 |
|
@return |
188 |
|
@since |
189 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
190 |
2 |
public Exception getLastError()... |
191 |
|
{ |
192 |
2 |
return (Exception) this.execution.getContext().getProperty(ERROR_KEY); |
193 |
|
} |
194 |
|
|
195 |
|
|
196 |
|
@link |
197 |
|
|
198 |
|
@param |
199 |
|
@see |
200 |
|
@since |
201 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
202 |
2 |
private void setError(Exception exception)... |
203 |
|
{ |
204 |
2 |
this.execution.getContext().setProperty(ERROR_KEY, exception); |
205 |
|
} |
206 |
|
|
207 |
|
} |