bes  Updated for version 3.17.0
SampleSayCommand.cc
1 // SampleSayCommand.cc
2 
3 // This file is part of bes, A C++ back-end server implementation framework
4 // for the OPeNDAP Data Access Protocol.
5 
6 // Copyright (c) 2004-2009 University Corporation for Atmospheric Research
7 // Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 //
23 // You can contact University Corporation for Atmospheric Research at
24 // 3080 Center Green Drive, Boulder, CO 80301
25 
26 // (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
27 // Please read the full copyright statement in the file COPYRIGHT_UCAR.
28 //
29 // Authors:
30 // pwest Patrick West <pwest@ucar.edu>
31 // jgarcia Jose Garcia <jgarcia@ucar.edu>
32 
33 #include "SampleSayCommand.h"
34 #include "BESTokenizer.h"
35 #include "BESResponseHandlerList.h"
36 #include "BESSyntaxUserError.h"
37 #include "SampleResponseNames.h"
38 
40 SampleSayCommand::parse_request( BESTokenizer &tokenizer,
42 {
43  string my_token ;
44 
45  /* No sub command, so proceed with the default command
46  */
47  dhi.action = SAY_RESPONSE ;
48  BESResponseHandler *retResponse =
49  BESResponseHandlerList::TheList()->find_handler( SAY_RESPONSE ) ;
50  if( !retResponse )
51  {
52  string s = (string)"No response handler for command " + SAY_RESPONSE ;
53  throw BESSyntaxUserError( s, __FILE__, __LINE__ ) ;
54  }
55 
56  my_token = tokenizer.get_next_token() ;
57  if( my_token == ";" )
58  {
59  tokenizer.parse_error( my_token + " not expected\n" ) ;
60  }
61 
62  // Here is where your code would parse the tokens
63  dhi.data[SAY_WHAT] = my_token ;
64 
65  // Next token should be the token "to"
66  my_token = tokenizer.get_next_token() ;
67  if( my_token != "to" )
68  {
69  tokenizer.parse_error( my_token + " not expected\n" ) ;
70  }
71 
72  // Next token should be what is being said
73  my_token = tokenizer.get_next_token() ;
74  if( my_token == ";" )
75  {
76  tokenizer.parse_error( my_token + " not expected\n" ) ;
77  }
78  dhi.data[SAY_TO] = my_token ;
79 
80  // Last token should be the terminating semicolon (;)
81  my_token = tokenizer.get_next_token() ;
82  if( my_token != ";" )
83  {
84  tokenizer.parse_error( my_token + " not expected\n" ) ;
85  }
86 
87  return retResponse ;
88 }
89 
96 void
97 SampleSayCommand::dump( ostream &strm ) const
98 {
99  strm << BESIndent::LMarg << "SampleSayCommand::dump - ("
100  << (void *)this << ")" << endl ;
101  BESIndent::Indent() ;
102  BESCommand::dump( strm ) ;
103  BESIndent::UnIndent() ;
104 }
105 
virtual BESResponseHandler * find_handler(const string &handler)
returns the response handler with the given name from the list
tokenizer for the BES request command string
Definition: BESTokenizer.h:70
string & get_next_token()
returns the next token from the token list
error thrown if there is a user syntax error in the request or any other user error ...
handler object that knows how to create a specific response object
Structure storing information used by the BES to handle the request.
map< string, string > data
the map of string data that will be required for the current request.
void parse_error(const string &s="")
throws an exception giving the tokens up to the point of the problem
Definition: BESTokenizer.cc:63
virtual void dump(ostream &strm) const
dumps information about this object
string action
the response object requested, e.g. das, dds