BESXMLGetCommand.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
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 "BESDapNames.h"
00040 #include "BESXMLUtils.h"
00041 #include "BESUtil.h"
00042 #include "BESSyntaxUserError.h"
00043 #include "BESDebug.h"
00044
00045 BESXMLGetCommand::BESXMLGetCommand( const BESDataHandlerInterface &base_dhi )
00046 : BESXMLCommand( base_dhi ), _sub_cmd( 0 )
00047 {
00048 }
00049
00056 void
00057 BESXMLGetCommand::parse_request( xmlNode *node )
00058 {
00059 string name ;
00060 string value ;
00061 map<string, string> props ;
00062 BESXMLUtils::GetNodeInfo( node, name, value, props ) ;
00063 if( name != GET_RESPONSE )
00064 {
00065 string err = "The specified command " + name
00066 + " is not a get command" ;
00067 throw BESSyntaxUserError( err, __FILE__, __LINE__ ) ;
00068 }
00069
00070
00071
00072 string type = props["type"] ;
00073 if( type.empty() )
00074 {
00075 string err = name + " command: Must specify data product type" ;
00076 throw BESSyntaxUserError( err, __FILE__, __LINE__ ) ;
00077 }
00078 string new_cmd = (string)GET_RESPONSE + "." + type ;
00079 p_xmlcmd_builder bldr = BESXMLCommand::find_command( new_cmd ) ;
00080 if( bldr )
00081 {
00082
00083 _sub_cmd = bldr( _dhi ) ;
00084 if( !_sub_cmd )
00085 {
00086 string err = (string)"Failed to build command object for "
00087 + new_cmd ;
00088 throw BESInternalError( err, __FILE__, __LINE__ ) ;
00089 }
00090
00091
00092 _sub_cmd->parse_request( node ) ;
00093
00094
00095 return ;
00096 }
00097
00098 parse_basic_get( node, name, type, value, props ) ;
00099 _str_cmd += ";" ;
00100
00101
00102
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 _str_cmd = (string)"get " + type ;
00114
00115 _definition = props["definition"] ;
00116 if( _definition.empty() )
00117 {
00118 string err = name + " command: Must specify definition" ;
00119 throw BESSyntaxUserError( err, __FILE__, __LINE__ ) ;
00120 }
00121 _str_cmd += " for " + _definition ;
00122
00123 string returnAs = props["returnAs"] ;
00124 if( returnAs.empty() )
00125 {
00126 returnAs = DAP2_FORMAT ;
00127 }
00128 _dhi.data[RETURN_CMD] = returnAs ;
00129
00130 _str_cmd += " return as " + returnAs ;
00131
00132 _dhi.action = "get." ;
00133 _dhi.action += BESUtil::lowercase( type ) ;
00134 BESDEBUG( "besxml", "Converted xml element name to command "
00135 << _dhi.action << endl ) ;
00136 }
00137
00144 BESDataHandlerInterface &
00145 BESXMLGetCommand::get_dhi()
00146 {
00147 if( _sub_cmd ) return _sub_cmd->get_dhi() ;
00148
00149 return _dhi ;
00150 }
00151
00159 void
00160 BESXMLGetCommand::prep_request()
00161 {
00162
00163 if( _sub_cmd )
00164 {
00165 _sub_cmd->prep_request() ;
00166 return ;
00167 }
00168
00169
00170
00171
00172 BESDefine *d = BESDefinitionStorageList::TheList()->look_for( _definition );
00173 if( !d )
00174 {
00175 string s = (string)"Unable to find definition " + _definition ;
00176 throw BESSyntaxUserError( s, __FILE__, __LINE__ ) ;
00177 }
00178
00179 BESDefine::containers_citer i = d->first_container() ;
00180 BESDefine::containers_citer ie = d->end_container() ;
00181 while( i != ie )
00182 {
00183 _dhi.containers.push_back( *i ) ;
00184 i++ ;
00185 }
00186 _dhi.data[AGG_CMD] = d->get_agg_cmd() ;
00187 _dhi.data[AGG_HANDLER] = d->get_agg_handler() ;
00188
00189 }
00190
00197 void
00198 BESXMLGetCommand::dump( ostream &strm ) const
00199 {
00200 strm << BESIndent::LMarg << "BESXMLGetCommand::dump - ("
00201 << (void *)this << ")" << endl ;
00202 BESIndent::Indent() ;
00203 BESXMLCommand::dump( strm ) ;
00204 BESIndent::UnIndent() ;
00205 }
00206
00207 BESXMLCommand *
00208 BESXMLGetCommand::CommandBuilder( const BESDataHandlerInterface &base_dhi )
00209 {
00210 return new BESXMLGetCommand( base_dhi ) ;
00211 }
00212