51#include "D4BaseTypeFactory.h"
52#include "D4Attributes.h"
64const string c_xml_xsi =
"http://www.w3.org/2001/XMLSchema-instance";
65const string c_xml_namespace =
"http://www.w3.org/XML/1998/namespace";
67const string c_default_dap40_schema_location =
"http://xml.opendap.org/dap/dap4.0.xsd";
69const string c_dap40_namespace =
"http://xml.opendap.org/ns/DAP/4.0#";
71const string c_dap_40_n_sl = c_dap40_namespace +
" " + c_default_dap40_schema_location;
78DMR::m_duplicate(
const DMR &dmr)
83 d_factory = dmr.d_factory;
86 d_filename = dmr.d_filename;
88 d_dap_major = dmr.d_dap_major;
89 d_dap_minor = dmr.d_dap_minor;
90 d_dap_version = dmr.d_dap_version;
92 d_dmr_version = dmr.d_dmr_version;
94 d_request_xml_base = dmr.d_request_xml_base;
96 d_namespace = dmr.d_namespace;
98 d_max_response_size_kb = dmr.d_max_response_size_kb;
100 d_ce_empty = dmr.d_ce_empty;
104 d_root =
static_cast<D4Group*
>(dmr.d_root->ptr_duplicate());
105 DBG(cerr <<
"dmr.d_root: " << dmr.d_root << endl);
106 DBG(cerr <<
"d_root (from ptr_dup(): " << d_root << endl);
124 : d_factory(factory), d_name(name), d_filename(
""),
125 d_dap_major(4), d_dap_minor(0),
126 d_dmr_version(
"1.0"), d_request_xml_base(
""),
127 d_namespace(c_dap40_namespace), d_max_response_size_kb(0),
128 d_ce_empty(false),d_root(0)
155 : d_factory(factory), d_name(dds.get_dataset_name()),
156 d_filename(dds.filename()), d_dap_major(4), d_dap_minor(0),
157 d_dmr_version(
"1.0"), d_request_xml_base(
""),
158 d_namespace(c_dap40_namespace), d_max_response_size_kb(0),d_ce_empty(false), d_root(0)
173 : d_factory(0), d_name(
""), d_filename(
""), d_dap_major(4), d_dap_minor(0),
174 d_dap_version(
"4.0"), d_dmr_version(
"1.0"), d_request_xml_base(
""),
175 d_namespace(c_dap40_namespace), d_max_response_size_kb(0), d_ce_empty(false),d_root(0)
196DMR::operator=(
const DMR &rhs)
226 DBG(cerr << __func__ <<
"() - Transforming top level variable: " <<
227 " (" << (*i)->type_name() <<
":'" << (*i)->name() <<
"':"<<(
void *)(*i) <<
228 ") (root:"<< root_grp <<
")"<< endl; );
229 (*i)->transform_to_dap4(root_grp, root_grp);
230 DBG(cerr << __func__ <<
"() - top level variable: '" <<
231 (*i)->name() <<
"' (type:" << (*i)->type_name() <<
") Transformed"<< endl; );
234 DBG(cerr << __func__ <<
"() - Skipping variable: " <<
235 d4_var->type_name() <<
" " << d4_var->name() <<
" because a variable with" <<
236 " this name already exists in the root group." << endl; );
262 DBG( cerr << __func__ <<
"() - BEGIN" << endl);
272 unique_ptr< vector<BaseType *>> top_vars(
root()->transform_to_dap2(&(dds->
get_attr_table())));
273 for (vector<BaseType *>::iterator i = top_vars->begin(), e = top_vars->end(); i != e; i++) {
278 for (vector<BaseType *>::iterator i = top_vars->begin(), e = top_vars->end(); i != e; i++) {
283 DBG( cerr << __func__ <<
"() - END" << endl);
298 if (!d_root) d_root =
static_cast<D4Group*
>(d_factory->
NewVariable(dods_group_c,
"/"));
310 istringstream iss(v);
312 int major = -1, minor = -1;
314 if (!iss.eof() && !iss.fail())
316 if (!iss.eof() && !iss.fail())
318 if (!iss.eof() && !iss.fail())
321 if (major == -1 || minor == -1 or dot !=
'.')
322 throw InternalErr(__FILE__, __LINE__,
"Could not parse dap version. Value given: " + v);
333 switch (d_dap_major) {
335 d_namespace = c_dap40_namespace;
388 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"Dataset") < 0)
389 throw InternalErr(__FILE__, __LINE__,
"Could not write Dataset element");
393 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:xml",
394 (
const xmlChar*) c_xml_namespace.c_str()) < 0)
395 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:xml");
397 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:xsi", (
const xmlChar*) c_xml_xsi.c_str())
399 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:xsi");
401 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xsi:schemaLocation",
402 (
const xmlChar*) c_dap_40_n_sl.c_str()) < 0)
403 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:schemaLocation");
406 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns", (
const xmlChar*)
get_namespace().c_str()) < 0)
407 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns");
410 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xml:base",
412 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xml:base");
415 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"dapVersion", (
const xmlChar*)dap_version().c_str()) < 0)
416 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for dapVersion");
418 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"dmrVersion", (
const xmlChar*)dmr_version().c_str()) < 0)
419 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for dapVersion");
421 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)
name().c_str()) < 0)
422 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
426 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
427 throw InternalErr(__FILE__, __LINE__,
"Could not end the top-level Group element");
441 strm << DapIndent::LMarg <<
"DMR::dump - ("
442 << (
void *)
this <<
")" << endl ;
443 DapIndent::Indent() ;
444 strm << DapIndent::LMarg <<
"factory: " << (
void *)d_factory << endl ;
445 strm << DapIndent::LMarg <<
"name: " << d_name << endl ;
446 strm << DapIndent::LMarg <<
"filename: " << d_filename << endl ;
447 strm << DapIndent::LMarg <<
"protocol major: " << d_dap_major << endl;
448 strm << DapIndent::LMarg <<
"protocol minor: " << d_dap_minor << endl;
450 DapIndent::UnIndent() ;
The basic data type for the DODS DAP types.
virtual D4Attributes * attributes()
BaseType * var(const string &name, bool exact_match=true, btp_stack *s=nullptr) override
btp_stack no longer needed; use back pointers (BaseType::get_parent())
virtual BaseType * NewVariable(Type t, const string &name) const
uint64_t request_size_kb(bool constrained)
Get the estimated size of a response in kilobytes. This method looks at the variables in the DDS and ...
virtual std::vector< BaseType * > * transform_to_dap2(AttrTable *parent_attr_table)
Transform the D4Group's variables to DAP2 variables.
long request_size(bool constrained)
void print_dap4(XMLWriter &xml, bool constrained=false)
void add_var_nocopy(BaseType *bt)
Adds the variable to the DDS.
virtual AttrTable & get_attr_table()
BaseTypeFactory * set_factory(BaseTypeFactory *factory)
string get_dataset_name() const
Vars_iter var_end()
Return an iterator.
void dump(std::ostream &strm) const override
dumps information about this object
virtual DDS * getDDS()
Build a DDS from a DMR.
void set_dap_version(const std::string &version_string)
std::string get_namespace() const
Get the namespace associated with the DMR.
std::string request_xml_base() const
Get the URL that will return this DMR.
virtual void build_using_dds(DDS &dds)
long request_size(bool constrained)
Get the estimated response size, in kilobytes.
uint64_t request_size_kb(bool constrained)
Compute the estimated response size, in kilobytes.
std::string filename() const
void print_dap4(XMLWriter &xml, bool constrained=false)
libdap base object for common functionality of libdap objects
A class for software fault reporting.
top level DAP object to house generic methods