49 #include "XMLWriter.h"
50 #include "D4BaseTypeFactory.h"
51 #include "D4Attributes.h"
56 #include "DapIndent.h"
63 const string c_xml_xsi =
"http://www.w3.org/2001/XMLSchema-instance";
64 const string c_xml_namespace =
"http://www.w3.org/XML/1998/namespace";
66 const string c_default_dap40_schema_location =
"http://xml.opendap.org/dap/dap4.0.xsd";
68 const string c_dap40_namespace =
"http://xml.opendap.org/ns/DAP/4.0#";
70 const string c_dap_40_n_sl = c_dap40_namespace +
" " + c_default_dap40_schema_location;
77 DMR::m_duplicate(
const DMR &dmr)
82 d_factory = dmr.d_factory;
85 d_filename = dmr.d_filename;
87 d_dap_major = dmr.d_dap_major;
88 d_dap_minor = dmr.d_dap_minor;
89 d_dap_version = dmr.d_dap_version;
91 d_dmr_version = dmr.d_dmr_version;
93 d_request_xml_base = dmr.d_request_xml_base;
95 d_namespace = dmr.d_namespace;
97 d_max_response_size_kb = dmr.d_max_response_size_kb;
99 d_ce_empty = dmr.d_ce_empty;
103 d_root =
static_cast<D4Group*
>(dmr.d_root->ptr_duplicate());
104 DBG(cerr <<
"dmr.d_root: " << dmr.d_root << endl);
105 DBG(cerr <<
"d_root (from ptr_dup(): " << d_root << endl);
123 : d_factory(factory), d_name(name), d_filename(
""),
124 d_dap_major(4), d_dap_minor(0),
125 d_dmr_version(
"1.0"), d_request_xml_base(
""),
126 d_namespace(c_dap40_namespace), d_max_response_size_kb(0),
127 d_ce_empty(false),d_root(0)
154 : d_factory(factory), d_name(dds.get_dataset_name()),
155 d_filename(dds.filename()), d_dap_major(4), d_dap_minor(0),
156 d_dmr_version(
"1.0"), d_request_xml_base(
""),
157 d_namespace(c_dap40_namespace), d_max_response_size_kb(0),d_ce_empty(false), d_root(0)
186 : d_factory(0), d_name(
""), d_filename(
""), d_dap_major(4), d_dap_minor(0),
187 d_dap_version(
"4.0"), d_dmr_version(
"1.0"), d_request_xml_base(
""),
188 d_namespace(c_dap40_namespace), d_max_response_size_kb(0), d_ce_empty(false),d_root(0)
211 DMR::operator=(
const DMR &rhs)
243 DBG(cerr << __func__ <<
"() - Transforming top level variable: " <<
244 " (" << (*i)->type_name() <<
":'" << (*i)->name() <<
"':"<<(
void *)(*i) <<
245 ") (root:"<< root_grp <<
")"<< endl; );
246 (*i)->transform_to_dap4(root_grp, root_grp);
247 DBG(cerr << __func__ <<
"() - top level variable: '" <<
248 (*i)->name() <<
"' (type:" << (*i)->type_name() <<
") Transformed"<< endl; );
251 DBG(cerr << __func__ <<
"() - Skipping variable: " <<
252 d4_var->
type_name() <<
" " << d4_var->
name() <<
" because a variable with" <<
253 " this name already exists in the root group." << endl; );
275 DBG( cerr << __func__ <<
"() - BEGIN" << endl);
288 vector<BaseType *>::iterator vIter = top_vars->begin();
289 vector<BaseType *>::iterator vEnd = top_vars->end();
290 for (; vIter != vEnd; vIter++) {
296 set<string> shared_dim_candidates;
298 vector<BaseType *> dropped_vars;
301 DBG( cerr << __func__ <<
"() - Processing top level variable '"<< (*i)->type_name() <<
" " << (*i)->name() <<
"' to DDS." << endl; );
302 vector<BaseType *> *new_vars = (*i)->transform_to_dap2(&(dds->
get_attr_table()));
304 vector<BaseType*>::iterator vIter = new_vars->begin();
305 vector<BaseType*>::iterator end = new_vars->end();
306 for(; vIter!=end; vIter++ ) {
307 BaseType *new_var = (*vIter);
308 DBG( cerr << __func__ <<
"() - Adding variable name: '"<< new_var->name() <<
"' " <<
309 "type: " << new_var->type() <<
" " <<
310 "type_name: " << new_var->type_name() <<
" to DDS." << endl; );
312 Grid *grid =
dynamic_cast <Grid *
>(new_var);
314 Grid::Map_iter m = grid->map_begin();
315 for(; m != grid->map_end(); m++) {
316 shared_dim_candidates.insert((*m)->name());
324 DBG( cerr << __func__ <<
"Adding variable '"<< (*i)->type_name() <<
" " << (*i)->name() <<
"' to drop list." << endl; );
325 dropped_vars.push_back((*i));
328 AttrTable *dv_table = Constructor::make_dropped_vars_attr_table(&dropped_vars);
330 DBG( cerr << __func__ <<
"() - Adding dropped variable AttrTable." << endl);
337 for(; gIter!=gEnd; gIter++) {
338 D4Group *grp = *gIter;
339 DBG( cerr << __func__ <<
"() - Processing D4Group " << grp->name() << endl);
340 vector<BaseType *> *d2_vars = grp->transform_to_dap2(dds_at);
342 DBG( cerr << __func__ <<
"() - Processing " << grp->name() <<
" Member Variables." << endl);
343 vector<BaseType *>::iterator vIter = d2_vars->begin();
344 vector<BaseType *>::iterator vEnd = d2_vars->end();
345 for(; vIter!=vEnd; vIter++) {
346 DBG( cerr << __func__ <<
"() - Processing " << grp->name() <<
" Member Variable: " << (*vIter)->name() << endl);
353 DBG( cerr << __func__ <<
"() - END" << endl);
379 DBG( cerr << __func__ <<
"() - BEGIN" << endl);
391 for (vector<BaseType *>::iterator i = top_vars->begin(), e = top_vars->end(); i != e; i++) {
396 DBG( cerr << __func__ <<
"() - END" << endl);
412 if (!d_root) d_root =
static_cast<D4Group*
>(d_factory->
NewVariable(dods_group_c,
"/"));
424 istringstream iss(v);
426 int major = -1, minor = -1;
428 if (!iss.eof() && !iss.fail())
430 if (!iss.eof() && !iss.fail())
432 if (!iss.eof() && !iss.fail())
435 if (major == -1 || minor == -1 or dot !=
'.')
436 throw InternalErr(__FILE__, __LINE__,
"Could not parse dap version. Value given: " + v);
447 switch (d_dap_major) {
449 d_namespace = c_dap40_namespace;
502 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"Dataset") < 0)
503 throw InternalErr(__FILE__, __LINE__,
"Could not write Dataset element");
507 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:xml",
508 (
const xmlChar*) c_xml_namespace.c_str()) < 0)
509 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:xml");
511 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:xsi", (
const xmlChar*) c_xml_xsi.c_str())
513 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:xsi");
515 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xsi:schemaLocation",
516 (
const xmlChar*) c_dap_40_n_sl.c_str()) < 0)
517 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:schemaLocation");
520 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns", (
const xmlChar*)
get_namespace().c_str()) < 0)
521 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns");
524 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xml:base",
526 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xml:base");
529 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"dapVersion", (
const xmlChar*)dap_version().c_str()) < 0)
530 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for dapVersion");
532 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"dmrVersion", (
const xmlChar*)dmr_version().c_str()) < 0)
533 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for dapVersion");
535 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)
name().c_str()) < 0)
536 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
540 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
541 throw InternalErr(__FILE__, __LINE__,
"Could not end the top-level Group element");
555 strm << DapIndent::LMarg <<
"DMR::dump - ("
556 << (
void *)
this <<
")" << endl ;
557 DapIndent::Indent() ;
558 strm << DapIndent::LMarg <<
"factory: " << (
void *)d_factory << endl ;
559 strm << DapIndent::LMarg <<
"name: " << d_name << endl ;
560 strm << DapIndent::LMarg <<
"filename: " << d_filename << endl ;
561 strm << DapIndent::LMarg <<
"protocol major: " << d_dap_major << endl;
562 strm << DapIndent::LMarg <<
"protocol minor: " << d_dap_minor << endl;
564 DapIndent::UnIndent() ;
Contains the attributes for a dataset.
virtual AttrTable * append_container(const string &name)
Add a container to the attribute table.
The basic data type for the DODS DAP types.
virtual string type_name() const
Returns the type of the class instance as a string.
virtual string name() const
Returns the name of the class instance.
virtual D4Attributes * attributes()
virtual void transform_to_dap4(D4Group *root, Constructor *container)
DAP2 to DAP4 transform.
virtual BaseType * var(const string &name, bool exact_match=true, btp_stack *s=0)
btp_stack no longer needed; use back pointers (BaseType::get_parent())
virtual void add_var_nocopy(BaseType *bt, Part part=nil)
void transform_to_dap4(AttrTable &at)
copy attributes from DAP2 to DAP4
virtual BaseType * NewVariable(Type t, const string &name) const
groupsIter grp_begin()
Get an iterator to the start of the values.
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 ...
groupsIter grp_end()
Get an iterator to the end of the values.
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()
string get_dataset_name() const
Vars_iter var_begin()
Return an iterator to the first variable.
BaseTypeFactory * set_factory(BaseTypeFactory *factory)
Vars_iter var_end()
Return an iterator.
void add_var(BaseType *bt)
Adds a copy of the variable to the DDS. Using the ptr_duplicate() method, perform a deep copy on the ...
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 dump(std::ostream &strm) const
dumps information about this object
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