All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 "../common/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 
41  : m_isOpened(false)
42 {
43 }
44 
46 {}
47 
48 std::string te::wcs::DataSource::getType() const
49 {
51 }
52 
53 const std::map<std::string, std::string>& te::wcs::DataSource::getConnectionInfo() const
54 {
55  return m_connectionInfo;
56 }
57 
58 void te::wcs::DataSource::setConnectionInfo(const std::map<std::string, std::string>& connInfo)
59 {
60  m_connectionInfo = connInfo;
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  return std::auto_ptr<te::da::DataSourceTransactor>(new Transactor(m_connectionInfo.find("URI")->second, m_connectionInfo.find("COVERAGE_NAME")->second));
69 }
70 
72 {
73  if(m_isOpened)
74  return;
75 
76  verifyConnectionInfo();
77 
78  std::string request = BuildRequest(m_connectionInfo.find("URI")->second, m_connectionInfo.find("COVERAGE_NAME")->second);
79 
80  GDALDataset* gds = static_cast<GDALDataset*>(GDALOpen(request.c_str(), GA_ReadOnly));
81  if(gds == 0)
82  throw Exception(TE_TR("Error establishing connection with the informed server!"));
83 
84  GDALClose(gds);
85 
86  m_isOpened = true;
87 }
88 
90 {
91  m_isOpened = false;
92 }
93 
95 {
96  return m_isOpened;
97 }
98 
100 {
101  if(m_connectionInfo.empty())
102  return false;
103 
104  std::map<std::string, std::string>::const_iterator it = m_connectionInfo.find("URI");
105  if(it == m_connectionInfo.end())
106  return false;
107 
108  GDALDataset* gds = static_cast<GDALDataset*>(GDALOpen(it->second.c_str(), GA_ReadOnly));
109  if(gds == 0)
110  return false;
111 
112  GDALClose(gds);
113 
114  return true;
115 }
116 
118 {
119  return sm_capabilities;
120 }
121 
123 {
124  sm_capabilities = capabilities;
125 }
126 
128 {
129  return 0;
130 }
131 
132 void te::wcs::DataSource::create(const std::map<std::string, std::string>& /*dsInfo*/)
133 {
134  throw Exception(TE_TR("The create() method is not supported by the WCS driver!"));
135 }
136 
137 void te::wcs::DataSource::drop(const std::map<std::string, std::string>& /*dsInfo*/)
138 {
139  throw Exception(TE_TR("The drop() method is not supported by the WCS driver!"));
140 }
141 
142 bool te::wcs::DataSource::exists(const std::map<std::string, std::string>& dsInfo)
143 {
144  if(dsInfo.empty())
145  return false;
146 
147  std::map<std::string, std::string>::const_iterator it = dsInfo.find("URI");
148  if(it == dsInfo.end())
149  return false;
150 
151  GDALDataset* gds = static_cast<GDALDataset*>(GDALOpen(it->second.c_str(), GA_ReadOnly));
152  if(gds == 0)
153  return false;
154 
155  GDALClose(gds);
156 
157  return true;
158 }
159 
160 std::vector<std::string> te::wcs::DataSource::getDataSourceNames(const std::map<std::string, std::string>& /*dsInfo*/)
161 {
162  return std::vector<std::string>();
163 }
164 
165 std::vector<te::common::CharEncoding> te::wcs::DataSource::getEncodings(const std::map<std::string, std::string>& /*dsInfo*/)
166 {
167  return std::vector<te::common::CharEncoding>();
168 }
169 
171 {
172  if(m_connectionInfo.empty())
173  throw Exception(TE_TR("The connection information is empty!"));
174 
175  std::map<std::string, std::string>::const_iterator it = m_connectionInfo.find("URI");
176  if(it == m_connectionInfo.end())
177  throw Exception(TE_TR("The connection information is invalid. Missing URI parameter!"));
178 
179  it = m_connectionInfo.find("COVERAGE_NAME");
180  if(it == m_connectionInfo.end())
181  throw Exception(TE_TR("The connection information is invalid. Missing COVERAGE_NAME parameter!"));
182 }
void open()
It opens the data source and makes it ready for using.
Definition: DataSource.cpp:71
const te::da::SQLDialect * getDialect() const
It returns the data source SQL dialect, if there is one.
Definition: DataSource.cpp:127
void close()
It closes the data source and clears all the resources used by its internal communication channel...
Definition: DataSource.cpp:89
Implementation of the data source for the WCS driver.
Implementation of the transactor for the WCS driver.
Utility functions for WCS driver.
An exception class for the TerraLib WCS module.
void setConnectionInfo(const std::map< std::string, std::string > &connInfo)
It sets the connection information to be used when connecting to the data source. ...
Definition: DataSource.cpp:58
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...
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:347
std::auto_ptr< te::da::DataSourceTransactor > getTransactor()
It returns an object that can execute transactions in the context of a data source.
Definition: DataSource.cpp:63
std::string getType() const
It returns the data source type name (in UPPER CASE). Ex: POSTGIS, SQLITE, WFS, WMS, or MYSQL.
Definition: DataSource.cpp:48
bool isValid() const
It checks if the data source is valid (available for using).
Definition: DataSource.cpp:99
te::da::DataSourceCapabilities capabilities
std::vector< te::common::CharEncoding > getEncodings(const std::map< std::string, std::string > &dsInfo)
It gets the encodings for the data source.
Definition: DataSource.cpp:165
const std::map< std::string, std::string > & getConnectionInfo() const
It returns the set of parameters used to set up the access channel to the underlying repository...
Definition: DataSource.cpp:53
const te::da::DataSourceCapabilities & getCapabilities() const
It returns the known capabilities of the data source.
Definition: DataSource.cpp:117
#define TE_WCS_DRIVER_IDENTIFIER
The WCS driver identifier string.
Definition: Config.h:39
std::string BuildRequest(const std::string &serviceURL, const std::string &coverageName, const te::gm::Envelope *e=0)
Definition: Utils.cpp:34
static te::da::DataSourceCapabilities sm_capabilities
Definition: DataSource.h:98
~DataSource()
Virtual destructor.
Definition: DataSource.cpp:45
void create(const std::map< std::string, std::string > &dsInfo)
It creates a new data source.
Definition: DataSource.cpp:132
std::vector< std::string > getDataSourceNames(const std::map< std::string, std::string > &dsInfo)
It gets the data source names available in a driver.
Definition: DataSource.cpp:160
Implementation of the transactor for the WCS driver.
Definition: Transactor.h:48
bool isOpened() const
It returns true if the data source is opened, otherwise it returns false.
Definition: DataSource.cpp:94
static void setCapabilities(const te::da::DataSourceCapabilities &capabilities)
Definition: DataSource.cpp:122
void verifyConnectionInfo() const
Definition: DataSource.cpp:170
void drop(const std::map< std::string, std::string > &dsInfo)
It removes the data source with the connection information from a driver.
Definition: DataSource.cpp:137
bool exists(const std::map< std::string, std::string > &dsInfo)
Check the existence of a data source in a driver.
Definition: DataSource.cpp:142