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 "BESInfo.h"
00036 #include "BESSyntaxUserError.h"
00037
00038 BESCatalogList *BESCatalogList::_instance = 0 ;
00039
00044 BESCatalogList::~BESCatalogList()
00045 {
00046 catalog_iter i = _catalogs.begin() ;
00047 catalog_iter e = _catalogs.end() ;
00048 for( ; i != e; i++ )
00049 {
00050 BESCatalog *catalog = (*i).second ;
00051 if( catalog ) delete catalog ;
00052 }
00053 }
00054
00062 bool
00063 BESCatalogList::add_catalog(BESCatalog * catalog)
00064 {
00065 bool stat = false;
00066 if (find_catalog(catalog->get_catalog_name()) == 0) {
00067 #if 0
00068 _catalogs[catalog->get_catalog_name()] = catalog;
00069 #endif
00070 string name = catalog->get_catalog_name() ;
00071 std::pair<const std::string, BESCatalog*> p =
00072 std::make_pair( name, catalog ) ;
00073 stat = _catalogs.insert(p).second;
00074 #if 0
00075 stat = true;
00076 #endif
00077 }
00078 return stat;
00079 }
00080
00090 bool
00091 BESCatalogList::del_catalog( const string &catalog_name )
00092 {
00093 bool ret = false ;
00094 BESCatalog *cat = 0 ;
00095 BESCatalogList::catalog_iter i ;
00096 i = _catalogs.find( catalog_name ) ;
00097 if( i != _catalogs.end() )
00098 {
00099 cat = (*i).second;
00100 _catalogs.erase( i ) ;
00101 delete cat ;
00102 ret = true ;
00103 }
00104 return ret ;
00105 }
00106
00113 BESCatalog *
00114 BESCatalogList::find_catalog( const string &catalog_name )
00115 {
00116 BESCatalog *ret = 0 ;
00117 BESCatalogList::catalog_citer i ;
00118 i = _catalogs.find( catalog_name ) ;
00119 if( i != _catalogs.end() )
00120 {
00121 ret = (*i).second;
00122 }
00123 return ret ;
00124 }
00125
00158 void
00159 BESCatalogList::show_catalog( const string &container,
00160 const string &coi,
00161 BESInfo *info )
00162 {
00163
00164 if( _catalogs.size() == 1 )
00165 {
00166 catalog_citer i = _catalogs.begin() ;
00167 BESCatalog *catalog = (*i).second ;
00168 catalog->show_catalog( container, coi, info ) ;
00169 }
00170 else if( _catalogs.size() != 0 )
00171 {
00172
00173
00174 if( container.empty() )
00175 {
00176 map<string,string> a1 ;
00177 a1["thredds_collection"] = "\"true\"" ;
00178 a1["isData"] = "\"false\"" ;
00179 info->begin_tag( "dataset", &a1 ) ;
00180 info->add_tag( "name", "/" ) ;
00181
00182 a1["catalogRoot"] = "\"true\"" ;
00183 catalog_citer i = _catalogs.begin() ;
00184 catalog_citer e = _catalogs.end() ;
00185 for( ; i != e; i++ )
00186 {
00187 string name = (*i).first ;
00188 BESCatalog *catalog = (*i).second ;
00189 info->begin_tag( "dataset", &a1 ) ;
00190 info->add_tag( "name", name ) ;
00191 info->end_tag( "dataset" ) ;
00192 }
00193
00194 info->end_tag( "dataset" ) ;
00195 }
00196 else
00197 {
00198
00199
00200
00201 string::size_type colon = container.find( ":" ) ;
00202 if( colon == string::npos )
00203 {
00204 string serr = "You must specify a catalog to use." ;
00205 throw BESSyntaxUserError( 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 catalog->show_catalog( rest, coi, info ) ;
00216 }
00217 else
00218 {
00219 string serr = "The catalog " + name + " does not exist." ;
00220 throw BESSyntaxUserError( serr, __FILE__, __LINE__ ) ;
00221 }
00222 }
00223 }
00224 }
00225 }
00226
00229 BESCatalogList *
00230 BESCatalogList::TheCatalogList()
00231 {
00232 if( _instance == 0 )
00233 {
00234 _instance = new BESCatalogList ;
00235 }
00236 return _instance ;
00237 }
00238
00246 void
00247 BESCatalogList::dump( ostream &strm ) const
00248 {
00249 strm << BESIndent::LMarg << "BESCatalogList::dump - ("
00250 << (void *)this << ")" << endl ;
00251 BESIndent::Indent() ;
00252 if( _catalogs.size() )
00253 {
00254 strm << BESIndent::LMarg << "catalog list:" << endl ;
00255 BESIndent::Indent() ;
00256 catalog_citer i = _catalogs.begin() ;
00257 catalog_citer e = _catalogs.end() ;
00258 for( ; i != e; i++ )
00259 {
00260 BESCatalog *catalog = (*i).second ;
00261 strm << BESIndent::LMarg << (*i).first << catalog << endl ;
00262 }
00263 BESIndent::UnIndent() ;
00264 }
00265 else
00266 {
00267 strm << BESIndent::LMarg << "catalog list: empty" << endl ;
00268 }
00269 BESIndent::UnIndent() ;
00270 }
00271