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 "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
00070
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
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
00091 _sub_cmd->parse_request( node ) ;
00092
00093
00094 return ;
00095 }
00096
00097 _str_cmd = (string)"get " + type ;
00098
00099 parse_basic_get( node, name, type, value, props ) ;
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 _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
00154 if( _sub_cmd )
00155 {
00156 _sub_cmd->prep_request() ;
00157 return ;
00158 }
00159
00160
00161
00162
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