50#include "NCMLContainer.h"
51#include "NCMLContainerStorage.h"
53#include <BESSyntaxUserError.h>
54#include <BESInternalError.h>
57#include <libdap/util.h>
74NCMLContainer::NCMLContainer(
const string &sym_name,
const string &xml_doc) :
75 BESContainer(sym_name,
"",
"ncml"), _xml_doc(xml_doc), _accessed(false)
80 BESContainer(copy_from), _xml_doc(copy_from._xml_doc), _accessed(copy_from._accessed)
85 string err = (string)
"The Container has already been accessed, " +
"can not create a copy of this container.";
92 if (copy_to._accessed) {
93 string err = (string)
"The Container has already been accessed, " +
"can not duplicate this resource.";
94 throw BESInternalError(err, __FILE__, __LINE__);
96 copy_to._xml_doc = _xml_doc;
97 copy_to._accessed =
false;
104 NCMLContainer *container =
new NCMLContainer;
105 _duplicate(*container);
109NCMLContainer::~NCMLContainer()
123 BESDEBUG(
"ncml",
"accessing " << _xml_doc << endl);
131 string tempfile_template = NCMLContainerStorage::NCML_TempDir +
"/ncml_module_XXXXXX";
132 char *tempfile_c = mktemp((
char *) tempfile_template.c_str());
136 tempfile = tempfile_c;
139 string err = (string)
"Unable to create temporary ncml document " + _tmp_file_name;
143 _tmp_file_name = NCMLContainerStorage::NCML_TempDir +
"/" + tempfile +
".ncml";
155 string _tmp_file_name = libdap::open_temp_fstream(ostrm,
156 NCMLContainerStorage::NCML_TempDir +
"/ncml_module_XXXXXX",
".ncml");
159 string err = (string)
"Unable to write out the ncml document " + _tmp_file_name;
161 char *str = strerror(errno);
162 if (str) err += (string)
" " + str;
168 ostrm <<
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl;
171 ostrm << _xml_doc << endl;
178 return _tmp_file_name;
189 if (_accessed && !_tmp_file_name.empty()) {
190 unlink(_tmp_file_name.c_str());
206 strm << BESIndent::LMarg <<
"NCMLContainer::dump - (" << (
void *)
this <<
")" << endl;
209 strm << BESIndent::LMarg <<
"temporary file: " << _tmp_file_name << endl;
212 strm << BESIndent::LMarg <<
"temporary file: not open" << endl;
215 BESIndent::UnIndent();
A container is something that holds data. E.G., a netcdf file or a database entry.
void dump(std::ostream &strm) const override
dumps information about this object
void _duplicate(BESContainer ©_to)
duplicate this instance into the passed container
exception thrown if internal error encountered
Container representing a NCML request.
virtual bool release()
release the NCML cached resources
virtual void dump(ostream &strm) const
dumps information about this object
virtual BESContainer * ptr_duplicate()
pure abstract method to duplicate this instances of BESContainer
virtual string access()
access the NCML target response by making the NCML request