BESGetCommand.cc

Go to the documentation of this file.
00001 // BESGetCommand.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 "BESGetCommand.h"
00034 #include "BESTokenizer.h"
00035 #include "BESResponseHandlerList.h"
00036 #include "BESDefinitionStorageList.h"
00037 #include "BESDefinitionStorage.h"
00038 #include "BESDefine.h"
00039 #include "BESSyntaxUserError.h"
00040 #include "BESDataNames.h"
00041 
00066 BESResponseHandler *
00067 BESGetCommand::parse_request( BESTokenizer &tokenizer,
00068                               BESDataHandlerInterface &dhi )
00069 {
00070     string def_name ;
00071 
00072     string my_token = parse_options( tokenizer, dhi ) ;
00073 
00074     /* First we will make sure that the developer has not over-written this
00075      * command to work with a sub command. In other words, they have a new
00076      * command called "get something" that is parsed differently than the
00077      * default get command. Look up get.something
00078      */
00079 
00080     string newcmd = _cmd + "." + my_token ;
00081     BESCommand *cmdobj = BESCommand::find_command( newcmd ) ;
00082     if( cmdobj && cmdobj != BESCommand::TermCommand )
00083     {
00084         return cmdobj->parse_request( tokenizer, dhi ) ;
00085     }
00086 
00087     /* No subcommand - so proceed as a default get command
00088      */
00089     BESResponseHandler *retResponse =
00090         BESResponseHandlerList::TheList()->find_handler( newcmd ) ;
00091     if( !retResponse )
00092     {
00093         string err( "Command " ) ;
00094         err += _cmd + " " + my_token ;
00095         err += " does not have a registered response handler" ;
00096         throw BESSyntaxUserError( err, __FILE__, __LINE__ ) ;
00097     }
00098     dhi.action = newcmd ;
00099 
00100     my_token = tokenizer.get_next_token() ;
00101     if( my_token != "for" )
00102     {
00103         tokenizer.parse_error( my_token + " not expected\n" ) ;
00104     }
00105     else
00106     {
00107         def_name = tokenizer.get_next_token() ;
00108 
00109         my_token = tokenizer.get_next_token() ;
00110         if( my_token == "return" )
00111         {
00112             my_token = tokenizer.get_next_token() ;
00113             if( my_token != "as" )
00114             {
00115                 tokenizer.parse_error( my_token + " not expected, expecting \"as\"" ) ;
00116             }
00117             else
00118             {
00119                 my_token = tokenizer.get_next_token() ;
00120                 dhi.data[RETURN_CMD] =
00121                     tokenizer.remove_quotes( my_token ) ;
00122 
00123                 my_token = tokenizer.get_next_token() ;
00124                 if( my_token != ";" )
00125                 {
00126                     tokenizer.parse_error( my_token + " not expected, expecting ';'" ) ;
00127                 }
00128             }
00129         }
00130         else
00131         {
00132             if( my_token != ";" )
00133             {
00134                 tokenizer.parse_error( my_token + " not expected, expecting \"return\" or ';'" ) ;
00135             }
00136         }
00137     }
00138 
00139     // FIX: should this be using dot notation? Like get das for volatile.d ;
00140     // Or do it like the containers, just find the first one available? Same
00141     // question for containers then?
00142     /*
00143     string store_name = PERSISTENCE_VOLATILE ;
00144     BESDefinitionStorage *store =
00145         BESDefinitionStorageList::TheList()->find_def( store_name ) ;
00146     if( !store )
00147     {
00148         throw BESSyntaxUserError( (string)"Unable to find definition store " + store_name ) ;
00149     }
00150     */
00151 
00152     BESDefine *d = BESDefinitionStorageList::TheList()->look_for( def_name ) ;
00153     if( !d )
00154     {
00155         string s = (string)"Unable to find definition " + def_name ;
00156         throw BESSyntaxUserError( s, __FILE__, __LINE__ ) ;
00157     }
00158 
00159     BESDefine::containers_citer i = d->first_container() ;
00160     BESDefine::containers_citer ie = d->end_container() ;
00161     while( i != ie )
00162     {
00163         dhi.containers.push_back( *i ) ;
00164         i++ ;
00165     }
00166     dhi.data[AGG_CMD] = d->get_agg_cmd() ;
00167     dhi.data[AGG_HANDLER] = d->get_agg_handler() ;
00168 
00169     return retResponse ;
00170 }
00171 
00178 void
00179 BESGetCommand::dump( ostream &strm ) const
00180 {
00181     strm << BESIndent::LMarg << "BESGetCommand::dump - ("
00182                              << (void *)this << ")" << endl ;
00183     BESIndent::Indent() ;
00184     BESCommand::dump( strm ) ;
00185     BESIndent::UnIndent() ;
00186 }
00187 

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