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 = dmr.d_max_response_size;
101 d_root =
static_cast<D4Group*
>(dmr.d_root->ptr_duplicate());
102 DBG(cerr <<
"dmr.d_root: " << dmr.d_root << endl);
103 DBG(cerr <<
"d_root (from ptr_dup(): " << d_root << endl);
121 : d_factory(factory), d_name(name), d_filename(
""),
122 d_dap_major(4), d_dap_minor(0),
123 d_dmr_version(
"1.0"), d_request_xml_base(
""),
124 d_namespace(c_dap40_namespace), d_max_response_size(0), d_root(0)
151 : d_factory(factory), d_name(dds.get_dataset_name()),
152 d_filename(dds.
filename()), d_dap_major(4), d_dap_minor(0),
153 d_dmr_version(
"1.0"), d_request_xml_base(
""),
154 d_namespace(c_dap40_namespace), d_max_response_size(0), d_root(0)
183 : d_factory(0), d_name(
""), d_filename(
""), d_dap_major(4), d_dap_minor(0),
184 d_dap_version(
"4.0"), d_dmr_version(
"1.0"), d_request_xml_base(
""),
185 d_namespace(c_dap40_namespace), d_max_response_size(0), d_root(0)
208 DMR::operator=(
const DMR &rhs)
240 DBG(cerr << __func__ <<
"() - Transforming top level variable: " <<
241 " (" << (*i)->type_name() <<
":'" << (*i)->name() <<
"':"<<(
void *)(*i) <<
242 ") (root:"<< root_grp <<
")"<< endl; );
243 (*i)->transform_to_dap4(root_grp, root_grp);
244 DBG(cerr << __func__ <<
"() - top level variable: '" <<
245 (*i)->name() <<
"' (type:" << (*i)->type_name() <<
") Transformed"<< endl; );
248 DBG(cerr << __func__ <<
"() - Skipping variable: " <<
249 d4_var->
type_name() <<
" " << d4_var->
name() <<
" because a variable with" <<
250 " this name already exists in the root group." << endl; );
272 DBG( cerr << __func__ <<
"() - BEGIN" << endl);
285 vector<BaseType *>::iterator vIter = top_vars->begin();
286 vector<BaseType *>::iterator vEnd = top_vars->end();
287 for (; vIter != vEnd; vIter++) {
293 set<string> shared_dim_candidates;
295 vector<BaseType *> dropped_vars;
296 for (D4Group::Vars_iter i = root->
var_begin(), e = root->
var_end(); i != e; ++i)
298 DBG( cerr << __func__ <<
"() - Processing top level variable '"<< (*i)->type_name() <<
" " << (*i)->name() <<
"' to DDS." << endl; );
299 vector<BaseType *> *new_vars = (*i)->transform_to_dap2(&(dds->
get_attr_table()));
301 vector<BaseType*>::iterator vIter = new_vars->begin();
302 vector<BaseType*>::iterator end = new_vars->end();
303 for(; vIter!=end; vIter++ ) {
305 DBG( cerr << __func__ <<
"() - Adding variable name: '"<< new_var->
name() <<
"' " <<
306 "type: " << new_var->
type() <<
" " <<
307 "type_name: " << new_var->
type_name() <<
" to DDS." << endl; );
309 Grid *grid = dynamic_cast <
Grid *>(new_var);
312 for(; m != grid->
map_end(); m++) {
313 shared_dim_candidates.insert((*m)->name());
321 DBG( cerr << __func__ <<
"Adding variable '"<< (*i)->type_name() <<
" " << (*i)->name() <<
"' to drop list." << endl; );
322 dropped_vars.push_back((*i));
325 AttrTable *dv_table = Constructor::make_dropped_vars_attr_table(&dropped_vars);
327 DBG( cerr << __func__ <<
"() - Adding dropped variable AttrTable." << endl);
332 D4Group::groupsIter gIter = root->
grp_begin();
333 D4Group::groupsIter gEnd = root->
grp_end();
334 for(; gIter!=gEnd; gIter++) {
336 DBG( cerr << __func__ <<
"() - Processing D4Group " << grp->
name() << endl);
339 DBG( cerr << __func__ <<
"() - Processing " << grp->
name() <<
" Member Variables." << endl);
340 vector<BaseType *>::iterator vIter = d2_vars->begin();
341 vector<BaseType *>::iterator vEnd = d2_vars->end();
342 for(; vIter!=vEnd; vIter++) {
343 DBG( cerr << __func__ <<
"() - Processing " << grp->
name() <<
" Member Variable: " << (*vIter)->name() << endl);
350 DBG( cerr << __func__ <<
"() - END" << endl);
376 DBG( cerr << __func__ <<
"() - BEGIN" << endl);
388 for (vector<BaseType *>::iterator i = top_vars->begin(), e = top_vars->end(); i != e; i++) {
393 DBG( cerr << __func__ <<
"() - END" << endl);
409 if (!d_root) d_root =
static_cast<D4Group*
>(d_factory->NewVariable(dods_group_c,
"/"));
421 istringstream iss(v);
423 int major = -1, minor = -1;
425 if (!iss.eof() && !iss.fail())
427 if (!iss.eof() && !iss.fail())
429 if (!iss.eof() && !iss.fail())
432 if (major == -1 || minor == -1 or dot !=
'.')
433 throw InternalErr(__FILE__, __LINE__,
"Could not parse dap version. Value given: " + v);
444 switch (d_dap_major) {
446 d_namespace = c_dap40_namespace;
480 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"Dataset") < 0)
481 throw InternalErr(__FILE__, __LINE__,
"Could not write Dataset element");
485 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:xml",
486 (
const xmlChar*) c_xml_namespace.c_str()) < 0)
487 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:xml");
489 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:xsi", (
const xmlChar*) c_xml_xsi.c_str())
491 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:xsi");
493 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xsi:schemaLocation",
494 (
const xmlChar*) c_dap_40_n_sl.c_str()) < 0)
495 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:schemaLocation");
498 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns", (
const xmlChar*)
get_namespace().c_str()) < 0)
499 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns");
502 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xml:base",
504 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xml:base");
507 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"dapVersion", (
const xmlChar*)dap_version().c_str()) < 0)
508 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for dapVersion");
510 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"dmrVersion", (
const xmlChar*)dmr_version().c_str()) < 0)
511 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for dapVersion");
513 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)
name().c_str()) < 0)
514 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
518 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
519 throw InternalErr(__FILE__, __LINE__,
"Could not end the top-level Group element");
533 strm << DapIndent::LMarg <<
"DMR::dump - (" 534 << (
void *)
this <<
")" << endl ;
535 DapIndent::Indent() ;
536 strm << DapIndent::LMarg <<
"factory: " << (
void *)d_factory << endl ;
537 strm << DapIndent::LMarg <<
"name: " << d_name << endl ;
538 strm << DapIndent::LMarg <<
"filename: " << d_filename << endl ;
539 strm << DapIndent::LMarg <<
"protocol major: " << d_dap_major << endl;
540 strm << DapIndent::LMarg <<
"protocol minor: " << d_dap_minor << endl;
542 DapIndent::UnIndent() ;
virtual string name() const
Returns the name of the class instance.
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())
void print_dap4(XMLWriter &xml, bool constrained=false)
Contains the attributes for a dataset.
Vars_iter var_begin()
Return an iterator to the first variable.
virtual string get_name() const
Get the name of this attribute table.
virtual void add_var_nocopy(BaseType *bt, Part part=nil)
void add_var_nocopy(BaseType *bt)
Adds the variable to the DDS.
string get_dataset_name() const
top level DAP object to house generic methods
A class for software fault reporting.
std::string filename() const
Map_iter map_begin()
Returns an iterator referencing the first Map vector.
long request_size(bool constrained)
virtual AttrTable * append_container(const string &name)
Add a container to the attribute table.
virtual D4BaseTypeFactory * factory()
virtual Type type() const
Returns the type of the class instance.
std::string request_xml_base() const
Get the URL that will return this DMR.
groupsIter grp_end()
Get an iterator to the end of the values.
long request_size(bool constrained)
Get the estimated response size, in kilo bytes.
Holds the Grid data type.
virtual void transform_to_dap4(D4Group *root, Constructor *container)
DAP2 to DAP4 transform.
virtual D4Attributes * attributes()
void set_dap_version(const std::string &version_string)
virtual AttrTable & get_attr_table()
virtual void build_using_dds(DDS &dds)
groupsIter grp_begin()
Get an iterator to the start of the values.
BaseTypeFactory * set_factory(BaseTypeFactory *factory)
virtual std::vector< BaseType * > * transform_to_dap2(AttrTable *parent_attr_table)
Transform the D4Group's variables to DAP2 variables.
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
virtual string type_name() const
Returns the type of the class instance as a string.
void print_dap4(XMLWriter &xml, bool constrained=false)
virtual DDS * getDDS()
Build a DDS from a DMR.
void transform_to_dap4(AttrTable &at)
copy attributes from DAP2 to DAP4
std::string get_namespace() const
Get the namespace associated with the DMR.
virtual void dump(std::ostream &strm) const
dumps information about this object
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 ...