48 #include "XMLWriter.h" 49 #include "D4BaseTypeFactory.h" 50 #include "D4Attributes.h" 61 const string c_xml_xsi =
"http://www.w3.org/2001/XMLSchema-instance";
62 const string c_xml_namespace =
"http://www.w3.org/XML/1998/namespace";
64 const string c_default_dap40_schema_location =
"http://xml.opendap.org/dap/dap4.0.xsd";
66 const string c_dap40_namespace =
"http://xml.opendap.org/ns/DAP/4.0#";
68 const string c_dap_40_n_sl = c_dap40_namespace +
" " + c_default_dap40_schema_location;
75 DMR::m_duplicate(
const DMR &dmr)
80 d_factory = dmr.d_factory;
83 d_filename = dmr.d_filename;
85 d_dap_major = dmr.d_dap_major;
86 d_dap_minor = dmr.d_dap_minor;
87 d_dap_version = dmr.d_dap_version;
89 d_dmr_version = dmr.d_dmr_version;
91 d_request_xml_base = dmr.d_request_xml_base;
93 d_namespace = dmr.d_namespace;
95 d_max_response_size = dmr.d_max_response_size;
98 d_root = dmr.d_root->ptr_duplicate();
99 DBG(cerr <<
"dmr.d_root: " << dmr.d_root << endl);
100 DBG(cerr <<
"d_root (from ptr_dup(): " << d_root << endl);
118 : d_factory(factory), d_name(name), d_filename(
""),
119 d_dap_major(4), d_dap_minor(0),
120 d_dmr_version(
"1.0"), d_request_xml_base(
""),
121 d_namespace(c_dap40_namespace), d_max_response_size(0), d_root(0)
148 : d_factory(factory), d_name(dds.get_dataset_name()),
149 d_filename(dds.
filename()), d_dap_major(4), d_dap_minor(0),
150 d_dmr_version(
"1.0"), d_request_xml_base(
""),
151 d_namespace(c_dap40_namespace), d_max_response_size(0), d_root(0)
180 : d_factory(0), d_name(
""), d_filename(
""), d_dap_major(4), d_dap_minor(0),
181 d_dap_version(
"4.0"), d_dmr_version(
"1.0"), d_request_xml_base(
""),
182 d_namespace(c_dap40_namespace), d_max_response_size(0), d_root(0)
205 DMR::operator=(
const DMR &rhs)
244 if (!d_root) d_root =
static_cast<D4Group*
>(d_factory->NewVariable(dods_group_c,
"/"));
256 istringstream iss(v);
258 int major = -1, minor = -1;
260 if (!iss.eof() && !iss.fail())
262 if (!iss.eof() && !iss.fail())
264 if (!iss.eof() && !iss.fail())
267 if (major == -1 || minor == -1 or dot !=
'.')
268 throw InternalErr(__FILE__, __LINE__,
"Could not parse dap version. Value given: " + v);
279 switch (d_dap_major) {
281 d_namespace = c_dap40_namespace;
315 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"Dataset") < 0)
316 throw InternalErr(__FILE__, __LINE__,
"Could not write Dataset element");
320 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:xml",
321 (
const xmlChar*) c_xml_namespace.c_str()) < 0)
322 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:xml");
324 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:xsi", (
const xmlChar*) c_xml_xsi.c_str())
326 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:xsi");
328 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xsi:schemaLocation",
329 (
const xmlChar*) c_dap_40_n_sl.c_str()) < 0)
330 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:schemaLocation");
333 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns", (
const xmlChar*)
get_namespace().c_str()) < 0)
334 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns");
337 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xml:base",
339 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xml:base");
342 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"dapVersion", (
const xmlChar*)dap_version().c_str()) < 0)
343 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for dapVersion");
345 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"dmrVersion", (
const xmlChar*)dmr_version().c_str()) < 0)
346 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for dapVersion");
348 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)
name().c_str()) < 0)
349 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
353 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
354 throw InternalErr(__FILE__, __LINE__,
"Could not end the top-level Group element");
368 strm << DapIndent::LMarg <<
"DMR::dump - (" 369 << (
void *)
this <<
")" << endl ;
370 DapIndent::Indent() ;
371 strm << DapIndent::LMarg <<
"factory: " << (
void *)d_factory << endl ;
372 strm << DapIndent::LMarg <<
"name: " << d_name << endl ;
373 strm << DapIndent::LMarg <<
"filename: " << d_filename << endl ;
374 strm << DapIndent::LMarg <<
"protocol major: " << d_dap_major << endl;
375 strm << DapIndent::LMarg <<
"protocol minor: " << d_dap_minor << endl;
377 DapIndent::UnIndent() ;
void print_dap4(XMLWriter &xml, bool constrained=false)
Vars_iter var_begin()
Return an iterator to the first variable.
virtual void add_var_nocopy(BaseType *bt, Part part=nil)
virtual void dump(ostream &strm) const
dumps information about this object
string request_xml_base() const
Get the URL that will return this DMR/DDX/DataThing.
A class for software fault reporting.
long request_size(bool constrained)
virtual D4BaseTypeFactory * factory()
long request_size(bool constrained)
Get the estimated response size, in kilo bytes.
virtual D4Attributes * attributes()
virtual AttrTable & get_attr_table()
virtual void build_using_dds(DDS &dds)
Vars_iter var_end()
Return an iterator.
The basic data type for the DODS DAP types.
libdap base object for common functionality of libdap objects
string get_namespace() const
Get the namespace associated with the DDS - likely set only by DDX responses.
void set_dap_version(const string &version_string)
void print_dap4(XMLWriter &xml, bool constrained=false)
string get_dataset_name() const
void transform_to_dap4(AttrTable &at)
copy attributes from DAP2 to DAP4
virtual BaseType * transform_to_dap4(D4Group *root, Constructor *container)
DAP2 to DAP4 transform.