bes  Updated for version 3.20.5
NCMLModule.cc
1 // This file is part of the "NcML Module" project, a BES module designed
3 // to allow NcML files to be used to be used as a wrapper to add
4 // AIS to existing datasets of any format.
5 //
6 // Copyright (c) 2009 OPeNDAP, Inc.
7 // Author: Michael Johnson <m.johnson@opendap.org>
8 //
9 // For more information, please also see the main website: http://opendap.org/
10 //
11 // This library is free software; you can redistribute it and/or
12 // modify it under the terms of the GNU Lesser General Public
13 // License as published by the Free Software Foundation; either
14 // version 2.1 of the License, or (at your option) any later version.
15 //
16 // This library is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 // Lesser General Public License for more details.
20 //
21 // You should have received a copy of the GNU Lesser General Public
22 // License along with this library; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 //
25 // Please see the files COPYING and COPYRIGHT for more information on the GLPL.
26 //
27 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
29 
30 #include "config.h"
31 
32 #include <iostream>
33 
34 #include <BESCatalogDirectory.h>
35 #include <BESCatalogList.h>
36 #include <BESContainerStorageList.h>
37 #include <BESFileContainerStorage.h>
38 #include <BESDapService.h>
39 #include <BESDebug.h>
40 #include <BESRequestHandlerList.h>
41 #include <BESResponseHandlerList.h>
42 #include <BESResponseNames.h>
43 #include <BESXMLCommand.h>
44 #include <BESContainerStorageList.h>
45 #include <TheBESKeys.h>
46 #include <BESInternalError.h>
47 
48 #include "NCMLModule.h"
49 #include "NCMLRequestHandler.h"
50 #include "NCMLResponseNames.h"
51 
52 #if 0
53 // Not used. jhrg 8/12/15
54 #include "NCMLCacheAggXMLCommand.h"
55 #include "NCMLContainerStorage.h"
56 #endif
57 
58 using std::endl;
59 using namespace ncml_module;
60 
61 static const char* const NCML_CATALOG = "catalog";
62 
63 void NCMLModule::initialize(const string &modname)
64 {
65  BESDEBUG(modname, "Initializing NCML Module " << modname << endl);
66 
67  BESRequestHandlerList::TheList()->add_handler(modname, new NCMLRequestHandler(modname));
68 
69  // If new commands are needed, then let's declare this once here. If
70  // not, then you can remove this line.
71 #if 0
72  // Not used. jhrg 4/16/14
73  addCommandAndResponseHandlers(modname);
74 #endif
75  // Dap services
77 
78  if (!BESCatalogList::TheCatalogList()->ref_catalog(NCML_CATALOG)) {
80  }
81 
82  if (!BESContainerStorageList::TheList()->ref_persistence(NCML_CATALOG)) {
83  BESFileContainerStorage *csc = new BESFileContainerStorage(NCML_CATALOG);
84  BESContainerStorageList::TheList()->add_persistence(csc);
85  }
86 
87 #if 0
88  // Not used. jhrg 8/12/15
89  BESContainerStorageList::TheList()->add_persistence(new NCMLContainerStorage(modname));
90 
91  const string key = "NCML.TempDirectory";
92  string val;
93  bool found = false;
94  TheBESKeys::TheKeys()->get_value(key, val, found);
95  if (!found || val.empty() || val == "/") {
96  string err = (string) "The parameter " + key + " must be set to use the NCML module";
97  throw BESInternalError(err, __FILE__, __LINE__);
98  }
99 
100  NCMLContainerStorage::NCML_TempDir = val;
101 #endif
102 
103  BESDebug::Register(modname);
104 
105  BESDEBUG(modname, "Done Initializing NCML Module " << modname << endl);
106 }
107 
108 void NCMLModule::terminate(const string &modname)
109 {
110  BESDEBUG(modname, "Cleaning NCML module " << modname << endl);
111 
112  BESRequestHandler *rh = BESRequestHandlerList::TheList()->remove_handler(modname);
113  if (rh) delete rh;
114 
115  // If new commands were added, remove them here.
116 #if 0
117  // Not used. jhrg 4/16/14
118  removeCommandAndResponseHandlers();
119 #endif
120 
121  BESContainerStorageList::TheList()->deref_persistence(NCML_CATALOG);
122 
123  BESContainerStorageList::TheList()->deref_persistence(modname);
124 
125  BESCatalogList::TheCatalogList()->deref_catalog(NCML_CATALOG);
126 
127  // Cleanup libxml2. jhrg 7/6/15
128  xmlCleanupParser();
129 
130  BESDEBUG(modname, "Done Cleaning NCML module " << modname << endl);
131 }
132 
133 extern "C" {
134 BESAbstractModule *maker()
135 {
136  return new NCMLModule;
137 }
138 }
139 
140 void NCMLModule::dump(ostream &strm) const
141 {
142  strm << BESIndent::LMarg << "NCMLModule::dump - (" << (void *) this << ")" << endl;
143 }
144 
145 #if 0
146 // Not used. jhrg 4/16/14
147 void NCMLModule::addCommandAndResponseHandlers(const string& modname)
148 {
149  BESDEBUG(modname, "Adding module extensions..." << endl);
150  addCacheAggCommandAndResponseHandlers(modname);
151  BESDEBUG(modname, "... done adding module extensions." << endl);
152 }
153 
154 void NCMLModule::addCacheAggCommandAndResponseHandlers(const string& modname)
155 {
156  string cmdName = ModuleConstants::CACHE_AGG_RESPONSE;
157 
158  BESDEBUG( modname, " adding "
159  << cmdName
160  << " response handler" << endl );
161  BESResponseHandlerList::TheList()->add_handler(cmdName, NCMLCacheAggResponseHandler::makeInstance);
162 
163  BESDEBUG(modname, " adding " << cmdName << " command" << endl );
164  BESXMLCommand::add_command(cmdName, NCMLCacheAggXMLCommand::makeInstance);
165 }
166 
167 void NCMLModule::removeCommandAndResponseHandlers()
168 {
169  BESDEBUG(ModuleConstants::NCML_NAME, "Removing module extensions..." << endl);
170  removeCacheAggCommandAndResponseHandlers();
171  BESDEBUG(ModuleConstants::NCML_NAME, "... done removing module extensions." << endl);
172 }
173 
174 void NCMLModule::removeCacheAggCommandAndResponseHandlers()
175 {
176  string cmdName = ModuleConstants::CACHE_AGG_RESPONSE;
177 
178  BESDEBUG( ModuleConstants::NCML_NAME, " removing " << cmdName
179  << " response handler" << endl );
180  BESResponseHandlerList::TheList()->remove_handler(cmdName);
181 
182  BESDEBUG( ModuleConstants::NCML_NAME, " removing " << cmdName << " command" << endl );
184 }
185 #endif
BESRequestHandler
Represents a specific data type request handler.
Definition: BESRequestHandler.h:77
BESRequestHandlerList::remove_handler
virtual BESRequestHandler * remove_handler(const std::string &handler_name)
remove and return the specified request handler
Definition: BESRequestHandlerList.cc:72
BESContainerStorageList::deref_persistence
virtual bool deref_persistence(const std::string &persist_name)
dereference a persistent store in the list.
Definition: BESContainerStorageList.cc:161
ncml_module::ModuleConstants::CACHE_AGG_RESPONSE
static const std::string CACHE_AGG_RESPONSE
Definition: NCMLResponseNames.h:44
BESCatalogDirectory
Catalogs from a directory structure.
Definition: BESCatalogDirectory.h:57
BESAbstractModule
Definition: BESAbstractModule.h:42
ncml_module::NCMLModule::dump
virtual void dump(ostream &strm) const
dump the contents of this object to the specified ostream
Definition: NCMLModule.cc:140
BESContainerStorageList::add_persistence
virtual bool add_persistence(BESContainerStorage *p)
Add a persistent store to the list.
Definition: BESContainerStorageList.cc:79
ncml_module::ModuleConstants::NCML_NAME
static const std::string NCML_NAME
Definition: NCMLResponseNames.h:38
BESXMLCommand::add_command
static void add_command(const std::string &cmd_str, p_xmlcmd_builder cmd)
Add a command to the possible commands allowed by this BES.
Definition: BESXMLCommand.cc:81
BESCatalogList::TheCatalogList
static BESCatalogList * TheCatalogList()
Get the singleton BESCatalogList instance.
Definition: BESCatalogList.cc:81
TheBESKeys::TheKeys
static TheBESKeys * TheKeys()
Definition: TheBESKeys.cc:61
ncml_module::NCMLModule
Definition: NCMLModule.h:36
BESFileContainerStorage
implementation of BESContainerStorage that represents a data within a catalog repository
Definition: BESFileContainerStorage.h:82
BESRequestHandlerList::add_handler
virtual bool add_handler(const std::string &handler_name, BESRequestHandler *handler)
add a request handler to the list of registered handlers for this server
Definition: BESRequestHandlerList.cc:50
BESDebug::Register
static void Register(const std::string &flagName)
register the specified debug flag
Definition: BESDebug.h:138
BESResponseHandlerList::remove_handler
virtual bool remove_handler(const string &handler)
removes a response handler from the list
Definition: BESResponseHandlerList.cc:70
BESCatalogList::add_catalog
virtual bool add_catalog(BESCatalog *catalog)
adds the specified catalog to the list
Definition: BESCatalogList.cc:162
BESInternalError
exception thrown if inernal error encountered
Definition: BESInternalError.h:43
TheBESKeys::get_value
void get_value(const std::string &s, std::string &val, bool &found)
Retrieve the value of a given key, if set.
Definition: TheBESKeys.cc:420
ncml_module
NcML Parser for adding/modifying/removing metadata (attributes) to existing local datasets using NcML...
Definition: AggregationElement.cc:72
BESDapService::handle_dap_service
static void handle_dap_service(const string &handler)
static function to register a handler to handle the dap services
Definition: BESDapService.cc:38
BESXMLCommand::del_command
static void del_command(const std::string &cmd_str)
Deletes the command called cmd_str from the list of possible commands.
Definition: BESXMLCommand.cc:91
BESResponseHandlerList::add_handler
virtual bool add_handler(const string &handler, p_response_handler handler_method)
add a response handler to the list
Definition: BESResponseHandlerList.cc:51
ncml_module::NCMLRequestHandler
Definition: NCMLRequestHandler.h:40