mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Jean-Noël Rouvignac
03.17.2016 758fa048a39b3c362776400a9373ebeef86700af
Removed Attribute.getOptions()
12 files modified
292 ■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/server/tools/makeldif/TemplateEntry.java 34 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/types/AbstractAttribute.java 34 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/types/Attribute.java 10 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/types/AttributeBuilder.java 68 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/types/CollectiveVirtualAttribute.java 17 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/types/Entry.java 34 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/types/SubEntry.java 15 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/types/VirtualAttribute.java 10 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/util/LDIFReader.java 10 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/util/LDIFWriter.java 34 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/protocols/ldap/LDAPBinaryOptionTestCase.java 4 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/types/AttributeBuilderTest.java 22 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/tools/makeldif/TemplateEntry.java
@@ -36,9 +36,14 @@
import java.util.List;
import org.forgerock.opendj.ldap.ByteString;
import org.opends.server.core.DirectoryServer;
import org.forgerock.opendj.ldap.schema.AttributeType;
import org.opends.server.types.*;
import org.opends.server.core.DirectoryServer;
import org.opends.server.types.Attribute;
import org.opends.server.types.AttributeBuilder;
import org.opends.server.types.DN;
import org.opends.server.types.LDIFExportConfig;
import org.opends.server.types.ObjectClass;
import org.opends.server.types.RDN;
import org.opends.server.util.LDIFException;
/**
@@ -387,12 +392,13 @@
            continue;
          }
          StringBuilder attrName = attrNameWithOptions(a);
          String attrName = a.getNameWithOptions();
          if (typesOnly)
          {
            attrName.append(":");
            StringBuilder attrLine = new StringBuilder(attrName);
            attrLine.append(":");
            writeLDIFLine(attrName, writer, wrapLines, wrapColumn);
            writeLDIFLine(attrLine, writer, wrapLines, wrapColumn);
          }
          else
          {
@@ -430,12 +436,13 @@
              continue;
            }
            StringBuilder attrName = attrNameWithOptions(a);
            String attrName = a.getNameWithOptions();
            if (typesOnly)
            {
              attrName.append(":");
              StringBuilder attrLine = new StringBuilder(attrName);
              attrLine.append(":");
              writeLDIFLine(attrName, writer, wrapLines, wrapColumn);
              writeLDIFLine(attrLine, writer, wrapLines, wrapColumn);
            }
            else
            {
@@ -457,17 +464,6 @@
    return true;
  }
  private StringBuilder attrNameWithOptions(Attribute a)
  {
    StringBuilder attrName = new StringBuilder(a.getName());
    for (String o : a.getOptions())
    {
      attrName.append(";");
      attrName.append(o);
    }
    return attrName;
  }
  private boolean contains(List<Attribute> urlAttrList, ByteString v)
  {
    if (urlAttrList != null)
opendj-server-legacy/src/main/java/org/opends/server/types/AbstractAttribute.java
@@ -26,10 +26,7 @@
 */
package org.opends.server.types;
import static org.opends.server.util.StaticUtils.*;
import java.util.Collection;
import java.util.Set;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.DecodeException;
@@ -140,7 +137,7 @@
    StringBuilder buffer = new StringBuilder();
    buffer.append(getName());
    for (String option : getOptions())
    for (String option : getAttributeDescription().getOptions())
    {
      buffer.append(';');
      buffer.append(option);
@@ -167,35 +164,10 @@
    return hashCode;
  }
  /**
   * {@inheritDoc}
   * <p>
   * This implementation calls {@link #getOptions()} to
   * retrieve this attribute's set of options and then compares them
   * one at a time against the provided option. All comparisons are
   * case insensitive.
   */
  @Override
  public boolean hasOption(String option)
  {
    // FIXME use AttributeDescription instead
    return containsOption(getOptions(), option);
  }
  private static boolean containsOption(Set<String> options, String optionToFind)
  {
    String normToFind = toLowerCase(optionToFind);
    // Cannot use Set.contains() because the options are not normalized.
    for (String o : options)
    {
      String norm = toLowerCase(o);
      if (norm.equals(normToFind))
      {
        return true;
      }
    }
    return false;
    return getAttributeDescription().hasOption(option);
  }
  /**
@@ -207,7 +179,7 @@
  @Override
  public boolean hasOptions()
  {
    return !getOptions().isEmpty();
    return getAttributeDescription().hasOptions();
  }
  /**
opendj-server-legacy/src/main/java/org/opends/server/types/Attribute.java
@@ -29,7 +29,6 @@
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.forgerock.opendj.ldap.AttributeDescription;
import org.forgerock.opendj.ldap.ByteString;
@@ -147,15 +146,6 @@
  String getNameWithOptions();
  /**
   * Retrieves the unmodifiable set of attribute options for this attribute. The returned set of
   * options are not normalized.
   *
   * @return The unmodifiable set of attribute options for this attribute.
   * @Deprecated use {@link #getAttributeDescription()}
   */
  Set<String> getOptions();
  /**
   * Indicates whether this attribute has any value(s) that are
   * greater than or equal to the provided value.
   *
opendj-server-legacy/src/main/java/org/opends/server/types/AttributeBuilder.java
@@ -230,12 +230,6 @@
    }
    @Override
    public Set<String> getOptions()
    {
      return Collections.unmodifiableSet(toSet(attributeDescription.getOptions()));
    }
    @Override
    public boolean hasOption(String option)
    {
      return attributeDescription.hasOption(option);
@@ -496,12 +490,6 @@
    {
      return getName();
    }
    @Override
    public Set<String> getOptions()
    {
      return Collections.emptySet();
    }
  }
@@ -971,11 +959,7 @@
  {
    this(attribute.getAttributeType(), attribute.getName());
    for (String option : attribute.getOptions())
    {
      setOption(option);
    }
    setOptions(attribute.getAttributeDescription().getOptions());
    if (!omitValues)
    {
      addAll(attribute);
@@ -1498,55 +1482,19 @@
    return isModified;
  }
  /**
   * Indicates whether this attribute builder has exactly the
   * specified set of options.
   * Indicates whether this attribute builder has exactly the specified set of options.
   *
   * This implementation returns
   * {@link java.util.AbstractCollection#isEmpty()}
   * if the provided set of options is <code>null</code>.
   * Otherwise it checks that the size of the provided
   * set of options is equal to the size of this attribute
   * builder options, returns <code>false</code> if the
   * sizes differ. If the sizes are the same then each
   * option in the provided set is checked and if all the
   * provided options are present <code>true</code> is
   * returned.
   *
   * @param  options
   *         The set of options for which to make the
   *         determination (may be <code>null</code>).
   * @return <code>true</code> if this attribute
   *         builder has exactly the specified
   *         set of options.
   * @param attributeDescription
   *          The attribute description containing the set of options for which to make the
   *          determination
   * @return <code>true</code> if this attribute builder has exactly the specified set of options.
   */
  public boolean optionsEqual(Set<String> options)
  public boolean optionsEqual(AttributeDescription attributeDescription)
  {
    if (options == null)
    {
      return this.options.isEmpty();
    }
    if (this.options.size() != options.size())
    {
      return false;
    }
    for (String option : options)
    {
      if (!this.options.contains(option))
      {
        return false;
      }
    }
    return true;
    return toAttribute0().getAttributeDescription().equals(attributeDescription);
  }
  /**
   * Returns the number of attribute values in this attribute builder.
   *
opendj-server-legacy/src/main/java/org/opends/server/types/CollectiveVirtualAttribute.java
@@ -24,12 +24,10 @@
 *      Copyright 2009 Sun Microsystems, Inc.
 *      Portions Copyright 2014-2016 ForgeRock AS
 */
package org.opends.server.types;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.forgerock.opendj.ldap.AttributeDescription;
import org.forgerock.opendj.ldap.ByteString;
@@ -56,13 +54,11 @@
    this.attribute = attribute;
  }
  /** {@inheritDoc} */
  @Override
  public ConditionResult approximatelyEqualTo(ByteString assertionValue) {
    return attribute.approximatelyEqualTo(assertionValue);
  }
  /** {@inheritDoc} */
  @Override
  public boolean contains(ByteString value) {
    return attribute.contains(value);
@@ -86,55 +82,42 @@
  }
  @Override
  public Set<String> getOptions() {
    return attribute.getOptions();
  }
  /** {@inheritDoc} */
  @Override
  public ConditionResult greaterThanOrEqualTo(ByteString assertionValue) {
    return attribute.greaterThanOrEqualTo(assertionValue);
  }
  /** {@inheritDoc} */
  @Override
  public boolean isVirtual() {
    return true;
  }
  /** {@inheritDoc} */
  @Override
  public Iterator<ByteString> iterator() {
    return attribute.iterator();
  }
  /** {@inheritDoc} */
  @Override
  public ConditionResult lessThanOrEqualTo(ByteString assertionValue) {
    return attribute.lessThanOrEqualTo(assertionValue);
  }
  /** {@inheritDoc} */
  @Override
  public ConditionResult matchesSubstring(ByteString subInitial,
          List<ByteString> subAny, ByteString subFinal) {
    return attribute.matchesSubstring(subInitial, subAny, subFinal);
  }
  /** {@inheritDoc} */
  @Override
  public int size() {
    return attribute.size();
  }
  /** {@inheritDoc} */
  @Override
  public int hashCode()
  {
    return attribute.hashCode();
  }
  /** {@inheritDoc} */
  @Override
  public void toString(StringBuilder buffer) {
    attribute.toString(buffer);
opendj-server-legacy/src/main/java/org/opends/server/types/Entry.java
@@ -3684,13 +3684,7 @@
    {
      for (Attribute a : attrList)
      {
        StringBuilder attrName = new StringBuilder(a.getName());
        for (String o : a.getOptions())
        {
          attrName.append(";");
          attrName.append(o);
        }
        String attrName = a.getNameWithOptions();
        for (ByteString v : a)
        {
          StringBuilder attrLine = new StringBuilder(attrName);
@@ -3919,18 +3913,13 @@
      BufferedWriter writer, boolean wrapLines, int wrapColumn)
      throws IOException
  {
    StringBuilder attrName = new StringBuilder(attribute.getName());
    for (String o : attribute.getOptions())
    {
      attrName.append(";");
      attrName.append(o);
    }
    String attrName = attribute.getNameWithOptions();
    if (typesOnly)
    {
      attrName.append(":");
      StringBuilder attrLine = new StringBuilder(attrName);
      attrLine.append(":");
      LDIFWriter.writeLDIFLine(attrName, writer, wrapLines, wrapColumn);
      LDIFWriter.writeLDIFLine(attrLine, writer, wrapLines, wrapColumn);
    }
    else
    {
@@ -4201,16 +4190,7 @@
          buffer.append(",");
        }
        buffer.append(a.getName());
        if (a.hasOptions())
        {
          for (String optionString : a.getOptions())
          {
            buffer.append(";");
            buffer.append(optionString);
          }
        }
        buffer.append(a.getNameWithOptions());
        buffer.append("={");
        Iterator<ByteString> valueIterator = a.iterator();
@@ -4686,7 +4666,7 @@
          // Now add in remaining options from original attribute
          // (this will not overwrite options already present).
          builder.setOptions(attribute.getOptions());
          builder.setOptions(attribute.getAttributeDescription().getOptions());
          if (!omitValues)
          {
opendj-server-legacy/src/main/java/org/opends/server/types/SubEntry.java
@@ -26,16 +26,13 @@
 */
package org.opends.server.types;
import org.forgerock.opendj.ldap.schema.AttributeType;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.schema.AttributeType;
import org.opends.server.core.DirectoryServer;
import static org.opends.messages.SchemaMessages.*;
@@ -270,9 +267,13 @@
        {
          AttributeBuilder builder = new AttributeBuilder(subAttr.getAttributeType());
          builder.addAll(subAttr);
          Set<String> options = new LinkedHashSet<>(subAttr.getOptions());
          options.remove(ATTR_OPTION_COLLECTIVE);
          builder.setOptions(options);
          for (String option : subAttr.getAttributeDescription().getOptions())
          {
            if (!option.equals(ATTR_OPTION_COLLECTIVE))
            {
              builder.setOption(option);
            }
          }
          Attribute attr = builder.toAttribute();
          CollectiveVirtualAttribute collectiveAttr = new CollectiveVirtualAttribute(attr);
          this.collectiveAttributes.add(collectiveAttr);
opendj-server-legacy/src/main/java/org/opends/server/types/VirtualAttribute.java
@@ -27,10 +27,8 @@
package org.opends.server.types;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.forgerock.opendj.ldap.AttributeDescription;
import org.forgerock.opendj.ldap.ByteString;
@@ -119,14 +117,6 @@
    return attributeDescription;
  }
  @Override
  public Set<String> getOptions()
  {
    return Collections.emptySet();
  }
  /**
   * Retrieves the virtual attribute rule that governs the behavior of
   * this virtual attribute.
opendj-server-legacy/src/main/java/org/opends/server/util/LDIFReader.java
@@ -47,9 +47,11 @@
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.LocalizableMessageBuilder;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.ldap.AttributeDescription;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ByteStringBuilder;
import org.forgerock.opendj.ldap.ModificationType;
import org.forgerock.opendj.ldap.schema.AttributeType;
import org.opends.server.api.plugin.PluginResult;
import org.opends.server.core.DirectoryServer;
import org.opends.server.core.PluginConfigManager;
@@ -58,7 +60,6 @@
import org.opends.server.types.AcceptRejectWarn;
import org.opends.server.types.Attribute;
import org.opends.server.types.AttributeBuilder;
import org.forgerock.opendj.ldap.schema.AttributeType;
import org.opends.server.types.Attributes;
import org.opends.server.types.DN;
import org.opends.server.types.DirectoryException;
@@ -799,7 +800,9 @@
    int colonPos = parseColonPosition(lines, line);
    String attrDescr = line.substring(0, colonPos);
    final Attribute attribute = parseAttrDescription(attrDescr);
    final String attrName = attribute.getName();
    final AttributeDescription attrDesc = attribute.getAttributeDescription();
    final AttributeType attrType = attrDesc.getAttributeType();
    final String attrName = attrType.getNameOrOID();
    // Now parse the attribute value.
    ByteString value = parseSingleValue(lines, line, entryDN, colonPos, attrName);
@@ -838,7 +841,6 @@
    }
    else
    {
      AttributeType attrType = DirectoryServer.getAttributeType(attrName);
      if (! importConfig.includeAttribute(attrType))
      {
        if (logger.isTraceEnabled())
@@ -903,7 +905,7 @@
      // options.  If so, then try to add a value to that attribute.
      for (AttributeBuilder a : attrList)
      {
        if (a.optionsEqual(attribute.getOptions()))
        if (a.optionsEqual(attrDesc))
        {
          if (!a.add(attributeValue) && checkSchema)
          {
opendj-server-legacy/src/main/java/org/opends/server/util/LDIFWriter.java
@@ -37,9 +37,16 @@
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.ldap.ByteSequence;
import org.forgerock.opendj.ldap.ByteString;
import org.opends.server.tools.makeldif.TemplateEntry;
import org.forgerock.opendj.ldap.schema.AttributeType;
import org.opends.server.types.*;
import org.opends.server.tools.makeldif.TemplateEntry;
import org.opends.server.types.Attribute;
import org.opends.server.types.DN;
import org.opends.server.types.Entry;
import org.opends.server.types.LDIFExportConfig;
import org.opends.server.types.Modification;
import org.opends.server.types.RDN;
import org.opends.server.types.RawAttribute;
import org.opends.server.types.RawModification;
import static org.forgerock.util.Reject.*;
import static org.opends.server.util.StaticUtils.*;
@@ -434,13 +441,7 @@
    {
      for (Attribute a : entry.getUserAttribute(attrType))
      {
        StringBuilder attrName = new StringBuilder(a.getName());
        for (String o : a.getOptions())
        {
          attrName.append(";");
          attrName.append(o);
        }
        StringBuilder attrName = new StringBuilder(a.getNameWithOptions());
        for (ByteString v : a)
        {
          writeAttribute(attrName, v, writer, wrapLines, wrapColumn);
@@ -506,12 +507,7 @@
        {
          StringBuilder attrName = new StringBuilder();
          attrName.append("# ");
          attrName.append(a.getName());
          for (String o : a.getOptions())
          {
            attrName.append(";");
            attrName.append(o);
          }
          attrName.append(a.getNameWithOptions());
          for (ByteString v : a)
          {
@@ -571,13 +567,7 @@
      Modification m    = iterator.next();
      Attribute    a    = m.getAttribute();
      StringBuilder nameBuffer = new StringBuilder(a.getName());
      for (String o : a.getOptions())
      {
        nameBuffer.append(";");
        nameBuffer.append(o);
      }
      String  name = nameBuffer.toString();
      String name = a.getNameWithOptions();
      StringBuilder modTypeLine = new StringBuilder();
      modTypeLine.append(m.getModificationType());
opendj-server-legacy/src/test/java/org/opends/server/protocols/ldap/LDAPBinaryOptionTestCase.java
@@ -22,7 +22,7 @@
 *
 *
 *      Copyright  2008 Sun Microsystems, Inc.
 *      Portions Copyright 2012-2015 ForgeRock AS
 *      Portions Copyright 2012-2016 ForgeRock AS
 */
package org.opends.server.protocols.ldap;
@@ -209,7 +209,7 @@
    List<Attribute> attrs = e.getAttribute("usercertificate");
    Attribute a = attrs.get(0);
    assertNotNull(a);
    assertTrue(a.getOptions().contains("binary"));
    assertThat(a.getAttributeDescription().getOptions()).contains("binary");
  }
  /**
opendj-server-legacy/src/test/java/org/opends/server/types/AttributeBuilderTest.java
@@ -1127,8 +1127,7 @@
    builder.setOptions(Arrays.asList(threeOptions));
    Attribute a = builder.toAttribute();
    Assert.assertTrue(a.getOptions().containsAll(Arrays.asList(threeOptions)));
    Assert.assertEquals(a.getOptions().size(), threeOptions.length);
    assertThat(a.getAttributeDescription().getOptions()).containsOnly(threeOptions);
  }
@@ -1364,7 +1363,7 @@
  /**
   * Tests {@link Attribute#getOptions()}.
   * Tests {@link AttributeDescription#getOptions()}.
   *
   * @param testCase
   *          Test case index (useful for debugging).
@@ -1384,22 +1383,7 @@
      AttributeType type, String name, String[] options, String[] values)
      throws Exception
  {
    // Check getOptions().
    Set<String> s = a.getOptions();
    Assert.assertEquals(s.size(), options.length);
    Assert.assertTrue(s.containsAll(Arrays.asList(options)));
    try
    {
      // The option set must be unmodifiable.
      s.add("xxxx");
      Assert.fail("getOptions() returned a modifiable option set");
    }
    catch (UnsupportedOperationException e)
    {
      // Expected exception.
    }
    assertThat(a.getAttributeDescription().getOptions()).containsOnly(options);
  }