35#include <libdap/DDS.h>
38#include <RequestServiceTimer.h>
40#include "get_xml_data.h"
53#include "XDStructure.h"
54#include "XDSequence.h"
57const char *DAP_SCHEMA =
"http://xml.opendap.org/ns/dap/3.3#";
61#define MODULE "xml_data"
62#define prolog string("get_xml_data::").append(__func__).append("() - ")
73void get_data_values_as_xml(DDS *dds, XMLWriter *writer)
78 if (xmlTextWriterStartElementNS(writer->get_writer(), NULL, (
const xmlChar*)
"Dataset", (
const xmlChar*)DAP_SCHEMA) < 0)
79 throw InternalErr(__FILE__, __LINE__,
"Error starting the Dataset element for response ");
81 DDS::Vars_iter i = dds->var_begin();
82 while (i != dds->var_end()) {
86 BESDEBUG(
"xd",
"Printing the values for " << (*i)->name() <<
" (" << (*i)->type_name() <<
")" << endl);
87 dynamic_cast<XDOutput &
>(**i).print_xml_data(writer,
true);
92 if (xmlTextWriterEndElement(writer->get_writer()) < 0)
93 throw InternalErr(__FILE__, __LINE__,
"Error ending Dataset element.");
96 catch (InternalErr &e) {
97 xmlErrorPtr error = xmlGetLastError();
98 if (error && error->message)
99 throw InternalErr(e.get_error_message() +
"; libxml: " + error->message);
101 throw InternalErr(e.get_error_message() +
"; libxml: no message");
105DDS *dds_to_xd_dds(DDS * dds)
107 BESDEBUG(
"xd",
"In datadds_to_xd_datadds" << endl);
112 DDS *xd_dds =
new DDS(dds->get_factory(), dds->get_dataset_name());
114 DDS::Vars_iter i = dds->var_begin();
115 while (i != dds->var_end()) {
116 BaseType *abt = basetype_to_xd(*i);
117 xd_dds->add_var(abt);
126 xd_dds->tag_nested_sequences();
132basetype_to_xd(BaseType *bt)
135 throw InternalErr(__FILE__, __LINE__,
"Null BaseType to XD factory");
137 switch (bt->type()) {
160 return new XDStr(
dynamic_cast<Str *
>(bt));
163 return new XDUrl(
dynamic_cast<Url *
>(bt));
166 return new XDArray(
dynamic_cast<Array *
>(bt));
168 case dods_structure_c:
169 return new XDStructure(
dynamic_cast<Structure *
>(bt));
171 case dods_sequence_c:
175 return new XDGrid(
dynamic_cast<Grid *
>(bt));
178 throw InternalErr(__FILE__, __LINE__,
"Unknown type");
static RequestServiceTimer * TheTimer()
Return a pointer to a singleton timer instance. If an instance does not exist it will create and init...
void throw_if_timeout_expired(const std::string &message, const std::string &file, const int line)
Checks the RequestServiceTimer to determine if the time spent servicing the request at this point has...