1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.plugin.charts.source

File ObjectDataSourceFactory.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart0.png
83% of files have more coverage

Code metrics

6
27
3
1
95
62
11
0.41
9
3
3.67

Classes

Class Line # Actions
ObjectDataSourceFactory 32 27 0% 11 36
0.00%
 

Contributing tests

No tests hitting this source file were found.

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.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   
 
32    public class ObjectDataSourceFactory implements DataSourceFactory
33    {
34   
35    private static DataSourceFactory uniqueInstance = new ObjectDataSourceFactory();
36   
 
37  0 toggle private ObjectDataSourceFactory()
38    {
39    // empty
40    }
41   
 
42  0 toggle public static DataSourceFactory getInstance()
43    {
44  0 return uniqueInstance;
45    }
46   
 
47  0 toggle @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    }