00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
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
00045 BESCatalogList::~BESCatalogList()
00046 {
00047 catalog_iter i = _catalogs.begin() ;
00048 catalog_iter e = _catalogs.end() ;
00049 for( ; i != e; i++ )
00050 {
00051 BESCatalog *catalog = (*i).second ;
00052 if( catalog ) delete catalog ;
00053 }
00054 }
00055
00063 bool
00064 BESCatalogList::add_catalog(BESCatalog * catalog)
00065 {
00066 bool stat = false;
00067 if (find_catalog(catalog->get_catalog_name()) == 0) {
00068 #if 0
00069 _catalogs[catalog->get_catalog_name()] = catalog;
00070 #endif
00071 string name = catalog->get_catalog_name() ;
00072 std::pair<const std::string, BESCatalog*> p =
00073 std::make_pair( name, catalog ) ;
00074 stat = _catalogs.insert(p).second;
00075 #if 0
00076 stat = true;
00077 #endif
00078 }
00079 return stat;
00080 }
00081
00091 bool
00092 BESCatalogList::del_catalog( const string &catalog_name )
00093 {
00094 bool ret = false ;
00095 BESCatalog *cat = 0 ;
00096 BESCatalogList::catalog_iter i ;
00097 i = _catalogs.find( catalog_name ) ;
00098 if( i != _catalogs.end() )
00099 {
00100 cat = (*i).second;
00101 _catalogs.erase( i ) ;
00102 delete cat ;
00103 ret = true ;
00104 }
00105 return ret ;
00106 }
00107
00114 BESCatalog *
00115 BESCatalogList::find_catalog( const string &catalog_name )
00116 {
00117 BESCatalog *ret = 0 ;
00118 BESCatalogList::catalog_citer i ;
00119 i = _catalogs.find( catalog_name ) ;
00120 if( i != _catalogs.end() )
00121 {
00122 ret = (*i).second;
00123 }
00124 return ret ;
00125 }
00126
00155 void
00156 BESCatalogList::show_catalog( const string &container,
00157 const string &coi,
00158 BESInfo *info )
00159 {
00160 bool done = false ;
00161
00162 if( _catalogs.size() == 1 )
00163 {
00164 catalog_citer i = _catalogs.begin() ;
00165 BESCatalog *catalog = (*i).second ;
00166 done = catalog->show_catalog( container, coi, info ) ;
00167 }
00168 else if( _catalogs.size() != 0 )
00169 {
00170
00171
00172 if( container.empty() )
00173 {
00174 map<string,string> a1 ;
00175 a1["thredds_collection"] = "\"true\"" ;
00176 a1["isData"] = "\"false\"" ;
00177 info->begin_tag( "dataset", &a1 ) ;
00178 info->add_tag( "name", "/" ) ;
00179
00180 a1["catalogRoot"] = "\"true\"" ;
00181 catalog_citer i = _catalogs.begin() ;
00182 catalog_citer e = _catalogs.end() ;
00183 for( ; i != e; i++ )
00184 {
00185 string name = (*i).first ;
00186 BESCatalog *catalog = (*i).second ;
00187 info->begin_tag( "dataset", &a1 ) ;
00188 info->add_tag( "name", name ) ;
00189 info->end_tag( "dataset" ) ;
00190 }
00191
00192 info->end_tag( "dataset" ) ;
00193
00194 done = true ;
00195 }
00196 else
00197 {
00198
00199
00200
00201 string::size_type colon = container.find( ":" ) ;
00202 if( colon == string::npos )
00203 {
00204 string serr = "Multiple catalogs present but none specified in request" ;
00205 throw BESHandlerException( serr, __FILE__, __LINE__ ) ;
00206 }
00207 else
00208 {
00209
00210 string name = container.substr( 0, colon ) ;
00211 string rest = container.substr( colon+1, container.length() - colon ) ;
00212 BESCatalog *catalog = _catalogs[ name ] ;
00213 if( catalog )
00214 {
00215 done = catalog->show_catalog( rest, coi, info ) ;
00216 }
00217 else
00218 {
00219 string serr = "The catalog " + name + " does not exist." ;
00220 throw BESHandlerException( serr, __FILE__, __LINE__ ) ;
00221 }
00222 }
00223 }
00224 }
00225 if( done == false )
00226 {
00227 string serr ;
00228 if( container != "" )
00229 {
00230 serr = (string)"Unable to find catalog information for container "
00231 + container ;
00232 }
00233 else
00234 {
00235 serr = "Unable to find catalog information for root" ;
00236 }
00237 throw BESHandlerException( serr, __FILE__, __LINE__ ) ;
00238 }
00239 }
00240
00243 BESCatalogList *
00244 BESCatalogList::TheCatalogList()
00245 {
00246 if( _instance == 0 )
00247 {
00248 _instance = new BESCatalogList ;
00249 }
00250 return _instance ;
00251 }
00252
00260 void
00261 BESCatalogList::dump( ostream &strm ) const
00262 {
00263 strm << BESIndent::LMarg << "BESCatalogList::dump - ("
00264 << (void *)this << ")" << endl ;
00265 BESIndent::Indent() ;
00266 if( _catalogs.size() )
00267 {
00268 strm << BESIndent::LMarg << "catalog list:" << endl ;
00269 BESIndent::Indent() ;
00270 catalog_citer i = _catalogs.begin() ;
00271 catalog_citer e = _catalogs.end() ;
00272 for( ; i != e; i++ )
00273 {
00274 BESCatalog *catalog = (*i).second ;
00275 strm << BESIndent::LMarg << (*i).first << catalog << endl ;
00276 }
00277 BESIndent::UnIndent() ;
00278 }
00279 else
00280 {
00281 strm << BESIndent::LMarg << "catalog list: empty" << endl ;
00282 }
00283 BESIndent::UnIndent() ;
00284 }
00285