Back to index

nordugrid-arc-nox  1.1.0~rc6
ArcFnFactory.cpp
Go to the documentation of this file.
00001 #ifdef HAVE_CONFIG_H
00002 #include <config.h>
00003 #endif
00004 
00005 #include <arc/security/ClassLoader.h>
00006 
00007 #include "ArcFnFactory.h"
00008 #include <arc/security/ArcPDP/fn/EqualFunction.h>
00009 #include <arc/security/ArcPDP/fn/MatchFunction.h>
00010 #include <arc/security/ArcPDP/fn/InRangeFunction.h>
00011 #include <arc/security/ArcPDP/attr/StringAttribute.h>
00012 #include <arc/security/ArcPDP/attr/DateTimeAttribute.h>
00013 #include <arc/security/ArcPDP/attr/X500NameAttribute.h>
00014 #include <arc/security/ArcPDP/attr/AnyURIAttribute.h>
00015 
00016 
00017 /*
00018 loader_descriptors __arc_fnfactory_modules__  = {
00019     { "fn.factory", 0, &get_fn_factory },
00020     { NULL, 0, NULL }
00021 };
00022 */
00023 
00024 
00025 using namespace Arc;
00026 
00027 namespace ArcSec {
00028 
00029 Arc::Plugin* get_arcpdp_fn_factory (Arc::PluginArgument*) {
00030     return new ArcSec::ArcFnFactory();
00031 }
00032 
00033 void ArcFnFactory::initFunctions(){
00035   //fnmap.insert(pair<std::string, Function*>(StringFunction.identify, new StringFunction));
00036   //fnmap.insert(pair<std::string, Function*>(DateMathFunction.identify, new DateMathFunction));
00039   //EqualFunctions
00040   std::string fnName = EqualFunction::getFunctionName(StringAttribute::getIdentifier());
00041   std::string argType = StringAttribute::getIdentifier();
00042   fnmap.insert(std::pair<std::string, Function*>(fnName, new EqualFunction(fnName, argType)));
00043 
00044   fnName = EqualFunction::getFunctionName(DateTimeAttribute::getIdentifier());
00045   argType = DateTimeAttribute::getIdentifier();
00046   fnmap.insert(std::pair<std::string, Function*>(fnName, new EqualFunction(fnName, argType)));
00047 
00048   fnName = EqualFunction::getFunctionName(DateAttribute::getIdentifier());
00049   argType = DateAttribute::getIdentifier();
00050   fnmap.insert(std::pair<std::string, Function*>(fnName, new EqualFunction(fnName, argType)));
00051 
00052   fnName = EqualFunction::getFunctionName(TimeAttribute::getIdentifier());
00053   argType = TimeAttribute::getIdentifier();
00054   fnmap.insert(std::pair<std::string, Function*>(fnName, new EqualFunction(fnName, argType)));
00055 
00056   fnName = EqualFunction::getFunctionName(DurationAttribute::getIdentifier());
00057   argType = DurationAttribute::getIdentifier();
00058   fnmap.insert(std::pair<std::string, Function*>(fnName, new EqualFunction(fnName, argType)));
00059 
00060   fnName = EqualFunction::getFunctionName(PeriodAttribute::getIdentifier());
00061   argType = PeriodAttribute::getIdentifier();
00062   fnmap.insert(std::pair<std::string, Function*>(fnName, new EqualFunction(fnName, argType)));
00063 
00064   fnName = EqualFunction::getFunctionName(X500NameAttribute::getIdentifier());
00065   argType = X500NameAttribute::getIdentifier();
00066   fnmap.insert(std::pair<std::string, Function*>(fnName, new EqualFunction(fnName, argType)));
00067 
00068   fnName = EqualFunction::getFunctionName(AnyURIAttribute::getIdentifier());
00069   argType = AnyURIAttribute::getIdentifier();
00070   fnmap.insert(std::pair<std::string, Function*>(fnName, new EqualFunction(fnName, argType)));
00071 
00072   //MatchFunctions
00073   fnName = MatchFunction::getFunctionName(StringAttribute::getIdentifier());
00074   argType = StringAttribute::getIdentifier();
00075   fnmap.insert(std::pair<std::string, Function*>(fnName, new MatchFunction(fnName, argType)));
00076 
00077   fnName = MatchFunction::getFunctionName(X500NameAttribute::getIdentifier());
00078   argType = X500NameAttribute::getIdentifier();
00079   fnmap.insert(std::pair<std::string, Function*>(fnName, new MatchFunction(fnName, argType)));
00080 
00081   fnName = MatchFunction::getFunctionName(AnyURIAttribute::getIdentifier());
00082   argType = AnyURIAttribute::getIdentifier();
00083   fnmap.insert(std::pair<std::string, Function*>(fnName, new MatchFunction(fnName, argType)));
00084 
00085   //InRangeFunctions
00086   fnName = InRangeFunction::getFunctionName(StringAttribute::getIdentifier());
00087   argType = StringAttribute::getIdentifier();
00088   fnmap.insert(std::pair<std::string, Function*>(fnName, new InRangeFunction(fnName, argType)));
00089 
00090   fnName = InRangeFunction::getFunctionName(PeriodAttribute::getIdentifier());
00091   argType = PeriodAttribute::getIdentifier();
00092   fnmap.insert(std::pair<std::string, Function*>(fnName, new InRangeFunction(fnName, argType)));
00093 }
00094 
00095 ArcFnFactory::ArcFnFactory(){
00096   initFunctions();
00097 }
00098 
00099 Function* ArcFnFactory::createFn(const std::string& type){
00100   FnMap::iterator it; 
00101   if((it=fnmap.find(type)) != fnmap.end())
00102     return (*it).second;
00103   else return NULL;
00104 }
00105 
00106 ArcFnFactory::~ArcFnFactory(){
00107   FnMap::iterator it;
00108   for(it = fnmap.begin(); it != fnmap.end(); it = fnmap.begin()){
00109     Function* fn = (*it).second;
00110     fnmap.erase(it);
00111     if(fn) delete fn;
00112   }
00113 }
00114 
00115 } // namespace ArcSec
00116