diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/votable/controller/VOTableController.java b/src/main/java/eu/omp/irap/vespa/epntapclient/votable/controller/VOTableController.java new file mode 100644 index 0000000..454d556 --- /dev/null +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/votable/controller/VOTableController.java @@ -0,0 +1,101 @@ +/** + * This file is a part of EpnTAPClient. + * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer. + * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861 + * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planétologie. + * + * This program is free software: you can + * redistribute it and/or modify it under the terms of the GNU General Public License as published + * by the Free Software Foundation, either version 3 of the License, or (at your option) any later + * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. You should have received a copy of + * the GNU General Public License along with this program. If not, see + * . + */ +package eu.omp.irap.vespa.epntapclient.votable.controller; + +import eu.omp.irap.vespa.epntapclient.votable.model.Table; +import eu.omp.irap.vespa.epntapclient.votable.model.VOTABLE; +import eu.omp.irap.vespa.epntapclient.votable.view.VOTableView; + +/** + * @author N. Jourdane + */ +public class VOTableController { + + /** The view of the VOTable */ + VOTableView view; + + /** The VOTable model */ + VOTABLE voTable; + + /** + * Method constructor + * + * @param voTablePath The path of the VOTable XML file. + */ + public VOTableController(String voTablePath) { + view = new VOTableView(this); + + try { + voTable = VOTableParser.parseVOTable(voTablePath); + fillView(); + } catch (Exception e) { + view.displayError("VOTable can not be displayed", e.getMessage()); + } + } + + /** + * Method constructor + * + * @param targetURL The url of the registry to communicate (ie. "http://reg.g-vo.org"). + * @param serviceType The type of service (ie. "tap"). + * @param queryLanguage The language used for the queries (ie. "ADQL"). + * @param query The query to ask to the registry. + */ + public VOTableController(String targetURL, String serviceType, String queryLanguage, + String query) { + view = new VOTableView(this); + String voTablePath; + + try { + voTablePath = VOTableConnection.sendQuery(targetURL, serviceType, queryLanguage, + query); + voTable = VOTableParser.parseVOTable(voTablePath); + fillView(); + } catch (Exception e) { + view.displayError("VOTable can not be displayed", e.getMessage()); + } + } + + /** + * Fill the view with the VOTable data. + * + * @throws Exception If there are more than 1 resource or table in the VOTable. + */ + private void fillView() throws Exception { + // TODO: Traiter le cas où il y a plus d'une ressource et d'une table. + if (voTable.getRESOURCE().size() != 1) { + throw new Exception("VOTable with more than one resource are not yet supported."); + } + if (voTable.getRESOURCE().get(0).getLINKAndTABLEOrRESOURCE().size() != 1) { + throw new Exception("VOTable with more than one table are not yet supported."); + } + Table table = (Table) (voTable.getRESOURCE().get(0).getLINKAndTABLEOrRESOURCE().get(0)); + try { + VOTableDataParser dataParser = new VOTableDataParser(table); + view.buildArray(dataParser.getColumnsName(), dataParser.getDataArray()); + } catch (Exception e) { + view.displayError("VOTable can not be displayed", + "Can not parse VOTable data.\nReason:\n" + e.getMessage()); + } + } + + /** + * @return The view of the VOTable. + */ + public VOTableView getView() { + return view; + } +} -- libgit2 0.21.2