bes  Updated for version 3.19.1
BESSetContainerResponseHandler.cc
1 // BESSetContainerResponseHandler.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 "BESSetContainerResponseHandler.h"
34 #include "BESSilentInfo.h"
35 #include "BESContainerStorageList.h"
36 #include "BESContainerStorage.h"
37 #include "BESDataNames.h"
38 #include "BESSyntaxUserError.h"
39 #include "BESResponseNames.h"
40 #include "BESDebug.h"
41 
42 BESSetContainerResponseHandler::BESSetContainerResponseHandler(const string &name) :
43  BESResponseHandler(name)
44 {
45 }
46 
47 BESSetContainerResponseHandler::~BESSetContainerResponseHandler()
48 {
49 }
50 
86 {
87  dhi.action_name = SETCONTAINER_STR;
88  BESInfo *info = new BESSilentInfo();
89  _response = info;
90 
91  string store_name = dhi.data[STORE_NAME];
92  string symbolic_name = dhi.data[SYMBOLIC_NAME];
93  string real_name = dhi.data[REAL_NAME];
94  string container_type = dhi.data[CONTAINER_TYPE];
95  BESDEBUG( "bes", "BESSetContainerResponseHandler::execute store = "
96  << dhi.data[STORE_NAME] << endl );
97  BESDEBUG( "bes", "BESSetContainerResponseHandler::execute symbolic = "
98  << dhi.data[SYMBOLIC_NAME] << endl );
99  BESDEBUG( "bes", "BESSetContainerResponseHandler::execute real = "
100  << dhi.data[REAL_NAME] << endl );
101  BESDEBUG( "bes", "BESSetContainerResponseHandler::execute type = "
102  << dhi.data[CONTAINER_TYPE] << endl );
103  BESContainerStorage *cp = BESContainerStorageList::TheList()->find_persistence(store_name);
104  if (cp) {
105  BESDEBUG("bes", "BESSetContainerResponseHandler::execute adding the container..." << endl);
106  cp->del_container(symbolic_name);
107  cp->add_container(symbolic_name, real_name, container_type);
108  BESDEBUG("bes", "BESSetContainerResponseHandler::execute Done" << endl);
109 
110  }
111  else {
112  string ret = (string) "Unable to add container \"" + symbolic_name + "\" to container storage \"" + store_name
113  + "\". Store does not exist.";
114  throw BESSyntaxUserError(ret, __FILE__, __LINE__);
115  }
116 }
117 
131 {
132  if (_response) {
133  BESInfo *info = dynamic_cast<BESInfo *>(_response);
134  if (!info)
135  throw BESInternalError("cast error", __FILE__, __LINE__);
136  info->transmit(transmitter, dhi);
137  }
138 }
139 
146 void BESSetContainerResponseHandler::dump(ostream &strm) const
147 {
148  strm << BESIndent::LMarg << "BESSetContainerResponseHandler::dump - (" << (void *) this << ")" << endl;
149  BESIndent::Indent();
151  BESIndent::UnIndent();
152 }
153 
155 BESSetContainerResponseHandler::SetContainerResponseBuilder(const string &name)
156 {
157  return new BESSetContainerResponseHandler(name);
158 }
159 
silent informational response object
Definition: BESSilentInfo.h:49
provides persistent storage for data storage information represented by a container.
exception thrown if inernal error encountered
virtual BESContainerStorage * find_persistence(const string &persist_name)
find the persistence store with the given name
virtual void dump(ostream &strm) const
dumps information about this object
virtual void transmit(BESTransmitter *transmitter, BESDataHandlerInterface &dhi)
transmit the response object built by the execute command using the specified transmitter object ...
virtual void transmit(BESTransmitter *transmitter, BESDataHandlerInterface &dhi)=0
transmit the informational object
error thrown if there is a user syntax error in the request or any other user error ...
response handler that creates a container given the symbolic name, real name, and data type...
handler object that knows how to create a specific response object
informational response object
Definition: BESInfo.h:68
virtual void add_container(const string &sym_name, const string &real_name, const string &type)=0
adds a container with the provided information
virtual void execute(BESDataHandlerInterface &dhi)
executes the command to create a new container or replaces an already existing container based on the...
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
virtual bool del_container(const string &s_name)=0
removes a container with the given symbolic name