BESCatalogList.cc

Go to the documentation of this file.
00001 // BESCatalogList.cc
00002 
00003 // This file is part of bes, A C++ back-end server implementation framework
00004 // for the OPeNDAP Data Access Protocol.
00005 
00006 // Copyright (c) 2004,2005 University Corporation for Atmospheric Research
00007 // Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
00008 //
00009 // This library is free software; you can redistribute it and/or
00010 // modify it under the terms of the GNU Lesser General Public
00011 // License as published by the Free Software Foundation; either
00012 // version 2.1 of the License, or (at your option) any later version.
00013 // 
00014 // This library is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 // Lesser General Public License for more details.
00018 // 
00019 // You should have received a copy of the GNU Lesser General Public
00020 // License along with this library; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 //
00023 // You can contact University Corporation for Atmospheric Research at
00024 // 3080 Center Green Drive, Boulder, CO 80301
00025  
00026 // (c) COPYRIGHT University Corporation for Atmostpheric Research 2004-2005
00027 // Please read the full copyright statement in the file COPYRIGHT_UCAR.
00028 //
00029 // Authors:
00030 //      pwest       Patrick West <pwest@ucar.edu>
00031 //      jgarcia     Jose Garcia <jgarcia@ucar.edu>
00032 
00033 #include "BESCatalogList.h"
00034 #include "BESCatalog.h"
00035 #include "BESResponseException.h"
00036 #include "BESInfo.h"
00037 #include "BESHandlerException.h"
00038 
00039 BESCatalogList *BESCatalogList::_instance = 0 ;
00040 
00041 BESCatalogList::~BESCatalogList()
00042 {
00043     catalog_iter i = _catalogs.begin() ;
00044     catalog_iter e = _catalogs.end() ;
00045     for( ; i != e; i++ )
00046     {
00047         BESCatalog *catalog = (*i).second ;
00048         if( catalog ) delete catalog ;
00049     }
00050 }
00051 
00052 bool BESCatalogList::add_catalog(BESCatalog * catalog)
00053 {
00054     bool stat = false;
00055     if (find_catalog(catalog->get_catalog_name()) == 0) {
00056 #if 0
00057         _catalogs[catalog->get_catalog_name()] = catalog;
00058 #endif
00059         std::pair<const std::string, BESCatalog*> p = std::make_pair("test", catalog);
00060         stat = _catalogs.insert(p).second;
00061 #if 0
00062         stat = true;
00063 #endif
00064     }
00065     return stat;
00066 }
00067 
00068 bool
00069 BESCatalogList::rem_catalog( const string &catalog_name )
00070 {
00071     BESCatalog *ret = 0 ;
00072     BESCatalogList::catalog_iter i ;
00073     i = _catalogs.find( catalog_name ) ;
00074     if( i != _catalogs.end() )
00075     {
00076         ret = (*i).second;
00077         _catalogs.erase( i ) ;
00078     }
00079     return ret ;
00080 }
00081 
00082 BESCatalog *
00083 BESCatalogList::find_catalog( const string &catalog_name )
00084 {
00085     BESCatalog *ret = 0 ;
00086     BESCatalogList::catalog_citer i ;
00087     i = _catalogs.find( catalog_name ) ;
00088     if( i != _catalogs.end() )
00089     {
00090         ret = (*i).second;
00091     }
00092     return ret ;
00093 }
00094 
00095 void
00096 BESCatalogList::show_catalog( const string &container,
00097                            const string &coi,
00098                            BESInfo *info )
00099 {
00100     catalog_citer i = _catalogs.begin() ;
00101     catalog_citer e = _catalogs.end() ;
00102     bool done = false ;
00103     for( ; i != e && done == false; i++ )
00104     {
00105         BESCatalog *catalog = (*i).second ;
00106         done = catalog->show_catalog( container, coi, info ) ;
00107     }
00108     if( done == false )
00109     {
00110         string serr ;
00111         if( container != "" )
00112         {
00113             serr = (string)"Unable to find catalog information for container "
00114                    + container ;
00115         }
00116         else
00117         {
00118             serr = "Unable to find catalog information for root" ;
00119         }
00120         throw BESHandlerException( serr, __FILE__, __LINE__ ) ;
00121         //info->add_exception( "Error", serr, __FILE__, __LINE__ ) ;
00122     }
00123 }
00124 
00125 BESCatalogList *
00126 BESCatalogList::TheCatalogList()
00127 {
00128     if( _instance == 0 )
00129     {
00130         _instance = new BESCatalogList ;
00131     }
00132     return _instance ;
00133 }
00134 
00142 void
00143 BESCatalogList::dump( ostream &strm ) const
00144 {
00145     strm << BESIndent::LMarg << "BESCatalogList::dump - ("
00146                              << (void *)this << ")" << endl ;
00147     BESIndent::Indent() ;
00148     if( _catalogs.size() )
00149     {
00150         strm << BESIndent::LMarg << "catalog list:" << endl ;
00151         BESIndent::Indent() ;
00152         catalog_citer i = _catalogs.begin() ;
00153         catalog_citer e = _catalogs.end() ;
00154         for( ; i != e; i++ )
00155         {
00156             BESCatalog *catalog = (*i).second ;
00157             strm << BESIndent::LMarg << (*i).first << catalog << endl ;
00158         }
00159         BESIndent::UnIndent() ;
00160     }
00161     else
00162     {
00163         strm << BESIndent::LMarg << "catalog list: empty" << endl ;
00164     }
00165     BESIndent::UnIndent() ;
00166 }
00167 

Generated on Wed Aug 29 03:20:58 2007 for OPeNDAP Back End Server (BES) by  doxygen 1.5.2