bes  Updated for version 3.20.6
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 std::ostream;
60 using std::string;
61 using namespace ncml_module;
62 
63 static const char* const NCML_CATALOG = "catalog";
64 
65 void NCMLModule::initialize(const string &modname)
66 {
67  BESDEBUG(modname, "Initializing NCML Module " << modname << endl);
68 
69  BESRequestHandlerList::TheList()->add_handler(modname, new NCMLRequestHandler(modname));
70 
71  // If new commands are needed, then let's declare this once here. If
72  // not, then you can remove this line.
73 #if 0
74  // Not used. jhrg 4/16/14
75  addCommandAndResponseHandlers(modname);
76 #endif
77  // Dap services
79 
80  if (!BESCatalogList::TheCatalogList()->ref_catalog(NCML_CATALOG)) {
82  }
83 
84  if (!BESContainerStorageList::TheList()->ref_persistence(NCML_CATALOG)) {
85  BESFileContainerStorage *csc = new BESFileContainerStorage(NCML_CATALOG);
86  BESContainerStorageList::TheList()->add_persistence(csc);
87  }
88 
89 #if 0
90  // Not used. jhrg 8/12/15
91  BESContainerStorageList::TheList()->add_persistence(new NCMLContainerStorage(modname));
92 
93  const string key = "NCML.TempDirectory";
94  string val;
95  bool found = false;
96  TheBESKeys::TheKeys()->get_value(key, val, found);
97  if (!found || val.empty() || val == "/") {
98  string err = (string) "The parameter " + key + " must be set to use the NCML module";
99  throw BESInternalError(err, __FILE__, __LINE__);
100  }
101 
102  NCMLContainerStorage::NCML_TempDir = val;
103 #endif
104 
105  BESDebug::Register(modname);
106 
107  BESDEBUG(modname, "Done Initializing NCML Module " << modname << endl);
108 }
109 
110 void NCMLModule::terminate(const string &modname)
111 {
112  BESDEBUG(modname, "Cleaning NCML module " << modname << endl);
113 
114  BESRequestHandler *rh = BESRequestHandlerList::TheList()->remove_handler(modname);
115  if (rh) delete rh;
116 
117  // If new commands were added, remove them here.
118 #if 0
119  // Not used. jhrg 4/16/14
120  removeCommandAndResponseHandlers();
121 #endif
122 
123  BESContainerStorageList::TheList()->deref_persistence(NCML_CATALOG);
124 
125  BESContainerStorageList::TheList()->deref_persistence(modname);
126 
127  BESCatalogList::TheCatalogList()->deref_catalog(NCML_CATALOG);
128 
129  // Cleanup libxml2. jhrg 7/6/15
130  xmlCleanupParser();
131 
132  BESDEBUG(modname, "Done Cleaning NCML module " << modname << endl);
133 }
134 
135 extern "C" {
136 BESAbstractModule *maker()
137 {
138  return new NCMLModule;
139 }
140 }
141 
142 void NCMLModule::dump(ostream &strm) const
143 {
144  strm << BESIndent::LMarg << "NCMLModule::dump - (" << (void *) this << ")" << endl;
145 }
146 
147 #if 0
148 // Not used. jhrg 4/16/14
149 void NCMLModule::addCommandAndResponseHandlers(const string& modname)
150 {
151  BESDEBUG(modname, "Adding module extensions..." << endl);
152  addCacheAggCommandAndResponseHandlers(modname);
153  BESDEBUG(modname, "... done adding module extensions." << endl);
154 }
155 
156 void NCMLModule::addCacheAggCommandAndResponseHandlers(const string& modname)
157 {
158  string cmdName = ModuleConstants::CACHE_AGG_RESPONSE;
159 
160  BESDEBUG( modname, " adding "
161  << cmdName
162  << " response handler" << endl );
163  BESResponseHandlerList::TheList()->add_handler(cmdName, NCMLCacheAggResponseHandler::makeInstance);
164 
165  BESDEBUG(modname, " adding " << cmdName << " command" << endl );
166  BESXMLCommand::add_command(cmdName, NCMLCacheAggXMLCommand::makeInstance);
167 }
168 
169 void NCMLModule::removeCommandAndResponseHandlers()
170 {
171  BESDEBUG(ModuleConstants::NCML_NAME, "Removing module extensions..." << endl);
172  removeCacheAggCommandAndResponseHandlers();
173  BESDEBUG(ModuleConstants::NCML_NAME, "... done removing module extensions." << endl);
174 }
175 
176 void NCMLModule::removeCacheAggCommandAndResponseHandlers()
177 {
178  string cmdName = ModuleConstants::CACHE_AGG_RESPONSE;
179 
180  BESDEBUG( ModuleConstants::NCML_NAME, " removing " << cmdName
181  << " response handler" << endl );
182  BESResponseHandlerList::TheList()->remove_handler(cmdName);
183 
184  BESDEBUG( ModuleConstants::NCML_NAME, " removing " << cmdName << " command" << endl );
186 }
187 #endif
BESRequestHandler
Represents a specific data type request handler.
Definition: BESRequestHandler.h:74
BESRequestHandlerList::remove_handler
virtual BESRequestHandler * remove_handler(const std::string &handler_name)
remove and return the specified request handler
Definition: BESRequestHandlerList.cc:76
BESContainerStorageList::deref_persistence
virtual bool deref_persistence(const std::string &persist_name)
dereference a persistent store in the list.
Definition: BESContainerStorageList.cc:163
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:52
BESAbstractModule
Definition: BESAbstractModule.h:40
BESContainerStorageList::add_persistence
virtual bool add_persistence(BESContainerStorage *p)
Add a persistent store to the list.
Definition: BESContainerStorageList.cc:81
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:86
BESCatalogList::TheCatalogList
static BESCatalogList * TheCatalogList()
Get the singleton BESCatalogList instance.
Definition: BESCatalogList.cc:81
TheBESKeys::TheKeys
static TheBESKeys * TheKeys()
Definition: TheBESKeys.cc:62
ncml_module::NCMLModule
Definition: NCMLModule.h:36
BESFileContainerStorage
implementation of BESContainerStorage that represents a data within a catalog repository
Definition: BESFileContainerStorage.h:77
BESResponseHandlerList::remove_handler
virtual bool remove_handler(const std::string &handler)
removes a response handler from the list
Definition: BESResponseHandlerList.cc:74
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:54
BESDebug::Register
static void Register(const std::string &flagName)
register the specified debug flag
Definition: BESDebug.h:138
BESCatalogList::add_catalog
virtual bool add_catalog(BESCatalog *catalog)
adds the specified catalog to the list
Definition: BESCatalogList.cc:162
BESInternalError
exception thrown if internal 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:272
ncml_module::NCMLModule::dump
virtual void dump(std::ostream &strm) const
dump the contents of this object to the specified ostream
Definition: NCMLModule.cc:142
ncml_module
NcML Parser for adding/modifying/removing metadata (attributes) to existing local datasets using NcML...
Definition: AggregationElement.cc:72
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:96
BESDapService::handle_dap_service
static void handle_dap_service(const std::string &handler)
static function to register a handler to handle the dap services
Definition: BESDapService.cc:40
BESResponseHandlerList::add_handler
virtual bool add_handler(const std::string &handler, p_response_handler handler_method)
add a response handler to the list
Definition: BESResponseHandlerList.cc:55
ncml_module::NCMLRequestHandler
Definition: NCMLRequestHandler.h:40