30#include "W10nJsonTransform.h" 
   40using std::ostringstream;
 
   41using std::istringstream;
 
   43#include <libdap/DDS.h> 
   44#include <libdap/Type.h> 
   45#include <libdap/Structure.h> 
   46#include <libdap/Constructor.h> 
   47#include <libdap/Array.h> 
   48#include <libdap/Grid.h> 
   49#include <libdap/Str.h> 
   50#include <libdap/Sequence.h> 
   51#include <libdap/Str.h> 
   52#include <libdap/Url.h> 
   55#include <BESInternalError.h> 
   56#include <BESContextManager.h> 
   57#include <BESSyntaxUserError.h> 
   59#include <w10n_utils.h> 
   66unsigned int W10nJsonTransform::json_simple_type_array_worker(
ostream *strm, T *values,
 
   69    if (currentDim == 0 || !flatten) *strm << 
"[";
 
   71    unsigned int currentDimSize = (*shape)[currentDim];
 
   73    for (
unsigned int i = 0; i < currentDimSize; i++) {
 
   74        if (currentDim < shape->size() - 1) {
 
   75            indx = json_simple_type_array_worker<T>(strm, values, indx, shape, currentDim + 1, flatten);
 
   76            if (i + 1 != currentDimSize) *strm << 
", ";
 
   80            if (
typeid(T) == 
typeid(std::string)) {
 
   83                std::string val = 
reinterpret_cast<std::string*
>(values)[indx++];
 
   84                *strm << 
"\"" << w10n::escape_for_json(val) << 
"\"";
 
   87                *strm << values[indx++];
 
   92    if (currentDim == 0 || !flatten) *strm << 
"]";
 
 
   97void W10nJsonTransform::json_array_starter(
ostream *strm, libdap::Array *a, std::string indent)
 
  100    bool found_w10n_callback = 
false;
 
  101    std::string w10n_callback = BESContextManager::TheManager()->get_context(W10N_CALLBACK_KEY, found_w10n_callback);
 
  102    BESDEBUG(W10N_DEBUG_KEY, 
"W10nJsonTransform::json_simple_type_array() - w10n_callback: "<< w10n_callback << endl);
 
  104    BESDEBUG(W10N_DEBUG_KEY,
 
  105        "W10nJsonTransform::json_simple_type_array() - Processing Array of " << a->var()->type_name() << endl);
 
  107    if (found_w10n_callback) {
 
  108        *strm << w10n_callback << 
"(";
 
  111    *strm << 
"{" << endl;
 
  113    std::string child_indent = indent + _indent_increment;
 
  115    BESDEBUG(W10N_DEBUG_KEY, 
"W10nJsonTransform::json_simple_type_array() - Writing variable metadata..." << endl);
 
  117    writeVariableMetadata(strm, a, child_indent);
 
  118    *strm << 
"," << endl;
 
  120    BESDEBUG(W10N_DEBUG_KEY, 
"W10nJsonTransform::json_simple_type_array() - Writing variable data..." << endl);
 
  123    *strm << child_indent << 
"\"data\": ";
 
  126void W10nJsonTransform::json_array_ender(
ostream *strm, std::string indent)
 
  129    bool found_w10n_meta_object = 
false;
 
  130    std::string w10n_meta_object = BESContextManager::TheManager()->
get_context(W10N_META_OBJECT_KEY,
 
  131        found_w10n_meta_object);
 
  132    BESDEBUG(W10N_DEBUG_KEY,
 
  133        "W10nJsonTransform::json_simple_type_array_ender() - w10n_meta_object: "<< w10n_meta_object << endl);
 
  135    bool found_w10n_callback = 
false;
 
  136    std::string w10n_callback = BESContextManager::TheManager()->
get_context(W10N_CALLBACK_KEY, found_w10n_callback);
 
  137    BESDEBUG(W10N_DEBUG_KEY, 
"W10nJsonTransform::json_simple_type_array() - w10n_callback: "<< w10n_callback << endl);
 
  139    std::string child_indent = indent + _indent_increment;
 
  141    if (found_w10n_meta_object)
 
  142        *strm << 
"," << endl << child_indent << w10n_meta_object << endl;
 
  146    *strm << indent << 
"}" << endl;
 
  148    if (found_w10n_callback) {
 
  159template<
typename T> 
void W10nJsonTransform::json_simple_type_array_sender(
ostream *strm, libdap::Array *a)
 
  162    bool found_w10n_flatten = 
false;
 
  163    std::string w10n_flatten = BESContextManager::TheManager()->
get_context(W10N_FLATTEN_KEY, found_w10n_flatten);
 
  164    BESDEBUG(W10N_DEBUG_KEY,
 
  165        "W10nJsonTransform::json_simple_type_array_sender() - w10n_flatten: "<< w10n_flatten << endl);
 
  167    int numDim = a->dimensions(
true);
 
  168    vector<unsigned int> shape(numDim);
 
  169    long length = w10n::computeConstrainedShape(a, &shape);
 
  171    vector<T> src(length);
 
  172    a->value(src.data());
 
  173    unsigned int indx = json_simple_type_array_worker(strm, src.data(), 0, &shape, 0, found_w10n_flatten);
 
  176        BESDEBUG(W10N_DEBUG_KEY,
 
  177            "json_simple_type_array_sender() - indx NOT equal to content length! indx:  " << indx << 
"  length: " << length << endl);
 
  185void W10nJsonTransform::json_string_array_sender(
ostream *strm, libdap::Array *a)
 
  188    bool found_w10n_flatten = 
false;
 
  189    std::string w10n_flatten = BESContextManager::TheManager()->
get_context(W10N_FLATTEN_KEY, found_w10n_flatten);
 
  190    BESDEBUG(W10N_DEBUG_KEY,
 
  191        "W10nJsonTransform::json_simple_type_array_sender() - w10n_flatten: "<< w10n_flatten << endl);
 
  193    int numDim = a->dimensions(
true);
 
  194    vector<unsigned int> shape(numDim);
 
  195    long length = w10n::computeConstrainedShape(a, &shape);
 
  198    vector<std::string> sourceValues;
 
  199    a->value(sourceValues);
 
  200    unsigned int indx = json_simple_type_array_worker(strm, (std::string *) (sourceValues.data()), 0, &shape, 0,
 
  204        BESDEBUG(W10N_DEBUG_KEY,
 
  205            "json_simple_type_array_sender() - indx NOT equal to content length! indx:  " << indx << 
"  length: " << length << endl);
 
  213template<
typename T> 
void W10nJsonTransform::json_simple_type_array(
ostream *strm, libdap::Array *a, std::string indent)
 
  215    json_array_starter(strm, a, indent);
 
  216    json_simple_type_array_sender<T>(strm, a);
 
  217    json_array_ender(strm, indent);
 
 
  224void W10nJsonTransform::json_string_array(
ostream *strm, libdap::Array *a, std::string indent)
 
  226    json_array_starter(strm, a, indent);
 
  227    json_string_array_sender(strm, a);
 
  228    json_array_ender(strm, indent);
 
  234void W10nJsonTransform::writeDatasetMetadata(
ostream *strm, libdap::DDS *dds, std::string indent)
 
  237    *strm << indent << 
"\"name\": \"" << dds->get_dataset_name() << 
"\"," << endl;
 
  240    writeAttributes(strm, dds->get_attr_table(), indent);
 
  241    *strm << 
"," << endl;
 
  248void W10nJsonTransform::writeVariableMetadata(
ostream *strm, libdap::BaseType *bt, std::string indent)
 
  252    *strm << indent << 
"\"name\": \"" << bt->name() << 
"\"," << endl;
 
  253    libdap::BaseType *var = bt;
 
  256    if (bt->type() == libdap::dods_array_c) {
 
  257        libdap::Array *a = (libdap::Array *) bt;
 
  260    if (!var->is_constructor_type()) *strm << indent << 
"\"type\": \"" << var->type_name() << 
"\"," << endl;
 
  263    writeAttributes(strm, bt->get_attr_table(), indent);
 
  279    _dds(dds), _localfile(localfile), _indent_increment(
"  "), _ostrm(0), _usingTempFile(false)
 
  282        std::string msg = 
"W10nJsonTransform:  ERROR! A null DDS reference was passed to the constructor";
 
  283        BESDEBUG(W10N_DEBUG_KEY, msg << endl);
 
  287    if (_localfile.empty()) {
 
  288        std::string msg = 
"W10nJsonTransform:  An empty local file name passed to constructor";
 
  289        BESDEBUG(W10N_DEBUG_KEY, msg << endl);
 
  290        throw BESInternalError(msg, __FILE__, __LINE__);
 
 
  295    _dds(dds), _localfile(
""), _indent_increment(
"  "), _ostrm(ostrm), _usingTempFile(false)
 
  298        std::string msg = 
"W10nJsonTransform:  ERROR! A null DDS reference was passed to the constructor";
 
  299        BESDEBUG(W10N_DEBUG_KEY, msg << endl);
 
  304        std::string msg = 
"W10nJsonTransform:  ERROR! A null std::ostream pointer was passed to the constructor";
 
  305        BESDEBUG(W10N_DEBUG_KEY, msg << endl);
 
  306        throw BESInternalError(msg, __FILE__, __LINE__);
 
  329    strm << BESIndent::LMarg << 
"W10nJsonTransform::dump - (" << (
void *) 
this << 
")" << endl;
 
  331    strm << BESIndent::LMarg << 
"temporary file = " << _localfile << endl;
 
  335    BESIndent::UnIndent();
 
 
  342void W10nJsonTransform::writeAttributes(
ostream *strm, libdap::AttrTable &attr_table, std::string indent)
 
  345    std::string child_indent = indent + _indent_increment;
 
  348    *strm << indent << 
"\"attributes\": [";
 
  354    if (attr_table.get_size() != 0) {
 
  356        libdap::AttrTable::Attr_iter begin = attr_table.attr_begin();
 
  357        libdap::AttrTable::Attr_iter end = attr_table.attr_end();
 
  359        for (libdap::AttrTable::Attr_iter at_iter = begin; at_iter != end; at_iter++) {
 
  361            switch (attr_table.get_attr_type(at_iter)) {
 
  362            case libdap::Attr_container: {
 
  363                libdap::AttrTable *atbl = attr_table.get_attr_table(at_iter);
 
  366                if (at_iter != begin) *strm << 
"," << endl;
 
  369                *strm << child_indent << 
"{" << endl;
 
  372                if (atbl->get_name().size() > 0)
 
  373                    *strm << child_indent + _indent_increment << 
"\"name\": \"" << atbl->get_name() << 
"\"," << endl;
 
  376                writeAttributes(strm, *atbl, child_indent + _indent_increment);
 
  377                *strm << endl << child_indent << 
"}";
 
  384                if (at_iter != begin) *strm << 
"," << endl;
 
  387                *strm << child_indent << 
"{\"name\": \"" << attr_table.get_name(at_iter) << 
"\", ";
 
  390                *strm << 
"\"value\": [";
 
  391                vector<std::string> *values = attr_table.get_attr_vector(at_iter);
 
  393                for (std::vector<std::string>::size_type i = 0; i < values->size(); i++) {
 
  396                    if (i > 0) *strm << 
",";
 
  399                    if (attr_table.get_attr_type(at_iter) == libdap::Attr_string
 
  400                        || attr_table.get_attr_type(at_iter) == libdap::Attr_url) {
 
  402                        std::string value = (*values)[i];
 
  403                        *strm << w10n::escape_for_json(value);
 
  408                        *strm << (*values)[i];
 
  419        *strm << endl << indent;
 
  429std::ostream *W10nJsonTransform::getOutputStream()
 
  432    _usingTempFile = 
false;
 
  433    std::fstream _tempFile;
 
  436        _tempFile.open(_localfile.c_str(), std::fstream::out);
 
  438            std::string msg = 
"Could not open temp file: " + _localfile;
 
  439            BESDEBUG(W10N_DEBUG_KEY, 
"W10nJsonTransform::getOutputStream() - ERROR! "<< msg << endl);
 
  440            throw BESInternalError(msg, __FILE__, __LINE__);
 
  443        _usingTempFile = 
true;
 
  449void W10nJsonTransform::releaseOutputStream()
 
  451    if (_usingTempFile) {
 
  452        ((std::fstream *) _ostrm)->close();
 
  457void W10nJsonTransform::sendW10nMetaForDDS()
 
  460    std::ostream *strm = getOutputStream();
 
  462        sendW10nMetaForDDS(strm, _dds, 
"");
 
  463        releaseOutputStream();
 
  466        releaseOutputStream();
 
  472void W10nJsonTransform::sendW10nMetaForDDS(
ostream *strm, libdap::DDS *dds, std::string indent)
 
  475    bool found_w10n_meta_object = 
false;
 
  476    std::string w10n_meta_object = BESContextManager::TheManager()->
get_context(W10N_META_OBJECT_KEY,
 
  477        found_w10n_meta_object);
 
  478    BESDEBUG(W10N_DEBUG_KEY,
 
  479        "W10nJsonTransform::json_simple_type_array() - w10n_meta_object: "<< w10n_meta_object << endl);
 
  481    bool found_w10n_callback = 
false;
 
  482    std::string w10n_callback = BESContextManager::TheManager()->
get_context(W10N_CALLBACK_KEY, found_w10n_callback);
 
  483    BESDEBUG(W10N_DEBUG_KEY, 
"W10nJsonTransform::json_simple_type_array() - w10n_callback: "<< w10n_callback << endl);
 
  488    vector<libdap::BaseType *> leaves;
 
  489    vector<libdap::BaseType *> nodes;
 
  491    libdap::DDS::Vars_iter vi = dds->var_begin();
 
  492    libdap::DDS::Vars_iter ve = dds->var_end();
 
  493    for (; vi != ve; vi++) {
 
  494        libdap::BaseType *v = *vi;
 
  496            libdap::Type type = v->type();
 
  497            if (type == libdap::dods_array_c) {
 
  498                type = v->var()->type();
 
  500            if (v->is_constructor_type() || (v->is_vector_type() && v->var()->is_constructor_type())) {
 
  509    if (found_w10n_callback) {
 
  510        *strm << w10n_callback << 
"(";
 
  514    *strm << 
"{" << endl;
 
  515    std::string child_indent = indent + _indent_increment;
 
  518    writeDatasetMetadata(strm, dds, child_indent);
 
  521    *strm << child_indent << 
"\"leaves\": [";
 
  522    if (leaves.size() > 0) *strm << endl;
 
  523    for (std::vector<libdap::BaseType *>::size_type l = 0; l < leaves.size(); l++) {
 
  524        libdap::BaseType *v = leaves[l];
 
  525        BESDEBUG(W10N_DEBUG_KEY, 
"Processing LEAF: " << v->name() << endl);
 
  527            *strm << 
"," << endl;
 
  530        sendW10nMetaForVariable(strm, v, child_indent + _indent_increment, 
false);
 
  532    if (leaves.size() > 0) *strm << endl << child_indent;
 
  533    *strm << 
"]," << endl;
 
  536    *strm << child_indent << 
"\"nodes\": [";
 
  537    if (nodes.size() > 0) *strm << endl;
 
  538    for (std::vector<libdap::BaseType *>::size_type n = 0; n < nodes.size(); n++) {
 
  539        libdap::BaseType *v = nodes[n];
 
  540        BESDEBUG(W10N_DEBUG_KEY, 
"Processing NODE: " << v->name() << endl);
 
  542            *strm << 
"," << endl;
 
  544        sendW10nMetaForVariable(strm, v, child_indent + _indent_increment, 
false);
 
  546    if (nodes.size() > 0) *strm << endl << child_indent;
 
  550    if (found_w10n_meta_object)
 
  551        *strm << 
"," << endl << child_indent << w10n_meta_object << endl;
 
  557    if (found_w10n_callback) {
 
  565void W10nJsonTransform::sendW10nMetaForVariable(
ostream *strm, libdap::BaseType *bt, std::string indent, 
bool isTop)
 
  568    bool found_w10n_meta_object = 
false;
 
  569    std::string w10n_meta_object = BESContextManager::TheManager()->
get_context(W10N_META_OBJECT_KEY,
 
  570        found_w10n_meta_object);
 
  571    BESDEBUG(W10N_DEBUG_KEY,
 
  572        "W10nJsonTransform::json_simple_type_array() - w10n_meta_object: "<< w10n_meta_object << endl);
 
  574    bool found_w10n_callback = 
false;
 
  575    std::string w10n_callback = BESContextManager::TheManager()->
get_context(W10N_CALLBACK_KEY, found_w10n_callback);
 
  576    BESDEBUG(W10N_DEBUG_KEY, 
"W10nJsonTransform::json_simple_type_array() - w10n_callback: "<< w10n_callback << endl);
 
  578    bool found_w10n_flatten = 
false;
 
  579    std::string w10n_flatten = BESContextManager::TheManager()->
get_context(W10N_FLATTEN_KEY, found_w10n_flatten);
 
  580    BESDEBUG(W10N_DEBUG_KEY, 
"W10nJsonTransform::json_simple_type_array() - w10n_flatten: "<< w10n_flatten << endl);
 
  582    bool found_w10n_traverse = 
false;
 
  583    std::string w10n_traverse = BESContextManager::TheManager()->
get_context(W10N_TRAVERSE_KEY, found_w10n_traverse);
 
  584    BESDEBUG(W10N_DEBUG_KEY, 
"W10nJsonTransform::json_simple_type_array() - w10n_traverse: "<< w10n_traverse << endl);
 
  586    if (isTop && found_w10n_callback) {
 
  587        *strm << w10n_callback << 
"(";
 
  590    *strm << indent << 
"{" << endl;\
 
  591    std::string child_indent = indent + _indent_increment;
 
  593    writeVariableMetadata(strm, bt, child_indent);
 
  595    if (bt->type() == libdap::dods_array_c) {
 
  596        *strm << 
"," << endl;
 
  598        libdap::Array *a = (libdap::Array *) bt;
 
  599        int numDim = a->dimensions(
true);
 
  600        vector<unsigned int> shape(numDim);
 
  601        long length = w10n::computeConstrainedShape(a, &shape);
 
  603        if (found_w10n_flatten) {
 
  604            *strm << child_indent << 
"\"shape\": [" << length << 
"]";
 
  608            *strm << child_indent << 
"\"shape\": [";
 
  609            for (std::vector<unsigned int>::size_type i = 0; i < shape.size(); i++) {
 
  610                if (i > 0) *strm << 
",";
 
  617        if (bt->is_constructor_type() && (found_w10n_traverse || isTop)) {
 
  618            *strm << 
"," << endl;
 
  620            libdap::Constructor *ctor = (libdap::Constructor *) bt;
 
  622            vector<libdap::BaseType *> leaves;
 
  623            vector<libdap::BaseType *> nodes;
 
  624            libdap::Constructor::Vars_iter vi = ctor->var_begin();
 
  625            libdap::Constructor::Vars_iter ve = ctor->var_end();
 
  626            for (; vi != ve; vi++) {
 
  627                libdap::BaseType *v = *vi;
 
  629                    libdap::Type type = v->type();
 
  630                    if (type == libdap::dods_array_c) {
 
  631                        type = v->var()->type();
 
  633                    if (v->is_constructor_type() || (v->is_vector_type() && v->var()->is_constructor_type())) {
 
  643            *strm << child_indent << 
"\"leaves\": [";
 
  644            if (leaves.size() > 0) *strm << endl;
 
  645            for (std::vector<libdap::BaseType *>::size_type l = 0; l < leaves.size(); l++) {
 
  646                libdap::BaseType *v = leaves[l];
 
  647                BESDEBUG(W10N_DEBUG_KEY, 
"Processing LEAF: " << v->name() << endl);
 
  653                sendW10nMetaForVariable(strm, v, child_indent + _indent_increment, 
false);
 
  655            if (leaves.size() > 0) *strm << endl << child_indent;
 
  656            *strm << 
"]," << endl;
 
  659            *strm << child_indent << 
"\"nodes\": [";
 
  660            if (nodes.size() > 0) *strm << endl;
 
  661            for (std::vector<libdap::BaseType *>::size_type n = 0; n < nodes.size(); n++) {
 
  662                libdap::BaseType *v = nodes[n];
 
  663                BESDEBUG(W10N_DEBUG_KEY, 
"Processing NODE: " << v->name() << endl);
 
  665                    *strm << 
"," << endl;
 
  667                sendW10nMetaForVariable(strm, v, child_indent + _indent_increment, 
false);
 
  669            if (nodes.size() > 0) *strm << endl << child_indent;
 
  675            if (!bt->is_constructor_type()) {
 
  684    if (isTop && found_w10n_meta_object) {
 
  685        *strm << 
"," << endl << child_indent << w10n_meta_object << endl;
 
  688    *strm << endl << indent << 
"}";
 
  690    if (isTop && found_w10n_callback) {
 
  696void W10nJsonTransform::sendW10nMetaForVariable(std::string &vName, 
bool isTop)
 
  699    libdap::BaseType *bt = _dds->var(vName);
 
  702        std::string msg = 
"The dataset does not contain a variable named '" + vName + 
"'";
 
  703        BESDEBUG(W10N_DEBUG_KEY, 
"W10nJsonTransform::sendW10nMetaForVariable() - ERROR! " << msg << endl);
 
  704        throw BESSyntaxUserError(msg, __FILE__, __LINE__);
 
  707    std::ostream *strm = getOutputStream();
 
  709        sendW10nMetaForVariable(strm, bt, 
"", isTop);
 
  711        releaseOutputStream();
 
  714        releaseOutputStream();
 
  720void W10nJsonTransform::sendW10nDataForVariable(std::string &vName)
 
  723    libdap::BaseType *bt = _dds->var(vName);
 
  726        std::string msg = 
"The dataset does not contain a variable named '" + vName + 
"'";
 
  727        BESDEBUG(W10N_DEBUG_KEY, 
"W10nJsonTransform::sendW10nDataForVariable() - ERROR! " << msg << endl);
 
  728        throw BESSyntaxUserError(msg, __FILE__, __LINE__);
 
  731    std::ostream *strm = getOutputStream();
 
  733        sendW10nDataForVariable(strm, bt, 
"");
 
  734        releaseOutputStream();
 
  737        releaseOutputStream();
 
  743void W10nJsonTransform::sendW10nDataForVariable(
ostream *strm, libdap::BaseType *bt, std::string indent)
 
  746    if (bt->is_simple_type()) {
 
  748        sendW10nData(strm, bt, indent);
 
  751    else if (bt->type() == libdap::dods_array_c && bt->var()->is_simple_type()) {
 
  752        sendW10nData(strm, (libdap::Array *) bt, indent);
 
  756        std::string msg = 
"The variable '" + bt->name() + 
"' is not a simple type or an Array of simple types. ";
 
  757        msg += 
"The w10n protocol does not support the transmission of data for complex types.";
 
  758        BESDEBUG(W10N_DEBUG_KEY, 
"W10nJsonTransform::sendW10nDataForVariable() - ERROR! " << msg << endl);
 
  759        throw BESSyntaxUserError(msg, __FILE__, __LINE__);
 
  768void W10nJsonTransform::sendW10nData(
ostream *strm, libdap::BaseType *b, std::string indent)
 
  771    BESDEBUG(W10N_DEBUG_KEY, 
"W10nJsonTransform::sendW10nData() - Sending data for simple type "<< b->name() << endl);
 
  773    bool found_w10n_meta_object = 
false;
 
  774    std::string w10n_meta_object = BESContextManager::TheManager()->
get_context(W10N_META_OBJECT_KEY,
 
  775        found_w10n_meta_object);
 
  776    BESDEBUG(W10N_DEBUG_KEY,
 
  777        "W10nJsonTransform::json_simple_type_array() - w10n_meta_object: "<< w10n_meta_object << endl);
 
  779    bool found_w10n_callback = 
false;
 
  780    std::string w10n_callback = BESContextManager::TheManager()->
get_context(W10N_CALLBACK_KEY, found_w10n_callback);
 
  781    BESDEBUG(W10N_DEBUG_KEY, 
"W10nJsonTransform::json_simple_type_array() - w10n_callback: "<< w10n_callback << endl);
 
  783    bool found_w10n_flatten = 
false;
 
  784    std::string w10n_flatten = BESContextManager::TheManager()->
get_context(W10N_FLATTEN_KEY, found_w10n_flatten);
 
  785    BESDEBUG(W10N_DEBUG_KEY, 
"W10nJsonTransform::json_simple_type_array() - w10n_flatten: "<< w10n_flatten << endl);
 
  787    std::string child_indent = indent + _indent_increment;
 
  789    if (found_w10n_callback) {
 
  790        *strm << w10n_callback << 
"(";
 
  793    *strm << 
"{" << endl;
 
  795    writeVariableMetadata(strm, b, child_indent);
 
  796    *strm << 
"," << endl;
 
  798    *strm << child_indent << 
"\"data\": ";
 
  800    if (b->type() == libdap::dods_str_c || b->type() == libdap::dods_url_c) {
 
  801        libdap::Str *strVar = (libdap::Str *) b;
 
  802        *strm << 
"\"" << w10n::escape_for_json(strVar->value()) << 
"\"";
 
  805        b->print_val(*strm, 
"", 
false);
 
  808    if (found_w10n_meta_object)
 
  809        *strm << 
"," << endl << child_indent << w10n_meta_object << endl;
 
  815    if (found_w10n_callback) {
 
  824void W10nJsonTransform::sendW10nData(
ostream *strm, libdap::Array *a, std::string indent)
 
  827    BESDEBUG(W10N_DEBUG_KEY,
 
  828        "W10nJsonTransform::transform() - Processing Array. " << 
" a->type_name(): " << a->type_name() << 
" a->var()->type_name(): " << a->var()->type_name() << endl);
 
  830    switch (a->var()->type()) {
 
  832    case libdap::dods_byte_c:
 
  833        json_simple_type_array<libdap::dods_byte>(strm, a, indent);
 
  836    case libdap::dods_int16_c:
 
  837        json_simple_type_array<libdap::dods_int16>(strm, a, indent);
 
  840    case libdap::dods_uint16_c:
 
  841        json_simple_type_array<libdap::dods_uint16>(strm, a, indent);
 
  844    case libdap::dods_int32_c:
 
  845        json_simple_type_array<libdap::dods_int32>(strm, a, indent);
 
  848    case libdap::dods_uint32_c:
 
  849        json_simple_type_array<libdap::dods_uint32>(strm, a, indent);
 
  852    case libdap::dods_float32_c:
 
  853        json_simple_type_array<libdap::dods_float32>(strm, a, indent);
 
  856    case libdap::dods_float64_c:
 
  857        json_simple_type_array<libdap::dods_float64>(strm, a, indent);
 
  860    case libdap::dods_str_c: {
 
  861        json_string_array(strm, a, indent);
 
  864        string s = (string) 
"W10nJsonTransform:  Arrays of String objects not a supported return type.";
 
  865        BESDEBUG(W10N_DEBUG_KEY, 
"W10nJsonTransform::sendW10nMetaForVariable() - ERROR! " << s << endl);
 
  866        throw BESInternalError(s, __FILE__, __LINE__);
 
  871    case libdap::dods_url_c: {
 
  872        json_string_array(strm, a, indent);
 
  876        string s = (string) 
"W10nJsonTransform:  Arrays of URL objects not a supported return type.";
 
  877        BESDEBUG(W10N_DEBUG_KEY, 
"W10nJsonTransform::sendW10nMetaForVariable() - ERROR! " << s << endl);
 
  878        throw BESInternalError(s, __FILE__, __LINE__);
 
  883    case libdap::dods_structure_c: {
 
  884        std::string s = (std::string) 
"W10nJsonTransform:  Arrays of Structure objects not a supported return type.";
 
  885        BESDEBUG(W10N_DEBUG_KEY, 
"W10nJsonTransform::sendW10nMetaForVariable() - ERROR! " << s << endl);
 
  886        throw BESInternalError(s, __FILE__, __LINE__);
 
  889    case libdap::dods_grid_c: {
 
  890        std::string s = (std::string) 
"W10nJsonTransform:  Arrays of Grid objects not a supported return type.";
 
  891        BESDEBUG(W10N_DEBUG_KEY, 
"W10nJsonTransform::sendW10nMetaForVariable() - ERROR! " << s << endl);
 
  892        throw BESInternalError(s, __FILE__, __LINE__);
 
  896    case libdap::dods_sequence_c: {
 
  897        std::string s = (std::string) 
"W10nJsonTransform:  Arrays of Sequence objects not a supported return type.";
 
  898        BESDEBUG(W10N_DEBUG_KEY, 
"W10nJsonTransform::sendW10nMetaForVariable() - ERROR! " << s << endl);
 
  899        throw BESInternalError(s, __FILE__, __LINE__);
 
  903    case libdap::dods_array_c: {
 
  904        std::string s = (std::string) 
"W10nJsonTransform:  Arrays of Array objects not a supported return type.";
 
  905        BESDEBUG(W10N_DEBUG_KEY, 
"W10nJsonTransform::sendW10nMetaForVariable() - ERROR! " << s << endl);
 
  906        throw BESInternalError(s, __FILE__, __LINE__);
 
  909    case libdap::dods_int8_c:
 
  910    case libdap::dods_uint8_c:
 
  911    case libdap::dods_int64_c:
 
  912    case libdap::dods_uint64_c:
 
  914    case libdap::dods_enum_c:
 
  915    case libdap::dods_group_c: {
 
  916        std::string s = (std::string) 
"W10nJsonTransform:  DAP4 types not yet supported.";
 
  917        BESDEBUG(W10N_DEBUG_KEY, 
"W10nJsonTransform::sendW10nMetaForVariable() - ERROR! " << s << endl);
 
  918        throw BESInternalError(s, __FILE__, __LINE__);
 
  923        std::string s = (std::string) 
"W10nJsonTransform:  Unrecognized type.";
 
  924        BESDEBUG(W10N_DEBUG_KEY, 
"W10nJsonTransform::sendW10nMetaForVariable() - ERROR! " << s << endl);
 
  925        throw BESInternalError(s, __FILE__, __LINE__);
 
virtual std::string get_context(const std::string &name, bool &found)
retrieve the value of the specified context from the BES
 
Structure storing information used by the BES to handle the request.
 
exception thrown if internal error encountered