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