30 #include <BESSyntaxUserError.h>
31 #include <BESInternalError.h>
32 #include <BESNotFoundError.h>
35 #include <TheBESKeys.h>
36 #include <WhiteList.h>
38 #include "CmrContainer.h"
41 #include "RemoteHttpResource.h"
46 #define prolog std::string("CmrContainer::").append(__func__).append("() - ")
60 CmrContainer::CmrContainer(
const string &sym_name,
61 const string &real_name,
const string &type) :
62 BESContainer(sym_name, real_name, type), d_remoteResource(0) {
64 BESDEBUG( MODULE, prolog <<
"BEGIN sym_name: " << sym_name
65 <<
" real_name: " << real_name <<
" type: " << type << endl);
70 BESDEBUG(MODULE, prolog <<
"path: '" << path <<
"' path_elements.size(): " << path_elements.size() << endl);
105 BESDEBUG( MODULE, prolog <<
"END" << endl);
113 BESContainer(copy_from), d_remoteResource(copy_from.d_remoteResource) {
116 if (d_remoteResource) {
117 string err = (string)
"The Container has already been accessed, "
118 +
"can not create a copy of this container.";
124 if (copy_to.d_remoteResource) {
125 string err = (string)
"The Container has already been accessed, "
126 +
"can not duplicate this resource.";
129 copy_to.d_remoteResource = d_remoteResource;
136 _duplicate(*container);
140 CmrContainer::~CmrContainer() {
141 if (d_remoteResource) {
153 BESDEBUG( MODULE, prolog <<
"BEGIN" << endl);
157 BESDEBUG( MODULE, prolog <<
"path: " << path << endl);
159 Granule *granule = CmrUtils::getTemporalFacetGranule(path);
161 throw BESNotFoundError(
"Failed locate a granule associated with the path "+path,__FILE__,__LINE__);
163 string url = granule->getDataAccessUrl();
171 if(!d_remoteResource) {
172 BESDEBUG( MODULE, prolog <<
"Building new RemoteResource." << endl );
176 BESDEBUG( MODULE, prolog <<
"Located remote resource." << endl );
180 BESDEBUG( MODULE, prolog <<
"Using local cache file: " << cachedResource << endl );
182 type = d_remoteResource->
getType();
184 BESDEBUG( MODULE, prolog <<
"Type: " << type << endl );
187 BESDEBUG( MODULE, prolog <<
"Done accessing " <<
get_real_name() <<
" returning cached file " << cachedResource << endl);
188 BESDEBUG( MODULE, prolog <<
"Done accessing " << *
this << endl);
189 BESDEBUG( MODULE, prolog <<
"END" << endl);
191 return cachedResource;
203 BESDEBUG( MODULE, prolog <<
"BEGIN" << endl);
204 if (d_remoteResource) {
205 BESDEBUG( MODULE, prolog <<
"Releasing RemoteResource" << endl);
206 delete d_remoteResource;
207 d_remoteResource = 0;
209 BESDEBUG( MODULE, prolog <<
"END" << endl);
221 strm << BESIndent::LMarg << prolog <<
"(" << (
void *)
this
225 if (d_remoteResource) {
226 strm << BESIndent::LMarg <<
"RemoteResource.getCacheFileName(): " << d_remoteResource->
getCacheFileName()
228 strm << BESIndent::LMarg <<
"response headers: ";
234 vector<string>::const_iterator i = hdrs->begin();
235 vector<string>::const_iterator e = hdrs->end();
236 for (; i != e; i++) {
237 string hdr_line = (*i);
238 strm << BESIndent::LMarg << hdr_line << endl;
240 BESIndent::UnIndent();
242 strm <<
"none" << endl;
245 strm << BESIndent::LMarg <<
"response not yet obtained" << endl;
247 BESIndent::UnIndent();