Back to index

nordugrid-arc-nox  1.1.0~rc6
SecAttr.cpp
Go to the documentation of this file.
00001 #include "SecAttr.h"
00002 
00003 
00004 namespace Arc {
00005 
00006 SecAttrFormat SecAttr::UNDEFINED;
00007 SecAttrFormat SecAttr::ARCAuth("arc");
00008 SecAttrFormat SecAttr::XACML("xacml");
00009 SecAttrFormat SecAttr::SAML("saml");
00010 SecAttrFormat SecAttr::GACL("gacl");
00011 
00012 bool SecAttr::equal(const SecAttr&) const {
00013   return false;
00014 }
00015 
00016 SecAttr::operator bool() const {
00017   return false;
00018 }
00019 
00020 bool SecAttr::Export(SecAttrFormat format,std::string &val) const {
00021   NS ns;
00022   XMLNode x(ns, "");
00023   if(!Export(format,x)) return false;
00024   x.GetXML(val);
00025   return true;
00026 }
00027 
00028 bool SecAttr::Export(SecAttrFormat, XMLNode&) const {
00029   return false;
00030 }
00031 
00032 bool SecAttr::Import(SecAttrFormat format,const std::string &val) {
00033   XMLNode x(val);
00034   if(!x) return false;
00035   return Import(format,x);
00036 }
00037 
00038 bool SecAttr::Import(SecAttrFormat, XMLNode) {
00039   return false;
00040 }
00041 
00042 MultiSecAttr::operator bool() const {
00043   return !attrs_.empty();
00044 }
00045 
00046 bool MultiSecAttr::Export(SecAttrFormat format,XMLNode &val) const {
00047   // Name of created node to be replaced by inheriting class
00048   if(!val) {
00049     NS ns;
00050     XMLNode(ns,"MultiSecAttr").New(val);
00051   } else {
00052     val.Name("MultiSecAttr");
00053   };
00054   for(std::list<SecAttr*>::const_iterator a = attrs_.begin();
00055                a!=attrs_.end();++a) {
00056     NS ns; XMLNode x(ns,"");
00057     if(!((*a)->Export(format,x))) return false;
00058     val.NewChild(x);
00059   }
00060   return true;
00061 }
00062 
00063 bool MultiSecAttr::Import(SecAttrFormat format,XMLNode val) {
00064   XMLNode x = val.Child(0);
00065   for(;(bool)x;x=x[1]) {
00066     if(!Add(format,x)) return false;
00067   }
00068   return true;
00069 }
00070 
00071 // This method to be implemented in inheriting classes
00072 // or there must be an automatic detection of registered
00073 // object types implemented.
00074 bool MultiSecAttr::Add(SecAttrFormat, XMLNode&) {
00075   return false;
00076 }
00077 
00078 // This implemention assumes odrered lists of attributes
00079 bool MultiSecAttr::equal(const SecAttr &b) const {
00080   try {
00081     const MultiSecAttr& b_ = dynamic_cast<const MultiSecAttr&>(b);
00082     std::list<SecAttr*>::const_iterator i_a = attrs_.begin();
00083     std::list<SecAttr*>::const_iterator i_b = b_.attrs_.begin();
00084     for(;;) {
00085       if((i_a == attrs_.end()) && (i_b == b_.attrs_.end())) break;
00086       if(i_a == attrs_.end()) return false;
00087       if(i_b == b_.attrs_.end()) return false;
00088       if((**i_a) != (**i_b)) return false;
00089     }
00090     return true;
00091   } catch(std::exception&) { };
00092   return false;
00093 }
00094 
00095 }
00096