TLDAPEntry.cxx

Go to the documentation of this file.
00001 // @(#)root/ldap:$Id: TLDAPEntry.cxx 20882 2007-11-19 11:31:26Z rdm $
00002 // Author: Evgenia Smirnova   21/09/2001
00003 
00004 /*************************************************************************
00005  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00006  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00007  *************************************************************************/
00008 
00009 #include "TLDAPEntry.h"
00010 #include "TLDAPAttribute.h"
00011 #include "Riostream.h"
00012 
00013 
00014 ClassImp(TLDAPEntry)
00015 
00016 //______________________________________________________________________________
00017 TLDAPEntry::TLDAPEntry(const char *dn) : fNCount(0)
00018 {
00019    // Creates the new TLDAPEntry object with the specified DN (distinguished
00020    // name) and the empty list of attributes.
00021    // const char *dn: The DN of the entry. You can change it later by calling
00022    //                 the SetDn() member function
00023 
00024    SetDn(dn);
00025    fAttr = new TList;
00026    fAttr->SetOwner();
00027 }
00028 
00029 //______________________________________________________________________________
00030 TLDAPEntry::TLDAPEntry(const TLDAPEntry &e) : TObject(e), fNCount(e.fNCount)
00031 {
00032    // Copy ctor.
00033 
00034    SetDn(e.GetDn());
00035    fAttr = new TList;
00036    fAttr->SetOwner();
00037 
00038    TIter next(e.fAttr);
00039    while (TLDAPAttribute *att = (TLDAPAttribute *)next()) {
00040       fAttr->AddLast(new TLDAPAttribute(*att));
00041    }
00042 }
00043 
00044 //______________________________________________________________________________
00045 TLDAPEntry& TLDAPEntry::operator=(const TLDAPEntry& lde) 
00046 {
00047    // Equal operator
00048    if(this!=&lde) {
00049       TObject::operator=(lde);
00050       fDn=lde.fDn;
00051       fAttr=lde.fAttr;
00052       fNCount=lde.fNCount;
00053    } return *this;
00054 }
00055 
00056 //______________________________________________________________________________
00057 TLDAPEntry::~TLDAPEntry()
00058 {
00059    // Deletes all the attributes of the entry.
00060 
00061    delete fAttr;
00062 }
00063 
00064 //______________________________________________________________________________
00065 void TLDAPEntry::AddAttribute(const TLDAPAttribute &attr)
00066 {
00067    // Add an attribute to the entry.
00068    // TLDAPAtrribute attr: attribute to be added.
00069 
00070    fAttr->AddLast(new TLDAPAttribute(attr));
00071 }
00072 
00073 //______________________________________________________________________________
00074 void TLDAPEntry::Print(Option_t *) const
00075 {
00076    // Print entry in LDIF format.
00077 
00078    cout << "dn: "<< fDn << endl;
00079    TLDAPAttribute *attr = GetAttribute("objectClass");
00080    if (attr != 0)
00081       attr->Print();
00082    Int_t n = GetCount();
00083    for (Int_t i = 0; i < n; i++) {
00084       attr = (TLDAPAttribute*) fAttr->At(i);
00085       if (TString(attr->GetName()).CompareTo("objectClass", TString::kIgnoreCase) != 0)
00086          attr->Print();
00087    }
00088    cout << endl;
00089 }
00090 
00091 //______________________________________________________________________________
00092 TLDAPAttribute *TLDAPEntry::GetAttribute() const
00093 {
00094    // Get next attribute of the entry. Returns zero after the last attribute,
00095    // then returns the first attribute again.
00096 
00097    Int_t n = GetCount();
00098    if (n > fNCount) {
00099       return (TLDAPAttribute*)fAttr->At(fNCount++);
00100    } else {
00101       fNCount = 0;
00102       return 0;
00103    }
00104 }
00105 
00106 //______________________________________________________________________________
00107 TLDAPAttribute *TLDAPEntry::GetAttribute(const char *name) const
00108 {
00109    // Get attribute by name.
00110    // Doesn't affect the order of attributes to be returned from the
00111    // next GetAttribute() call. Attribute name is case insensitive.
00112 
00113    Int_t n = GetCount();
00114    for (Int_t i = 0; i < n; i++) {
00115       if (TString(((TLDAPAttribute*)fAttr->At(i))->GetName()).CompareTo(name, TString::kIgnoreCase) == 0) {
00116          return (TLDAPAttribute*)fAttr->At(i);
00117       }
00118    }
00119    return 0;
00120 }
00121 
00122 //______________________________________________________________________________
00123 void TLDAPEntry::DeleteAttribute(const char *name)
00124 {
00125    // Delete attribute by name.
00126    // Attribute name is case insensitive.
00127 
00128    Int_t n = GetCount();
00129    for (Int_t i = 0; i < n; i++) {
00130       if (TString(((TLDAPAttribute*)fAttr->At(i))->GetName()).CompareTo(name, TString::kIgnoreCase) == 0) {
00131          delete fAttr->Remove(fAttr->At(i));
00132          if (fNCount > i) fNCount--;
00133          return;
00134       }
00135    }
00136 }
00137 
00138 //______________________________________________________________________________
00139 Bool_t TLDAPEntry::IsReferral() const
00140 {
00141    // Check if entry is referal.
00142 
00143    Bool_t att = kFALSE;
00144    Bool_t obj = kFALSE;
00145    Int_t n = GetCount();
00146    TString name;
00147    for (Int_t i = 0; (i < n) && (!att || !obj); i++) {
00148       name = TString(((TLDAPAttribute*) fAttr->At(i))->GetName());
00149       if (name.CompareTo("ref", TString::kIgnoreCase) == 0) {
00150          att = kTRUE;
00151       } else {
00152          if (name.CompareTo("objectclass", TString::kIgnoreCase) == 0) {
00153             TLDAPAttribute *attr = (TLDAPAttribute*)fAttr->At(i);
00154             Int_t valcnt = attr->GetCount() + 1;
00155             for (Int_t j = 0; (j < valcnt) && (!obj); j++)
00156                obj |= (Bool_t)TString(attr->GetValue()).CompareTo("referral", TString::kIgnoreCase);
00157          }
00158       }
00159    }
00160    return (att && obj);
00161 }
00162 
00163 //______________________________________________________________________________
00164 TList *TLDAPEntry::GetReferrals() const
00165 {
00166    // Get the TList of referrals.
00167    // Returns an empty list if entry is not referral.
00168    // User is responsible for deleting returned TList.
00169 
00170    TList *list = new TList;
00171    TLDAPAttribute *ref = GetAttribute("ref");
00172    if (ref != 0) {
00173       Int_t n = ref->GetCount();
00174       for (Int_t i = 0; i < n; i++) {
00175          list->Add(ref->fValues->At(i));
00176       }
00177    }
00178    return list;
00179 }
00180 
00181 //______________________________________________________________________________
00182 LDAPMod **TLDAPEntry::GetMods(Int_t op)
00183 {
00184    // Get array of "LDAPMod" structures for entry.
00185 
00186    Int_t n = GetCount();
00187    LDAPMod **mods = new LDAPMod* [n + 1];
00188    for (Int_t i = 0; i < n; i++)
00189       mods[i] = ((TLDAPAttribute*)(fAttr->At(i)))->GetMod(op);
00190    mods[n] = 0;
00191    return mods;
00192 }

Generated on Tue Jul 5 14:45:41 2011 for ROOT_528-00b_version by  doxygen 1.5.1