All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Module.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 Module.cpp
22 
23  \brief The TerraLib Xerces module is a plugin.
24 */
25 
26 // TerraLib
27 #include "../common/Logger.h"
28 #include "../common/Translator.h"
29 
30 #include "Exception.h"
31 #include "Module.h"
32 #include "ReaderFactory.h"
33 #include "WriterFactory.h"
34 
35 // Xerces-C++
36 #include <xercesc/util/PlatformUtils.hpp>
37 #include <xercesc/util/XMLString.hpp>
38 
40 
42  : te::plugin::CppPlugin(pInfo)
43 {
44 }
45 
47 {
48 }
49 
51 {
52  if(m_initialized)
53  return;
54 
55  try
56  {
57  xercesc::XMLPlatformUtils::Initialize();
58  }
59  catch(const xercesc::XMLException& e)
60  {
61  char* exceptMesg = xercesc::XMLString::transcode(e.getMessage());
62 
63  std::string m = TE_TR("Error during Xerces initialization. Exception messages is: ");
64  m += exceptMesg;
65 
66  xercesc::XMLString::release(&exceptMesg);
67 
68  throw te::xerces::Exception(m);
69  }
70 
71  // it initializes the reader factory based on Xerces
74 
75  TE_LOG_TRACE(TE_TR("TerraLib Xerces driver startup!"));
76 
77  m_initialized = true;
78 }
79 
81 {
82  if(!m_initialized)
83  return;
84 
85  // it finalizes the reader factory based on Xerces
88 
89  try
90  {
91  xercesc::XMLPlatformUtils::Terminate();
92  }
93  catch(const xercesc::XMLException& e)
94  {
95  char* exceptMesg = xercesc::XMLString::transcode(e.getMessage());
96 
97  std::string m = TE_TR("Error during Xerces finalization. Exception messages is: ");
98  m += exceptMesg;
99 
100  xercesc::XMLString::release(&exceptMesg);
101 
102  throw te::xerces::Exception(m);
103  }
104 
105  TE_LOG_TRACE(TE_TR("TerraLib Xerces driver shutdown!"));
106 
107  m_initialized = true;
108 }
109 
111 
112 
113 
#define TE_LOG_TRACE(msg)
Use this tag in order to log a message to a specified logger with the TRACE level.
Definition: Logger.h:137
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:347
void startup()
This method will be called by TerraLib to startup some plugin's functionality.
Definition: Module.cpp:50
static void initialize()
It initializes the factory: it will be registered in the abstract factory WriterFactory.
void shutdown()
This method will be called by TerraLib to shutdown plugin's functionality.
Definition: Module.cpp:80
#define PLUGIN_CALL_BACK_IMPL(PLUGIN_CLASS_NAME)
This macro should be used by C++ plugins in order to declare the exportable/callable DLL function...
Definition: Config.h:57
static void initialize()
It initializes the factory: it will be registered in the abstract factory ReaderFactory.
static void finalize()
It finalizes the factory: it will be destroyed and will be unregistered from the abstract factory Rea...
Module(const te::plugin::PluginInfo &pInfo)
Plugin constructor.
Definition: Module.cpp:41
static bool m_initialized
Definition: Module.h:97
An exception class for the xerces module.
The TerraLib Xerces module is a plugin.
Definition: Module.h:42
The basic information about a plugin.
Definition: PluginInfo.h:61
static void finalize()
It finalizes the factory: it will be destroyed and will be unregistered from the abstract factory Wri...
This is the concrete factory for XML writer built on top of Xerces-C++ parser.