36 #include <BESConstraintFuncs.h> 37 #include <BESContainerStorage.h> 38 #include <BESContainerStorageList.h> 39 #include <BESDapNames.h> 40 #include <BESDapResponse.h> 41 #include <BESDataDDSResponse.h> 42 #include <BESDataHandlerInterface.h> 43 #include <BESDDSResponse.h> 44 #include <BESStopWatch.h> 45 #include <BESInternalError.h> 46 #include <BESResponseHandler.h> 47 #include <BESResponseNames.h> 48 #include <BESRequestHandlerList.h> 49 #include <BESServiceRegistry.h> 50 #include <BESTextInfo.h> 52 #include <BESVersionInfo.h> 57 #include "DDSLoader.h" 58 #include "NCMLDebug.h" 68 long DDSLoader::_gensymID = 0L;
73 _dhi(dhi), _hijacked(false), _filename(
""), _store(0), _containerSymbol(
""), _origAction(
""), _origActionName(
74 ""), _origContainer(0), _origResponse(0)
80 _dhi(proto._dhi), _hijacked(false), _filename(
""), _store(0), _containerSymbol(
""), _origAction(
81 ""), _origActionName(
""), _origContainer(0), _origResponse(0)
86 DDSLoader::operator=(
const DDSLoader& rhs)
88 BESDEBUG(
"ncml",
"DDSLoader::operator=: " << endl);
112 removeContainerFromStorage();
128 if (&_dhi != &rhs._dhi) _dhi.
make_copy(rhs._dhi);
140 auto_ptr<BESDapResponse> DDSLoader::load(
const string& location, ResponseType type)
145 loadInto(location, type, response.get());
152 VALID_PTR(pResponse);
153 VALID_PTR(_dhi.response_handler);
159 _filename = location;
180 THROW_NCML_INTERNAL_ERROR(
"DDSLoader::load expected BESDDSResponse or BESDataDDSResponse but got neither!");
186 BESDEBUG(
"ncml",
"Before BESRequestHandlerList::TheList()->execute_current" << endl);
187 BESDEBUG(
"ncml",
"Handler name: " << BESRequestHandlerList::TheList()->get_handler_names() << endl);
191 BESDEBUG(
"ncml",
"After BESRequestHandlerList::TheList()->execute_current" << endl);
194 *(BESLog::TheLog()) <<
"WARNING - " <<
string(__PRETTY_FUNCTION__) <<
": " << e.
get_file() <<
":" << e.
get_line() <<
": " 195 << e.
get_message() <<
" (the exception was re-thrown)."<< endl;
203 removeContainerFromStorage();
216 bool is_url(std::string location){
217 std::string http(
"http://");
218 std::string https(
"https://");
221 std::string tip = location.substr(0,http.size());
222 std::transform(tip.begin(), tip.end(), tip.begin(), ::tolower);
223 bool result = http.compare(tip)==0;
226 tip = location.substr(0,https.size());
227 std::transform(tip.begin(), tip.end(), tip.begin(), ::tolower);
229 result = result || http.compare(tip)==0;
237 DDSLoader::addNewContainerToStorage()
241 VALID_PTR(store_list);
245 if(is_url(_filename)){
246 BESDEBUG(
"ncml", __func__ <<
"() - GATEWAY CONTAINER!" << endl);
253 throw BESInternalError(
"couldn't find the catalog storage", __FILE__, __LINE__);
259 string newSymbol = getNextContainerName() +
"__" + _filename;
268 _containerSymbol = newSymbol;
273 throw BESInternalError(
"couldn't find the container we just added:" + newSymbol, __FILE__, __LINE__);
279 void DDSLoader::removeContainerFromStorage()
290 *(BESLog::TheLog()) <<
"WARNING: tried to remove symbol " << _containerSymbol
291 <<
" from singleton but unexpectedly it was not there." << endl;
293 _containerSymbol =
"";
298 void DDSLoader::snapshotDHI()
300 VALID_PTR(_dhi.response_handler);
302 BESDEBUG(
"ncml",
"DDSLoader::snapshotDHI() - Taking snapshot of DataHAndlerInterface for (action: " << _dhi.
action <<
" action_name: " << _dhi.action_name <<
")" << endl );
303 BESDEBUG(
"ncml_verbose",
"original dhi = " << _dhi << endl );
307 _origAction = _dhi.
action;
308 _origActionName = _dhi.action_name;
312 BESDEBUG(
"ncml",
"DDSLoader::snapshotDHI() - Replaced with DataHAndlerInterface for (action: " << _dhi.
action <<
" action_name: " << _dhi.action_name <<
")" << endl );
317 void DDSLoader::restoreDHI()
319 VALID_PTR(_dhi.response_handler);
339 _dhi.
action = _origAction;
340 _dhi.action_name = _origActionName;
344 BESDEBUG(
"ncml",
"DDSLoader::restoreDHI() - Restored of DataHAndlerInterface for (action: " << _dhi.
action <<
" action_name: " << _dhi.action_name <<
")" << endl );
346 BESDEBUG(
"ncml_verbose",
"restored dhi = " << _dhi << endl );
350 _origActionName =
"";
358 void DDSLoader::ensureClean()
367 removeContainerFromStorage();
371 std::string DDSLoader::getNextContainerName()
373 static const string _sPrefix =
"__DDSLoader_Container_ID_";
375 std::ostringstream oss;
376 oss << _sPrefix << (_gensymID);
382 if (type == eRT_RequestDDX) {
384 return auto_ptr<BESDapResponse>(
new BESDDSResponse(
new DDS(0 ,
"virtual")));
386 else if (type == eRT_RequestDataDDS) {
391 THROW_NCML_INTERNAL_ERROR(
"DDSLoader::makeResponseForType() got unknown type!");
397 if (type == eRT_RequestDDX) {
400 else if (type == eRT_RequestDataDDS) {
401 return DATA_RESPONSE;
404 THROW_NCML_INTERNAL_ERROR(
"DDSLoader::getActionForType(): unknown type!");
409 if (type == eRT_RequestDDX) {
410 return DDX_RESPONSE_STR;
412 else if (type == eRT_RequestDataDDS) {
413 return DATA_RESPONSE_STR;
416 THROW_NCML_INTERNAL_ERROR(
"DDSLoader::getActionNameForType(): unknown type!");
421 if (type == eRT_RequestDDX) {
422 return dynamic_cast<BESDDSResponse*>(pResponse);
424 else if (type == eRT_RequestDataDDS) {
425 return dynamic_cast<BESDataDDSResponse*>(pResponse);
static std::auto_ptr< BESDapResponse > makeResponseForType(ResponseType type)
provides persistent storage for data storage information represented by a container.
exception thrown if inernal error encountered
static std::string getActionNameForType(ResponseType type)
Holds a DDS object within the BES.
static bool checkResponseIsValidType(ResponseType type, BESDapResponse *pResponse)
virtual std::string get_message()
get the error message for this exception
Helper class for temporarily hijacking an existing dhi to load a DDX response for one particular file...
static std::string getActionForType(ResponseType type)
static libdap::DDS * getDDSFromEitherResponse(BESDapResponse *response)
virtual BESContainerStorage * find_persistence(const std::string &persist_name)
find the persistence store with the given name
virtual BESResponseObject * set_response_object(BESResponseObject *o)
replaces the current response object with the specified one, returning the current response object
virtual BESContainer * look_for(const std::string &sym_name)=0
looks for a container in this persistent store
void make_copy(const BESDataHandlerInterface ©_from)
deprecated
virtual BESResponseObject * get_response_object()
return the current response object
Abstract exception class for the BES with basic string message.
virtual bool del_container(const std::string &s_name)=0
removes a container with the given symbolic name
void loadInto(const std::string &location, ResponseType type, BESDapResponse *pResponse)
Load a DDX or DataDDS response into the given pResponse object, which must be non-null.
Provides a mechanism for accessing container information from different container stores registered w...
Represents an OPeNDAP DataDDS DAP2 data object within the BES.
virtual ~DDSLoader()
Dtor restores the state of dhi Restores the state of the dhi to what it was when object if it is stil...
Represents an OPeNDAP DAP response object within the BES.
Structure storing information used by the BES to handle the request.
virtual std::string get_file()
get the file name where the exception was thrown
string get_request_xml_base() const
Return the xml:base URL for this request.
virtual void execute_current(BESDataHandlerInterface &dhi)
Execute a single method for the current container that will fill in the response object rather than i...
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.
DDSLoader(BESDataHandlerInterface &dhi)
Create a loader that will hijack dhi on a load call, then restore it's state.
string action
the response object requested, e.g. das, dds
BESContainer * container
pointer to current container in this interface
virtual int get_line()
get the line number where the exception was thrown
void cleanup()
restore dhi to clean state