66#include "InternalErr.h"
97const string c_xml_xsi =
"http://www.w3.org/2001/XMLSchema-instance";
98const string c_xml_namespace =
"http://www.w3.org/XML/1998/namespace";
100const string grddl_transformation_dap32 =
"http://xml.opendap.org/transforms/ddxToRdfTriples.xsl";
102const string c_default_dap20_schema_location =
"http://xml.opendap.org/dap/dap2.xsd";
103const string c_default_dap32_schema_location =
"http://xml.opendap.org/dap/dap3.2.xsd";
104const string c_default_dap40_schema_location =
"http://xml.opendap.org/dap/dap4.0.xsd";
106const string c_dap20_namespace =
"http://xml.opendap.org/ns/DAP2";
107const string c_dap32_namespace =
"http://xml.opendap.org/ns/DAP/3.2#";
108const string c_dap40_namespace =
"http://xml.opendap.org/ns/DAP/4.0#";
110const string c_dap_20_n_sl = c_dap20_namespace +
" " + c_default_dap20_schema_location;
111const string c_dap_32_n_sl = c_dap32_namespace +
" " + c_default_dap32_schema_location;
112const string c_dap_40_n_sl = c_dap40_namespace +
" " + c_default_dap40_schema_location;
117const string TOP_LEVEL_ATTRS_CONTAINER_NAME =
"DAP4_GLOBAL";
124void dds_switch_to_buffer(
void *new_buffer);
125void dds_delete_buffer(
void * buffer);
126void *dds_buffer(FILE *fp);
131DDS::duplicate(
const DDS &dds)
133 DBG(cerr <<
"Entering DDS::duplicate... " <<endl);
135 BaseTypeFactory *d_factory;
139 string d_container_name;
140 Structure *d_container;
145 string d_dap_version;
146 string d_request_xml_base;
151 vector<BaseType *> vars;
158 long d_max_response_size;
161 d_factory = dds.d_factory;
164 d_filename = dds.d_filename;
165 d_container_name = dds.d_container_name;
166 d_container = dds.d_container;
168 d_dap_major = dds.d_dap_major;
169 d_dap_minor = dds.d_dap_minor;
171 d_dap_version = dds.d_dap_version;
172 d_request_xml_base = dds.d_request_xml_base;
173 d_namespace = dds.d_namespace;
177 DDS &dds_tmp =
const_cast<DDS &
>(dds);
180 for (Vars_iter i = dds_tmp.var_begin(); i != dds_tmp.var_end(); i++) {
184 d_timeout = dds.d_timeout;
187 d_keywords = dds.d_keywords;
190 d_max_response_size_kb = dds.d_max_response_size_kb;
206 : d_factory(factory), d_name(name), d_container_name(
""), d_container(0),
207 d_request_xml_base(
""),
208 d_timeout(0), d_max_response_size_kb(0)
210 DBG(cerr <<
"Building a DDS for the default version (2.0)" << endl);
233 : d_factory(factory), d_name(name), d_container_name(
""), d_container(0),
234 d_request_xml_base(
""),
235 d_timeout(0), d_max_response_size_kb(0)
237 DBG(cerr <<
"Building a DDS for version: " << version << endl);
247 DBG(cerr <<
"Entering DDS(const DDS &rhs) ..." << endl);
249 DBG(cerr <<
" bye." << endl);
255 for (Vars_iter i = vars.begin(); i != vars.end(); i++) {
257 delete btp ; btp = 0;
262DDS::operator=(
const DDS &rhs)
264 DBG(cerr <<
"Entering DDS::operator= ..." << endl);
270 DBG(cerr <<
" bye." << endl);
295 "Error transferring attributes: working on a container in dds, but not das");
301 (*i)->transfer_attributes(top);
307 DBG(cerr <<
"Processing the attributes for: " << (*var)->d_name() <<
" a " << (*var)->type_name() << endl);
308 (*var)->transfer_attributes(top);
321 if ((*i)->type == Attr_container && (*i)->attributes->is_global_attribute()) {
325 d_attr.append_container(at, at->
get_name());
329 AttrTable::Attr_iter at_cont_p = top_level->attr_begin();
330 while (at_cont_p != top_level->attr_end()) {
334 if ((*at_cont_p)->type == Attr_container && (*at_cont_p)->attributes->is_global_attribute()) {
335 DBG(cerr << (*at_cont_p)->d_name <<
" is a global attribute." << endl);
339 d_attr.append_container(at, at->
get_name());
413 if (d_dap_minor >= 0) {
415 oss << d_dap_major <<
"." << d_dap_minor;
416 d_dap_version = oss.str();
428 if (d_dap_major >= 0) {
430 oss << d_dap_major <<
"." << d_dap_minor;
431 d_dap_version = oss.str();
443 istringstream iss(v);
445 int major = -1, minor = -1;
447 if (!iss.eof() && !iss.fail())
449 if (!iss.eof() && !iss.fail())
451 if (!iss.eof() && !iss.fail())
454 if (major == -1 || minor == -1 or dot !=
'.')
455 throw InternalErr(__FILE__, __LINE__,
"Could not parse dap version. Value given: " + v);
466 switch (d_dap_major) {
468 d_namespace = c_dap20_namespace;
471 d_namespace = c_dap32_namespace;
474 d_namespace = c_dap40_namespace;
477 throw InternalErr(__FILE__, __LINE__,
"Unknown DAP version.");
491 int major = floor(d);
492 int minor = (d-major)*10;
494 DBG(cerr <<
"Major: " << major <<
", Minor: " << minor << endl);
497 oss << major <<
"." << minor;
514 return d_container_name;
542 d_container_name = cn;
565[[deprecated(
"Use DDS::get_request_size_kb()")]]
569 for (Vars_iter i = vars.begin(); i != vars.end(); i++) {
572 w += (*i)->width(constrained);
575 w += (*i)->width(constrained);
595 uint64_t req_size = 0;
596 for (Vars_iter i = vars.begin(); i != vars.end(); i++) {
599 req_size += (*i)->width(constrained);
602 req_size += (*i)->width(constrained);
605 return req_size/1024;
616 throw InternalErr(__FILE__, __LINE__,
"Trying to add a BaseType object with a NULL pointer.");
618 if (bt->is_dap4_only_type())
619 throw InternalErr(__FILE__, __LINE__,
"Attempt to add a DAP4 type to a DAP2 DDS.");
621 DBG2(cerr <<
"In DDS::add_var(), bt's address is: " << bt << endl);
624 DBG2(cerr <<
"In DDS::add_var(), btp's address is: " << btp << endl);
628 d_container->add_var(bt);
644 throw InternalErr(__FILE__, __LINE__,
"Trying to add a BaseType object with a NULL pointer.");
646 DBG2(cerr <<
"In DDS::add_var(), bt's address is: " << bt << endl);
649 d_container->add_var_nocopy(bt);
668 d_container->del_var( n ) ;
672 for (Vars_iter i = vars.begin(); i != vars.end(); i++) {
673 if ((*i)->name() == n) {
689 if (i != vars.end()) {
705 for (Vars_iter i_tmp = i1; i_tmp != i2; i_tmp++) {
748 return d_container->var( name,
false, s ) ;
754 return leaf_match(name, s);
758DDS::leaf_match(
const string &n, BaseType::btp_stack *s)
760 DBG(cerr <<
"DDS::leaf_match: Looking for " << n << endl);
762 for (Vars_iter i = vars.begin(); i != vars.end(); i++) {
764 DBG(cerr <<
"DDS::leaf_match: Looking for " << n <<
" in: " << btp->
name() << endl);
766 if (btp->
name() == n) {
767 DBG(cerr <<
"Found " << n <<
" in: " << btp->
name() << endl);
772 BaseType *found = btp->
var(n,
false, s);
774 DBG(cerr <<
"Found " << n <<
" in: " << btp->
name() << endl);
778#if STRUCTURE_ARRAY_SYNTAX_OLD
781 BaseType *found = btp->
var()->
var(n,
false, s);
783 DBG(cerr <<
"Found " << n <<
" in: " << btp->
var()->d_name() << endl);
794DDS::exact_match(
const string &name, BaseType::btp_stack *s)
796 for (Vars_iter i = vars.begin(); i != vars.end(); i++) {
798 DBG2(cerr <<
"Looking for " << d_name <<
" in: " << btp << endl);
800 if (btp->name() == name) {
801 DBG2(cerr <<
"Found " << d_name <<
" in: " << btp << endl);
806 string::size_type dot_pos = name.find(
".");
807 if (dot_pos != string::npos) {
808 string aggregate = name.substr(0, dot_pos);
809 string field = name.substr(dot_pos + 1);
811 BaseType *agg_ptr =
var(aggregate, s);
813 DBG2(cerr <<
"Descending into " << agg_ptr->name() << endl);
814 return agg_ptr->var(field,
true, s);
835 return vars.rbegin();
856 return vars.begin() + i;
865 return *(vars.begin() + i);
876 if (ptr->is_dap4_only_type())
877 throw InternalErr(__FILE__, __LINE__,
"Attempt to add a DAP4 type to a DAP2 DDS.");
893 if (ptr->is_dap4_only_type())
894 throw InternalErr(__FILE__, __LINE__,
"Attempt to add a DAP4 type to a DAP2 DDS.");
909#if USE_LOCAL_TIMEOUT_SCHEME
919#if USE_LOCAL_TIMEOUT_SCHEME
940#if USE_LOCAL_TIMEOUT_SCHEME
949#if USE_LOCAL_TIMEOUT_SCHEME
960 for (Vars_iter i = vars.begin(); i != vars.end(); i++) {
961 if ((*i)->type() == dods_sequence_c)
963 else if ((*i)->type() == dods_structure_c)
972 FILE *in = fopen(fname.c_str(),
"r");
975 throw Error(cannot_read_file,
"Could not open: " + fname);
994 int new_fd = _dup(fd);
996 int new_fd = dup(fd);
1000 throw InternalErr(__FILE__, __LINE__,
"Could not access file.");
1001 FILE *in = fdopen(new_fd,
"r");
1004 throw InternalErr(__FILE__, __LINE__,
"Could not access file.");
1027 throw InternalErr(__FILE__, __LINE__,
"Null input stream.");
1030 void *buffer = dds_buffer(in);
1031 dds_switch_to_buffer(buffer);
1035 bool status = ddsparse(&arg) == 0;
1037 dds_delete_buffer(buffer);
1039 DBG2(cout <<
"Status from parser: " << status << endl);
1043 if (!status || !arg.status()) {
1055 fwrite(oss.str().data(),
sizeof(
char), oss.str().length(), out);
1062 out <<
"Dataset {\n" ;
1064 for (Vars_citer i = vars.begin(); i != vars.end(); i++) {
1065 (*i)->print_decl(out) ;
1068 out <<
"} " <<
id2www(d_name) <<
";\n" ;
1095 vector<AttrTable*> tables;
1104 bool it_does =
false;
1105 for (vector<AttrTable*>::iterartor i = tables.begin(), e = tables.end(); it_does || i != e; ++i) {
1129 Grid* grid =
dynamic_cast<Grid*
>(btp);
1134 for (Constructor::Vars_iter i = cons->
var_begin(), e = cons->
var_end(); i != e; i++) {
1151static string four_spaces =
" ";
1152void print_var_das(ostream &out, BaseType *bt,
string indent =
"") {
1157 AttrTable attr_table = bt->get_attr_table();
1160 Constructor *cnstrctr =
dynamic_cast<Constructor *
>(bt);
1162 Grid *grid =
dynamic_cast<Grid *
>(bt);
1164 Array *gridArray = grid->get_array();
1165 AttrTable arrayAT = gridArray->get_attr_table();
1168 gridArray->get_attr_table().print(out, indent + four_spaces);
1172 for (Grid::Map_iter mIter = grid->map_begin();
1173 mIter != grid->map_end(); ++mIter) {
1174 BaseType *currentMap = *mIter;
1176 print_var_das(out, currentMap, indent + four_spaces);
1181 attr_table.print(out, indent + four_spaces);
1182 Constructor::Vars_iter i = cnstrctr->var_begin();
1183 Constructor::Vars_iter e = cnstrctr->var_end();
1184 for (; i != e; i++) {
1190 print_var_das(out, *i, indent + four_spaces);
1195 attr_table.print(out, indent + four_spaces);
1198 out << indent <<
"}" << endl;
1214 out <<
"Attributes {" << endl;
1215 for (Vars_citer i = vars.begin(); i != vars.end(); i++) {
1217 print_var_das(out, *i, four_spaces);
1220 d_attr.print(out,indent);
1252get_unique_top_level_global_container_name(
DAS *das)
1258 return TOP_LEVEL_ATTRS_CONTAINER_NAME;
1267 if (!(i < UINT_MAX))
1268 throw InternalErr(__FILE__, __LINE__,
"Cannot add top-level attributes to the DAS");
1269 name = TOP_LEVEL_ATTRS_CONTAINER_NAME + oss.str();
1286 Grid *grid =
dynamic_cast<Grid *
>(bt);
1291 for( AttrTable::Attr_iter atIter = arrayAT.
attr_begin(); atIter!=arrayAT.
attr_end(); ++atIter){
1293 string childName = arrayAT.
get_name(atIter);
1294 if (type == Attr_container){
1306 for (Constructor::Vars_iter i = cons->
var_begin(), e = cons->
var_end(); i != e; i++) {
1319 for (Vars_citer i = vars.begin(); i != vars.end(); i++) {
1321 AttrTable *childAttrT =
new AttrTable((*i)->get_attr_table());
1323 das->add_table((*i)->name(), childAttrT);
1328 auto_ptr<AttrTable> global(
new AttrTable);
1330 for (AttrTable::Attr_iter i = d_attr.attr_begin(); i != d_attr.attr_end(); ++i) {
1333 if (d_attr.get_attr_table(i)) {
1334 das->add_table(d_attr.get_name(i),
new AttrTable(*(d_attr.get_attr_table(i))));
1338 global->append_attr(d_attr.get_name(i), d_attr.get_type(i), d_attr.get_attr_vector(i));
1343 if (global->get_size() > 0) {
1344 das->add_table(get_unique_top_level_global_container_name(das), global.get());
1364 fwrite(oss.str().data(),
sizeof(
char), oss.str().length(), out);
1380 out <<
"Dataset {\n" ;
1382 for (Vars_citer i = vars.begin(); i != vars.end(); i++) {
1386 (*i)->print_decl(out,
" ",
true,
false,
true) ;
1389 out <<
"} " <<
id2www(d_name) <<
";\n" ;
1410 fwrite(oss.str().data(), 1, oss.str().length(), out);
1430class VariablePrintXMLWriter :
public unary_function<BaseType *, void>
1435 VariablePrintXMLWriter(
XMLWriter &xml,
bool constrained)
1436 : d_xml(xml), d_constrained(constrained)
1438 void operator()(BaseType *bt)
1440 bt->print_xml_writer(d_xml, d_constrained);
1475 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"Group") < 0)
1476 throw InternalErr(__FILE__, __LINE__,
"Could not write Group element");
1477 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)d_name.c_str()) < 0)
1478 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
1480 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"dapVersion", (
const xmlChar*)get_dap_version().c_str()) < 0)
1481 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for dapVersion");
1484 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:xml", (
const xmlChar*)c_xml_namespace.c_str()) < 0)
1485 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:xml");
1487 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xml:base", (
const xmlChar*)
get_request_xml_base().c_str()) < 0)
1488 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xml:base");
1491 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns", (
const xmlChar*)
get_namespace().c_str()) < 0)
1492 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns");
1496 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"Dataset") < 0)
1497 throw InternalErr(__FILE__, __LINE__,
"Could not write Dataset element");
1498 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)d_name.c_str()) < 0)
1499 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
1500 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:xsi", (
const xmlChar*)
"http://www.w3.org/2001/XMLSchema-instance") < 0)
1501 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:xsi");
1503 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xsi:schemaLocation", (
const xmlChar*)c_dap_32_n_sl.c_str()) < 0)
1504 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:schemaLocation");
1506 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:grddl", (
const xmlChar*)
"http://www.w3.org/2003/g/data-view#") < 0)
1507 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:grddl");
1509 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"grddl:transformation", (
const xmlChar*)grddl_transformation_dap32.c_str()) < 0)
1510 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:transformation");
1512 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns", (
const xmlChar*)c_dap32_namespace.c_str()) < 0)
1513 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns");
1514 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:dap", (
const xmlChar*)c_dap32_namespace.c_str()) < 0)
1515 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:dap");
1517 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"dapVersion", (
const xmlChar*)
"3.2") < 0)
1518 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for dapVersion");
1521 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:xml", (
const xmlChar*)c_xml_namespace.c_str()) < 0)
1522 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:xml");
1524 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xml:base", (
const xmlChar*)
get_request_xml_base().c_str()) < 0)
1525 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xml:base");
1529 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"Dataset") < 0)
1530 throw InternalErr(__FILE__, __LINE__,
"Could not write Dataset element");
1531 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)d_name.c_str()) < 0)
1532 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for d_name");
1533 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:xsi", (
const xmlChar*)
"http://www.w3.org/2001/XMLSchema-instance") < 0)
1534 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:xsi");
1536 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns", (
const xmlChar*)c_dap20_namespace.c_str()) < 0)
1537 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns");
1539 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xsi:schemaLocation", (
const xmlChar*)c_dap_20_n_sl.c_str()) < 0)
1540 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:schemaLocation");
1545 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"Dataset") < 0)
1546 throw InternalErr(__FILE__, __LINE__,
"Could not write Dataset element");
1547 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)d_name.c_str()) < 0)
1548 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for d_name");
1549 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:xsi", (
const xmlChar*)
"http://www.w3.org/2001/XMLSchema-instance") < 0)
1550 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:xsi");
1552 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns", (
const xmlChar*)c_dap20_namespace.c_str()) < 0)
1553 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns");
1555 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xsi:schemaLocation", (
const xmlChar*)c_dap_20_n_sl.c_str()) < 0)
1556 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:schemaLocation");
1560 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"Dataset") < 0)
1561 throw InternalErr(__FILE__, __LINE__,
"Could not write Dataset element");
1562 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)d_name.c_str()) < 0)
1563 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
1564 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:xsi", (
const xmlChar*)
"http://www.w3.org/2001/XMLSchema-instance") < 0)
1565 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:xsi");
1567 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xsi:schemaLocation", (
const xmlChar*)c_dap_32_n_sl.c_str()) < 0)
1568 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:schemaLocation");
1570 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:grddl", (
const xmlChar*)
"http://www.w3.org/2003/g/data-view#") < 0)
1571 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:grddl");
1573 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"grddl:transformation", (
const xmlChar*)grddl_transformation_dap32.c_str()) < 0)
1574 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:transformation");
1576 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns", (
const xmlChar*)c_dap32_namespace.c_str()) < 0)
1577 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns");
1578 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:dap", (
const xmlChar*)c_dap32_namespace.c_str()) < 0)
1579 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:dap");
1581 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"dapVersion", (
const xmlChar*)
"3.2") < 0)
1582 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for dapVersion");
1585 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:xml", (
const xmlChar*)c_xml_namespace.c_str()) < 0)
1586 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:xml");
1588 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xml:base", (
const xmlChar*)
get_request_xml_base().c_str()) < 0)
1589 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xml:base");
1592#error Must define DAP2_DDX or DAP3_2_DDX
1596 d_attr.print_xml_writer(xml);
1599 for_each(
var_begin(),
var_end(), VariablePrintXMLWriter(xml, constrained));
1609 if (!blob.empty()) {
1610 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"blob") < 0)
1611 throw InternalErr(__FILE__, __LINE__,
"Could not write blob element");
1612 string cid =
"cid:" + blob;
1613 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"href", (
const xmlChar*) cid.c_str()) < 0)
1614 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for d_name");
1615 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
1616 throw InternalErr(__FILE__, __LINE__,
"Could not end blob element");
1620 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"blob") < 0)
1621 throw InternalErr(__FILE__, __LINE__,
"Could not write blob element");
1622 string cid =
"cid:" + blob;
1623 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"href", (
const xmlChar*) cid.c_str()) < 0)
1624 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for d_name");
1625 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
1626 throw InternalErr(__FILE__, __LINE__,
"Could not end blob element");
1629 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"dataBLOB") < 0)
1630 throw InternalErr(__FILE__, __LINE__,
"Could not write dataBLOB element");
1631 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"href", (
const xmlChar*)
"") < 0)
1632 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for d_name");
1633 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
1634 throw InternalErr(__FILE__, __LINE__,
"Could not end dataBLOB element");
1639 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"dataBLOB") < 0)
1640 throw InternalErr(__FILE__, __LINE__,
"Could not write dataBLOB element");
1641 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"href", (
const xmlChar*)
"") < 0)
1642 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for d_name");
1643 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
1644 throw InternalErr(__FILE__, __LINE__,
"Could not end dataBLOB element");
1646 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"blob") < 0)
1647 throw InternalErr(__FILE__, __LINE__,
"Could not write blob element");
1648 string cid =
"cid:" + blob;
1649 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"href", (
const xmlChar*) cid.c_str()) < 0)
1650 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for d_name");
1651 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
1652 throw InternalErr(__FILE__, __LINE__,
"Could not end blob element");
1654 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
1655 throw InternalErr(__FILE__, __LINE__,
"Could not end Dataset element");
1657#error Must define DAP2_DDX or DAP3_2_DDX
1660 out << xml.get_doc();
1680 throw InternalErr(__FILE__, __LINE__,
"Tried to print a DMR with DAP major version less than 4");
1685 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"Group") < 0)
1686 throw InternalErr(__FILE__, __LINE__,
"Could not write Group element");
1688 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:xml",
1689 (
const xmlChar*) c_xml_namespace.c_str()) < 0)
1690 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:xml");
1692 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:xsi", (
const xmlChar*) c_xml_xsi.c_str())
1694 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:xsi");
1696 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xsi:schemaLocation",
1697 (
const xmlChar*) c_dap_40_n_sl.c_str()) < 0)
1698 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:schemaLocation");
1700 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns",
1702 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns");
1704 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"dapVersion",
1705 (
const xmlChar*) get_dap_version().c_str()) < 0)
1706 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for dapVersion");
1708 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"dmrVersion", (
const xmlChar*) get_dmr_version().c_str()) < 0)
1709 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for dapVersion");
1712 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xml:base",
1714 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xml:base");
1717 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*) d_name.c_str()) < 0)
1718 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
1721 d_attr.print_xml_writer(xml);
1724 for_each(
var_begin(),
var_end(), VariablePrintXMLWriter(xml, constrained));
1726 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
1727 throw InternalErr(__FILE__, __LINE__,
"Could not end the top-level Group element");
1729 out << xml.get_doc();
1752 cerr <<
"A dataset must have a d_name" << endl;
1757 if (!unique_names(vars, d_name,
"Dataset", msg))
1761 for (Vars_iter i = vars.begin(); i != vars.end(); i++)
1762 if (!(*i)->check_semantics(msg,
true))
1796 BaseType::btp_stack *s =
new BaseType::btp_stack;
1799 auto_ptr<BaseType::btp_stack> s(
new BaseType::btp_stack);
1801 DBG2(cerr <<
"DDS::mark: Looking for " << n << endl);
1805 throw Error(malformed_expr,
"Could not find variable " + n);
1807 DBG2(cerr <<
"Could not find variable " << n << endl);
1816 DBG2(cerr <<
"DDS::mark: Set variable " << variable->d_name()
1817 <<
" (a " << variable->
type_name() <<
")" << endl);
1823 while (!s->empty()) {
1824 s->top()->BaseType::set_send_p(state);
1826 DBG2(cerr <<
"DDS::mark: Set variable " << s->top()->d_name()
1827 <<
" (a " << s->top()->type_name() <<
")" << endl);
1829 string parent_name = (s->top()->get_parent()) ? s->top()->get_parent()->name():
"none";
1830 string parent_type = (s->top()->get_parent()) ? s->top()->get_parent()->type_name():
"none";
1831 DBG2(cerr <<
"DDS::mark: Parent variable " << parent_name <<
" (a " << parent_type <<
")" << endl);
1851 for (Vars_iter i = vars.begin(); i != vars.end(); i++)
1852 (*i)->set_send_p(state);
1865 strm << DapIndent::LMarg <<
"DDS::dump - ("
1866 << (
void *)
this <<
")" << endl ;
1867 DapIndent::Indent() ;
1868 strm << DapIndent::LMarg <<
"d_name: " << d_name << endl ;
1869 strm << DapIndent::LMarg <<
"filename: " << d_filename << endl ;
1870 strm << DapIndent::LMarg <<
"protocol major: " << d_dap_major << endl;
1871 strm << DapIndent::LMarg <<
"protocol minor: " << d_dap_minor << endl;
1872 strm << DapIndent::LMarg <<
"factory: " << (
void *)d_factory << endl ;
1874 strm << DapIndent::LMarg <<
"global attributes:" << endl ;
1875 DapIndent::Indent() ;
1877 DapIndent::UnIndent() ;
1880 strm << DapIndent::LMarg <<
"vars:" << endl ;
1881 DapIndent::Indent() ;
1882 Vars_citer i = vars.begin() ;
1883 Vars_citer ie = vars.end() ;
1884 for (; i != ie; i++) {
1887 DapIndent::UnIndent() ;
1890 strm << DapIndent::LMarg <<
"vars: none" << endl ;
1893 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 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)
virtual BaseType * ptr_duplicate()=0
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.