41 #include <sys/types.h>
68 #include "InternalErr.h"
70 #include "Keywords2.h"
76 #include "DapIndent.h"
88 #include "Structure.h"
99 const string c_xml_xsi =
"http://www.w3.org/2001/XMLSchema-instance";
100 const string c_xml_namespace =
"http://www.w3.org/XML/1998/namespace";
102 const string grddl_transformation_dap32 =
"http://xml.opendap.org/transforms/ddxToRdfTriples.xsl";
104 const string c_default_dap20_schema_location =
"http://xml.opendap.org/dap/dap2.xsd";
105 const string c_default_dap32_schema_location =
"http://xml.opendap.org/dap/dap3.2.xsd";
106 const string c_default_dap40_schema_location =
"http://xml.opendap.org/dap/dap4.0.xsd";
108 const string c_dap20_namespace =
"http://xml.opendap.org/ns/DAP2";
109 const string c_dap32_namespace =
"http://xml.opendap.org/ns/DAP/3.2#";
110 const string c_dap40_namespace =
"http://xml.opendap.org/ns/DAP/4.0#";
112 const string c_dap_20_n_sl = c_dap20_namespace +
" " + c_default_dap20_schema_location;
113 const string c_dap_32_n_sl = c_dap32_namespace +
" " + c_default_dap32_schema_location;
114 const string c_dap_40_n_sl = c_dap40_namespace +
" " + c_default_dap40_schema_location;
119 const string TOP_LEVEL_ATTRS_CONTAINER_NAME =
"DAP4_GLOBAL";
126 void dds_switch_to_buffer(
void *new_buffer);
127 void dds_delete_buffer(
void * buffer);
128 void *dds_buffer(FILE *fp);
133 DDS::duplicate(
const DDS &dds)
135 DBG(cerr <<
"Entering DDS::duplicate... " <<endl);
137 BaseTypeFactory *d_factory;
141 string d_container_name;
142 Structure *d_container;
147 string d_dap_version;
148 string d_request_xml_base;
153 vector<BaseType *> vars;
160 long d_max_response_size;
163 d_factory = dds.d_factory;
166 d_filename = dds.d_filename;
167 d_container_name = dds.d_container_name;
168 d_container = dds.d_container;
170 d_dap_major = dds.d_dap_major;
171 d_dap_minor = dds.d_dap_minor;
173 d_dap_version = dds.d_dap_version;
174 d_request_xml_base = dds.d_request_xml_base;
175 d_namespace = dds.d_namespace;
179 DDS &dds_tmp =
const_cast<DDS &
>(dds);
182 for (Vars_iter i = dds_tmp.var_begin(); i != dds_tmp.var_end(); i++) {
186 d_timeout = dds.d_timeout;
189 d_keywords = dds.d_keywords;
192 d_max_response_size_kb = dds.d_max_response_size_kb;
208 : d_factory(factory), d_name(name), d_container_name(
""), d_container(0),
209 d_request_xml_base(
""),
210 d_timeout(0), d_max_response_size_kb(0)
212 DBG(cerr <<
"Building a DDS for the default version (2.0)" << endl);
235 : d_factory(factory), d_name(name), d_container_name(
""), d_container(0),
236 d_request_xml_base(
""),
237 d_timeout(0), d_max_response_size_kb(0)
239 DBG(cerr <<
"Building a DDS for version: " << version << endl);
249 DBG(cerr <<
"Entering DDS(const DDS &rhs) ..." << endl);
251 DBG(cerr <<
" bye." << endl);
257 for (Vars_iter i = vars.begin(); i != vars.end(); i++) {
259 delete btp ; btp = 0;
264 DDS::operator=(
const DDS &rhs)
266 DBG(cerr <<
"Entering DDS::operator= ..." << endl);
272 DBG(cerr <<
" bye." << endl);
297 "Error transferring attributes: working on a container in dds, but not das");
303 (*i)->transfer_attributes(top);
309 DBG(cerr <<
"Processing the attributes for: " << (*var)->d_name() <<
" a " << (*var)->type_name() << endl);
310 (*var)->transfer_attributes(top);
323 if ((*i)->type == Attr_container && (*i)->attributes->is_global_attribute()) {
327 d_attr.append_container(at, at->
get_name());
331 AttrTable::Attr_iter at_cont_p = top_level->attr_begin();
332 while (at_cont_p != top_level->attr_end()) {
336 if ((*at_cont_p)->type == Attr_container && (*at_cont_p)->attributes->is_global_attribute()) {
337 DBG(cerr << (*at_cont_p)->d_name <<
" is a global attribute." << endl);
341 d_attr.append_container(at, at->
get_name());
415 if (d_dap_minor >= 0) {
417 oss << d_dap_major <<
"." << d_dap_minor;
418 d_dap_version = oss.str();
430 if (d_dap_major >= 0) {
432 oss << d_dap_major <<
"." << d_dap_minor;
433 d_dap_version = oss.str();
445 istringstream iss(v);
447 int major = -1, minor = -1;
449 if (!iss.eof() && !iss.fail())
451 if (!iss.eof() && !iss.fail())
453 if (!iss.eof() && !iss.fail())
456 if (major == -1 || minor == -1 or dot !=
'.')
457 throw InternalErr(__FILE__, __LINE__,
"Could not parse dap version. Value given: " + v);
468 switch (d_dap_major) {
470 d_namespace = c_dap20_namespace;
473 d_namespace = c_dap32_namespace;
476 d_namespace = c_dap40_namespace;
479 throw InternalErr(__FILE__, __LINE__,
"Unknown DAP version.");
493 int major = floor(d);
494 int minor = (d-major)*10;
496 DBG(cerr <<
"Major: " << major <<
", Minor: " << minor << endl);
499 oss << major <<
"." << minor;
516 return d_container_name;
544 d_container_name = cn;
572 for (Vars_iter i = vars.begin(); i != vars.end(); i++) {
575 w += (*i)->width(constrained);
578 w += (*i)->width(constrained);
598 uint64_t req_size = 0;
599 for (Vars_iter i = vars.begin(); i != vars.end(); i++) {
602 req_size += (*i)->width(constrained);
605 req_size += (*i)->width(constrained);
608 return req_size/1024;
619 throw InternalErr(__FILE__, __LINE__,
"Trying to add a BaseType object with a NULL pointer.");
621 if (bt->is_dap4_only_type())
622 throw InternalErr(__FILE__, __LINE__,
"Attempt to add a DAP4 type to a DAP2 DDS.");
624 DBG2(cerr <<
"In DDS::add_var(), bt's address is: " << bt << endl);
627 DBG2(cerr <<
"In DDS::add_var(), btp's address is: " << btp << endl);
631 d_container->add_var(bt);
647 throw InternalErr(__FILE__, __LINE__,
"Trying to add a BaseType object with a NULL pointer.");
649 DBG2(cerr <<
"In DDS::add_var(), bt's address is: " << bt << endl);
652 d_container->add_var_nocopy(bt);
671 d_container->del_var( n ) ;
675 for (Vars_iter i = vars.begin(); i != vars.end(); i++) {
676 if ((*i)->name() == n) {
692 if (i != vars.end()) {
708 for (Vars_iter i_tmp = i1; i_tmp != i2; i_tmp++) {
751 return d_container->var( name,
false, s ) ;
757 return leaf_match(name, s);
761 DDS::leaf_match(
const string &n, BaseType::btp_stack *s)
763 DBG(cerr <<
"DDS::leaf_match: Looking for " << n << endl);
765 for (Vars_iter i = vars.begin(); i != vars.end(); i++) {
767 DBG(cerr <<
"DDS::leaf_match: Looking for " << n <<
" in: " << btp->
name() << endl);
769 if (btp->
name() == n) {
770 DBG(cerr <<
"Found " << n <<
" in: " << btp->
name() << endl);
775 BaseType *found = btp->
var(n,
false, s);
777 DBG(cerr <<
"Found " << n <<
" in: " << btp->
name() << endl);
781 #if STRUCTURE_ARRAY_SYNTAX_OLD
784 BaseType *found = btp->
var()->
var(n,
false, s);
786 DBG(cerr <<
"Found " << n <<
" in: " << btp->
var()->d_name() << endl);
797 DDS::exact_match(
const string &name, BaseType::btp_stack *s)
799 for (Vars_iter i = vars.begin(); i != vars.end(); i++) {
801 DBG2(cerr <<
"Looking for " << d_name <<
" in: " << btp << endl);
803 if (btp->name() == name) {
804 DBG2(cerr <<
"Found " << d_name <<
" in: " << btp << endl);
809 string::size_type dot_pos = name.find(
".");
810 if (dot_pos != string::npos) {
811 string aggregate = name.substr(0, dot_pos);
812 string field = name.substr(dot_pos + 1);
814 BaseType *agg_ptr =
var(aggregate, s);
816 DBG2(cerr <<
"Descending into " << agg_ptr->name() << endl);
817 return agg_ptr->var(field,
true, s);
838 return vars.rbegin();
859 return vars.begin() + i;
868 return *(vars.begin() + i);
879 if (ptr->is_dap4_only_type())
880 throw InternalErr(__FILE__, __LINE__,
"Attempt to add a DAP4 type to a DAP2 DDS.");
896 if (ptr->is_dap4_only_type())
897 throw InternalErr(__FILE__, __LINE__,
"Attempt to add a DAP4 type to a DAP2 DDS.");
912 #if USE_LOCAL_TIMEOUT_SCHEME
922 #if USE_LOCAL_TIMEOUT_SCHEME
941 DDS::set_timeout(
int)
943 #if USE_LOCAL_TIMEOUT_SCHEME
952 #if USE_LOCAL_TIMEOUT_SCHEME
963 for (Vars_iter i = vars.begin(); i != vars.end(); i++) {
964 if ((*i)->type() == dods_sequence_c)
966 else if ((*i)->type() == dods_structure_c)
975 FILE *in = fopen(fname.c_str(),
"r");
978 throw Error(cannot_read_file,
"Could not open: " + fname);
997 int new_fd = _dup(fd);
999 int new_fd = dup(fd);
1003 throw InternalErr(__FILE__, __LINE__,
"Could not access file.");
1004 FILE *in = fdopen(new_fd,
"r");
1007 throw InternalErr(__FILE__, __LINE__,
"Could not access file.");
1030 throw InternalErr(__FILE__, __LINE__,
"Null input stream.");
1033 void *buffer = dds_buffer(in);
1034 dds_switch_to_buffer(buffer);
1038 bool status = ddsparse(&arg) == 0;
1040 dds_delete_buffer(buffer);
1042 DBG2(cout <<
"Status from parser: " << status << endl);
1046 if (!status || !arg.status()) {
1058 fwrite(oss.str().data(),
sizeof(
char), oss.str().length(), out);
1065 out <<
"Dataset {\n" ;
1067 for (Vars_citer i = vars.begin(); i != vars.end(); i++) {
1068 (*i)->print_decl(out) ;
1071 out <<
"} " <<
id2www(d_name) <<
";\n" ;
1098 vector<AttrTable*> tables;
1107 bool it_does =
false;
1108 for (vector<AttrTable*>::iterartor i = tables.begin(), e = tables.end(); it_does || i != e; ++i) {
1132 Grid* grid =
dynamic_cast<Grid*
>(btp);
1137 for (Constructor::Vars_iter i = cons->
var_begin(), e = cons->
var_end(); i != e; i++) {
1154 static string four_spaces =
" ";
1155 void print_var_das(ostream &out, BaseType *bt,
string indent =
"") {
1160 AttrTable attr_table = bt->get_attr_table();
1163 Constructor *cnstrctr =
dynamic_cast<Constructor *
>(bt);
1165 Grid *grid =
dynamic_cast<Grid *
>(bt);
1167 Array *gridArray = grid->get_array();
1168 AttrTable arrayAT = gridArray->get_attr_table();
1171 gridArray->get_attr_table().print(out, indent + four_spaces);
1175 for (Grid::Map_iter mIter = grid->map_begin();
1176 mIter != grid->map_end(); ++mIter) {
1177 BaseType *currentMap = *mIter;
1179 print_var_das(out, currentMap, indent + four_spaces);
1184 attr_table.print(out, indent + four_spaces);
1185 Constructor::Vars_iter i = cnstrctr->var_begin();
1186 Constructor::Vars_iter e = cnstrctr->var_end();
1187 for (; i != e; i++) {
1193 print_var_das(out, *i, indent + four_spaces);
1198 attr_table.print(out, indent + four_spaces);
1201 out << indent <<
"}" << endl;
1217 out <<
"Attributes {" << endl;
1218 for (Vars_citer i = vars.begin(); i != vars.end(); i++) {
1220 print_var_das(out, *i, four_spaces);
1223 d_attr.print(out,indent);
1255 get_unique_top_level_global_container_name(
DAS *das)
1261 return TOP_LEVEL_ATTRS_CONTAINER_NAME;
1270 if (!(i < UINT_MAX))
1271 throw InternalErr(__FILE__, __LINE__,
"Cannot add top-level attributes to the DAS");
1272 name = TOP_LEVEL_ATTRS_CONTAINER_NAME + oss.str();
1289 Grid *grid =
dynamic_cast<Grid *
>(bt);
1294 for( AttrTable::Attr_iter atIter = arrayAT.
attr_begin(); atIter!=arrayAT.
attr_end(); ++atIter){
1296 string childName = arrayAT.
get_name(atIter);
1297 if (type == Attr_container){
1309 for (Constructor::Vars_iter i = cons->
var_begin(), e = cons->
var_end(); i != e; i++) {
1322 for (Vars_citer i = vars.begin(); i != vars.end(); i++) {
1324 AttrTable *childAttrT =
new AttrTable((*i)->get_attr_table());
1326 das->add_table((*i)->name(), childAttrT);
1331 auto_ptr<AttrTable> global(
new AttrTable);
1333 for (AttrTable::Attr_iter i = d_attr.attr_begin(); i != d_attr.attr_end(); ++i) {
1336 if (d_attr.get_attr_table(i)) {
1337 das->add_table(d_attr.get_name(i),
new AttrTable(*(d_attr.get_attr_table(i))));
1341 global->append_attr(d_attr.get_name(i), d_attr.get_type(i), d_attr.get_attr_vector(i));
1346 if (global->get_size() > 0) {
1347 das->add_table(get_unique_top_level_global_container_name(das), global.get());
1367 fwrite(oss.str().data(),
sizeof(
char), oss.str().length(), out);
1383 out <<
"Dataset {\n" ;
1385 for (Vars_citer i = vars.begin(); i != vars.end(); i++) {
1389 (*i)->print_decl(out,
" ",
true,
false,
true) ;
1392 out <<
"} " <<
id2www(d_name) <<
";\n" ;
1413 fwrite(oss.str().data(), 1, oss.str().length(), out);
1433 class VariablePrintXMLWriter :
public unary_function<BaseType *, void>
1438 VariablePrintXMLWriter(
XMLWriter &xml,
bool constrained)
1439 : d_xml(xml), d_constrained(constrained)
1441 void operator()(BaseType *bt)
1443 bt->print_xml_writer(d_xml, d_constrained);
1478 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"Group") < 0)
1479 throw InternalErr(__FILE__, __LINE__,
"Could not write Group element");
1480 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)d_name.c_str()) < 0)
1481 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
1483 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"dapVersion", (
const xmlChar*)get_dap_version().c_str()) < 0)
1484 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for dapVersion");
1487 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:xml", (
const xmlChar*)c_xml_namespace.c_str()) < 0)
1488 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:xml");
1490 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xml:base", (
const xmlChar*)
get_request_xml_base().c_str()) < 0)
1491 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xml:base");
1494 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns", (
const xmlChar*)
get_namespace().c_str()) < 0)
1495 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns");
1499 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"Dataset") < 0)
1500 throw InternalErr(__FILE__, __LINE__,
"Could not write Dataset element");
1501 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)d_name.c_str()) < 0)
1502 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
1503 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:xsi", (
const xmlChar*)
"http://www.w3.org/2001/XMLSchema-instance") < 0)
1504 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:xsi");
1506 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xsi:schemaLocation", (
const xmlChar*)c_dap_32_n_sl.c_str()) < 0)
1507 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:schemaLocation");
1509 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:grddl", (
const xmlChar*)
"http://www.w3.org/2003/g/data-view#") < 0)
1510 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:grddl");
1512 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"grddl:transformation", (
const xmlChar*)grddl_transformation_dap32.c_str()) < 0)
1513 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:transformation");
1515 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns", (
const xmlChar*)c_dap32_namespace.c_str()) < 0)
1516 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns");
1517 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:dap", (
const xmlChar*)c_dap32_namespace.c_str()) < 0)
1518 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:dap");
1520 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"dapVersion", (
const xmlChar*)
"3.2") < 0)
1521 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for dapVersion");
1524 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:xml", (
const xmlChar*)c_xml_namespace.c_str()) < 0)
1525 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:xml");
1527 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xml:base", (
const xmlChar*)
get_request_xml_base().c_str()) < 0)
1528 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xml:base");
1532 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"Dataset") < 0)
1533 throw InternalErr(__FILE__, __LINE__,
"Could not write Dataset element");
1534 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)d_name.c_str()) < 0)
1535 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for d_name");
1536 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:xsi", (
const xmlChar*)
"http://www.w3.org/2001/XMLSchema-instance") < 0)
1537 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:xsi");
1539 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns", (
const xmlChar*)c_dap20_namespace.c_str()) < 0)
1540 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns");
1542 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xsi:schemaLocation", (
const xmlChar*)c_dap_20_n_sl.c_str()) < 0)
1543 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:schemaLocation");
1548 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"Dataset") < 0)
1549 throw InternalErr(__FILE__, __LINE__,
"Could not write Dataset element");
1550 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)d_name.c_str()) < 0)
1551 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for d_name");
1552 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:xsi", (
const xmlChar*)
"http://www.w3.org/2001/XMLSchema-instance") < 0)
1553 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:xsi");
1555 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns", (
const xmlChar*)c_dap20_namespace.c_str()) < 0)
1556 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns");
1558 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xsi:schemaLocation", (
const xmlChar*)c_dap_20_n_sl.c_str()) < 0)
1559 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:schemaLocation");
1563 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"Dataset") < 0)
1564 throw InternalErr(__FILE__, __LINE__,
"Could not write Dataset element");
1565 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)d_name.c_str()) < 0)
1566 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
1567 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:xsi", (
const xmlChar*)
"http://www.w3.org/2001/XMLSchema-instance") < 0)
1568 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:xsi");
1570 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xsi:schemaLocation", (
const xmlChar*)c_dap_32_n_sl.c_str()) < 0)
1571 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:schemaLocation");
1573 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:grddl", (
const xmlChar*)
"http://www.w3.org/2003/g/data-view#") < 0)
1574 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:grddl");
1576 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"grddl:transformation", (
const xmlChar*)grddl_transformation_dap32.c_str()) < 0)
1577 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:transformation");
1579 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns", (
const xmlChar*)c_dap32_namespace.c_str()) < 0)
1580 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns");
1581 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:dap", (
const xmlChar*)c_dap32_namespace.c_str()) < 0)
1582 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:dap");
1584 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"dapVersion", (
const xmlChar*)
"3.2") < 0)
1585 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for dapVersion");
1588 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:xml", (
const xmlChar*)c_xml_namespace.c_str()) < 0)
1589 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:xml");
1591 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xml:base", (
const xmlChar*)
get_request_xml_base().c_str()) < 0)
1592 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xml:base");
1595 #error Must define DAP2_DDX or DAP3_2_DDX
1599 d_attr.print_xml_writer(xml);
1602 for_each(
var_begin(),
var_end(), VariablePrintXMLWriter(xml, constrained));
1612 if (!blob.empty()) {
1613 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"blob") < 0)
1614 throw InternalErr(__FILE__, __LINE__,
"Could not write blob element");
1615 string cid =
"cid:" + blob;
1616 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"href", (
const xmlChar*) cid.c_str()) < 0)
1617 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for d_name");
1618 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
1619 throw InternalErr(__FILE__, __LINE__,
"Could not end blob element");
1623 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"blob") < 0)
1624 throw InternalErr(__FILE__, __LINE__,
"Could not write blob element");
1625 string cid =
"cid:" + blob;
1626 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"href", (
const xmlChar*) cid.c_str()) < 0)
1627 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for d_name");
1628 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
1629 throw InternalErr(__FILE__, __LINE__,
"Could not end blob element");
1632 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"dataBLOB") < 0)
1633 throw InternalErr(__FILE__, __LINE__,
"Could not write dataBLOB element");
1634 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"href", (
const xmlChar*)
"") < 0)
1635 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for d_name");
1636 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
1637 throw InternalErr(__FILE__, __LINE__,
"Could not end dataBLOB element");
1642 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"dataBLOB") < 0)
1643 throw InternalErr(__FILE__, __LINE__,
"Could not write dataBLOB element");
1644 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"href", (
const xmlChar*)
"") < 0)
1645 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for d_name");
1646 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
1647 throw InternalErr(__FILE__, __LINE__,
"Could not end dataBLOB element");
1649 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"blob") < 0)
1650 throw InternalErr(__FILE__, __LINE__,
"Could not write blob element");
1651 string cid =
"cid:" + blob;
1652 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"href", (
const xmlChar*) cid.c_str()) < 0)
1653 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for d_name");
1654 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
1655 throw InternalErr(__FILE__, __LINE__,
"Could not end blob element");
1657 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
1658 throw InternalErr(__FILE__, __LINE__,
"Could not end Dataset element");
1660 #error Must define DAP2_DDX or DAP3_2_DDX
1663 out << xml.get_doc();
1683 throw InternalErr(__FILE__, __LINE__,
"Tried to print a DMR with DAP major version less than 4");
1688 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"Group") < 0)
1689 throw InternalErr(__FILE__, __LINE__,
"Could not write Group element");
1691 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:xml",
1692 (
const xmlChar*) c_xml_namespace.c_str()) < 0)
1693 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:xml");
1695 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:xsi", (
const xmlChar*) c_xml_xsi.c_str())
1697 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:xsi");
1699 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xsi:schemaLocation",
1700 (
const xmlChar*) c_dap_40_n_sl.c_str()) < 0)
1701 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:schemaLocation");
1703 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns",
1705 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns");
1707 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"dapVersion",
1708 (
const xmlChar*) get_dap_version().c_str()) < 0)
1709 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for dapVersion");
1711 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"dmrVersion", (
const xmlChar*) get_dmr_version().c_str()) < 0)
1712 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for dapVersion");
1715 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xml:base",
1717 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xml:base");
1720 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*) d_name.c_str()) < 0)
1721 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
1724 d_attr.print_xml_writer(xml);
1727 for_each(
var_begin(),
var_end(), VariablePrintXMLWriter(xml, constrained));
1729 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
1730 throw InternalErr(__FILE__, __LINE__,
"Could not end the top-level Group element");
1732 out << xml.get_doc();
1755 cerr <<
"A dataset must have a d_name" << endl;
1760 if (!unique_names(vars, d_name,
"Dataset", msg))
1764 for (Vars_iter i = vars.begin(); i != vars.end(); i++)
1765 if (!(*i)->check_semantics(msg,
true))
1799 BaseType::btp_stack *s =
new BaseType::btp_stack;
1802 auto_ptr<BaseType::btp_stack> s(
new BaseType::btp_stack);
1804 DBG2(cerr <<
"DDS::mark: Looking for " << n << endl);
1808 throw Error(malformed_expr,
"Could not find variable " + n);
1810 DBG2(cerr <<
"Could not find variable " << n << endl);
1819 DBG2(cerr <<
"DDS::mark: Set variable " << variable->d_name()
1820 <<
" (a " << variable->
type_name() <<
")" << endl);
1826 while (!s->empty()) {
1827 s->top()->BaseType::set_send_p(state);
1829 DBG2(cerr <<
"DDS::mark: Set variable " << s->top()->d_name()
1830 <<
" (a " << s->top()->type_name() <<
")" << endl);
1832 string parent_name = (s->top()->get_parent()) ? s->top()->get_parent()->name():
"none";
1833 string parent_type = (s->top()->get_parent()) ? s->top()->get_parent()->type_name():
"none";
1834 DBG2(cerr <<
"DDS::mark: Parent variable " << parent_name <<
" (a " << parent_type <<
")" << endl);
1854 for (Vars_iter i = vars.begin(); i != vars.end(); i++)
1855 (*i)->set_send_p(state);
1868 strm << DapIndent::LMarg <<
"DDS::dump - ("
1869 << (
void *)
this <<
")" << endl ;
1870 DapIndent::Indent() ;
1871 strm << DapIndent::LMarg <<
"d_name: " << d_name << endl ;
1872 strm << DapIndent::LMarg <<
"filename: " << d_filename << endl ;
1873 strm << DapIndent::LMarg <<
"protocol major: " << d_dap_major << endl;
1874 strm << DapIndent::LMarg <<
"protocol minor: " << d_dap_minor << endl;
1875 strm << DapIndent::LMarg <<
"factory: " << (
void *)d_factory << endl ;
1877 strm << DapIndent::LMarg <<
"global attributes:" << endl ;
1878 DapIndent::Indent() ;
1880 DapIndent::UnIndent() ;
1883 strm << DapIndent::LMarg <<
"vars:" << endl ;
1884 DapIndent::Indent() ;
1885 Vars_citer i = vars.begin() ;
1886 Vars_citer ie = vars.end() ;
1887 for (; i != ie; i++) {
1890 DapIndent::UnIndent() ;
1893 strm << DapIndent::LMarg <<
"vars: none" << endl ;
1896 DapIndent::UnIndent() ;
A multidimensional array of identical data types.
Contains the attributes for a dataset.
virtual AttrTable * append_container(const string &name)
Add a container to the attribute table.
virtual AttrTable * get_attr_table(const string &name)
Get an attribute container.
virtual Attr_iter attr_end()
virtual vector< string > * get_attr_vector(const string &name)
Get a vector-valued attribute.
virtual unsigned int append_attr(const string &name, const string &type, const string &value)
Add an attribute to the table.
virtual Attr_iter attr_begin()
virtual string get_name() const
Get the name of this attribute table.
virtual unsigned int get_size() const
Get the number of entries in this attribute table.
virtual AttrType get_attr_type(const string &name)
Get the type of an attribute.
The basic data type for the DODS DAP types.
virtual BaseType * ptr_duplicate()=0
virtual string type_name() const
Returns the type of the class instance as a string.
virtual AttrTable & get_attr_table()
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)
Returns a pointer to a member of a constructor class.
virtual bool is_vector_type() const
Returns true if the instance is a vector (i.e., array) type variable.
virtual bool is_constructor_type() const
Returns true if the instance is a constructor (i.e., Structure, Sequence or Grid) type variable.
virtual void set_send_p(bool state)
Hold attribute data for a DAP2 dataset.
virtual AttrTable * get_top_level_attributes()
Returns the top most set of attributes.
AttrTable * get_table(AttrTable::Attr_iter &i)
Returns the referenced variable attribute table.
virtual string container_name() const
Returns the name of the current attribute container when multiple files used to build this DAS.
void set_dataset_name(const string &n)
void set_dap_major(int p)
void mark_all(bool state)
void print_dmr(ostream &out, bool constrained)
Print the DAP4 DMR object using a DDS.
Vars_riter var_rend()
Return a reverse iterator.
void add_var_nocopy(BaseType *bt)
Adds the variable to the DDS.
bool check_semantics(bool all=false)
Check the semantics of each of the variables represented in the DDS.
virtual AttrTable & get_attr_table()
uint64_t get_request_size_kb(bool constrained)
Get the estimated response size in kilobytes.
virtual void transfer_attributes(DAS *das)
void set_dap_minor(int p)
Vars_riter var_rbegin()
Return a reverse iterator.
string get_namespace() const
Get the namespace associated with the DDS - likely set only by DDX responses.
int num_var()
Returns the number of variables in the DDS.
Vars_iter get_vars_iter(int i)
Get an iterator.
void print(FILE *out)
Print the entire DDS to the specified file.
BaseType * get_var_index(int i)
Get a variable.
int get_request_size(bool constrained)
Get the estimated response size in bytes.
string get_dataset_name() const
void del_var(const string &n)
Removes a variable from the DDS.
void parse(string fname)
Parse a DDS from a file with the given d_name.
BaseType * var(const string &n, BaseType::btp_stack &s)
void print_xml(FILE *out, bool constrained, const string &blob="")
void insert_var(Vars_iter i, BaseType *ptr)
Insert a variable before the referenced element.
bool mark(const string &name, bool state)
Mark the send_p flag of the named variable to state.
int get_dap_minor() const
Get the DAP minor version as sent by the client.
DDS(BaseTypeFactory *factory, const string &name="")
void tag_nested_sequences()
Traverse DDS, set Sequence leaf nodes.
DAS * get_das()
Get a DAS object.
void print_constrained(FILE *out)
Print a constrained DDS to the specified file.
Vars_iter var_begin()
Return an iterator to the first variable.
void insert_var_nocopy(Vars_iter i, BaseType *ptr)
string get_request_xml_base() const
Get the URL that will return this DDS/DDX/DataThing.
int get_dap_major() const
Get the DAP major version as sent by the client.
Vars_iter var_end()
Return an iterator.
void set_dap_version(const string &version_string="2.0")
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 ...
void print_xml_writer(ostream &out, bool constrained, const string &blob="")
void print_das(ostream &out)
write the DAS response given the attribute information in the DDS
virtual void dump(ostream &strm) const
dumps information about this object
libdap base object for common functionality of libdap objects
A class for error processing.
std::string get_error_message() const
Holds the Grid data type.
Array * get_array()
Returns the Grid Array. This method returns the array using an Array*, so no cast is required.
A class for software fault reporting.
virtual void set_leaf_sequence(int lvl=1)
Mark the Sequence which holds the leaf elements.
Holds a structure (aggregate) type.
virtual void set_leaf_sequence(int level=1)
Traverse Structure, set Sequence leaf nodes.
top level DAP object to house generic methods
bool has_dap2_attributes(AttrTable &a)
string www2id(const string &in, const string &escape, const string &except)
string add_space_encoding(const string &s)
string AttrType_to_String(const AttrType at)
void fillConstructorAttrTable(AttrTable *at, BaseType *bt)
Recursive helper function for Building DAS entries for Constructor types.
string id2www(string in, const string &allowable)
Pass parameters by reference to a parser.