CAccessorAdminCollection Class Reference

#include <CAccessorAdminCollection.h>

List of all members.

Public Types

typedef CContent::const_iterator const_iterator

Public Member Functions

CContent::const_iterator begin () const
CContent::const_iterator end () const
 CAccessorAdminCollection (string inFileName)
void addCollection (CXMLElement *inCollectionElement)
const CXMLElementgetCollectionElement (string inID) const
const CXMLElementgetQueryParadimList (string inID) const
CAccessorAdmingetCurrentProxy ()
CAccessorAdmingetProxy (const string &inID)
string getDefaultAccessorID () const
string toXML (bool isPrivate=false) const
CXMLElementtoXMLElement () const
CXMLElementgetCollectionInConstruction ()
void startCollectionConstruction (CXMLElement *inRoot)

Public Attributes

CContent mIDToProxy
CAccessorAdminmCurrentProxy

Protected Attributes

CSelfDestroyPointer
< CAccessorFactoryContainer
mFactory

Private Attributes

CXMLElementmCollectionInConstruction

Classes

class  CContent


Detailed Description

This is in fact a collection of collections.

The accessorcollection contains CAccessorAdmins

Definition at line 39 of file CAccessorAdminCollection.h.


Member Typedef Documentation

typedef CContent::const_iterator CAccessorAdminCollection::const_iterator

for easier read access from the outside

Definition at line 61 of file CAccessorAdminCollection.h.


Constructor & Destructor Documentation

CAccessorAdminCollection::CAccessorAdminCollection ( string  inFileName  ) 

The Accessor collection gets its configuration out of the same file as the CSessionManager

Definition at line 117 of file CAccessorAdminCollection.cc.

References CXMLElement::addAttribute(), CXMLElement::addChild(), endAccessorAdminCollectionElement(), mFactory, CXMLElement::moveUp(), my_throw, and startAccessorAdminCollectionElement().

00117                                                                    :
00118   mCollectionInConstruction(0),
00119   mFactory(new CAccessorFactoryContainer()){
00120   {
00121     cout << "-----" << endl
00122    << "Configuring CAccessorAdminCollection" << endl;
00123     // an XMLElement specifying what directories to scan
00124     // presently this is just one directory,
00125     // the libdir
00126     CXMLElement* lFilesToScan(new CXMLElement("directories-to-scan",0));
00127     assert(lFilesToScan);
00128     cout << "." << flush;
00129     CXMLElement* lTemp(new CXMLElement("directory",0));
00130     assert(lTemp);
00131     cout << "." << __LIBDIR__ << "." << flush;
00132     lTemp->addAttribute("name",__LIBDIR__);
00133     cout << "." << flush;
00134     lFilesToScan->addChild(lTemp);
00135     cout << "." << flush;
00136     lFilesToScan->moveUp();
00137     cout << "." << flush;
00138     // configure the factory i.e. make it scan directories
00139     mFactory->configure(lFilesToScan);
00140     cout << "." << flush;
00141   }
00142 
00143   ifstream lConfigFile(inFileName.c_str());
00144   if(lConfigFile){
00145       lConfigFile.seekg(0,ios::end);
00146       int lSize=lConfigFile.tellg();
00147       char lConfigFileContent[lSize+1];
00148       
00149       lConfigFile.seekg(0,ios::beg);
00150       lConfigFile.read(lConfigFileContent,
00151       lSize);
00152       
00153       lConfigFileContent[lSize]=0;
00154       
00155       cout << "--" 
00156      << "gift::CAccessorAdminCollection : I read the config file " << endl
00157      << inFileName << endl
00158 #ifdef CAC_DEBUG_PRINTOUT
00159      << "This file contains the following string: " << endl
00160      << lConfigFileContent 
00161      << endl
00162 #endif
00163      << "Now we will parse the contents of this file using an XML parser "
00164      << endl;
00165 
00166       XML_Parser lParser = XML_ParserCreate(NULL);//default encoding
00167       XML_SetUserData(lParser,
00168           this);
00169       XML_SetElementHandler(lParser, 
00170           startAccessorAdminCollectionElement, 
00171           endAccessorAdminCollectionElement);
00172       int lDone=true;
00173 
00174       do {
00175   if (!XML_Parse(lParser, 
00176            lConfigFileContent, 
00177            lSize, 
00178            lDone)) {
00179     cerr << "CAccessorAdminCollection: XML ERROR: "
00180          << XML_ErrorString(XML_GetErrorCode(lParser))
00181          << " at line "
00182          << XML_GetCurrentLineNumber(lParser)
00183          << endl
00184          << "file was:["
00185          << endl
00186          << lConfigFileContent
00187          << "]"
00188          << endl;
00189     exit(1);// this happens only in the config file
00190   }
00191       } while (!lDone);
00192 
00193       cout << "The config file has been parsed " << endl
00194      << "successfully maybe other parts" << endl
00195      << "of the program will also parse" << endl
00196      << "the same config file. " << endl
00197      << "FINISHED configuring CAccessorAdminCollection." << endl;
00198       XML_ParserFree(lParser);  
00199   }else{
00200     my_throw(string(string("could not open config file_")+inFileName+string("_")).c_str());
00201   }
00202 };


Member Function Documentation

CAccessorAdminCollection::const_iterator CAccessorAdminCollection::begin (  )  const

for reading all accessors

Definition at line 110 of file CAccessorAdminCollection.cc.

References mIDToProxy.

Referenced by CAccessorAdminCollection::CContent::~CContent().

00110                                                                            {
00111   return mIDToProxy.begin();
00112 };

CAccessorAdminCollection::const_iterator CAccessorAdminCollection::end (  )  const

for reading all accessors

Definition at line 113 of file CAccessorAdminCollection.cc.

References mIDToProxy.

Referenced by CAccessorAdminCollection::CContent::~CContent().

00113                                                                          {
00114   return mIDToProxy.end();
00115 };

void CAccessorAdminCollection::addCollection ( CXMLElement inCollectionElement  ) 

add an accessor to a collection to our list of proxies.

Definition at line 204 of file CAccessorAdminCollection.cc.

References mrml_const::collection_id, mCurrentProxy, mFactory, mIDToProxy, my_throw, and CXMLElement::stringReadAttribute().

Referenced by endAccessorAdminCollectionElement().

00204                                                                             {
00205   pair<bool,string> lID=inCollectionElement->stringReadAttribute(mrml_const::collection_id);
00206   
00207   if(!lID.first){
00208     cout << "throwing: "
00209    << VEProgrammingMistake("addAccessor")
00210    << endl
00211    << flush;
00212     my_throw(VEProgrammingMistake("addAccessor"));
00213   }
00214 
00215   if(mIDToProxy.find(lID.second)
00216      !=
00217      mIDToProxy.end()){
00218     cout << "The ID I am looking for is:"
00219    << lID.second
00220    << ", and I did not find it"
00221    << endl;
00222     cout << "throwing: "
00223    << VEDoubleInsert("addAccessor")
00224    << endl
00225    << flush;
00226     my_throw(VEDoubleInsert("addAccessor"));
00227   }else{
00228     mIDToProxy[lID.second] = (mCurrentProxy = new CAccessorAdmin(*mFactory));
00229     mIDToProxy[lID.second]->setCollectionElement(inCollectionElement);
00230     cout << "CAccessorAdminCollection: Adding collection " 
00231    << inCollectionElement->stringReadAttribute("collection-name").second << endl
00232    << "under the ID " << lID.second << endl;
00233    
00234   }
00235 };

const CXMLElement * CAccessorAdminCollection::getCollectionElement ( string  inID  )  const

get a collection configuration element by its ID

get a collection configuration element by its ID

Definition at line 325 of file CAccessorAdminCollection.cc.

References mIDToProxy.

00325                                                                                  {
00326   CContent::const_iterator lFound(mIDToProxy.find(inID));
00327 
00328   if(lFound!=mIDToProxy.end()){
00329     return lFound->second->getCollectionElement();
00330   }
00331   return 0;
00332 }

const CXMLElement * CAccessorAdminCollection::getQueryParadimList ( string  inID  )  const

get a collection configuration element by its ID

get a query paradigm element by the ID of its collection

Definition at line 336 of file CAccessorAdminCollection.cc.

References mIDToProxy.

00336                                                                                 {
00337   CContent::const_iterator lFound(mIDToProxy.find(inID));
00338 
00339   if(lFound!=mIDToProxy.end()){
00340     return lFound->second->getQueryParadigmList();
00341   }
00342   return 0;
00343 }

CAccessorAdmin & CAccessorAdminCollection::getCurrentProxy (  ) 

get the proxy on which is presently worked on

Definition at line 237 of file CAccessorAdminCollection.cc.

References mCurrentProxy.

00237                                                          {
00238   return *mCurrentProxy;
00239 };

CAccessorAdmin & CAccessorAdminCollection::getProxy ( const string &  inID  ) 

get a proxy for a given collectionID if this collection is unknown, give back the first collection in the stack

Definition at line 241 of file CAccessorAdminCollection.cc.

References getDefaultAccessorID(), mIDToProxy, and my_throw.

Referenced by CQuery::CQuery(), CQParallel::finishInit(), generateDistanceMatrix(), CQMultiple::setAlgorithm(), CQInvertedFile::setAlgorithm(), and CQHierarchy::setAlgorithm().

00241                                                                     {
00242   if(mIDToProxy.find(inID)!=mIDToProxy.end())
00243     return *mIDToProxy[inID];
00244   else{
00245     cerr << "The ID I am looking for is:"
00246    << inID
00247    << ", and I did not find it"
00248    << endl;
00249     my_throw(VENotFound(string("I was looking for a proxy with the ID: mIDToProxy _"+inID+"_ . This probably means that the collection with the ID " + inID + " is not described in your config file.").c_str()));
00250 
00251     // my_throw(VENotFound(string("mIDToProxy _"+inID+"_").c_str()));
00252 
00253     //
00254     // quick fix by WM against people nuking our server... :-(
00255     //
00256     //  BE WARNED: this can fail, if not every query 
00257     //  processor works with every collection.
00258 
00259     // this code will not be reached.
00260     return *mIDToProxy[this->getDefaultAccessorID()];
00261   }
00262 };

string CAccessorAdminCollection::getDefaultAccessorID (  )  const

simply take the first.

Definition at line 266 of file CAccessorAdminCollection.cc.

References mIDToProxy.

Referenced by getProxy().

00266                                                           {
00267   return mIDToProxy.begin()->first;
00268 };

string CAccessorAdminCollection::toXML ( bool  isPrivate = false  )  const

some tags plus our content

Definition at line 292 of file CAccessorAdminCollection.cc.

References mrml_const::collection_list, and mIDToProxy.

Referenced by CSessionManager::toXML(), and toXMLElement().

00292                                                          {
00293   string lRetVal=string("<")+mrml_const::collection_list+">\n";
00294 
00295   
00296 
00297   for(CContent::const_iterator i=mIDToProxy.begin();
00298       i!=mIDToProxy.end();
00299       i++){
00300     lRetVal+=i->second->toXML(isPrivate);
00301   }
00302 
00303   lRetVal+=string("</")+mrml_const::collection_list+">\n";
00304   return lRetVal;
00305 };

CXMLElement * CAccessorAdminCollection::toXMLElement (  )  const

The content of this as an CXMLElement

Definition at line 271 of file CAccessorAdminCollection.cc.

References CXMLElement::addChild(), mrml_const::collection_list, mIDToProxy, CXMLElement::moveUp(), and toXML().

Referenced by CSessionManager::getCollections().

00271                                                         {
00272 
00273     cout << "x" 
00274    << flush
00275    << toXML(0)
00276    << endl;
00277 
00278   CXMLElement* lReturnValue(new CXMLElement(mrml_const::collection_list,0));
00279   
00280   for(CContent::const_iterator i=mIDToProxy.begin();
00281       i!=mIDToProxy.end();
00282       i++){
00283     CXMLElement* lNewChild(i->second->toXMLElement());
00284     if(lNewChild){
00285       lReturnValue->addChild(lNewChild);
00286       lReturnValue->moveUp();
00287     }
00288   }
00289   return lReturnValue;
00290 };

CXMLElement * CAccessorAdminCollection::getCollectionInConstruction (  ) 

get the XMLElement in construction

Definition at line 306 of file CAccessorAdminCollection.cc.

References mCollectionInConstruction.

Referenced by endAccessorAdminCollectionElement(), and startAccessorAdminCollectionElement().

00306                                                                   {
00307   return mCollectionInConstruction;
00308 }

void CAccessorAdminCollection::startCollectionConstruction ( CXMLElement inRoot  ) 

set the element

Definition at line 309 of file CAccessorAdminCollection.cc.

References mCollectionInConstruction.

Referenced by endAccessorAdminCollectionElement(), and startAccessorAdminCollectionElement().

00310                           {
00311   mCollectionInConstruction=inCollection;
00312 }


Member Data Documentation

A helper for building up an CXMLElement which will later serve as configuration for the new CAccessorAdmin

Definition at line 43 of file CAccessorAdminCollection.h.

Referenced by getCollectionInConstruction(), and startCollectionConstruction().

Definition at line 57 of file CAccessorAdminCollection.h.

Referenced by addCollection(), and getCurrentProxy().

The accessor factory container: Turn a name into an accessor

Definition at line 65 of file CAccessorAdminCollection.h.

Referenced by addCollection(), and CAccessorAdminCollection().


The documentation for this class was generated from the following files:

Generated on Wed Jan 7 00:30:59 2009 for Gift by  doxygen 1.5.6