attic/src/wms/DataSource.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib 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
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/wms/DataSource.cpp
22 
23  \brief Implementation of the data source for the WMS driver.
24 */
25 
26 // TerraLib
27 #include "../dataaccess/datasource/DataSourceTransactor.h"
28 #include "../common/StringUtils.h"
29 #include "../core/translator/Translator.h"
30 #include "DataSource.h"
31 #include "Exception.h"
32 #include "Transactor.h"
33 #include "Utils.h"
34 
35 // GDAL
36 #include <gdal_priv.h>
37 
39 
40 te::wms::DataSource::DataSource(const std::string& connInfo)
41  : te::da::DataSource(connInfo),
42  m_isOpened(false)
43 {
44 }
45 
47  : te::da::DataSource(uri),
48  m_isOpened(false)
49 {
50 }
51 
52 
54 {}
55 
56 std::string te::wms::DataSource::getType() const
57 {
59 }
60 
61 std::auto_ptr<te::da::DataSourceTransactor> te::wms::DataSource::getTransactor()
62 {
63  if(!m_isOpened)
64  throw Exception(TE_TR("The data source is not opened!"));
65 
66  return std::auto_ptr<te::da::DataSourceTransactor>(new Transactor(m_uri.uri(), m_layersInfo));
67 }
68 
70 {
71  if(m_isOpened)
72  return;
73 
75 
76  GDALDataset* gds = (GDALDataset*)GDALOpenEx(m_uri.uri().c_str(), GDAL_OF_READONLY, NULL, NULL, NULL);;
77  if(gds == 0)
78  throw Exception(TE_TR("Error establishing connection with the informed server!"));
79 
80  // Gets the layer informations from server
81  char** subdatasets = gds->GetMetadata("SUBDATASETS");
82 
83  // Builds the layer informations from informed GDAL subdatasets
84  BuildLayersInfo(subdatasets, m_layersInfo);
85 
86  GDALClose(gds);
87 
88  m_isOpened = true;
89 }
90 
92 {
93  m_isOpened = false;
94  m_layersInfo.clear();
95 }
96 
98 {
99  return m_isOpened;
100 }
101 
103 {
104  if (m_isOpened)
105  return true;
106 
108 
109  GDALDataset* gds = static_cast<GDALDataset*>(GDALOpen(m_uri.uri().c_str(), GA_ReadOnly));
110  if(gds == 0)
111  return false;
112 
113  GDALClose(gds);
114 
115  return true;
116 }
117 
119 {
120  return sm_capabilities;
121 }
122 
124 {
126 }
127 
129 {
130  return 0;
131 }
132 
133 const std::map<std::string, te::wms::WMSLayerInfo>& te::wms::DataSource::getLayersInfo() const
134 {
135  return m_layersInfo;
136 }
137 
138 void te::wms::DataSource::create(const std::string& /*connInfo*/)
139 {
140  throw Exception(TE_TR("The create() method is not supported by the WMS driver!"));
141 }
142 
143 void te::wms::DataSource::drop(const std::string& /*connInfo*/)
144 {
145  throw Exception(TE_TR("The drop() method is not supported by the WMS driver!"));
146 }
147 
148 bool te::wms::DataSource::exists(const std::string& connInfo)
149 {
150  if (connInfo.empty())
151  return false;
152 
153  const te::core::URI aux(connInfo);
154  if (!aux.isValid())
155  return false;
156 
157  std::string path = aux.path();
158  if (path.empty())
159  return false;
160 
161  GDALDataset* gds = static_cast<GDALDataset*>(GDALOpen(path.c_str(), GA_ReadOnly));
162  if (gds == 0)
163  return false;
164 
165  GDALClose(gds);
166 
167  return true;
168 }
169 
170 std::vector<std::string> te::wms::DataSource::getDataSourceNames(const std::string& /*connInfo*/)
171 {
172  return std::vector<std::string>();
173 }
174 
176 {
177  if (!m_uri.isValid())
178  throw Exception(TE_TR("The connection information is invalid!"));
179 
180  if (m_uri.path().empty())
181  throw Exception(TE_TR("The connection information is invalid. Missing the path parameter!"));
182 }
Implementation of the transactor for the WMS driver.
const te::da::DataSourceCapabilities & getCapabilities() const
It returns the known capabilities of the data source.
std::string path() const
Retrieving the path.
Definition: URI.cpp:118
std::auto_ptr< te::da::DataSourceTransactor > getTransactor()
It returns the set of parameters used to set up the access channel to the underlying repository...
Implementation of the data source for the WMS driver.
const std::map< std::string, WMSLayerInfo > & getLayersInfo() const
Base exception class for plugin module.
bool exists(const std::string &connInfo)
Check the existence of a data source in a driver.
It represents the SQL query dialect accepted by a given data source.
Definition: SQLDialect.h:55
bool isOpened() const
It returns true if the data source is opened, otherwise it returns false.
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
bool isValid() const
Return if the given URI is valid or not.
Definition: URI.cpp:133
void close()
It closes the data source and clears all the resources used by its internal communication channel...
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
#define TE_WMS_DRIVER_IDENTIFIER
const te::da::SQLDialect * getDialect() const
It returns the data source SQL dialect, if there is one.
std::map< std::string, WMSLayerInfo > m_layersInfo
void BuildLayersInfo(char **subdatasets, std::map< std::string, WMSLayerInfo > &info)
te::da::DataSourceCapabilities capabilities
URI C++ Library.
Definition: Attributes.h:37
static void setCapabilities(const te::da::DataSourceCapabilities &capabilities)
const std::string & uri() const
Retrieving the full URI.
Definition: URI.cpp:88
void drop(const std::string &connInfo)
It removes the data source with the connection information from a driver.
std::string getType() const
It returns the data source type name (in UPPER CASE). Ex: POSTGIS, SQLITE, WFS, WMS, or MYSQL.
A class for representing an Uniform Resource Identifier (URI).
Definition: URI.h:49
DataSource(const std::string &connInfo)
static te::da::DataSourceCapabilities sm_capabilities
te::core::URI m_uri
The URI used to describe the datasource connection;.
bool isValid() const
It checks if the data source is valid (available for using).
void open()
It opens the data source and makes it ready for using.
~DataSource()
Virtual destructor.
std::vector< std::string > getDataSourceNames(const std::string &connInfo)
It gets the data source names available in a driver.
void create(const std::string &connInfo)
It creates a new data source.