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
00100
00101
00102 BESXMLCommand::set_response() ;
00103 }
00104
00105 void
00106 BESXMLGetCommand::parse_basic_get( xmlNode *node,
00107 const string &name,
00108 const string &type,
00109 const string &value,
00110 map<string,string> &props )
00111 {
00112 _str_cmd = (string)"get " + type ;
00113
00114 _definition = props["definition"] ;
00115 if( _definition.empty() )
00116 {
00117 string err = name + " command: Must specify definition" ;
00118 throw BESSyntaxUserError( err, __FILE__, __LINE__ ) ;
00119 }
00120 _str_cmd += " for " + _definition ;
00121
00122 string returnAs = props["returnAs"] ;
00123 if( returnAs.empty() )
00124 {
00125 returnAs = DAP2_FORMAT ;
00126 }
00127 _dhi.data[RETURN_CMD] = returnAs ;
00128
00129 _str_cmd += " returnAs " + returnAs ;
00130
00131 _dhi.action = "get." ;
00132 _dhi.action += BESUtil::lowercase( type ) ;
00133 BESDEBUG( "besxml", "Converted xml element name to command "
00134 << _dhi.action << endl ) ;
00135 }
00136
00143 BESDataHandlerInterface &
00144 BESXMLGetCommand::get_dhi()
00145 {
00146 if( _sub_cmd ) return _sub_cmd->get_dhi() ;
00147
00148 return _dhi ;
00149 }
00150
00158 void
00159 BESXMLGetCommand::prep_request()
00160 {
00161
00162 if( _sub_cmd )
00163 {
00164 _sub_cmd->prep_request() ;
00165 return ;
00166 }
00167
00168
00169
00170
00171 BESDefine *d = BESDefinitionStorageList::TheList()->look_for( _definition );
00172 if( !d )
00173 {
00174 string s = (string)"Unable to find definition " + _definition ;
00175 throw BESSyntaxUserError( s, __FILE__, __LINE__ ) ;
00176 }
00177
00178 BESDefine::containers_citer i = d->first_container() ;
00179 BESDefine::containers_citer ie = d->end_container() ;
00180 while( i != ie )
00181 {
00182 _dhi.containers.push_back( *i ) ;
00183 i++ ;
00184 }
00185 _dhi.data[AGG_CMD] = d->get_agg_cmd() ;
00186 _dhi.data[AGG_HANDLER] = d->get_agg_handler() ;
00187
00188 }
00189
00196 void
00197 BESXMLGetCommand::dump( ostream &strm ) const
00198 {
00199 strm << BESIndent::LMarg << "BESXMLGetCommand::dump - ("
00200 << (void *)this << ")" << endl ;
00201 BESIndent::Indent() ;
00202 BESXMLCommand::dump( strm ) ;
00203 BESIndent::UnIndent() ;
00204 }
00205
00206 BESXMLCommand *
00207 BESXMLGetCommand::CommandBuilder( const BESDataHandlerInterface &base_dhi )
00208 {
00209 return new BESXMLGetCommand( base_dhi ) ;
00210 }
00211