From 59685c84348f8d71dc3bbd3513c5eb10cc738a8e Mon Sep 17 00:00:00 2001
From: matthew_swift <matthew_swift@localhost>
Date: Fri, 03 Nov 2006 16:39:22 +0000
Subject: [PATCH] Refactor DN and RDN classes and improve their test coverage.
---
opends/src/server/org/opends/server/backends/BackupBackend.java | 30 ++++++++++++++----------------
1 files changed, 14 insertions(+), 16 deletions(-)
diff --git a/opends/src/server/org/opends/server/backends/BackupBackend.java b/opends/src/server/org/opends/server/backends/BackupBackend.java
index 46b7195..fda38ea 100644
--- a/opends/src/server/org/opends/server/backends/BackupBackend.java
+++ b/opends/src/server/org/opends/server/backends/BackupBackend.java
@@ -245,19 +245,20 @@
LinkedHashMap<AttributeType,List<Attribute>> userAttrs =
new LinkedHashMap<AttributeType,List<Attribute>>(1);
- AttributeType[] attrTypes = backupBaseDN.getRDN().getAttributeTypes();
- AttributeValue[] attrValues = backupBaseDN.getRDN().getAttributeValues();
- for (int i=0; i < attrTypes.length; i++)
+ RDN rdn = backupBaseDN.getRDN();
+ int numAVAs = rdn.getNumValues();
+ for (int i=0; i < numAVAs; i++)
{
LinkedHashSet<AttributeValue> valueSet =
new LinkedHashSet<AttributeValue>(1);
- valueSet.add(attrValues[i]);
+ valueSet.add(rdn.getAttributeValue(i));
+ AttributeType attrType = rdn.getAttributeType(i);
ArrayList<Attribute> attrList = new ArrayList<Attribute>(1);
- attrList.add(new Attribute(attrTypes[i], attrTypes[i].getNameOrOID(),
+ attrList.add(new Attribute(attrType, attrType.getNameOrOID(),
valueSet));
- userAttrs.put(attrTypes[i], attrList);
+ userAttrs.put(attrType, attrList);
}
backupBaseEntry = new Entry(backupBaseDN, objectClasses, userAttrs,
@@ -370,7 +371,7 @@
// If so, then it must point to a backup directory. Otherwise, it must be
// two levels below the backup base entry and must point to a specific
// backup.
- DN parentDN = entryDN.getParent();
+ DN parentDN = entryDN.getParentDNInSuffix();
if (parentDN == null)
{
int msgID = MSGID_BACKUP_INVALID_BASE;
@@ -381,7 +382,7 @@
{
return getBackupDirectoryEntry(entryDN);
}
- else if (backupBaseDN.equals(parentDN.getParent()))
+ else if (backupBaseDN.equals(parentDN.getParentDNInSuffix()))
{
return getBackupEntry(entryDN);
}
@@ -528,7 +529,7 @@
// Next, get the backup directory from the parent DN.
- DN parentDN = entryDN.getParent();
+ DN parentDN = entryDN.getParentDNInSuffix();
if (parentDN == null)
{
int msgID = MSGID_BACKUP_NO_BACKUP_PARENT_DN;
@@ -929,7 +930,7 @@
}
}
}
- else if (backupBaseDN.equals(parentDN = baseDN.getParent()))
+ else if (backupBaseDN.equals(parentDN = baseDN.getParentDNInSuffix()))
{
Entry backupDirEntry = getBackupDirectoryEntry(baseDN);
@@ -983,7 +984,8 @@
}
else
{
- if ((parentDN == null) || (! backupBaseDN.equals(parentDN.getParent())))
+ if ((parentDN == null)
+ || (! backupBaseDN.equals(parentDN.getParentDNInSuffix())))
{
int msgID = MSGID_BACKUP_NO_SUCH_ENTRY;
String message = getMessage(msgID);
@@ -1475,13 +1477,9 @@
public static DN makeChildDN(DN parentDN, AttributeType rdnAttrType,
String rdnStringValue)
{
- RDN[] baseComponents = parentDN.getRDNComponents();
- RDN[] components = new RDN[baseComponents.length+1];
AttributeValue attrValue =
new AttributeValue(rdnAttrType, rdnStringValue);
- components[0] = new RDN(rdnAttrType, attrValue);
- System.arraycopy(baseComponents, 0, components, 1, baseComponents.length);
- return new DN(components);
+ return parentDN.concat(RDN.create(rdnAttrType, attrValue));
}
}
--
Gitblit v1.10.0