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 "BESContainerStorageCatalog.h"
00034 #include "BESContainer.h"
00035 #include "BESCatalogUtils.h"
00036 #include "BESInternalError.h"
00037 #include "BESForbiddenError.h"
00038 #include "BESInfo.h"
00039 #include "BESServiceRegistry.h"
00040 #include "GNURegex.h"
00041 #include "Error.h"
00042
00043 using namespace libdap ;
00044
00066 BESContainerStorageCatalog::BESContainerStorageCatalog( const string &n )
00067 : BESContainerStorageVolatile( n )
00068 {
00069 _utils = BESCatalogUtils::Utils( n ) ;
00070 _root_dir = _utils->get_root_dir() ;
00071 _follow_sym_links = _utils->follow_sym_links() ;
00072 }
00073
00074 BESContainerStorageCatalog::~BESContainerStorageCatalog()
00075 {
00076 }
00077
00106 void
00107 BESContainerStorageCatalog::add_container( const string &sym_name,
00108 const string &real_name,
00109 const string &type )
00110 {
00111
00112
00113
00114
00115 string::size_type stopat = real_name.length() - 1 ;
00116 while( real_name[stopat] == '/' )
00117 {
00118 stopat-- ;
00119 }
00120 string new_name = real_name.substr( 0, stopat + 1 ) ;
00121
00122 string basename ;
00123 string::size_type slash = new_name.rfind( "/" ) ;
00124 if( slash != string::npos )
00125 {
00126 basename = new_name.substr( slash+1, new_name.length() - slash ) ;
00127 }
00128 else
00129 {
00130 basename = new_name ;
00131 }
00132 if( !_utils->include( basename ) || _utils->exclude( basename ) )
00133 {
00134 string s = "Attempting to create a container with real name "
00135 + real_name + " which is on the exclude list" ;
00136 throw BESForbiddenError( s, __FILE__, __LINE__ ) ;
00137 }
00138
00139
00140
00141 string new_type = type ;
00142 if( new_type == "" )
00143 {
00144 BESCatalogUtils::match_citer i = _utils->match_list_begin() ;
00145 BESCatalogUtils::match_citer ie = _utils->match_list_end() ;
00146 bool done = false ;
00147 for( ; i != ie && !done; i++ )
00148 {
00149 BESCatalogUtils::type_reg match = (*i) ;
00150 try
00151 {
00152 Regex reg_expr( match.reg.c_str() ) ;
00153 if( reg_expr.match( real_name.c_str(), real_name.length() ) == real_name.length() )
00154 {
00155 new_type = match.type ;
00156 done = true ;
00157 }
00158 }
00159 catch( Error &e )
00160 {
00161 string serr = (string)"Unable to match data type, "
00162 + "malformed Catalog TypeMatch parameter "
00163 + "in bes configuration file around "
00164 + match.reg + ": " + e.get_error_message() ;
00165 throw BESInternalError( serr, __FILE__, __LINE__ ) ;
00166 }
00167 }
00168 }
00169 BESContainerStorageVolatile::add_container( sym_name, real_name, new_type );
00170 }
00171
00181 bool
00182 BESContainerStorageCatalog::isData( const string &inQuestion,
00183 list<string> &provides )
00184 {
00185 string node_type = "" ;
00186 BESCatalogUtils::match_citer i = _utils->match_list_begin() ;
00187 BESCatalogUtils::match_citer ie = _utils->match_list_end() ;
00188 bool done = false ;
00189 for( ; i != ie && !done; i++ )
00190 {
00191 BESCatalogUtils::type_reg match = (*i) ;
00192 try
00193 {
00194 Regex reg_expr( match.reg.c_str() ) ;
00195 if( reg_expr.match( inQuestion.c_str(), inQuestion.length() ) == inQuestion.length() )
00196 {
00197 node_type = match.type ;
00198 done = true ;
00199 }
00200 }
00201 catch( Error &e )
00202 {
00203 string serr = (string)"Unable to determine data products (is data), "
00204 + "malformed Catalog TypeMatch parameter "
00205 + "in bes configuration file around "
00206 + match.reg + ": " + e.get_error_message() ;
00207 throw BESInternalError( serr, __FILE__, __LINE__ ) ;
00208 }
00209 }
00210
00211 BESServiceRegistry::TheRegistry()->services_handled( node_type, provides ) ;
00212
00213 return done ;
00214 }
00215
00223 void
00224 BESContainerStorageCatalog::dump( ostream &strm ) const
00225 {
00226 strm << BESIndent::LMarg << "BESContainerStorageCatalog::dump - ("
00227 << (void *)this << ")" << endl ;
00228 BESIndent::Indent() ;
00229 strm << BESIndent::LMarg << "name: " << get_name() << endl ;
00230 strm << BESIndent::LMarg << "utils: " << get_name() << endl ;
00231 BESIndent::Indent() ;
00232 _utils->dump( strm ) ;
00233 BESIndent::UnIndent() ;
00234 BESIndent::UnIndent() ;
00235 }
00236