32#include <libxml/xmlerror.h>
37#include <libdap/DDS.h>
40#include <RequestServiceTimer.h>
42#include "get_xml_data.h"
55#include "XDStructure.h"
56#include "XDSequence.h"
59const char *DAP_SCHEMA =
"http://xml.opendap.org/ns/dap/3.3#";
63#define MODULE "xml_data"
64#define prolog string("get_xml_data::").append(__func__).append("() - ")
75void get_data_values_as_xml(DDS *dds, XMLWriter *writer)
80 if (xmlTextWriterStartElementNS(writer->get_writer(), NULL, (
const xmlChar*)
"Dataset", (
const xmlChar*)DAP_SCHEMA) < 0)
81 throw InternalErr(__FILE__, __LINE__,
"Error starting the Dataset element for response ");
83 DDS::Vars_iter i = dds->var_begin();
84 while (i != dds->var_end()) {
88 BESDEBUG(
"xd",
"Printing the values for " << (*i)->name() <<
" (" << (*i)->type_name() <<
")" << endl);
89 dynamic_cast<XDOutput &
>(**i).print_xml_data(writer,
true);
94 if (xmlTextWriterEndElement(writer->get_writer()) < 0)
95 throw InternalErr(__FILE__, __LINE__,
"Error ending Dataset element.");
98 catch (InternalErr &e) {
99 const xmlError *error = xmlGetLastError();
100 if (error && error->message)
101 throw InternalErr(e.get_error_message() +
"; libxml: " + error->message);
103 throw InternalErr(e.get_error_message() +
"; libxml: no message");
107DDS *dds_to_xd_dds(DDS * dds)
109 BESDEBUG(
"xd",
"In datadds_to_xd_datadds" << endl);
114 DDS *xd_dds =
new DDS(dds->get_factory(), dds->get_dataset_name());
116 DDS::Vars_iter i = dds->var_begin();
117 while (i != dds->var_end()) {
118 BaseType *abt = basetype_to_xd(*i);
119 xd_dds->add_var(abt);
128 xd_dds->tag_nested_sequences();
134basetype_to_xd(BaseType *bt)
137 throw InternalErr(__FILE__, __LINE__,
"Null BaseType to XD factory");
139 switch (bt->type()) {
141 return new XDByte(
dynamic_cast<Byte *
>(bt));
144 return new XDInt16(
dynamic_cast<Int16 *
>(bt));
147 return new XDUInt16(
dynamic_cast<UInt16 *
>(bt));
150 return new XDInt32(
dynamic_cast<Int32 *
>(bt));
153 return new XDUInt32(
dynamic_cast<UInt32 *
>(bt));
156 return new XDFloat32(
dynamic_cast<Float32 *
>(bt));
159 return new XDFloat64(
dynamic_cast<Float64 *
>(bt));
162 return new XDStr(
dynamic_cast<Str *
>(bt));
165 return new XDUrl(
dynamic_cast<Url *
>(bt));
168 return new XDArray(
dynamic_cast<Array *
>(bt));
170 case dods_structure_c:
171 return new XDStructure(
dynamic_cast<Structure *
>(bt));
173 case dods_sequence_c:
174 return new XDSequence(
dynamic_cast<Sequence *
>(bt));
177 return new XDGrid(
dynamic_cast<Grid *
>(bt));
180 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...