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