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);