OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
BESCatalogResponseHandler.cc
Go to the documentation of this file.
1 // BESCatalogResponseHandler.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 
34 #include "BESInfoList.h"
35 #include "BESInfo.h"
36 #include "BESRequestHandlerList.h"
37 #include "BESRequestHandler.h"
38 #include "BESDapNames.h"
39 #include "BESDataNames.h"
40 #include "BESCatalogList.h"
41 #include "BESCatalog.h"
42 #include "BESCatalogEntry.h"
43 #include "BESCatalogUtils.h"
44 #include "BESSyntaxUserError.h"
45 #include "BESNotFoundError.h"
46 
48  : BESResponseHandler( name )
49 {
50 }
51 
53 {
54 }
55 
66 void
68 {
70  _response = info ;
71 
72  string container = dhi.data[CONTAINER] ;
73  string catname ;
74  string defcatname = BESCatalogList::TheCatalogList()->default_catalog() ;
75  BESCatalog *defcat =
77  if( !defcat )
78  {
79  string err = (string)"Not able to find the default catalog "
80  + defcatname ;
81  throw BESInternalError( err, __FILE__, __LINE__ ) ;
82  }
83 
84  // remove all of the leading slashes
85  string::size_type notslash = container.find_first_not_of( "/", 0 ) ;
86  if( notslash != string::npos )
87  {
88  container = container.substr( notslash ) ;
89  }
90 
91  // see if there is a catalog name here. It's only a possible catalog
92  // name
93  string::size_type slash = container.find_first_of( "/", 0 ) ;
94  if( slash != string::npos )
95  {
96  catname = container.substr( 0, slash ) ;
97  }
98  else
99  {
100  catname = container ;
101  }
102 
103  // see if this catalog exists. If it does, then remove the catalog
104  // name from the container (node)
105  BESCatalog *catobj =
107  if( catobj )
108  {
109  if( slash != string::npos )
110  {
111  container = container.substr( slash+1 ) ;
112 
113  // remove repeated slashes
114  notslash = container.find_first_not_of( "/", 0 ) ;
115  if( notslash != string::npos )
116  {
117  container = container.substr( notslash ) ;
118  }
119  }
120  else
121  {
122  container = "" ;
123  }
124  }
125 
126  if( container.empty() ) container = "/" ;
127 
128  string coi = dhi.data[CATALOG_OR_INFO] ;
129 
130  BESCatalogEntry *entry = 0 ;
131  if( catobj )
132  {
133  entry = catobj->show_catalog( container, coi, entry ) ;
134  }
135  else
136  {
137  // we always want to get the container information from the
138  // default catalog, whether the node is / or not
139  entry = defcat->show_catalog( container, coi, entry ) ;
140 
141  // we only care to get the list of catalogs if the container is
142  // slash (/)
143  int num_cats = BESCatalogList::TheCatalogList()->num_catalogs() ;
144  if( container == "/" && num_cats > 1 )
145  {
147  entry,
148  false ) ;
149  }
150  }
151 
152  if( !entry )
153  {
154  string err = (string)"Failed to find node " + container ;
155  throw BESNotFoundError( err, __FILE__, __LINE__ ) ;
156  }
157 
158  // now that we have all the catalog entry information, display it
159  // start the response depending on if show catalog or show info
160  if( coi == CATALOG_RESPONSE )
161  {
162  info->begin_response( CATALOG_RESPONSE_STR, dhi ) ;
164  }
165  else
166  {
167  info->begin_response( SHOW_INFO_RESPONSE_STR, dhi ) ;
169  }
170 
171  // start with the first level entry
172  BESCatalogUtils::display_entry( entry, info ) ;
173 
174  // if we are doing a catalog response, then go one deeper
175  if( coi == CATALOG_RESPONSE )
176  {
179  for( ; ei != ee; ei++ )
180  {
181  BESCatalogUtils::display_entry( (*ei).second, info ) ;
182  info->end_tag( "dataset" ) ;
183  }
184  }
185  info->end_tag( "dataset" ) ;
186 
187  // end the response object
188  info->end_response() ;
189 
190  delete entry ;
191 }
192 
204 void
207 {
208  if( _response )
209  {
210  BESInfo *info = dynamic_cast<BESInfo *>(_response) ;
211  if( !info )
212  throw BESInternalError( "cast error", __FILE__, __LINE__ ) ;
213  info->transmit( transmitter, dhi ) ;
214  }
215 }
216 
223 void
224 BESCatalogResponseHandler::dump( ostream &strm ) const
225 {
226  strm << BESIndent::LMarg << "BESCatalogResponseHandler::dump - ("
227  << (void *)this << ")" << endl ;
229  BESResponseHandler::dump( strm ) ;
231 }
232 
235 {
236  return new BESCatalogResponseHandler( name ) ;
237 }
238 
error thrown if the resource requested cannot be found
virtual BESInfo * build_info()
Definition: BESInfoList.cc:77
virtual void end_response()
Definition: BESInfo.cc:131
exception thrown if inernal error encountered
static BESResponseHandler * CatalogResponseBuilder(const string &name)
virtual BESCatalog * find_catalog(const string &catalog_name)
find the catalog in the list with the specified name
virtual void execute(BESDataHandlerInterface &dhi)
executes the command 'show catalog|leaves [for ];' by returning nodes or leaves at the top leve...
static BESInfoList * TheList()
Definition: BESInfoList.cc:142
BESCatalogResponseHandler(const string &name)
virtual void transmit(BESTransmitter *transmitter, BESDataHandlerInterface &dhi)=0
transmit the informational object
virtual BESCatalogEntry * show_catalog(const string &container, const string &coi, BESCatalogEntry *entry)=0
virtual BESCatalogEntry * show_catalogs(BESDataHandlerInterface &dhi, BESCatalogEntry *entry, bool show_default=true)
show the list of catalogs
virtual catalog_citer get_ending_entry()
static void Indent()
Definition: BESIndent.cc:38
virtual catalog_citer get_beginning_entry()
BESResponseObject * _response
handler object that knows how to create a specific response object
informational response object
Definition: BESInfo.h:68
#define CATALOG_OR_INFO
Definition: BESDapNames.h:89
virtual string default_catalog()
#define SHOW_INFO_RESPONSE_STR
Definition: BESDapNames.h:78
static ostream & LMarg(ostream &strm)
Definition: BESIndent.cc:73
#define CONTAINER
Definition: BESDataNames.h:63
static void display_entry(BESCatalogEntry *entry, BESInfo *info)
virtual void dump(ostream &strm) const
dumps information about this object
#define CATALOG_RESPONSE
Definition: BESDapNames.h:75
abstract base class catalog object.
Definition: BESCatalog.h:47
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.
virtual void dump(ostream &strm) const
dumps information about this object
map< string, BESCatalogEntry * >::const_iterator catalog_citer
virtual void begin_response(const string &response_name, BESDataHandlerInterface &dhi)
begin the informational response
Definition: BESInfo.cc:123
static void UnIndent()
Definition: BESIndent.cc:44
static BESCatalogList * TheCatalogList()
returns the singleton BESCatalogList instance
virtual void transmit(BESTransmitter *transmitter, BESDataHandlerInterface &dhi)
transmit the response object built by the execute command using the specified transmitter object ...
#define CATALOG_RESPONSE_STR
Definition: BESDapNames.h:76
virtual void end_tag(const string &tag_name)
Definition: BESInfo.cc:149
virtual int num_catalogs()