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
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
00100
00101
00102
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
00128
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
00139
00140
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
00173
00174
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
00183
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