BESXMLGetCommand.cc

Go to the documentation of this file.
00001 // BESXMLGetCommand.cc
00002 
00003 // This file is part of bes, A C++ back-end server implementation framework
00004 // for the OPeNDAP Data Access Protocol.
00005 
00006 // Copyright (c) 2004-2009 University Corporation for Atmospheric Research
00007 // Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
00008 //
00009 // This library is free software; you can redistribute it and/or
00010 // modify it under the terms of the GNU Lesser General Public
00011 // License as published by the Free Software Foundation; either
00012 // version 2.1 of the License, or (at your option) any later version.
00013 // 
00014 // This library is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 // Lesser General Public License for more details.
00018 // 
00019 // You should have received a copy of the GNU Lesser General Public
00020 // License along with this library; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 //
00023 // You can contact University Corporation for Atmospheric Research at
00024 // 3080 Center Green Drive, Boulder, CO 80301
00025  
00026 // (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
00027 // Please read the full copyright statement in the file COPYRIGHT_UCAR.
00028 //
00029 // Authors:
00030 //      pwest       Patrick West <pwest@ucar.edu>
00031 //      jgarcia     Jose Garcia <jgarcia@ucar.edu>
00032 
00033 #include "BESXMLGetCommand.h"
00034 #include "BESDefinitionStorageList.h"
00035 #include "BESDefinitionStorage.h"
00036 #include "BESDefine.h"
00037 #include "BESDataNames.h"
00038 #include "BESResponseNames.h"
00039 #include "BESXMLUtils.h"
00040 #include "BESUtil.h"
00041 #include "BESSyntaxUserError.h"
00042 #include "BESDebug.h"
00043 
00044 BESXMLGetCommand::BESXMLGetCommand( const BESDataHandlerInterface &base_dhi )
00045     : BESXMLCommand( base_dhi ), _sub_cmd( 0 )
00046 {
00047 }
00048 
00055 void
00056 BESXMLGetCommand::parse_request( xmlNode *node )
00057 {
00058     string name ;
00059     string value ;
00060     map<string, string> props ;
00061     BESXMLUtils::GetNodeInfo( node, name, value, props ) ;
00062     if( name != GET_RESPONSE )
00063     {
00064         string err = "The specified command " + name
00065                      + " is not a get command" ;
00066         throw BESSyntaxUserError( err, __FILE__, __LINE__ ) ;
00067     }
00068 
00069     // grab the type first and check to see if there is a registered command
00070     // to handle get.<type> requests
00071     string type = props["type"] ;
00072     if( type.empty() )
00073     {
00074         string err = name + " command: Must specify data product type" ;
00075         throw BESSyntaxUserError( err, __FILE__, __LINE__ ) ;
00076     }
00077     string new_cmd = (string)GET_RESPONSE + "." + type ;
00078     p_xmlcmd_builder bldr = BESXMLCommand::find_command( new_cmd ) ;
00079     if( bldr )
00080     {
00081         // the base dhi was copied to this instance's _dhi variable.
00082         _sub_cmd = bldr( _dhi ) ;
00083         if( !_sub_cmd )
00084         {
00085             string err = (string)"Failed to build command object for "
00086                          + new_cmd ;
00087             throw BESInternalError( err, __FILE__, __LINE__ ) ;
00088         }
00089 
00090         // parse the request given the current node
00091         _sub_cmd->parse_request( node ) ;
00092 
00093         // return from this sub command
00094         return ;
00095     }
00096 
00097     _str_cmd = (string)"get " + type ;
00098 
00099     parse_basic_get( node, name, type, value, props ) ;
00100 
00101     // now that we've set the action, go get the response handler for the
00102     // action
00103     BESXMLCommand::set_response() ;
00104 }
00105 
00106 void
00107 BESXMLGetCommand::parse_basic_get( xmlNode *node,
00108                                    const string &name,
00109                                    const string &type,
00110                                    const string &value,
00111                                    map<string,string> &props )
00112 {
00113     _definition = props["definition"] ;
00114     if( _definition.empty() )
00115     {
00116         string err = name + " command: Must specify definition" ;
00117         throw BESSyntaxUserError( err, __FILE__, __LINE__ ) ;
00118     }
00119     _str_cmd += " for " + _definition ;
00120 
00121     string returnAs = props["returnAs"] ;
00122     if( returnAs.empty() )
00123     {
00124         returnAs = DAP2_FORMAT ;
00125     }
00126     _dhi.data[RETURN_CMD] = returnAs ;
00127 
00128     _str_cmd += " returnAs " + returnAs ;
00129 
00130     _dhi.action = "get." ;
00131     _dhi.action += BESUtil::lowercase( type ) ;
00132     BESDEBUG( "besxml", "Converted xml element name to command "
00133                         << _dhi.action << endl )
00134 }
00135 
00142 BESDataHandlerInterface &
00143 BESXMLGetCommand::get_dhi()
00144 {
00145     if( _sub_cmd ) return _sub_cmd->get_dhi() ;
00146 
00147     return _dhi ;
00148 }
00149 
00150 void
00151 BESXMLGetCommand::prep_request()
00152 {
00153     // if there is a sub command then execute the prep request on it
00154     if( _sub_cmd )
00155     {
00156         _sub_cmd->prep_request() ;
00157         return ;
00158     }
00159 
00160     // FIX: should this be using dot notation? Like get das for volatile.d ;
00161     // Or do it like the containers, just find the first one available? Same
00162     // question for containers then?
00163     BESDefine *d = BESDefinitionStorageList::TheList()->look_for( _definition );
00164     if( !d )
00165     {
00166         string s = (string)"Unable to find definition " + _definition ;
00167         throw BESSyntaxUserError( s, __FILE__, __LINE__ ) ;
00168     }
00169 
00170     BESDefine::containers_citer i = d->first_container() ;
00171     BESDefine::containers_citer ie = d->end_container() ;
00172     while( i != ie )
00173     {
00174         _dhi.containers.push_back( *i ) ;
00175         i++ ;
00176     }
00177     _dhi.data[AGG_CMD] = d->get_agg_cmd() ;
00178     _dhi.data[AGG_HANDLER] = d->get_agg_handler() ;
00179 
00180 }
00181 
00188 void
00189 BESXMLGetCommand::dump( ostream &strm ) const
00190 {
00191     strm << BESIndent::LMarg << "BESXMLGetCommand::dump - ("
00192                              << (void *)this << ")" << endl ;
00193     BESIndent::Indent() ;
00194     BESXMLCommand::dump( strm ) ;
00195     BESIndent::UnIndent() ;
00196 }
00197 
00198 BESXMLCommand *
00199 BESXMLGetCommand::CommandBuilder( const BESDataHandlerInterface &base_dhi )
00200 {
00201     return new BESXMLGetCommand( base_dhi ) ;
00202 }
00203 

Generated on 27 Oct 2009 for OPeNDAP Hyrax Back End Server (BES) by  doxygen 1.6.1