1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.rest.internal; |
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.List; |
24 |
|
|
25 |
|
import org.restlet.ext.jaxrs.InstantiateException; |
26 |
|
import org.restlet.ext.jaxrs.ObjectFactory; |
27 |
|
import org.xwiki.component.descriptor.ComponentDescriptor; |
28 |
|
import org.xwiki.component.descriptor.ComponentInstantiationStrategy; |
29 |
|
import org.xwiki.component.manager.ComponentLookupException; |
30 |
|
import org.xwiki.component.manager.ComponentManager; |
31 |
|
import org.xwiki.context.Execution; |
32 |
|
import org.xwiki.context.ExecutionContext; |
33 |
|
import org.xwiki.rest.internal.Constants; |
34 |
|
import org.xwiki.rest.XWikiRestComponent; |
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
@version |
43 |
|
|
|
|
| 94.7% |
Uncovered Elements: 1 (19) |
Complexity: 5 |
Complexity Density: 0.38 |
|
44 |
|
public class ComponentsObjectFactory implements ObjectFactory |
45 |
|
{ |
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
private ComponentManager componentManager; |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
@param |
55 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
56 |
18 |
public ComponentsObjectFactory(ComponentManager componentManager)... |
57 |
|
{ |
58 |
18 |
this.componentManager = componentManager; |
59 |
|
} |
60 |
|
|
|
|
| 93.8% |
Uncovered Elements: 1 (16) |
Complexity: 4 |
Complexity Density: 0.33 |
|
61 |
2055 |
@Override... |
62 |
|
@SuppressWarnings("unchecked") |
63 |
|
public <T> T getInstance(Class<T> clazz) throws InstantiateException |
64 |
|
{ |
65 |
2055 |
try { |
66 |
|
|
67 |
2055 |
XWikiRestComponent component = componentManager.getInstance(XWikiRestComponent.class, clazz.getName()); |
68 |
|
|
69 |
|
|
70 |
|
|
71 |
2055 |
ComponentDescriptor<XWikiRestComponent> componentDescriptor = |
72 |
|
componentManager.getComponentDescriptor(XWikiRestComponent.class, clazz.getName()); |
73 |
|
|
74 |
|
|
75 |
|
|
76 |
2055 |
ExecutionContext executionContext = componentManager.<Execution> getInstance(Execution.class).getContext(); |
77 |
2055 |
List<XWikiRestComponent> releasableComponentReferences = |
78 |
|
(List<XWikiRestComponent>) executionContext.getProperty(Constants.RELEASABLE_COMPONENT_REFERENCES); |
79 |
2055 |
if (releasableComponentReferences == null) { |
80 |
1709 |
releasableComponentReferences = new ArrayList<XWikiRestComponent>(); |
81 |
1709 |
executionContext.setProperty(Constants.RELEASABLE_COMPONENT_REFERENCES, releasableComponentReferences); |
82 |
|
} |
83 |
|
|
84 |
|
|
85 |
2055 |
if (componentDescriptor.getInstantiationStrategy() == ComponentInstantiationStrategy.PER_LOOKUP) { |
86 |
1562 |
releasableComponentReferences.add(component); |
87 |
|
} |
88 |
|
|
89 |
|
|
90 |
|
|
91 |
2055 |
return (T) component; |
92 |
|
} catch (ComponentLookupException e) { |
93 |
0 |
throw new InstantiateException(e); |
94 |
|
} |
95 |
|
} |
96 |
|
} |