1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.plugin.charts.source; |
21 |
|
|
22 |
|
import java.lang.reflect.Constructor; |
23 |
|
import java.lang.reflect.InvocationTargetException; |
24 |
|
import java.util.Map; |
25 |
|
|
26 |
|
import com.xpn.xwiki.XWikiContext; |
27 |
|
import com.xpn.xwiki.XWikiException; |
28 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
29 |
|
import com.xpn.xwiki.objects.BaseObject; |
30 |
|
import com.xpn.xwiki.plugin.charts.exceptions.DataSourceException; |
31 |
|
|
|
|
| 0% |
Uncovered Elements: 36 (36) |
Complexity: 11 |
Complexity Density: 0.41 |
|
32 |
|
public class ObjectDataSourceFactory implements DataSourceFactory |
33 |
|
{ |
34 |
|
|
35 |
|
private static DataSourceFactory uniqueInstance = new ObjectDataSourceFactory(); |
36 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
37 |
0 |
private ObjectDataSourceFactory()... |
38 |
|
{ |
39 |
|
|
40 |
|
} |
41 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
42 |
0 |
public static DataSourceFactory getInstance()... |
43 |
|
{ |
44 |
0 |
return uniqueInstance; |
45 |
|
} |
46 |
|
|
|
|
| 0% |
Uncovered Elements: 32 (32) |
Complexity: 9 |
Complexity Density: 0.35 |
|
47 |
0 |
@Override... |
48 |
|
public DataSource create(Map params, XWikiContext context) throws DataSourceException |
49 |
|
{ |
50 |
|
|
51 |
0 |
String docName = (String) params.get("doc"); |
52 |
0 |
if (docName == null) { |
53 |
0 |
throw new DataSourceException("source=type:object implies the presence of a doc argument"); |
54 |
|
} |
55 |
|
|
56 |
0 |
XWikiDocument doc; |
57 |
0 |
try { |
58 |
0 |
doc = context.getWiki().getDocument(docName, context); |
59 |
|
} catch (XWikiException e) { |
60 |
0 |
throw new DataSourceException(e); |
61 |
|
} |
62 |
|
|
63 |
0 |
String className = (String) params.get("class"); |
64 |
0 |
if (className == null) { |
65 |
0 |
throw new DataSourceException("source=type:object implies the presence of a class argument"); |
66 |
|
} |
67 |
|
|
68 |
0 |
int number; |
69 |
0 |
try { |
70 |
0 |
String s = (String) params.get("object_number"); |
71 |
0 |
try { |
72 |
0 |
number = Integer.parseInt(s); |
73 |
|
} catch (NumberFormatException e) { |
74 |
0 |
throw new DataSourceException(e); |
75 |
|
} |
76 |
|
} catch (NumberFormatException e) { |
77 |
0 |
throw new DataSourceException(e); |
78 |
|
} |
79 |
|
|
80 |
0 |
BaseObject xobj = doc.getObject("XWiki." + className, number); |
81 |
0 |
if (xobj == null) { |
82 |
0 |
throw new DataSourceException("XWiki." + className + "#" + number + " object not found"); |
83 |
|
} |
84 |
|
|
85 |
0 |
try { |
86 |
0 |
Class class_ = Class.forName(getClass().getPackage().getName() + "." + className); |
87 |
0 |
Constructor ctor = class_.getConstructor(new Class[] {BaseObject.class, XWikiContext.class}); |
88 |
0 |
return (DataSource) ctor.newInstance(new Object[] {xobj, context}); |
89 |
|
} catch (InvocationTargetException e) { |
90 |
0 |
throw new DataSourceException(e.getTargetException()); |
91 |
|
} catch (Exception e) { |
92 |
0 |
throw new DataSourceException(e); |
93 |
|
} |
94 |
|
} |
95 |
|
} |