CAccessorFactoryContainer Class Reference

#include <CAccessorFactoryContainer.h>

List of all members.

Public Types

typedef map< string,
CContentElement
CContent

Public Member Functions

 CAccessorFactoryContainer ()
void configure (CXMLElement *inConfigurationData)
 ~CAccessorFactoryContainer ()
void registerFactory (CAccessorFactory *inFactory, string inName)
CAccessoropenAccessor (string inName, const CXMLElement &inCollectionElement)
void closeAccessor (string inName)
bool isPresentFactory (string inName) const

Protected Attributes

CContent mContent

Private Attributes

CSelfDestroyPointer< CXMLElementmConfigurationData

Classes

class  CContentElement


Detailed Description

This is destined to hold a number of CAccessorFactories. The use of this is to have an open-close-counter for all the factories which have been registered in this

New elements are only constructed if necessary.

Author:
Wolfgang Müller

Definition at line 44 of file CAccessorFactoryContainer.h.


Member Typedef Documentation

Typedef: The content is a map of string to content element In this map is noted, which accessors are open for the collection with the given ID.

Definition at line 62 of file CAccessorFactoryContainer.h.


Constructor & Destructor Documentation

CAccessorFactoryContainer::CAccessorFactoryContainer (  ) 

construct this. In the case of static linking, this means the construction of factorys for all accessors.

Definition at line 49 of file CAccessorFactoryContainer.cc.

References registerFactory().

00049                                                     :
00050   mConfigurationData(0){
00051   //fill the accessor factory container in a sensible way
00052   //  (new CAFInvertedFile())->registerFactory(*this);
00053   // #ifdef __GIFT_BAYESIAN__
00054   //   (new CAFDistanceMatrix())->registerFactory(*this);
00055   // #endif
00056   // #ifdef __GIFT_WITH_MYSQL__
00057   //   (new CAFIFMySQL())->registerFactory(*this);
00058   // #endif
00059 
00060 #ifdef __GIFT_WITH_PERL__
00061    (new CAFPerl())->registerFactory(*this);
00062 #endif
00063   //(new CAFURL2FTS())->registerFactory(*this);
00064   //(new CAFHierarchy())->registerFactory(*this);
00065 }

CAccessorFactoryContainer::~CAccessorFactoryContainer (  ) 

The destructor destroys the CContentElements properly

Definition at line 140 of file CAccessorFactoryContainer.cc.

References mContent.

00140                                                      {
00141   for(CContent::iterator i=mContent.begin();
00142       i!=mContent.end();
00143       i++){
00144     delete i->second.mFactory;
00145   }
00146 };


Member Function Documentation

void CAccessorFactoryContainer::configure ( CXMLElement inConfigurationData  ) 

configure this

In the case of dynamic linking we will scan libdir for plugins

configure this

Definition at line 68 of file CAccessorFactoryContainer.cc.

References CXMLElement::child_list_begin(), CXMLElement::child_list_end(), getLibNameFromFileName(), CAFPlugin::getName(), CAFPlugin::isSane(), mConfigurationData, registerFactory(), and CXMLElement::stringReadAttribute().

00068                                                                          {
00069   mConfigurationData=inConfigurationData;
00070 #ifdef LINK_DYNAMICALLY
00071   cout << "--" << endl
00072        << "Configuring the CAccessorFactoryContainer:" << endl
00073        << "I am going to scan the following directorys for plugins "<< endl;
00074        
00075   set<string> lSeenLibs;
00076 
00077   if(inConfigurationData){
00078     for(list<CXMLElement*>::const_iterator i=inConfigurationData->child_list_begin();
00079   i!=inConfigurationData->child_list_end();
00080   i++
00081   ){
00082       if((*i)->getName()=="directory"){
00083   cout << (*i)->stringReadAttribute("name").second
00084        << endl;
00085   {
00086     pair<bool,string> lDirectoryName((*i)->stringReadAttribute("name"));
00087     DIR* lDirectory(0);
00088     if(lDirectoryName.first){
00089       lDirectory=opendir(lDirectoryName.second.c_str());
00090     }  
00091     if(!lDirectory){
00092       cerr << "FATAL ERROR, cannot find " << flush;
00093       if(lDirectoryName.first){
00094         cerr << lDirectoryName.second ;
00095       }
00096       cerr << endl;
00097       exit(20);
00098     }else{
00099       dirent* lDirectoryEntry;
00100       while(lDirectoryEntry=readdir(lDirectory)){
00101         string lFileName(lDirectoryEntry->d_name);
00102 
00103         pair<bool,string> lIsLibAndLibName(getLibNameFromFileName("libGIFTAc",lFileName));
00104         bool lIsLib(lIsLibAndLibName.first);
00105         string lLibName(lIsLibAndLibName.second);
00106 
00107         if(lIsLib && (lSeenLibs.find(lLibName)==lSeenLibs.end())){
00108     CAFPlugin* lPlugin(new CAFPlugin(lDirectoryName.second.c_str(),
00109              lFileName,
00110              lLibName));
00111     if(lPlugin->isSane()){
00112       cout << lFileName << " contains a sane GIFT Accessor plugin: " << lPlugin->getName() << endl;
00113       registerFactory(lPlugin,string(lPlugin->getName()));
00114       lSeenLibs.insert(lLibName);
00115     }else{
00116       cout << lFileName << " tested. Test FAILED. " << endl;
00117       delete lPlugin;
00118     }
00119         }
00120         else{
00121     if(!lIsLib){
00122       cout << "Not testing file:" << lFileName << " (File name does not match plugin name) " << endl;
00123     }else{
00124       cout << "Lib:" << lLibName << ", to be linked from " << lFileName << " already registered! " << endl;
00125     }
00126         }
00127       }
00128     }
00129   }
00130       }
00131     }
00132   }
00133   cout << "FINISHED configuring the CAccessorFactoryContainer."
00134        << endl;
00135 #endif
00136 };

void CAccessorFactoryContainer::registerFactory ( CAccessorFactory inFactory,
string  inName 
)

adding a factory to the content

Definition at line 150 of file CAccessorFactoryContainer.cc.

References mContent, and my_throw.

Referenced by CAccessorFactoryContainer(), configure(), CAFPlugin::registerFactory(), and CAccessorFactory::registerFactory().

00151                           {
00152   CContent::const_iterator lFound=mContent.find(inName);
00153   if(lFound!=mContent.end()){
00154     string lMessage("Accessor ");
00155     lMessage+=inName;
00156     lMessage+=" tried to register twice!";
00157     my_throw(VEProgrammingMistake(lMessage.c_str()));
00158   }else{
00159     mContent[inName].mFactory=inFactory;
00160     mContent[inName].mOpenCloseCounter=0;
00161   }
00162 };

CAccessor * CAccessorFactoryContainer::openAccessor ( string  inName,
const CXMLElement inCollectionElement 
)

opening an accessor: if the accessor is already constructed, then simply give the pointer, otherwhise construct a new one using the appropriate factory

Parameters:
name of the accessor to be created
inConfigurationData the configuration data of the CXMLElement to be created
opening an accessor: if the accessor is already constructed, then simply give the pointer, otherwhise construct a new one using the appropriate factory

Definition at line 176 of file CAccessorFactoryContainer.cc.

References mContent.

Referenced by CAccessorAdmin::openAccessor().

00177                                                       {
00178   CContent::const_iterator lFound=mContent.find(inName);
00179   if(lFound==mContent.end()){
00180     cerr << endl
00181    << "CAccessorFactoryContainer::openAccessor:"
00182    << inName << endl
00183    << " NOT FOUND." << endl;
00184     return 0;
00185   }else{
00186     if(!(mContent[inName].mOpenCloseCounter)){
00187       mContent[inName].mOpenCloseCounter++;
00188       cerr << endl
00189      << "CAccessorFactoryContainer::openAccessor:"
00190      << inName << endl
00191      << " NEWLY GENERATED." << endl;
00192     }else{
00193       cerr << endl
00194      << "CAccessorFactoryContainer::openAccessor:"
00195      << inName << endl
00196      << " REUSED." << endl;
00197     }
00198     return mContent[inName].mFactory->makeAccessor(inCollectionElement);
00199   }
00200 };

void CAccessorFactoryContainer::closeAccessor ( string  inName  ) 

closing an accessor. If there have been as many openAccessor as closeAccessor calls, the accessor will be delete-d.

closing an accessor. If there have been as many openAccessor as closeAccessor calls, the accessor will be delete-d.

Definition at line 207 of file CAccessorFactoryContainer.cc.

References mContent.

Referenced by CAccessorAdmin::closeAccessor().

00207                                                           {
00208   CContent::iterator lFound=mContent.find(inName);
00209   if((lFound!=mContent.end())
00210      &&
00211      !(--(lFound->second.mOpenCloseCounter))){
00212     lFound->second.mFactory->closeAccessor();
00213   }
00214 };

bool CAccessorFactoryContainer::isPresentFactory ( string  inName  )  const

Is a given factory present in the factory? Useful for building in order to avoid double registration and double dynamic linking.

Definition at line 164 of file CAccessorFactoryContainer.cc.

References mContent.

00164                                                                   {
00165   return(mContent.find(inName)!=mContent.end());
00166 }


Member Data Documentation

This tree contains the configuration data for this

Definition at line 48 of file CAccessorFactoryContainer.h.

Referenced by configure().


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