bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
NCMLModule.cc
1
2// 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
58using std::endl;
59using std::ostream;
60using std::string;
61using namespace ncml_module;
62
63static const char* const NCML_CATALOG = "catalog";
64
65void 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)) {
81 BESCatalogList::TheCatalogList()->add_catalog(new BESCatalogDirectory(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
110void 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
135extern "C" {
136BESAbstractModule *maker()
137{
138 return new NCMLModule;
139}
140}
141
142void 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
149void 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
156void NCMLModule::addCacheAggCommandAndResponseHandlers(const string& modname)
157{
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
169void 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
176void NCMLModule::removeCacheAggCommandAndResponseHandlers()
177{
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
static void handle_dap_service(const std::string &handler)
static function to register a handler to handle the dap services
static void Register(const std::string &flagName)
register the specified debug flag
Definition BESDebug.h:126
static void del_command(const std::string &cmd_str)
Deletes the command called cmd_str from the list of possible commands.
static void add_command(const std::string &cmd_str, p_xmlcmd_builder cmd)
Add a command to the possible commands allowed by this BES.
void get_value(const std::string &s, std::string &val, bool &found)
Retrieve the value of a given key, if set.
static TheBESKeys * TheKeys()
Access to the singleton.
Definition TheBESKeys.cc:85
virtual void dump(std::ostream &strm) const
dump the contents of this object to the specified ostream
NcML Parser for adding/modifying/removing metadata (attributes) to existing local datasets using NcML...
static const std::string CACHE_AGG_RESPONSE
static const std::string NCML_NAME