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., 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 
34 #include "BESInfoList.h"
35 #include "BESInfo.h"
36 #include "BESRequestHandlerList.h"
37 #include "BESRequestHandler.h"
38 #include "BESNames.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 
68  _response = info;
69 
70  string container = dhi.data[CONTAINER];
71  string catname;
72  string defcatname = BESCatalogList::TheCatalogList()->default_catalog();
74  if (!defcat) {
75  string err = (string) "Not able to find the default catalog "
76  + defcatname;
77  throw BESInternalError(err, __FILE__, __LINE__);
78  }
79 
80  // remove all of the leading slashes from the container name
81  string::size_type notslash = container.find_first_not_of("/", 0);
82  if (notslash != string::npos) {
83  container = container.substr(notslash);
84  }
85 
86  // see if there is a catalog name here. It's only a possible catalog
87  // name
88  string::size_type slash = container.find_first_of("/", 0);
89  if (slash != string::npos) {
90  catname = container.substr(0, slash);
91  } else {
92  catname = container;
93  }
94 
95  // see if this catalog exists. If it does, then remove the catalog
96  // name from the container (node)
98  catname);
99  if (catobj) {
100  if (slash != string::npos) {
101  container = container.substr(slash + 1);
102 
103  // remove repeated slashes
104  notslash = container.find_first_not_of("/", 0);
105  if (notslash != string::npos) {
106  container = container.substr(notslash);
107  }
108  } else {
109  container = "";
110  }
111  }
112 
113  if (container.empty())
114  container = "/";
115 
116  string coi = dhi.data[CATALOG_OR_INFO];
117 
118  BESCatalogEntry *entry = 0;
119  if (catobj) {
120  entry = catobj->show_catalog(container, coi, entry);
121  } else {
122  // we always want to get the container information from the
123  // default catalog, whether the node is / or not
124  entry = defcat->show_catalog(container, coi, entry);
125 
126  // we only care to get the list of catalogs if the container is
127  // slash (/)
128  int num_cats = BESCatalogList::TheCatalogList()->num_catalogs();
129  if (container == "/" && num_cats > 1) {
130  entry = BESCatalogList::TheCatalogList()->show_catalogs(dhi, entry,
131  false);
132  }
133  }
134 
135  if (!entry) {
136  string err = (string) "Failed to find node " + container;
137  throw BESNotFoundError(err, __FILE__, __LINE__);
138  }
139 
140  // now that we have all the catalog entry information, display it
141  // start the response depending on if show catalog or show info
142  if (coi == CATALOG_RESPONSE) {
145  } else {
148  }
149 
150  // start with the first level entry
151  BESCatalogUtils::display_entry(entry, info);
152 
153  // if we are doing a catalog response, then go one deeper
154  if (coi == CATALOG_RESPONSE) {
157  for (; ei != ee; ei++) {
158  BESCatalogUtils::display_entry((*ei).second, info);
159  info->end_tag("dataset");
160  }
161  }
162  info->end_tag("dataset");
163 
164  // end the response object
165  info->end_response();
166 
167  delete entry;
168 }
169 
181 void
184 {
185  if( _response )
186  {
187  BESInfo *info = dynamic_cast<BESInfo *>(_response) ;
188  if( !info )
189  throw BESInternalError( "cast error", __FILE__, __LINE__ ) ;
190  info->transmit( transmitter, dhi ) ;
191  }
192 }
193 
200 void
201 BESCatalogResponseHandler::dump( ostream &strm ) const
202 {
203  strm << BESIndent::LMarg << "BESCatalogResponseHandler::dump - ("
204  << (void *)this << ")" << endl ;
206  BESResponseHandler::dump( strm ) ;
208 }
209 
212 {
213  return new BESCatalogResponseHandler( name ) ;
214 }
215 
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
#define CATALOG_OR_INFO
Definition: BESNames.h:46
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
#define CATALOG_RESPONSE_STR
Definition: BESNames.h:39
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
virtual string default_catalog()
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
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
#define CATALOG_RESPONSE
Definition: BESNames.h:38
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 ...
virtual void end_tag(const string &tag_name)
Definition: BESInfo.cc:149
virtual int num_catalogs()
#define SHOW_INFO_RESPONSE_STR
Definition: BESNames.h:41