OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
BESXMLGetCommand.cc
Go to the documentation of this file.
1 // BESXMLGetCommand.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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 "BESXMLGetCommand.h"
35 #include "BESDefinitionStorage.h"
36 #include "BESDefine.h"
37 #include "BESDataNames.h"
38 #include "BESResponseNames.h"
39 #include "BESDapNames.h"
40 #include "BESXMLUtils.h"
41 #include "BESUtil.h"
42 #include "BESSyntaxUserError.h"
43 #include "BESDebug.h"
44 
46  : BESXMLCommand( base_dhi ), _sub_cmd( 0 )
47 {
48 }
49 
56 void
58 {
59  string name ;
60  string value ;
61  map<string, string> props ;
62  BESXMLUtils::GetNodeInfo( node, name, value, props ) ;
63  if( name != GET_RESPONSE )
64  {
65  string err = "The specified command " + name
66  + " is not a get command" ;
67  throw BESSyntaxUserError( err, __FILE__, __LINE__ ) ;
68  }
69 
70  // grab the type first and check to see if there is a registered command
71  // to handle get.<type> requests
72  string type = props["type"] ;
73  if( type.empty() )
74  {
75  string err = name + " command: Must specify data product type" ;
76  throw BESSyntaxUserError( err, __FILE__, __LINE__ ) ;
77  }
78  string new_cmd = (string)GET_RESPONSE + "." + type ;
80  if( bldr )
81  {
82  // the base dhi was copied to this instance's _dhi variable.
83  _sub_cmd = bldr( _dhi ) ;
84  if( !_sub_cmd )
85  {
86  string err = (string)"Failed to build command object for "
87  + new_cmd ;
88  throw BESInternalError( err, __FILE__, __LINE__ ) ;
89  }
90 
91  // parse the request given the current node
92  _sub_cmd->parse_request( node ) ;
93 
94  // return from this sub command
95  return ;
96  }
97 
98  parse_basic_get( node, name, type, value, props ) ;
99  _str_cmd += ";" ;
100 
101  // now that we've set the action, go get the response handler for the
102  // action
104 }
105 
106 void
108  const string &name,
109  const string &type,
110  const string &value,
111  map<string,string> &props )
112 {
113  _str_cmd = (string)"get " + type ;
114 
115  _definition = props["definition"] ;
116  if( _definition.empty() )
117  {
118  string err = name + " command: Must specify definition" ;
119  throw BESSyntaxUserError( err, __FILE__, __LINE__ ) ;
120  }
121  _str_cmd += " for " + _definition ;
122 
123  _space = props["space"] ;
124  if( !_space.empty() ) _str_cmd += " in " + _space ;
125 
126  string returnAs = props["returnAs"] ;
127  if( returnAs.empty() )
128  {
129  returnAs = DAP2_FORMAT ;
130  }
131  _dhi.data[RETURN_CMD] = returnAs ;
132 
133  _str_cmd += " return as " + returnAs ;
134 
135  _dhi.action = "get." ;
136  _dhi.action += BESUtil::lowercase( type ) ;
137  BESDEBUG( "besxml", "Converted xml element name to command "
138  << _dhi.action << endl ) ;
139 }
140 
149 {
150  if( _sub_cmd ) return _sub_cmd->get_dhi() ;
151 
152  return _dhi ;
153 }
154 
162 void
164 {
165  // if there is a sub command then execute the prep request on it
166  if( _sub_cmd )
167  {
168  _sub_cmd->prep_request() ;
169  return ;
170  }
171 
172  BESDefine *d = 0 ;
173 
174  if( !_space.empty() )
175  {
178  if( ds )
179  {
180  d = ds->look_for( _definition ) ;
181  }
182  }
183  else
184  {
185  d = BESDefinitionStorageList::TheList()->look_for( _definition ) ;
186  }
187 
188  if( !d )
189  {
190  string s = (string)"Unable to find definition " + _definition ;
191  throw BESSyntaxUserError( s, __FILE__, __LINE__ ) ;
192  }
193 
196  while( i != ie )
197  {
198  _dhi.containers.push_back( *i ) ;
199  i++ ;
200  }
201  _dhi.data[AGG_CMD] = d->get_agg_cmd() ;
203 
204 }
205 
212 void
213 BESXMLGetCommand::dump( ostream &strm ) const
214 {
215  strm << BESIndent::LMarg << "BESXMLGetCommand::dump - ("
216  << (void *)this << ")" << endl ;
218  BESXMLCommand::dump( strm ) ;
220 }
221 
224 {
225  return new BESXMLGetCommand( base_dhi ) ;
226 }
227