001/*
002 * CDDL HEADER START
003 *
004 * The contents of this file are subject to the terms of the
005 * Common Development and Distribution License, Version 1.0 only
006 * (the "License").  You may not use this file except in compliance
007 * with the License.
008 *
009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
010 * or http://forgerock.org/license/CDDLv1.0.html.
011 * See the License for the specific language governing permissions
012 * and limitations under the License.
013 *
014 * When distributing Covered Code, include this CDDL HEADER in each
015 * file and include the License file at legal-notices/CDDLv1_0.txt.
016 * If applicable, add the following below this CDDL HEADER, with the
017 * fields enclosed by brackets "[]" replaced with your own identifying
018 * information:
019 *      Portions Copyright [yyyy] [name of copyright owner]
020 *
021 * CDDL HEADER END
022 *
023 *
024 *      Copyright 2006-2008 Sun Microsystems, Inc.
025 *      Portions Copyright 2014-2015 ForgeRock AS
026 */
027package org.opends.server.util;
028
029import static org.forgerock.util.Reject.*;
030
031import java.util.ArrayList;
032import java.util.Collections;
033import java.util.Iterator;
034import java.util.List;
035import java.util.Map;
036
037import org.opends.server.types.Attribute;
038import org.opends.server.types.AttributeType;
039import org.opends.server.types.DN;
040
041
042
043/**
044 * This class defines a data structure for a change record entry for
045 * an add operation.  It includes a DN and a set of attributes, as well as
046 * methods to decode the entry.
047 */
048@org.opends.server.types.PublicAPI(
049     stability=org.opends.server.types.StabilityLevel.VOLATILE,
050     mayInstantiate=true,
051     mayExtend=false,
052     mayInvoke=true)
053public final class AddChangeRecordEntry extends ChangeRecordEntry
054{
055
056  /**
057   * The entry attributes for this operation.
058   */
059  private final List<Attribute> attributes;
060
061
062
063  /**
064   * Creates a new entry with the provided information.
065   *
066   * @param dn
067   *          The distinguished name for this entry.  It must not be
068   *          <CODE>null</CODE>.
069   * @param attributes
070   *          The entry attributes for this operation.  It must not be
071   *          <CODE>null</CODE>.
072   */
073  public AddChangeRecordEntry(DN dn,
074      Map<AttributeType,List<Attribute>> attributes)
075  {
076    super(dn);
077
078
079    ifNull(attributes);
080
081
082    this.attributes = new ArrayList<>(attributes.size());
083    for (List<Attribute> list : attributes.values())
084    {
085      this.attributes.addAll(list);
086    }
087  }
088
089
090
091  /**
092   * Retrieves the name of the change operation type.
093   *
094   * @return  The name of the change operation type.
095   */
096  public ChangeOperationType getChangeOperationType()
097  {
098    return ChangeOperationType.ADD;
099  }
100
101
102
103  /**
104   * Retrieves the entire set of attributes for this entry.
105   * <p>
106   * The returned list is read-only.
107   *
108   * @return The entire unmodifiable list of attributes for this entry.
109   */
110  public List<Attribute> getAttributes()
111  {
112    return Collections.unmodifiableList(attributes);
113  }
114
115
116
117  /** {@inheritDoc} */
118  @Override
119  public String toString()
120  {
121    StringBuilder buffer = new StringBuilder();
122    buffer.append("AddChangeRecordEntry(dn=\"");
123    buffer.append(getDN());
124    buffer.append("\", attrs={");
125
126    Iterator<Attribute> iterator = attributes.iterator();
127    while (iterator.hasNext())
128    {
129      buffer.append(iterator.next().getName());
130      if (iterator.hasNext())
131      {
132        buffer.append(", ");
133      }
134    }
135    buffer.append("})");
136
137    return buffer.toString();
138  }
139}
140