BESContainerStorageCatalog.cc

Go to the documentation of this file.
00001 // BESContainerStorageCatalog.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 "BESContainerStorageCatalog.h"
00034 #include "BESContainer.h"
00035 #include "BESCatalogUtils.h"
00036 #include "BESContainerStorageException.h"
00037 #include "BESInfo.h"
00038 #include "GNURegex.h"
00039 
00061 BESContainerStorageCatalog::BESContainerStorageCatalog( const string &n )
00062     : BESContainerStorageVolatile( n )
00063 {
00064     try
00065     {
00066         _utils = BESCatalogUtils::Utils( n ) ;
00067     }
00068     catch( BESException &e )
00069     {
00070         throw BESContainerStorageException( e.get_message(), e.get_file(), e.get_line() ) ;
00071     }
00072     _root_dir = _utils->get_root_dir() ;
00073 }
00074 
00075 BESContainerStorageCatalog::~BESContainerStorageCatalog()
00076 { 
00077 }
00078 
00094 void
00095 BESContainerStorageCatalog::add_container( const string &s_name,
00096                                            const string &r_name,
00097                                            const string &type )
00098 {
00099     // make sure that the real name passed in is not oon the exclude list
00100     // for the catalog. First, remove any trailing slashes. Then find the
00101     // basename of the remaining real name. The make sure it's not on the
00102     // exclude list.
00103     string::size_type stopat = r_name.length() - 1 ;
00104     while( r_name[stopat] == '/' )
00105     {
00106         stopat-- ;
00107     }
00108     string new_name = r_name.substr( 0, stopat + 1 ) ;
00109 
00110     string basename ;
00111     string::size_type slash = new_name.rfind( "/" ) ;
00112     if( slash != string::npos )
00113     {
00114         basename = new_name.substr( slash+1, new_name.length() - slash ) ;
00115     }
00116     else
00117     {
00118         basename = new_name ;
00119     }
00120     if( !_utils->include( basename ) || _utils->exclude( basename ) )
00121     {
00122         string s = "Attempting to create a container with real name "
00123                    + r_name + " which is on the exclude list" ;
00124         throw BESContainerStorageException( s, __FILE__, __LINE__ ) ;
00125     }
00126 
00127     // If the type is specified, then just pass that on. If not, then match
00128     // it against the types in the type list.
00129     string new_type = type ;
00130     if( new_type == "" )
00131     {
00132         BESCatalogUtils::match_citer i = _utils->match_list_begin() ;
00133         BESCatalogUtils::match_citer ie = _utils->match_list_end() ;
00134         bool done = false ;
00135         for( ; i != ie && !done; i++ )
00136         {
00137             BESCatalogUtils::type_reg match = (*i) ;
00138             // FIXME: Should we create the Regex and put it in the type_reg
00139             // structure list instead of compiling it each time? Could this
00140             // improve performance? pcw 09/08/06
00141             Regex reg_expr( match.reg.c_str() ) ;
00142             if( reg_expr.match( r_name.c_str(), r_name.length() ) != -1 )
00143             {
00144                 new_type = match.type ;
00145                 done = true ;
00146             }
00147         }
00148     }
00149     BESContainerStorageVolatile::add_container( s_name, r_name, new_type ) ;
00150 }
00151 
00161 bool
00162 BESContainerStorageCatalog::isData( const string &inQuestion,
00163                                     list<string> &provides )
00164 {
00165     string node_type = "" ;
00166     BESCatalogUtils::match_citer i = _utils->match_list_begin() ;
00167     BESCatalogUtils::match_citer ie = _utils->match_list_end() ;
00168     bool done = false ;
00169     for( ; i != ie && !done; i++ )
00170     {
00171         BESCatalogUtils::type_reg match = (*i) ;
00172         // FIXME: Should we create the Regex and put it in the type_reg
00173         // structure list instead of compiling it each time? Could this
00174         // improve performance? pcw 09/08/06
00175         Regex reg_expr( match.reg.c_str() ) ;
00176         if( reg_expr.match( inQuestion.c_str(), inQuestion.length() ) != -1 )
00177         {
00178             node_type = match.type ;
00179             done = true ;
00180         }
00181     }
00182     // Now that we have the type, go find the request handler and ask what it
00183     // provides (das, dds, ddx, data, etc...)
00184     return done ;
00185 }
00186 
00194 void
00195 BESContainerStorageCatalog::dump( ostream &strm ) const
00196 {
00197     strm << BESIndent::LMarg << "BESContainerStorageCatalog::dump - ("
00198                              << (void *)this << ")" << endl ;
00199     BESIndent::Indent() ;
00200     strm << BESIndent::LMarg << "name: " << get_name() << endl ;
00201     strm << BESIndent::LMarg << "utils: " << get_name() << endl ;
00202     BESIndent::Indent() ;
00203     _utils->dump( strm ) ;
00204     BESIndent::UnIndent() ;
00205     BESIndent::UnIndent() ;
00206 }
00207 

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