40 #include <sys/types.h> 65 #include "InternalErr.h" 67 #include "Keywords2.h" 73 #include "DapIndent.h" 85 #include "Structure.h" 96 const string c_xml_xsi =
"http://www.w3.org/2001/XMLSchema-instance";
97 const string c_xml_namespace =
"http://www.w3.org/XML/1998/namespace";
99 const string grddl_transformation_dap32 =
"http://xml.opendap.org/transforms/ddxToRdfTriples.xsl";
101 const string c_default_dap20_schema_location =
"http://xml.opendap.org/dap/dap2.xsd";
102 const string c_default_dap32_schema_location =
"http://xml.opendap.org/dap/dap3.2.xsd";
103 const string c_default_dap40_schema_location =
"http://xml.opendap.org/dap/dap4.0.xsd";
105 const string c_dap20_namespace =
"http://xml.opendap.org/ns/DAP2";
106 const string c_dap32_namespace =
"http://xml.opendap.org/ns/DAP/3.2#";
107 const string c_dap40_namespace =
"http://xml.opendap.org/ns/DAP/4.0#";
109 const string c_dap_20_n_sl = c_dap20_namespace +
" " + c_default_dap20_schema_location;
110 const string c_dap_32_n_sl = c_dap32_namespace +
" " + c_default_dap32_schema_location;
111 const string c_dap_40_n_sl = c_dap40_namespace +
" " + c_default_dap40_schema_location;
116 const string TOP_LEVEL_ATTRS_CONTAINER_NAME =
"DAP4_GLOBAL";
123 void dds_switch_to_buffer(
void *new_buffer);
124 void dds_delete_buffer(
void * buffer);
125 void *dds_buffer(FILE *fp);
130 DDS::duplicate(
const DDS &dds)
132 DBG(cerr <<
"Entering DDS::duplicate... " <<endl);
134 BaseTypeFactory *d_factory;
138 string d_container_name;
139 Structure *d_container;
144 string d_dap_version;
145 string d_request_xml_base;
150 vector<BaseType *> vars;
157 long d_max_response_size;
160 d_factory = dds.d_factory;
163 d_filename = dds.d_filename;
164 d_container_name = dds.d_container_name;
165 d_container = dds.d_container;
167 d_dap_major = dds.d_dap_major;
168 d_dap_minor = dds.d_dap_minor;
170 d_dap_version = dds.d_dap_version;
171 d_request_xml_base = dds.d_request_xml_base;
172 d_namespace = dds.d_namespace;
176 DDS &dds_tmp =
const_cast<DDS &
>(dds);
179 for (Vars_iter i = dds_tmp.var_begin(); i != dds_tmp.var_end(); i++) {
183 d_timeout = dds.d_timeout;
186 d_keywords = dds.d_keywords;
189 d_max_response_size = dds.d_max_response_size;
205 : d_factory(factory), d_name(name), d_container_name(
""), d_container(0),
206 d_request_xml_base(
""),
207 d_timeout(0), d_max_response_size(0)
209 DBG(cerr <<
"Building a DDS for the default version (2.0)" << endl);
232 : d_factory(factory), d_name(name), d_container_name(
""), d_container(0),
233 d_request_xml_base(
""),
234 d_timeout(0), d_max_response_size(0)
236 DBG(cerr <<
"Building a DDS for version: " << version << endl);
246 DBG(cerr <<
"Entering DDS(const DDS &rhs) ..." << endl);
248 DBG(cerr <<
" bye." << endl);
254 for (Vars_iter i = vars.begin(); i != vars.end(); i++) {
256 delete btp ; btp = 0;
261 DDS::operator=(
const DDS &rhs)
263 DBG(cerr <<
"Entering DDS::operator= ..." << endl);
269 DBG(cerr <<
" bye." << endl);
294 "Error transferring attributes: working on a container in dds, but not das");
300 (*i)->transfer_attributes(top);
306 DBG(cerr <<
"Processing the attributes for: " << (*var)->d_name() <<
" a " << (*var)->type_name() << endl);
307 (*var)->transfer_attributes(top);
320 if ((*i)->type == Attr_container && (*i)->attributes->is_global_attribute()) {
324 d_attr.append_container(at, at->
get_name());
328 AttrTable::Attr_iter at_cont_p = top_level->attr_begin();
329 while (at_cont_p != top_level->attr_end()) {
333 if ((*at_cont_p)->type == Attr_container && (*at_cont_p)->attributes->is_global_attribute()) {
334 DBG(cerr << (*at_cont_p)->d_name <<
" is a global attribute." << endl);
338 d_attr.append_container(at, at->
get_name());
412 if (d_dap_minor >= 0) {
414 oss << d_dap_major <<
"." << d_dap_minor;
415 d_dap_version = oss.str();
427 if (d_dap_major >= 0) {
429 oss << d_dap_major <<
"." << d_dap_minor;
430 d_dap_version = oss.str();
442 istringstream iss(v);
444 int major = -1, minor = -1;
446 if (!iss.eof() && !iss.fail())
448 if (!iss.eof() && !iss.fail())
450 if (!iss.eof() && !iss.fail())
453 if (major == -1 || minor == -1 or dot !=
'.')
454 throw InternalErr(__FILE__, __LINE__,
"Could not parse dap version. Value given: " + v);
465 switch (d_dap_major) {
467 d_namespace = c_dap20_namespace;
470 d_namespace = c_dap32_namespace;
473 d_namespace = c_dap40_namespace;
476 throw InternalErr(__FILE__, __LINE__,
"Unknown DAP version.");
490 int major = floor(d);
491 int minor = (d-major)*10;
493 DBG(cerr <<
"Major: " << major <<
", Minor: " << minor << endl);
496 oss << major <<
"." << minor;
513 return d_container_name;
541 d_container_name = cn;
568 for (Vars_iter i = vars.begin(); i != vars.end(); i++) {
571 w += (*i)->width(constrained);
574 w += (*i)->width(constrained);
588 throw InternalErr(__FILE__, __LINE__,
"Trying to add a BaseType object with a NULL pointer.");
590 if (bt->is_dap4_only_type())
591 throw InternalErr(__FILE__, __LINE__,
"Attempt to add a DAP4 type to a DAP2 DDS.");
593 DBG2(cerr <<
"In DDS::add_var(), bt's address is: " << bt << endl);
596 DBG2(cerr <<
"In DDS::add_var(), btp's address is: " << btp << endl);
600 d_container->add_var(bt);
616 throw InternalErr(__FILE__, __LINE__,
"Trying to add a BaseType object with a NULL pointer.");
618 DBG2(cerr <<
"In DDS::add_var(), bt's address is: " << bt << endl);
621 d_container->add_var_nocopy(bt);
640 d_container->del_var( n ) ;
644 for (Vars_iter i = vars.begin(); i != vars.end(); i++) {
645 if ((*i)->name() == n) {
661 if (i != vars.end()) {
677 for (Vars_iter i_tmp = i1; i_tmp != i2; i_tmp++) {
720 return d_container->var( name,
false, s ) ;
726 return leaf_match(name, s);
730 DDS::leaf_match(
const string &n, BaseType::btp_stack *s)
732 DBG(cerr <<
"DDS::leaf_match: Looking for " << n << endl);
734 for (Vars_iter i = vars.begin(); i != vars.end(); i++) {
736 DBG(cerr <<
"DDS::leaf_match: Looking for " << n <<
" in: " << btp->
name() << endl);
738 if (btp->
name() == n) {
739 DBG(cerr <<
"Found " << n <<
" in: " << btp->
name() << endl);
746 DBG(cerr <<
"Found " << n <<
" in: " << btp->
name() << endl);
750 #if STRUCTURE_ARRAY_SYNTAX_OLD 755 DBG(cerr <<
"Found " << n <<
" in: " << btp->
var()->d_name() << endl);
766 DDS::exact_match(
const string &name, BaseType::btp_stack *s)
768 for (Vars_iter i = vars.begin(); i != vars.end(); i++) {
770 DBG2(cerr <<
"Looking for " << d_name <<
" in: " << btp << endl);
772 if (btp->
name() == name) {
773 DBG2(cerr <<
"Found " << d_name <<
" in: " << btp << endl);
778 string::size_type dot_pos = name.find(
".");
779 if (dot_pos != string::npos) {
780 string aggregate = name.substr(0, dot_pos);
781 string field = name.substr(dot_pos + 1);
785 DBG2(cerr <<
"Descending into " << agg_ptr->
name() << endl);
786 return agg_ptr->
var(field,
true, s);
807 return vars.rbegin();
828 return vars.begin() + i;
837 return *(vars.begin() + i);
848 if (ptr->is_dap4_only_type())
849 throw InternalErr(__FILE__, __LINE__,
"Attempt to add a DAP4 type to a DAP2 DDS.");
865 if (ptr->is_dap4_only_type())
866 throw InternalErr(__FILE__, __LINE__,
"Attempt to add a DAP4 type to a DAP2 DDS.");
881 #if USE_LOCAL_TIMEOUT_SCHEME 891 #if USE_LOCAL_TIMEOUT_SCHEME 910 DDS::set_timeout(
int)
912 #if USE_LOCAL_TIMEOUT_SCHEME 921 #if USE_LOCAL_TIMEOUT_SCHEME 932 for (Vars_iter i = vars.begin(); i != vars.end(); i++) {
933 if ((*i)->type() == dods_sequence_c)
934 dynamic_cast<Sequence&>(**i).set_leaf_sequence();
935 else if ((*i)->type() == dods_structure_c)
936 dynamic_cast<Structure&>(**i).set_leaf_sequence();
944 FILE *in = fopen(fname.c_str(),
"r");
947 throw Error(cannot_read_file,
"Could not open: " + fname);
966 int new_fd = _dup(fd);
968 int new_fd = dup(fd);
972 throw InternalErr(__FILE__, __LINE__,
"Could not access file.");
973 FILE *in = fdopen(new_fd,
"r");
976 throw InternalErr(__FILE__, __LINE__,
"Could not access file.");
999 throw InternalErr(__FILE__, __LINE__,
"Null input stream.");
1002 void *buffer = dds_buffer(in);
1003 dds_switch_to_buffer(buffer);
1007 bool status = ddsparse(&arg) == 0;
1009 dds_delete_buffer(buffer);
1011 DBG2(cout <<
"Status from parser: " << status << endl);
1015 if (!status || !arg.status()) {
1027 fwrite(oss.str().data(),
sizeof(char), oss.str().length(), out);
1034 out <<
"Dataset {\n" ;
1036 for (Vars_citer i = vars.begin(); i != vars.end(); i++) {
1037 (*i)->print_decl(out) ;
1040 out <<
"} " <<
id2www(d_name) <<
";\n" ;
1067 vector<AttrTable*> tables;
1076 bool it_does =
false;
1077 for (vector<AttrTable*>::iterartor i = tables.begin(), e = tables.end(); it_does || i != e; ++i) {
1101 Grid* grid =
dynamic_cast<Grid*
>(btp);
1106 for (Constructor::Vars_iter i = cons->
var_begin(), e = cons->
var_end(); i != e; i++) {
1123 static string four_spaces =
" ";
1124 void print_var_das(ostream &out,
BaseType *bt,
string indent =
"") {
1134 Grid *grid =
dynamic_cast<Grid *
>(bt);
1144 for (Grid::Map_iter mIter = grid->
map_begin();
1145 mIter != grid->
map_end(); ++mIter) {
1148 print_var_das(out, currentMap, indent + four_spaces);
1153 attr_table.
print(out, indent + four_spaces);
1154 Constructor::Vars_iter i = cnstrctr->var_begin();
1155 Constructor::Vars_iter e = cnstrctr->var_end();
1156 for (; i != e; i++) {
1162 print_var_das(out, *i, indent + four_spaces);
1167 attr_table.
print(out, indent + four_spaces);
1170 out << indent <<
"}" << endl;
1186 out <<
"Attributes {" << endl;
1187 for (Vars_citer i = vars.begin(); i != vars.end(); i++) {
1189 print_var_das(out, *i, four_spaces);
1192 d_attr.print(out,indent);
1224 get_unique_top_level_global_container_name(
DAS *das)
1230 return TOP_LEVEL_ATTRS_CONTAINER_NAME;
1239 if (!(i < UINT_MAX))
1240 throw InternalErr(__FILE__, __LINE__,
"Cannot add top-level attributes to the DAS");
1241 name = TOP_LEVEL_ATTRS_CONTAINER_NAME + oss.str();
1258 Grid *grid =
dynamic_cast<Grid *
>(bt);
1263 for( AttrTable::Attr_iter atIter = arrayAT.
attr_begin(); atIter!=arrayAT.
attr_end(); ++atIter){
1265 string childName = arrayAT.
get_name(atIter);
1266 if (type == Attr_container){
1278 for (Constructor::Vars_iter i = cons->
var_begin(), e = cons->
var_end(); i != e; i++) {
1291 for (Vars_citer i = vars.begin(); i != vars.end(); i++) {
1295 das->
add_table((*i)->name(), childAttrT);
1300 auto_ptr<AttrTable> global(
new AttrTable);
1302 for (AttrTable::Attr_iter i = d_attr.attr_begin(); i != d_attr.attr_end(); ++i) {
1305 if (d_attr.get_attr_table(i)) {
1310 global->append_attr(d_attr.get_name(i), d_attr.get_type(i), d_attr.get_attr_vector(i));
1315 if (global->get_size() > 0) {
1316 das->
add_table(get_unique_top_level_global_container_name(das), global.get());
1336 fwrite(oss.str().data(),
sizeof(char), oss.str().length(), out);
1352 out <<
"Dataset {\n" ;
1354 for (Vars_citer i = vars.begin(); i != vars.end(); i++) {
1358 (*i)->print_decl(out,
" ",
true,
false,
true) ;
1361 out <<
"} " <<
id2www(d_name) <<
";\n" ;
1382 fwrite(oss.str().data(), 1, oss.str().length(), out);
1402 class VariablePrintXMLWriter :
public unary_function<BaseType *, void>
1407 VariablePrintXMLWriter(
XMLWriter &xml,
bool constrained)
1408 : d_xml(xml), d_constrained(constrained)
1447 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"Group") < 0)
1448 throw InternalErr(__FILE__, __LINE__,
"Could not write Group element");
1449 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)d_name.c_str()) < 0)
1450 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
1452 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"dapVersion", (
const xmlChar*)get_dap_version().c_str()) < 0)
1453 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for dapVersion");
1456 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:xml", (
const xmlChar*)c_xml_namespace.c_str()) < 0)
1457 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:xml");
1459 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xml:base", (
const xmlChar*)
get_request_xml_base().c_str()) < 0)
1460 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xml:base");
1463 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns", (
const xmlChar*)
get_namespace().c_str()) < 0)
1464 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns");
1468 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"Dataset") < 0)
1469 throw InternalErr(__FILE__, __LINE__,
"Could not write Dataset element");
1470 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)d_name.c_str()) < 0)
1471 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
1472 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:xsi", (
const xmlChar*)
"http://www.w3.org/2001/XMLSchema-instance") < 0)
1473 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:xsi");
1475 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xsi:schemaLocation", (
const xmlChar*)c_dap_32_n_sl.c_str()) < 0)
1476 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:schemaLocation");
1478 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:grddl", (
const xmlChar*)
"http://www.w3.org/2003/g/data-view#") < 0)
1479 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:grddl");
1481 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"grddl:transformation", (
const xmlChar*)grddl_transformation_dap32.c_str()) < 0)
1482 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:transformation");
1484 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns", (
const xmlChar*)c_dap32_namespace.c_str()) < 0)
1485 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns");
1486 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:dap", (
const xmlChar*)c_dap32_namespace.c_str()) < 0)
1487 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:dap");
1489 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"dapVersion", (
const xmlChar*)
"3.2") < 0)
1490 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for dapVersion");
1493 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:xml", (
const xmlChar*)c_xml_namespace.c_str()) < 0)
1494 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:xml");
1496 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xml:base", (
const xmlChar*)
get_request_xml_base().c_str()) < 0)
1497 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xml:base");
1501 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"Dataset") < 0)
1502 throw InternalErr(__FILE__, __LINE__,
"Could not write Dataset element");
1503 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)d_name.c_str()) < 0)
1504 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for d_name");
1505 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:xsi", (
const xmlChar*)
"http://www.w3.org/2001/XMLSchema-instance") < 0)
1506 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:xsi");
1508 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns", (
const xmlChar*)c_dap20_namespace.c_str()) < 0)
1509 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns");
1511 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xsi:schemaLocation", (
const xmlChar*)c_dap_20_n_sl.c_str()) < 0)
1512 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:schemaLocation");
1517 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"Dataset") < 0)
1518 throw InternalErr(__FILE__, __LINE__,
"Could not write Dataset element");
1519 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)d_name.c_str()) < 0)
1520 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for d_name");
1521 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:xsi", (
const xmlChar*)
"http://www.w3.org/2001/XMLSchema-instance") < 0)
1522 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:xsi");
1524 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns", (
const xmlChar*)c_dap20_namespace.c_str()) < 0)
1525 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns");
1527 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xsi:schemaLocation", (
const xmlChar*)c_dap_20_n_sl.c_str()) < 0)
1528 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:schemaLocation");
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 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*)
"xsi:schemaLocation", (
const xmlChar*)c_dap_32_n_sl.c_str()) < 0)
1540 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:schemaLocation");
1542 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:grddl", (
const xmlChar*)
"http://www.w3.org/2003/g/data-view#") < 0)
1543 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:grddl");
1545 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"grddl:transformation", (
const xmlChar*)grddl_transformation_dap32.c_str()) < 0)
1546 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:transformation");
1548 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns", (
const xmlChar*)c_dap32_namespace.c_str()) < 0)
1549 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns");
1550 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:dap", (
const xmlChar*)c_dap32_namespace.c_str()) < 0)
1551 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:dap");
1553 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"dapVersion", (
const xmlChar*)
"3.2") < 0)
1554 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for dapVersion");
1557 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:xml", (
const xmlChar*)c_xml_namespace.c_str()) < 0)
1558 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:xml");
1560 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xml:base", (
const xmlChar*)
get_request_xml_base().c_str()) < 0)
1561 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xml:base");
1564 #error Must define DAP2_DDX or DAP3_2_DDX 1568 d_attr.print_xml_writer(xml);
1571 for_each(
var_begin(),
var_end(), VariablePrintXMLWriter(xml, constrained));
1581 if (!blob.empty()) {
1582 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"blob") < 0)
1583 throw InternalErr(__FILE__, __LINE__,
"Could not write blob element");
1584 string cid =
"cid:" + blob;
1585 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"href", (
const xmlChar*) cid.c_str()) < 0)
1586 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for d_name");
1587 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
1588 throw InternalErr(__FILE__, __LINE__,
"Could not end blob element");
1592 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"blob") < 0)
1593 throw InternalErr(__FILE__, __LINE__,
"Could not write blob element");
1594 string cid =
"cid:" + blob;
1595 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"href", (
const xmlChar*) cid.c_str()) < 0)
1596 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for d_name");
1597 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
1598 throw InternalErr(__FILE__, __LINE__,
"Could not end blob element");
1601 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"dataBLOB") < 0)
1602 throw InternalErr(__FILE__, __LINE__,
"Could not write dataBLOB element");
1603 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"href", (
const xmlChar*)
"") < 0)
1604 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for d_name");
1605 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
1606 throw InternalErr(__FILE__, __LINE__,
"Could not end dataBLOB element");
1611 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"dataBLOB") < 0)
1612 throw InternalErr(__FILE__, __LINE__,
"Could not write dataBLOB element");
1613 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"href", (
const xmlChar*)
"") < 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 dataBLOB element");
1618 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"blob") < 0)
1619 throw InternalErr(__FILE__, __LINE__,
"Could not write blob element");
1620 string cid =
"cid:" + blob;
1621 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"href", (
const xmlChar*) cid.c_str()) < 0)
1622 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for d_name");
1623 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
1624 throw InternalErr(__FILE__, __LINE__,
"Could not end blob element");
1626 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
1627 throw InternalErr(__FILE__, __LINE__,
"Could not end Dataset element");
1629 #error Must define DAP2_DDX or DAP3_2_DDX 1632 out << xml.get_doc();
1652 throw InternalErr(__FILE__, __LINE__,
"Tried to print a DMR with DAP major version less than 4");
1657 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"Group") < 0)
1658 throw InternalErr(__FILE__, __LINE__,
"Could not write Group element");
1660 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:xml",
1661 (
const xmlChar*) c_xml_namespace.c_str()) < 0)
1662 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:xml");
1664 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns:xsi", (
const xmlChar*) c_xml_xsi.c_str())
1666 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:xsi");
1668 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xsi:schemaLocation",
1669 (
const xmlChar*) c_dap_40_n_sl.c_str()) < 0)
1670 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:schemaLocation");
1672 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns",
1674 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns");
1676 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"dapVersion",
1677 (
const xmlChar*) get_dap_version().c_str()) < 0)
1678 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for dapVersion");
1680 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"dmrVersion", (
const xmlChar*) get_dmr_version().c_str()) < 0)
1681 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for dapVersion");
1684 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xml:base",
1686 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xml:base");
1689 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*) d_name.c_str()) < 0)
1690 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
1693 d_attr.print_xml_writer(xml);
1696 for_each(
var_begin(),
var_end(), VariablePrintXMLWriter(xml, constrained));
1698 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
1699 throw InternalErr(__FILE__, __LINE__,
"Could not end the top-level Group element");
1701 out << xml.get_doc();
1724 cerr <<
"A dataset must have a d_name" << endl;
1729 if (!unique_names(vars, d_name,
"Dataset", msg))
1733 for (Vars_iter i = vars.begin(); i != vars.end(); i++)
1734 if (!(*i)->check_semantics(msg,
true))
1768 BaseType::btp_stack *s =
new BaseType::btp_stack;
1771 auto_ptr<BaseType::btp_stack> s(
new BaseType::btp_stack);
1773 DBG2(cerr <<
"DDS::mark: Looking for " << n << endl);
1777 throw Error(malformed_expr,
"Could not find variable " + n);
1779 DBG2(cerr <<
"Could not find variable " << n << endl);
1788 DBG2(cerr <<
"DDS::mark: Set variable " << variable->d_name()
1789 <<
" (a " << variable->
type_name() <<
")" << endl);
1795 while (!s->empty()) {
1796 s->top()->BaseType::set_send_p(state);
1798 DBG2(cerr <<
"DDS::mark: Set variable " << s->top()->d_name()
1799 <<
" (a " << s->top()->type_name() <<
")" << endl);
1801 string parent_name = (s->top()->get_parent()) ? s->top()->get_parent()->name():
"none";
1802 string parent_type = (s->top()->get_parent()) ? s->top()->get_parent()->type_name():
"none";
1803 DBG2(cerr <<
"DDS::mark: Parent variable " << parent_name <<
" (a " << parent_type <<
")" << endl);
1823 for (Vars_iter i = vars.begin(); i != vars.end(); i++)
1824 (*i)->set_send_p(state);
1837 strm << DapIndent::LMarg <<
"DDS::dump - (" 1838 << (
void *)
this <<
")" << endl ;
1839 DapIndent::Indent() ;
1840 strm << DapIndent::LMarg <<
"d_name: " << d_name << endl ;
1841 strm << DapIndent::LMarg <<
"filename: " << d_filename << endl ;
1842 strm << DapIndent::LMarg <<
"protocol major: " << d_dap_major << endl;
1843 strm << DapIndent::LMarg <<
"protocol minor: " << d_dap_minor << endl;
1844 strm << DapIndent::LMarg <<
"factory: " << (
void *)d_factory << endl ;
1846 strm << DapIndent::LMarg <<
"global attributes:" << endl ;
1847 DapIndent::Indent() ;
1849 DapIndent::UnIndent() ;
1852 strm << DapIndent::LMarg <<
"vars:" << endl ;
1853 DapIndent::Indent() ;
1854 Vars_citer i = vars.begin() ;
1855 Vars_citer ie = vars.end() ;
1856 for (; i != ie; i++) {
1859 DapIndent::UnIndent() ;
1862 strm << DapIndent::LMarg <<
"vars: none" << endl ;
1865 DapIndent::UnIndent() ;
virtual string name() const
Returns the name of the class instance.
AttrTable * get_table(AttrTable::Attr_iter &i)
Returns the referenced variable attribute table.
void print(FILE *out)
Print the entire DDS to the specified file.
virtual Attr_iter attr_end()
void insert_var_nocopy(Vars_iter i, BaseType *ptr)
Contains the attributes for a dataset.
Vars_iter get_vars_iter(int i)
Get an iterator.
string AttrType_to_String(const AttrType at)
void insert_var(Vars_iter i, BaseType *ptr)
Insert a variable before the referenced element.
Vars_iter var_begin()
Return an iterator to the first variable.
virtual void print_xml_writer(XMLWriter &xml, bool constrained=false)
string add_space_encoding(const string &s)
virtual string get_name() const
Get the name of this attribute table.
virtual AttrTable * add_table(const string &name, AttrTable *at)
Adds a variable attribute table to the DAS or the current dataset container attribute table...
DDS(BaseTypeFactory *factory, const string &name="")
int get_request_size(bool constrained)
Get the estimated response size.
BaseType * var(const string &n, BaseType::btp_stack &s)
virtual void transfer_attributes(DAS *das)
void print_xml(FILE *out, bool constrained, const string &blob="")
virtual void print(FILE *out, string pad=" ", bool dereference=false)
Prints the attribute table.
void print_xml_writer(ostream &out, bool constrained, const string &blob="")
void add_var_nocopy(BaseType *bt)
Adds the variable to the DDS.
Holds a structure (aggregate) type.
Vars_riter var_rend()
Return a reverse iterator.
string get_dataset_name() const
int num_var()
Returns the number of variables in the DDS.
DAS * get_das()
Get a DAS object.
top level DAP object to house generic methods
bool mark(const string &name, bool state)
Mark the send_p flag of the named variable to state.
A class for software fault reporting.
void parse(string fname)
Parse a DDS from a file with the given d_name.
Map_iter map_begin()
Returns an iterator referencing the first Map vector.
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 void set_send_p(bool state)
virtual bool is_constructor_type() const
Returns true if the instance is a constructor (i.e., Structure, Sequence or Grid) type variable...
void mark_all(bool state)
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.
void print_das(ostream &out)
write the DAS response given the attribute information in the DDS
Holds the Grid data type.
void print_dmr(ostream &out, bool constrained)
Print the DAP4 DMR object using a DDS.
virtual AttrTable & get_attr_table()
BaseType * get_var_index(int i)
Get a variable.
bool check_semantics(bool all=false)
Check the semantics of each of the variables represented in the DDS.
Array * get_array()
Returns the Grid Array. This method returns the array using an Array*, so no cast is required...
int get_dap_major() const
Get the DAP major version as sent by the client.
string get_request_xml_base() const
Get the URL that will return this DDS/DDX/DataThing.
std::string get_error_message() const
virtual AttrTable * get_top_level_attributes()
Returns the top most set of attributes.
virtual void dump(ostream &strm) const
dumps information about this object
virtual Attr_iter attr_begin()
virtual string container_name() const
Returns the name of the current attribute container when multiple files used to build this DAS...
virtual BaseType * ptr_duplicate()=0
string get_namespace() const
Get the namespace associated with the DDS - likely set only by DDX responses.
string www2id(const string &in, const string &escape, const string &except)
bool has_dap2_attributes(AttrTable &a)
Vars_iter var_end()
Return an iterator.
void tag_nested_sequences()
Traverse DDS, set Sequence leaf nodes.
virtual AttrTable & get_attr_table()
void set_dap_minor(int p)
virtual unsigned int append_attr(const string &name, const string &type, const string &value)
Add an attribute to the table.
void set_dataset_name(const string &n)
The basic data type for the DODS DAP types.
libdap base object for common functionality of libdap objects
Pass parameters by reference to a parser.
virtual AttrType get_attr_type(const string &name)
Get the type of an attribute.
void del_var(const string &n)
Removes a variable from the DDS.
virtual string type_name() const
Returns the type of the class instance as a string.
Vars_riter var_rbegin()
Return a reverse iterator.
virtual vector< string > * get_attr_vector(const string &name)
Get a vector-valued attribute.
Hold attribute data for a DAP2 dataset.
A class for error processing.
virtual unsigned int get_size() const
Get the number of entries in this attribute table.
void fillConstructorAttrTable(AttrTable *at, BaseType *bt)
Recursive helper function for Building DAS entries for Constructor types.
int get_dap_minor() const
Get the DAP minor version as sent by the client.
void set_dap_major(int p)
A multidimensional array of identical data types.
void print_constrained(FILE *out)
Print a constrained DDS to the specified file.
void set_dap_version(const string &version_string="2.0")
string id2www(string in, const string &allowable)
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 ...