Back to index

nordugrid-arc-nox  1.1.0~rc6
ArcAttributeFactory.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 "ArcAttributeFactory.h"
00008 #include <arc/security/ArcPDP/attr/AttributeProxy.h>
00009 #include <arc/security/ArcPDP/attr/StringAttribute.h>
00010 #include <arc/security/ArcPDP/attr/DateTimeAttribute.h>
00011 #include <arc/security/ArcPDP/attr/X500NameAttribute.h>
00012 #include <arc/security/ArcPDP/attr/AnyURIAttribute.h>
00013 #include <arc/security/ArcPDP/attr/GenericAttribute.h>
00014 
00015 #include "ArcAttributeProxy.h"
00016 
00017 /*
00018 loader_descriptors __arc_attrfactory_modules__  = {
00019     { "attr.factory", 0, &get_attr_factory },
00020     { NULL, 0, NULL }
00021 };
00022 */
00023 
00024 using namespace Arc;
00025 namespace ArcSec {
00026 
00027 Arc::Plugin* get_arcpdp_attr_factory (Arc::PluginArgument*) {
00028     return new ArcSec::ArcAttributeFactory();
00029 }
00030 
00031 void ArcAttributeFactory::initDatatypes(){
00032   //Some Arc specified attribute types
00033   apmap.insert(std::pair<std::string, AttributeProxy*>(StringAttribute::getIdentifier(), new ArcAttributeProxy<StringAttribute>));
00034   apmap.insert(std::pair<std::string, AttributeProxy*>(DateTimeAttribute::getIdentifier(), new ArcAttributeProxy<DateTimeAttribute>));
00035   apmap.insert(std::pair<std::string, AttributeProxy*>(DateAttribute::getIdentifier(), new ArcAttributeProxy<DateAttribute>));
00036   apmap.insert(std::pair<std::string, AttributeProxy*>(TimeAttribute::getIdentifier(), new ArcAttributeProxy<TimeAttribute>));
00037   apmap.insert(std::pair<std::string, AttributeProxy*>(DurationAttribute::getIdentifier(), new ArcAttributeProxy<DurationAttribute>));
00038   apmap.insert(std::pair<std::string, AttributeProxy*>(PeriodAttribute::getIdentifier(), new ArcAttributeProxy<PeriodAttribute>));
00039   apmap.insert(std::pair<std::string, AttributeProxy*>(X500NameAttribute::getIdentifier(), new ArcAttributeProxy<X500NameAttribute>));
00040   apmap.insert(std::pair<std::string, AttributeProxy*>(AnyURIAttribute::getIdentifier(), new ArcAttributeProxy<AnyURIAttribute>));
00041   apmap.insert(std::pair<std::string, AttributeProxy*>(GenericAttribute::getIdentifier(), new ArcAttributeProxy<GenericAttribute>));
00042 
00045 }
00046 
00047 ArcAttributeFactory::ArcAttributeFactory(){
00048   initDatatypes();
00049 }
00050 
00051 AttributeValue* ArcAttributeFactory::createValue(const XMLNode& node, const std::string& type){
00052   AttrProxyMap::iterator it;
00053   if((it=apmap.find(type)) != apmap.end())
00054     return ((*it).second)->getAttribute(node);
00055   // This may look like hack, but generic attribute needs special treatment
00056   GenericAttribute* attr = new GenericAttribute(
00057           (std::string)const_cast<XMLNode&>(node),
00058           (std::string)(const_cast<XMLNode&>(node).Attribute("AttributeId")));
00059   attr->setType(type);
00060   return attr;
00061   // return NULL;
00062 }
00063 
00064 ArcAttributeFactory::~ArcAttributeFactory(){
00065   AttrProxyMap::iterator it;
00066   for(it = apmap.begin(); it != apmap.end(); it = apmap.begin()){
00067     AttributeProxy* attrproxy = (*it).second;
00068     apmap.erase(it);
00069     if(attrproxy) delete attrproxy;
00070   }
00071 }
00072 
00073 } // namespace ArcSec
00074