Commit 43ee402600fe02761daf3f3cae02c5873d3cfffc
1 parent
2e9b5549
Exists in
master
Add the VOTable controller.
Showing
1 changed file
with
101 additions
and
0 deletions
Show diff stats
src/main/java/eu/omp/irap/vespa/epntapclient/votable/controller/VOTableController.java
0 → 100644
... | ... | @@ -0,0 +1,101 @@ |
1 | +/** | |
2 | + * This file is a part of EpnTAPClient. | |
3 | + * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer. | |
4 | + * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861 | |
5 | + * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planétologie. | |
6 | + * | |
7 | + * This program is free software: you can | |
8 | + * redistribute it and/or modify it under the terms of the GNU General Public License as published | |
9 | + * by the Free Software Foundation, either version 3 of the License, or (at your option) any later | |
10 | + * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY | |
11 | + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR | |
12 | + * PURPOSE. See the GNU General Public License for more details. You should have received a copy of | |
13 | + * the GNU General Public License along with this program. If not, see | |
14 | + * <http://www.gnu.org/licenses/>. | |
15 | + */ | |
16 | +package eu.omp.irap.vespa.epntapclient.votable.controller; | |
17 | + | |
18 | +import eu.omp.irap.vespa.epntapclient.votable.model.Table; | |
19 | +import eu.omp.irap.vespa.epntapclient.votable.model.VOTABLE; | |
20 | +import eu.omp.irap.vespa.epntapclient.votable.view.VOTableView; | |
21 | + | |
22 | +/** | |
23 | + * @author N. Jourdane | |
24 | + */ | |
25 | +public class VOTableController { | |
26 | + | |
27 | + /** The view of the VOTable */ | |
28 | + VOTableView view; | |
29 | + | |
30 | + /** The VOTable model */ | |
31 | + VOTABLE voTable; | |
32 | + | |
33 | + /** | |
34 | + * Method constructor | |
35 | + * | |
36 | + * @param voTablePath The path of the VOTable XML file. | |
37 | + */ | |
38 | + public VOTableController(String voTablePath) { | |
39 | + view = new VOTableView(this); | |
40 | + | |
41 | + try { | |
42 | + voTable = VOTableParser.parseVOTable(voTablePath); | |
43 | + fillView(); | |
44 | + } catch (Exception e) { | |
45 | + view.displayError("VOTable can not be displayed", e.getMessage()); | |
46 | + } | |
47 | + } | |
48 | + | |
49 | + /** | |
50 | + * Method constructor | |
51 | + * | |
52 | + * @param targetURL The url of the registry to communicate (ie. "http://reg.g-vo.org"). | |
53 | + * @param serviceType The type of service (ie. "tap"). | |
54 | + * @param queryLanguage The language used for the queries (ie. "ADQL"). | |
55 | + * @param query The query to ask to the registry. | |
56 | + */ | |
57 | + public VOTableController(String targetURL, String serviceType, String queryLanguage, | |
58 | + String query) { | |
59 | + view = new VOTableView(this); | |
60 | + String voTablePath; | |
61 | + | |
62 | + try { | |
63 | + voTablePath = VOTableConnection.sendQuery(targetURL, serviceType, queryLanguage, | |
64 | + query); | |
65 | + voTable = VOTableParser.parseVOTable(voTablePath); | |
66 | + fillView(); | |
67 | + } catch (Exception e) { | |
68 | + view.displayError("VOTable can not be displayed", e.getMessage()); | |
69 | + } | |
70 | + } | |
71 | + | |
72 | + /** | |
73 | + * Fill the view with the VOTable data. | |
74 | + * | |
75 | + * @throws Exception If there are more than 1 resource or table in the VOTable. | |
76 | + */ | |
77 | + private void fillView() throws Exception { | |
78 | + // TODO: Traiter le cas où il y a plus d'une ressource et d'une table. | |
79 | + if (voTable.getRESOURCE().size() != 1) { | |
80 | + throw new Exception("VOTable with more than one resource are not yet supported."); | |
81 | + } | |
82 | + if (voTable.getRESOURCE().get(0).getLINKAndTABLEOrRESOURCE().size() != 1) { | |
83 | + throw new Exception("VOTable with more than one table are not yet supported."); | |
84 | + } | |
85 | + Table table = (Table) (voTable.getRESOURCE().get(0).getLINKAndTABLEOrRESOURCE().get(0)); | |
86 | + try { | |
87 | + VOTableDataParser dataParser = new VOTableDataParser(table); | |
88 | + view.buildArray(dataParser.getColumnsName(), dataParser.getDataArray()); | |
89 | + } catch (Exception e) { | |
90 | + view.displayError("VOTable can not be displayed", | |
91 | + "Can not parse VOTable data.\nReason:\n" + e.getMessage()); | |
92 | + } | |
93 | + } | |
94 | + | |
95 | + /** | |
96 | + * @return The view of the VOTable. | |
97 | + */ | |
98 | + public VOTableView getView() { | |
99 | + return view; | |
100 | + } | |
101 | +} | ... | ... |