From f73b655466092169abac34833fb628fce1fcdebe Mon Sep 17 00:00:00 2001
From: jcduff <jcduff@localhost>
Date: Thu, 23 Oct 2008 14:04:24 +0000
Subject: [PATCH] The commit will bring the following features :     - An updated version of the underlying database. BDB JE 3.3 is now used.     - Attribute API refactoring providing a better abstraction and offering improved performances.     - A new GUI called the Control-Panel to replace the Status-Panel: the specifications for this       GUI are available on OpenDS Wiki and contains a link to a mockup.        See <https://www.opends.org/wiki/page/ControlPanelUISpecification>.     - Some changes in the replication protocol to implement "Assured Replication Mode". The        specifications are on OpenDS Wiki at <https://www.opends.org/wiki/page/AssuredMode> and section 7       described some of the replication changes required to support this. Assured Replication is not finished,       but the main replication protocol changes to support it are done. As explained by Gilles on an email on       the Dev mailing list (http://markmail.org/message/46rgo3meq3vriy4a), with these changes the newer versions       of OpenDS may not be able to replicate with OpenDS 1.0 instances.     - Support for Service Tags on the platforms where the functionality is available and enabled. Specifications       are published at <https://www.opends.org/wiki/page/OpenDSServiceTagEnabled>. For more information on       Service Tags see <http://wikis.sun.com/display/ServiceTag/Sun+Service+Tag+FAQ>.     - The Admin Connector service. In order to provide agentry of the OpenDS server at any time, a new service       has been added, dedicated to the administration, configuration and monitoring of the server.       An overview of the Admin Connector service and it's use is available on the       OpenDS wiki <https://www.opends.org/wiki/page/ManagingAdministrationTrafficToTheServer>     - Updates to the various command line tools to support the Admin Connector service.     - Some internal re-architecting of the server to put the foundation of future developments such as virtual       directory services. The new NetworkGroups and WorkFlow internal services which have been specified in       <https://www.opends.org/wiki/page/BasicOperationRoutingThroughNetworkGroup> are now implemented.     - Many bug fixes...

---
 opends/src/server/org/opends/server/util/LDIFReader.java |  156 ++++++++++++++++++++++++++-------------------------
 1 files changed, 79 insertions(+), 77 deletions(-)

diff --git a/opends/src/server/org/opends/server/util/LDIFReader.java b/opends/src/server/org/opends/server/util/LDIFReader.java
index 73581b8..123feca 100644
--- a/opends/src/server/org/opends/server/util/LDIFReader.java
+++ b/opends/src/server/org/opends/server/util/LDIFReader.java
@@ -44,7 +44,6 @@
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.LinkedHashSet;
 import java.util.LinkedList;
 import java.util.List;
 
@@ -55,6 +54,7 @@
 import org.opends.server.protocols.ldap.LDAPModification;
 import org.opends.server.types.AcceptRejectWarn;
 import org.opends.server.types.Attribute;
+import org.opends.server.types.AttributeBuilder;
 import org.opends.server.types.AttributeType;
 import org.opends.server.types.AttributeValue;
 import org.opends.server.types.DirectoryException;
@@ -852,10 +852,9 @@
     // Parse the attribute type description.
     int colonPos = parseColonPosition(lines, line);
     String attrDescr = line.substring(0, colonPos);
-    Attribute attribute = parseAttrDescription(attrDescr);
-    String attrName = attribute.getName();
-    String lowerName = toLowerCase(attrName);
-    LinkedHashSet<String> options = attribute.getOptions();
+    final Attribute attribute = parseAttrDescription(attrDescr);
+    final String attrName = attribute.getName();
+    final String lowerName = toLowerCase(attrName);
 
     // Now parse the attribute value.
     ASN1OctetString value = parseSingleValue(lines, line, entryDN,
@@ -913,6 +912,17 @@
         return;
       }
 
+       //The attribute is not being ignored so check for binary option.
+      if(!attrType.isBinary())
+      {
+       if(attribute.hasOption("binary"))
+        {
+          Message message = ERR_LDIF_INVALID_ATTR_OPTION.get(
+            String.valueOf(entryDN),lastEntryLineNumber, attrName);
+          logToRejectWriter(lines, message);
+          throw new LDIFException(message, lastEntryLineNumber,true);
+        }
+      }
       if (checkSchema &&
           (DirectoryServer.getSyntaxEnforcementPolicy() !=
                AcceptRejectWarn.ACCEPT))
@@ -945,12 +955,10 @@
         attrList = operationalAttributes.get(attrType);
         if (attrList == null)
         {
-          LinkedHashSet<AttributeValue> valueSet =
-               new LinkedHashSet<AttributeValue>();
-          valueSet.add(attributeValue);
-
+          AttributeBuilder builder = new AttributeBuilder(attribute, true);
+          builder.add(attributeValue);
           attrList = new ArrayList<Attribute>();
-          attrList.add(new Attribute(attrType, attrName, options, valueSet));
+          attrList.add(builder.toAttribute());
           operationalAttributes.put(attrType, attrList);
           return;
         }
@@ -960,12 +968,10 @@
         attrList = userAttributes.get(attrType);
         if (attrList == null)
         {
-          LinkedHashSet<AttributeValue> valueSet =
-               new LinkedHashSet<AttributeValue>();
-          valueSet.add(attributeValue);
-
+          AttributeBuilder builder = new AttributeBuilder(attribute, true);
+          builder.add(attributeValue);
           attrList = new ArrayList<Attribute>();
-          attrList.add(new Attribute(attrType, attrName, options, valueSet));
+          attrList.add(builder.toAttribute());
           userAttributes.put(attrType, attrList);
           return;
         }
@@ -974,12 +980,12 @@
 
       // Check to see if any of the attributes in the list have the same set of
       // options.  If so, then try to add a value to that attribute.
-      for (Attribute a : attrList)
-      {
-        if (a.optionsEqual(options))
+      for (int i = 0; i < attrList.size(); i++) {
+        Attribute a = attrList.get(i);
+
+        if (a.optionsEqual(attribute.getOptions()))
         {
-          LinkedHashSet<AttributeValue> valueSet = a.getValues();
-          if (valueSet.contains(attributeValue))
+          if (a.contains(attributeValue))
           {
             if (! checkSchema)
             {
@@ -988,7 +994,7 @@
               // values differ in capitalization.  Only reject the proposed
               // value if we find another value that is exactly the same as the
               // one that was provided.
-              for (AttributeValue v : valueSet)
+              for (AttributeValue v : a)
               {
                 if (v.getValue().equals(attributeValue.getValue()))
                 {
@@ -1014,7 +1020,7 @@
             }
           }
 
-          if (attrType.isSingleValue() && (! valueSet.isEmpty()) && checkSchema)
+          if (attrType.isSingleValue() && !a.isEmpty() && checkSchema)
           {
             Message message = ERR_LDIF_MULTIPLE_VALUES_FOR_SINGLE_VALUED_ATTR
                     .get(String.valueOf(entryDN),
@@ -1023,18 +1029,19 @@
             throw new LDIFException(message, lastEntryLineNumber, true);
           }
 
-          valueSet.add(attributeValue);
+          AttributeBuilder builder = new AttributeBuilder(a);
+          builder.add(attributeValue);
+          attrList.set(i, builder.toAttribute());
           return;
         }
       }
 
 
-      // No set of matching options was found, so create a new one and add it to
-      // the list.
-      LinkedHashSet<AttributeValue> valueSet =
-           new LinkedHashSet<AttributeValue>();
-      valueSet.add(attributeValue);
-      attrList.add(new Attribute(attrType, attrName, options, valueSet));
+      // No set of matching options was found, so create a new one and
+      // add it to the list.
+      AttributeBuilder builder = new AttributeBuilder(attribute, true);
+      builder.add(attributeValue);
+      attrList.add(builder.toAttribute());
       return;
     }
   }
@@ -1084,11 +1091,11 @@
     ASN1OctetString value = parseSingleValue(lines, line, entryDN,
         colonPos, attrName);
 
+    AttributeBuilder builder = new AttributeBuilder(attribute, true);
     AttributeType attrType = attribute.getAttributeType();
-    AttributeValue attributeValue = new AttributeValue(attrType, value);
-    attribute.getValues().add(attributeValue);
+    builder.add(new AttributeValue(attrType, value));
 
-    return attribute;
+    return builder.toAttribute();
   }
 
 
@@ -1168,53 +1175,51 @@
 
 
   /**
-   * Parse an AttributeDescription (an attribute type name and its options).
-   * @param attrDescr The attribute description to be parsed.
-   * @return A new attribute with no values, representing the attribute type
-   * and its options.
+   * Parse an AttributeDescription (an attribute type name and its
+   * options).
+   *
+   * @param attrDescr
+   *          The attribute description to be parsed.
+   * @return A new attribute with no values, representing the
+   *         attribute type and its options.
    */
   private static Attribute parseAttrDescription(String attrDescr)
   {
-    String attrName;
-    String lowerName;
-    LinkedHashSet<String> options;
+    AttributeBuilder builder;
     int semicolonPos = attrDescr.indexOf(';');
     if (semicolonPos > 0)
     {
-      attrName = attrDescr.substring(0, semicolonPos);
-      options = new LinkedHashSet<String>();
-      int nextPos = attrDescr.indexOf(';', semicolonPos+1);
+      builder = new AttributeBuilder(attrDescr.substring(0, semicolonPos));
+      int nextPos = attrDescr.indexOf(';', semicolonPos + 1);
       while (nextPos > 0)
       {
-        String option = attrDescr.substring(semicolonPos+1, nextPos);
+        String option = attrDescr.substring(semicolonPos + 1, nextPos);
         if (option.length() > 0)
         {
-          options.add(option);
+          builder.setOption(option);
           semicolonPos = nextPos;
-          nextPos = attrDescr.indexOf(';', semicolonPos+1);
+          nextPos = attrDescr.indexOf(';', semicolonPos + 1);
         }
       }
 
-      String option = attrDescr.substring(semicolonPos+1);
+      String option = attrDescr.substring(semicolonPos + 1);
       if (option.length() > 0)
       {
-        options.add(option);
+        builder.setOption(option);
       }
     }
     else
     {
-      attrName  = attrDescr;
-      options   = null;
+      builder = new AttributeBuilder(attrDescr);
     }
 
-    lowerName = toLowerCase(attrName);
-    AttributeType attrType = DirectoryServer.getAttributeType(lowerName);
-    if (attrType == null)
+    if(builder.getAttributeType().isBinary())
     {
-      attrType = DirectoryServer.getDefaultAttributeType(attrName);
+      //resetting doesn't hurt and returns false.
+      builder.setOption("binary");
     }
 
-    return new Attribute(attrType, attrName, options, null);
+    return builder.toAttribute();
   }
 
 
@@ -1401,11 +1406,7 @@
   {
     Attribute attr =
       readSingleValueAttribute(lines, line, entryDN, attributeName);
-    LinkedHashSet<AttributeValue> values = attr.getValues();
-
-    // Get the attribute value
-    Object[] vals = values.toArray();
-    return (((AttributeValue)vals[0]).getStringValue());
+    return attr.iterator().next().getStringValue();
   }
 
 
@@ -1433,35 +1434,39 @@
       Attribute attr =
         readSingleValueAttribute(lines, line, entryDN, null);
       String name = attr.getName();
-      LinkedHashSet<AttributeValue> values = attr.getValues();
 
       // Get the attribute description
-      String attrDescr = values.iterator().next().getStringValue();
+      String attrDescr = attr.iterator().next().getStringValue();
 
       String lowerName = toLowerCase(name);
-      if(lowerName.equals("add"))
+      if (lowerName.equals("add"))
       {
         modType = ModificationType.ADD;
-      } else if(lowerName.equals("delete"))
+      }
+      else if (lowerName.equals("delete"))
       {
         modType = ModificationType.DELETE;
-      } else if(lowerName.equals("replace"))
+      }
+      else if (lowerName.equals("replace"))
       {
         modType = ModificationType.REPLACE;
-      } else if(lowerName.equals("increment"))
+      }
+      else if (lowerName.equals("increment"))
       {
         modType = ModificationType.INCREMENT;
-      } else
+      }
+      else
       {
         // Invalid attribute name.
-        Message message = ERR_LDIF_INVALID_MODIFY_ATTRIBUTE.get(
-            name, "add, delete, replace, increment");
+        Message message = ERR_LDIF_INVALID_MODIFY_ATTRIBUTE.get(name,
+            "add, delete, replace, increment");
         throw new LDIFException(message, lineNumber, true);
       }
 
       // Now go through the rest of the attributes till the "-" line is
       // reached.
       Attribute modAttr = LDIFReader.parseAttrDescription(attrDescr);
+      AttributeBuilder builder = new AttributeBuilder(modAttr, true);
       while (! lines.isEmpty())
       {
         line = lines.remove();
@@ -1469,12 +1474,11 @@
         {
           break;
         }
-        Attribute a =
-          readSingleValueAttribute(lines, line, entryDN, attrDescr);
-        modAttr.getValues().addAll(a.getValues());
+        Attribute a = readSingleValueAttribute(lines, line, entryDN, attrDescr);
+        builder.addAll(a);
       }
 
-      LDAPAttribute ldapAttr = new LDAPAttribute(modAttr);
+      LDAPAttribute ldapAttr = new LDAPAttribute(builder.toAttribute());
       LDAPModification mod = new LDAPModification(modType, ldapAttr);
       modifications.add(mod);
     }
@@ -1535,15 +1539,13 @@
 
     // Reconstruct the object class attribute.
     AttributeType ocType = DirectoryServer.getObjectClassAttributeType();
-    LinkedHashSet<AttributeValue> ocValues =
-      new LinkedHashSet<AttributeValue>(objectClasses.size());
+    AttributeBuilder builder = new AttributeBuilder(ocType, "objectClass");
     for (String value : objectClasses.values()) {
       AttributeValue av = new AttributeValue(ocType, value);
-      ocValues.add(av);
+      builder.add(av);
     }
-    Attribute ocAttr = new Attribute(ocType, "objectClass", ocValues);
     List<Attribute> ocAttrList = new ArrayList<Attribute>(1);
-    ocAttrList.add(ocAttr);
+    ocAttrList.add(builder.toAttribute());
     attributes.put(ocType, ocAttrList);
 
     return new AddChangeRecordEntry(entryDN, attributes);

--
Gitblit v1.10.0