36 #include <mime_util.h>
37 #include <D4BaseTypeFactory.h>
39 #include "NCMLRequestHandler.h"
41 #include <BESConstraintFuncs.h>
42 #include <BESContainerStorage.h>
43 #include <BESContainerStorageList.h>
44 #include <BESDapNames.h>
45 #include "BESDataDDSResponse.h"
46 #include <BESDataNames.h>
47 #include <BESDASResponse.h>
48 #include <BESDDSResponse.h>
49 #include <BESDMRResponse.h>
52 #include "BESStopWatch.h"
53 #include <BESInternalError.h>
54 #include <BESDapError.h>
56 #include <BESRequestHandlerList.h>
57 #include <BESResponseHandler.h>
58 #include <BESResponseNames.h>
59 #include <BESServiceRegistry.h>
60 #include <BESTextInfo.h>
62 #include <BESVersionInfo.h>
63 #include <TheBESKeys.h>
65 #include "DDSLoader.h"
67 #include "NCMLDebug.h"
69 #include "NCMLParser.h"
70 #include "NCMLResponseNames.h"
71 #include "SimpleLocationParser.h"
77 bool NCMLRequestHandler::_global_attributes_container_name_set =
false;
78 string NCMLRequestHandler::_global_attributes_container_name =
"";
80 NCMLRequestHandler::NCMLRequestHandler(
const string &name) :
83 add_method(DAS_RESPONSE, NCMLRequestHandler::ncml_build_das);
84 add_method(DDS_RESPONSE, NCMLRequestHandler::ncml_build_dds);
85 add_method(DATA_RESPONSE, NCMLRequestHandler::ncml_build_data);
87 add_method(DMR_RESPONSE, NCMLRequestHandler::ncml_build_dmr);
88 add_method(DAP4DATA_RESPONSE, NCMLRequestHandler::ncml_build_dmr);
90 add_method(VERS_RESPONSE, NCMLRequestHandler::ncml_build_vers);
91 add_method(HELP_RESPONSE, NCMLRequestHandler::ncml_build_help);
93 if (NCMLRequestHandler::_global_attributes_container_name_set ==
false) {
94 bool key_found =
false;
99 NCMLRequestHandler::_global_attributes_container_name_set =
true;
101 NCMLRequestHandler::_global_attributes_container_name = value;
106 NCMLRequestHandler::~NCMLRequestHandler()
131 throw BESInternalError(
"couldn't find the catalog storage", __FILE__, __LINE__);
136 string new_sym = sym_name +
"_location1";
141 throw BESInternalError(
"couldn't find the container" + sym_name, __FILE__, __LINE__);
172 auto_ptr<BESDapResponse> loaded_bdds = parser.parse(filename, DDSLoader::eRT_RequestDDX);
182 DAS *das = bdas->get_das();
184 if (dds->get_dap_major() < 4)
185 NCMLUtil::hackGlobalAttributesForDAP2(dds->get_attr_table(),
186 NCMLRequestHandler::get_global_attributes_container_name());
205 auto_ptr<BESDapResponse> loaded_bdds(0);
209 loaded_bdds = parser.parse(filename, DDSLoader::eRT_RequestDDX);
211 if (!loaded_bdds.get()) {
212 throw BESInternalError(
"Null BESDDSResonse in ncml DDS handler.", __FILE__, __LINE__);
221 DDS *dds = bdds_out->
get_dds();
224 if (dds->get_dap_major() < 4)
225 NCMLUtil::hackGlobalAttributesForDAP2(dds->get_attr_table(),
226 NCMLRequestHandler::get_global_attributes_container_name());
240 dds->filename(name_path(filename));
241 dds->set_dataset_name(name_path(filename));
253 NCML_ASSERT_MSG(ddsResponse,
254 "NCMLRequestHandler::ncml_build_data(): expected BESDDSResponse* but didn't get it!!");
260 parser.parseInto(filename, DDSLoader::eRT_RequestDDX, ddsResponse);
263 DDS *dds = ddsResponse->
get_dds();
266 if (dds->get_dap_major() < 4)
267 NCMLUtil::hackGlobalAttributesForDAP2(dds->get_attr_table(),
268 NCMLRequestHandler::get_global_attributes_container_name());
275 dds->filename(name_path(filename));
276 dds->set_dataset_name(name_path(filename));
290 NCML_ASSERT_MSG(dataResponse,
291 "NCMLRequestHandler::ncml_build_data(): expected BESDataDDSResponse* but didn't get it!!");
297 parser.parseInto(filename, DDSLoader::eRT_RequestDataDDS, dataResponse);
312 dds->filename(name_path(filename));
313 dds->set_dataset_name(name_path(filename));
329 auto_ptr<BESDapResponse> loaded_bdds(0);
333 loaded_bdds = parser.parse(data_path, DDSLoader::eRT_RequestDDX);
334 if (!loaded_bdds.get())
throw BESInternalError(
"Null BESDDSResonse in ncml DDS handler.", __FILE__, __LINE__);
337 dds->filename(data_path);
338 dds->set_dataset_name(data_path);
340 catch (InternalErr &e) {
341 throw BESDapError(e.get_error_message(),
true, e.get_error_code(), __FILE__, __LINE__);
344 throw BESDapError(e.get_error_message(),
false, e.get_error_code(), __FILE__, __LINE__);
350 throw BESDapError(
"Caught unknown error build ** DMR response",
true, unknown_error, __FILE__, __LINE__);
361 DMR *dmr = bdmr.get_dmr();
362 dmr->set_factory(
new D4BaseTypeFactory);
363 dmr->build_using_dds(*dds);
379 if (!info)
throw InternalErr(__FILE__, __LINE__,
"Expected a BESVersionInfo instance");
381 info->add_module(MODULE_NAME, MODULE_VERSION);
388 if (!info)
throw InternalErr(__FILE__, __LINE__,
"Expected a BESVersionInfo instance");
392 map<string, string> attrs;
393 attrs[
"name"] = MODULE_NAME;
394 attrs[
"version"] = MODULE_VERSION;
396 list<string> services;
398 if (services.size() > 0) {
400 attrs[
"handles"] = handles;
402 info->begin_tag(
"module", &attrs);
405 info->end_tag(
"module");
412 strm << BESIndent::LMarg <<
"NCMLRequestHandler::dump - (" << (
void *)
this <<
")" << endl;
415 BESIndent::UnIndent();
Provides a mechanism for accessing container information from different container stores registered w...
virtual BESContainerStorage * find_persistence(const std::string &persist_name)
find the persistence store with the given name
provides persistent storage for data storage information represented by a container.
virtual bool del_container(const std::string &s_name)=0
removes a container with the given symbolic name
virtual BESContainer * look_for(const std::string &sym_name)=0
looks for a container in this persistent store
virtual void add_container(const std::string &sym_name, const std::string &real_name, const std::string &type)=0
adds a container with the provided information
A container is something that holds data. E.G., a netcdf file or a database entry.
std::string get_symbolic_name() const
retrieve the symbolic name for this container
virtual std::string access()=0
returns the true name of this container
Represents an OPeNDAP DAS DAP2 data object within the BES.
Holds a DDS object within the BES.
Represents an OPeNDAP DMR DAP4 data object within the BES.
error object created from libdap error objects and can handle those errors
virtual void set_dap4_function(BESDataHandlerInterface &dhi)
set the constraint depending on the context
virtual void set_dap4_constraint(BESDataHandlerInterface &dhi)
set the constraint depending on the context
virtual void set_constraint(BESDataHandlerInterface &dhi)
set the constraint depending on the context
Represents an OPeNDAP DataDDS DAP2 data object within the BES.
Structure storing information used by the BES to handle the request.
std::map< std::string, std::string > data
the map of string data that will be required for the current request.
BESContainer * container
pointer to current container in this interface
static bool IsSet(const std::string &flagName)
see if the debug context flagName is set to true
Abstract exception class for the BES with basic string message.
informational response object
virtual void add_data(const std::string &s)
add data to this informational object. If buffering is not set then the information is output directl...
exception thrown if internal error encountered
virtual void execute_current(BESDataHandlerInterface &dhi)
Execute a single method for the current container that will fill in the response object rather than i...
Represents a specific data type request handler.
virtual void dump(std::ostream &strm) const
dumps information about this object
virtual BESResponseObject * get_response_object()
return the current response object
Abstract base class representing a specific set of information in response to a request to the BES.
virtual void services_handled(const std::string &handler, std::list< std::string > &services)
returns the list of servies provided by the handler in question
virtual bool start(std::string name)
static std::string implode(const std::list< std::string > &values, char delim)
void get_value(const std::string &s, std::string &val, bool &found)
Retrieve the value of a given key, if set.
static TheBESKeys * TheKeys()
virtual void dump(std::ostream &strm) const
dumps information about this object
static libdap::DDS * getDDSFromEitherResponse(BESDapResponse *response)
static void populateDASFromDDS(libdap::DAS *das, const libdap::DDS &dds_const)
static void copyVariablesAndAttributesInto(libdap::DDS *dds_out, const libdap::DDS &dds_in)
Helper class for temporarily hijacking an existing dhi to load a DDX response for one particular file...
NcML Parser for adding/modifying/removing metadata (attributes) to existing local datasets using NcML...
static const std::string DOC_WIKI_URL
static const std::string NCML_NAME