BESContainerStorageList.cc

Go to the documentation of this file.
00001 // BESContainerStorageList.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 <iostream>
00034 
00035 using std::endl ;
00036 
00037 #include "BESContainerStorageList.h"
00038 #include "BESContainerStorage.h"
00039 #include "BESContainerStorageException.h"
00040 #include "BESContainer.h"
00041 #include "TheBESKeys.h"
00042 #include "BESLog.h"
00043 #include "BESInfo.h"
00044 
00045 BESContainerStorageList *BESContainerStorageList::_instance = 0 ;
00046 
00047 BESContainerStorageList::BESContainerStorageList()
00048     : _first( 0 )
00049 {
00050 }
00051 
00052 BESContainerStorageList::~BESContainerStorageList()
00053 {
00054     BESContainerStorageList::persistence_list *pl = _first ;
00055     while( pl )
00056     {
00057         if( pl->_persistence_obj )
00058         {
00059             delete pl->_persistence_obj ;
00060         }
00061         BESContainerStorageList::persistence_list *next = pl->_next ;
00062         delete pl ;
00063         pl = next ;
00064     }
00065 }
00066 
00079 bool
00080 BESContainerStorageList::add_persistence( BESContainerStorage *cp )
00081 {
00082     bool ret = false ;
00083     if( !_first )
00084     {
00085         _first = new BESContainerStorageList::persistence_list ;
00086         _first->_persistence_obj = cp ;
00087         _first->_next = 0 ;
00088         ret = true ;
00089     }
00090     else
00091     {
00092         BESContainerStorageList::persistence_list *pl = _first ;
00093         bool done = false ;
00094         while( done == false )
00095         {
00096             if( pl->_persistence_obj->get_name() != cp->get_name() )
00097             {
00098                 if( pl->_next )
00099                 {
00100                     pl = pl->_next ;
00101                 }
00102                 else
00103                 {
00104                     pl->_next = new BESContainerStorageList::persistence_list ;
00105                     pl->_next->_persistence_obj = cp ;
00106                     pl->_next->_next = 0 ;
00107                     done = true ;
00108                     ret = true ;
00109                 }
00110             }
00111             else
00112             {
00113                 done = true ;
00114                 ret = false ;
00115             }
00116         }
00117     }
00118     return ret ;
00119 }
00120 
00129 bool
00130 BESContainerStorageList::del_persistence( const string &persist_name )
00131 {
00132     bool ret = false ;
00133     BESContainerStorageList::persistence_list *pl = _first ;
00134     BESContainerStorageList::persistence_list *last = 0 ;
00135 
00136     bool done = false ;
00137     while( done == false )
00138     {
00139         if( pl )
00140         {
00141             if( pl->_persistence_obj->get_name() == persist_name )
00142             {
00143                 ret = true ;
00144                 done = true ;
00145                 if( pl == _first )
00146                 {
00147                     _first = _first->_next ;
00148                 }
00149                 else
00150                 {
00151                     last->_next = pl->_next ;
00152                 }
00153                 delete pl->_persistence_obj ;
00154                 delete pl ;
00155             }
00156             else
00157             {
00158                 last = pl ;
00159                 pl = pl->_next ;
00160             }
00161         }
00162         else
00163         {
00164             done = true ;
00165         }
00166     }
00167 
00168     return ret ;
00169 }
00170 
00179 BESContainerStorage *
00180 BESContainerStorageList::find_persistence( const string &persist_name )
00181 {
00182     BESContainerStorage *ret = NULL ;
00183     BESContainerStorageList::persistence_list *pl = _first ;
00184     bool done = false ;
00185     while( done == false )
00186     {
00187         if( pl )
00188         {
00189             if( persist_name == pl->_persistence_obj->get_name() )
00190             {
00191                 ret = pl->_persistence_obj ;
00192                 done = true ;
00193             }
00194             else
00195             {
00196                 pl = pl->_next ;
00197             }
00198         }
00199         else
00200         {
00201             done = true ;
00202         }
00203     }
00204     return ret ;
00205 }
00206 
00207 bool
00208 BESContainerStorageList::isnice()
00209 {
00210     bool ret = false ;
00211     string key = "BES.Container.Persistence" ;
00212     bool found = false ;
00213     string isnice = TheBESKeys::TheKeys()->get_key( key, found ) ;
00214     if( isnice == "Nice" || isnice == "nice" || isnice == "NICE" )
00215         ret = true ;
00216     else 
00217         ret = false ;
00218     return ret ;
00219 }
00220 
00242 void
00243 BESContainerStorageList::look_for( BESContainer &d )
00244 {
00245     BESContainerStorageList::persistence_list *pl = _first ;
00246     bool done = false ;
00247     while( done == false )
00248     {
00249         if( pl )
00250         {
00251             pl->_persistence_obj->look_for( d ) ;
00252             if( d.is_valid() )
00253             {
00254                 done = true ;
00255             }
00256             else
00257             {
00258                 pl = pl->_next ;
00259             }
00260         }
00261         else
00262         {
00263             done = true ;
00264         }
00265     }
00266     if( d.is_valid() == false )
00267     {
00268         if( isnice() )
00269         {
00270             (*BESLog::TheLog()) << "Could not find the symbolic name "
00271                           << d.get_symbolic_name().c_str() << endl ;
00272         }
00273         else
00274         {
00275             string s = (string)"Could not find the symbolic name "
00276                        + d.get_symbolic_name() ;
00277             throw BESContainerStorageException( s, __FILE__, __LINE__ ) ;
00278         }
00279     }
00280 }
00281 
00294 void
00295 BESContainerStorageList::show_containers( BESInfo &info )
00296 {
00297     BESContainerStorageList::persistence_list *pl = _first ;
00298     while( pl )
00299     {
00300         info.begin_tag( "store" ) ;
00301         pl->_persistence_obj->show_containers( info ) ;
00302         info.end_tag( "store" ) ;
00303         pl = pl->_next ;
00304     }
00305 }
00306 
00314 void
00315 BESContainerStorageList::dump( ostream &strm ) const
00316 {
00317     strm << BESIndent::LMarg << "BESContainerStorageList::dump - ("
00318                              << (void *)this << ")" << endl ;
00319     BESIndent::Indent() ;
00320     BESContainerStorageList::persistence_list *pl = _first ;
00321     if( pl )
00322     {
00323         strm << BESIndent::LMarg << "container storage:" << endl ;
00324         BESIndent::Indent() ;
00325         while( pl )
00326         {
00327             pl->_persistence_obj->dump( strm ) ;
00328             pl = pl->_next ;
00329         }
00330         BESIndent::UnIndent() ;
00331     }
00332     else
00333     {
00334         strm << BESIndent::LMarg << "container storage: empty" << endl ;
00335     }
00336     BESIndent::UnIndent() ;
00337 }
00338 
00339 BESContainerStorageList *
00340 BESContainerStorageList::TheList()
00341 {
00342     if( _instance == 0 )
00343     {
00344         _instance = new BESContainerStorageList ;
00345     }
00346     return _instance ;
00347 }
00348 

Generated on Wed Aug 29 02:59:01 2007 for OPeNDAP Back End Server (BES) by  doxygen 1.5.2