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

Matthew Swift
25.33.2012 263d085885df024dca9250cc03c807912b0a7662
opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/schema/SchemaElement.java
@@ -6,17 +6,16 @@
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at
 * trunk/opendj3/legal-notices/CDDLv1_0.txt
 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
 * or http://forgerock.org/license/CDDLv1.0.html.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at
 * trunk/opendj3/legal-notices/CDDLv1_0.txt.  If applicable,
 * add the following below this CDDL HEADER, with the fields enclosed
 * by brackets "[]" replaced with your own identifying information:
 * file and include the License file at legal-notices/CDDLv1_0.txt.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
@@ -28,8 +27,6 @@
package org.forgerock.opendj.ldap.schema;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -37,8 +34,6 @@
import com.forgerock.opendj.util.Validator;
/**
 * An abstract base class for LDAP schema definitions which contain an
 * description, and an optional set of extra properties.
@@ -47,137 +42,113 @@
 * schema definitions (e.g. object class definitions, and attribute type
 * definitions).
 */
abstract class SchemaElement
{
  // The description for this definition.
  final String description;
abstract class SchemaElement {
    // The description for this definition.
    final String description;
  // The set of additional name-value pairs.
  final Map<String, List<String>> extraProperties;
    // The set of additional name-value pairs.
    final Map<String, List<String>> extraProperties;
    SchemaElement(final String description, final Map<String, List<String>> extraProperties) {
        Validator.ensureNotNull(description, extraProperties);
        this.description = description;
  SchemaElement(final String description,
      final Map<String, List<String>> extraProperties)
  {
    Validator.ensureNotNull(description, extraProperties);
    this.description = description;
    // Assumes caller has made the map unmodifiable.
    this.extraProperties = extraProperties;
  }
  /**
   * Returns the description of this schema definition.
   *
   * @return The description of this schema definition.
   */
  public final String getDescription()
  {
    return description;
  }
  /**
   * Returns an unmodifiable list containing the values of the named "extra"
   * property for this schema definition.
   *
   * @param name
   *          The name of the "extra" property whose values are to be returned.
   * @return Returns an unmodifiable list containing the values of the named
   *         "extra" property for this schema definition, which may be empty if
   *         no such property is defined.
   */
  public final List<String> getExtraProperty(final String name)
  {
    final List<String> values = extraProperties.get(name);
    return values != null ? values : Collections.<String> emptyList();
  }
  /**
   * Returns an unmodifiable set containing the names of the "extra" properties
   * associated with this schema definition.
   *
   * @return Returns an unmodifiable set containing the names of the "extra"
   *         properties associated with this schema definition.
   */
  public final Set<String> getExtraPropertyNames()
  {
    return extraProperties.keySet();
  }
  /**
   * Builds a string representation of this schema definition in the form
   * specified in RFC 2252.
   *
   * @return The string representation of this schema definition in the form
   *         specified in RFC 2252.
   */
  final String buildDefinition()
  {
    final StringBuilder buffer = new StringBuilder();
    buffer.append("( ");
    toStringContent(buffer);
    if (!extraProperties.isEmpty())
    {
      for (final Map.Entry<String, List<String>> e : extraProperties.entrySet())
      {
        final String property = e.getKey();
        final List<String> valueList = e.getValue();
        buffer.append(" ");
        buffer.append(property);
        if (valueList.size() == 1)
        {
          buffer.append(" '");
          buffer.append(valueList.get(0));
          buffer.append("'");
        }
        else
        {
          buffer.append(" ( ");
          for (final String value : valueList)
          {
            buffer.append("'");
            buffer.append(value);
            buffer.append("' ");
          }
          buffer.append(")");
        }
      }
        // Assumes caller has made the map unmodifiable.
        this.extraProperties = extraProperties;
    }
    buffer.append(" )");
    /**
     * Returns the description of this schema definition.
     *
     * @return The description of this schema definition.
     */
    public final String getDescription() {
    return buffer.toString();
  }
        return description;
    }
    /**
     * Returns an unmodifiable list containing the values of the named "extra"
     * property for this schema definition.
     *
     * @param name
     *            The name of the "extra" property whose values are to be
     *            returned.
     * @return Returns an unmodifiable list containing the values of the named
     *         "extra" property for this schema definition, which may be empty
     *         if no such property is defined.
     */
    public final List<String> getExtraProperty(final String name) {
        final List<String> values = extraProperties.get(name);
        return values != null ? values : Collections.<String> emptyList();
    }
  /**
   * Appends a string representation of this schema definition's non-generic
   * properties to the provided buffer.
   *
   * @param buffer
   *          The buffer to which the information should be appended.
   */
  abstract void toStringContent(StringBuilder buffer);
    /**
     * Returns an unmodifiable set containing the names of the "extra"
     * properties associated with this schema definition.
     *
     * @return Returns an unmodifiable set containing the names of the "extra"
     *         properties associated with this schema definition.
     */
    public final Set<String> getExtraPropertyNames() {
        return extraProperties.keySet();
    }
    /**
     * Builds a string representation of this schema definition in the form
     * specified in RFC 2252.
     *
     * @return The string representation of this schema definition in the form
     *         specified in RFC 2252.
     */
    final String buildDefinition() {
        final StringBuilder buffer = new StringBuilder();
        buffer.append("( ");
        toStringContent(buffer);
        if (!extraProperties.isEmpty()) {
            for (final Map.Entry<String, List<String>> e : extraProperties.entrySet()) {
                final String property = e.getKey();
                final List<String> valueList = e.getValue();
                buffer.append(" ");
                buffer.append(property);
                if (valueList.size() == 1) {
                    buffer.append(" '");
                    buffer.append(valueList.get(0));
                    buffer.append("'");
                } else {
                    buffer.append(" ( ");
                    for (final String value : valueList) {
                        buffer.append("'");
                        buffer.append(value);
                        buffer.append("' ");
                    }
                    buffer.append(")");
                }
            }
        }
        buffer.append(" )");
        return buffer.toString();
    }
    /**
     * Appends a string representation of this schema definition's non-generic
     * properties to the provided buffer.
     *
     * @param buffer
     *            The buffer to which the information should be appended.
     */
    abstract void toStringContent(StringBuilder buffer);
}