attic/src/wcs/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/wcs/DataSource.cpp
22 
23  \brief Implementation of the data source for the WCS driver.
24 */
25 
26 // TerraLib
27 #include "../dataaccess/datasource/DataSourceTransactor.h"
28 #include "../common/StringUtils.h"
29 #include "../core/translator/Translator.h"
30 #include "../core/uri/URI.h"
31 #include "../core/uri/Utils.h"
32 #include "DataSource.h"
33 #include "Exception.h"
34 #include "Transactor.h"
35 #include "Utils.h"
36 
37 // GDAL
38 #include <gdal_priv.h>
39 
41 
42 te::wcs::DataSource::DataSource(const std::string& connInfo)
43  : te::da::DataSource(connInfo),
44  m_isOpened(false)
45 {
46 }
47 
49  : te::da::DataSource(uri),
50  m_isOpened(false)
51 {
52 }
53 
54 
56 {}
57 
58 std::string te::wcs::DataSource::getType() const
59 {
61 }
62 
63 std::auto_ptr<te::da::DataSourceTransactor> te::wcs::DataSource::getTransactor()
64 {
65  if(!m_isOpened)
66  throw Exception(TE_TR("The data source is not opened!"));
67 
68  std::map<std::string, std::string> kvp = te::core::Expand(m_uri.query());
69  std::map<std::string, std::string>::const_iterator it = kvp.begin();
70  std::map<std::string, std::string>::const_iterator itend = kvp.end();
71 
72  return std::auto_ptr<te::da::DataSourceTransactor>(new Transactor(m_uri.uri(), kvp["COVERAGE_NAME"]));
73 }
74 
76 {
77  if(m_isOpened)
78  return;
79 
81 
82  std::map<std::string, std::string> kvp = te::core::Expand(m_uri.query());
83  std::map<std::string, std::string>::const_iterator it = kvp.begin();
84  std::map<std::string, std::string>::const_iterator itend = kvp.end();
85 
86  std::string request = BuildRequest(m_uri.uri(), kvp["COVERAGE_NAME"]);
87 
88  GDALDataset* gds = static_cast<GDALDataset*>(GDALOpen(request.c_str(), GA_ReadOnly));
89  if(gds == 0)
90  throw Exception(TE_TR("Error establishing connection with the informed server!"));
91 
92  GDALClose(gds);
93 
94  m_isOpened = true;
95 }
96 
98 {
99  m_isOpened = false;
100 }
101 
103 {
104  return m_isOpened;
105 }
106 
108 {
109  if (m_isOpened)
110  return true;
111 
113 
114  GDALDataset* gds = static_cast<GDALDataset*>(GDALOpen(m_uri.uri().c_str(), GA_ReadOnly));
115  if (gds == 0)
116  return false;
117 
118  GDALClose(gds);
119 
120  return true;
121 }
122 
124 {
125  return sm_capabilities;
126 }
127 
129 {
131 }
132 
134 {
135  return 0;
136 }
137 
138 void te::wcs::DataSource::create(const std::string& /*connInfo*/)
139 {
140  throw Exception(TE_TR("The create() method is not supported by the WCS driver!"));
141 }
142 
143 void te::wcs::DataSource::drop(const std::string& /*connInfo*/ )
144 {
145  throw Exception(TE_TR("The drop() method is not supported by the WCS driver!"));
146 }
147 
148 bool te::wcs::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::wcs::DataSource::getDataSourceNames(const std::string& /*connInfo*/)
171 {
172  return std::vector<std::string>();
173 }
174 
175 std::vector<te::core::EncodingType> te::wcs::DataSource::getEncodings(const std::string& /*connInfo*/)
176 {
177  return std::vector<te::core::EncodingType>();
178 }
179 
181 {
182  if (!m_uri.isValid())
183  throw Exception(TE_TR("The connection information is invalid!"));
184 
185  std::map<std::string, std::string> kvp = te::core::Expand(m_uri.query());
186  std::map<std::string, std::string>::const_iterator it = kvp.begin();
187  std::map<std::string, std::string>::const_iterator itend = kvp.end();
188 
189  if (m_uri.path().empty())
190  throw Exception(TE_TR("The connection information is invalid. Missing the path parameter!"));
191 
192  it = kvp.find("COVERAGE_NAME");
193  if (it == itend || it->second.empty())
194  throw Exception(TE_TR("The connection information is invalid. Missing COVERAGE_NAME parameter!"));
195 }
bool exists(const std::string &connInfo)
Check the existence of a data source in a driver.
void open()
It opens the data source and makes it ready for using.
std::string path() const
Retrieving the path.
Definition: URI.cpp:118
const te::da::SQLDialect * getDialect() const
It returns the data source SQL dialect, if there is one.
void close()
It closes the data source and clears all the resources used by its internal communication channel...
Base exception class for plugin module.
It represents the SQL query dialect accepted by a given data source.
Definition: SQLDialect.h:55
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
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
std::string query() const
Retrieving the query.
Definition: URI.cpp:123
void create(const std::string &connInfo)
It creates a new data source.
std::auto_ptr< te::da::DataSourceTransactor > getTransactor()
It returns the set of parameters used to set up the access channel to the underlying repository...
std::string getType() const
It returns the data source type name (in UPPER CASE). Ex: POSTGIS, SQLITE, WFS, WMS, or MYSQL.
std::vector< std::string > getDataSourceNames(const std::string &connInfo)
It gets the data source names available in a driver.
bool isValid() const
It checks if the data source is valid (available for using).
DataSource(const std::string &connInfo)
te::da::DataSourceCapabilities capabilities
std::vector< te::core::EncodingType > getEncodings(const std::string &connInfo)
URI C++ Library.
Definition: Attributes.h:37
void drop(const std::string &connInfo)
It removes the data source with the connection information from a driver.
Implementation of the data source for the WCS driver.
const std::string & uri() const
Retrieving the full URI.
Definition: URI.cpp:88
const te::da::DataSourceCapabilities & getCapabilities() const
It returns the known capabilities of the data source.
std::string BuildRequest(const std::string &serviceURL, const std::string &coverageName, const te::gm::Envelope *e=0)
static te::da::DataSourceCapabilities sm_capabilities
~DataSource()
Virtual destructor.
A class for representing an Uniform Resource Identifier (URI).
Definition: URI.h:49
te::core::URI m_uri
The URI used to describe the datasource connection;.
TECOREEXPORT std::map< std::string, std::string > Expand(const std::string &query_str)
Split a query string into its components.
#define TE_WCS_DRIVER_IDENTIFIER
The WCS driver identifier string.
Implementation of the transactor for the WCS driver.
bool isOpened() const
It returns true if the data source is opened, otherwise it returns false.
static void setCapabilities(const te::da::DataSourceCapabilities &capabilities)