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 static org.forgerock.util.Reject.*;
020
021import org.forgerock.opendj.ldap.DN;
022import org.forgerock.opendj.ldap.RDN;
023
024
025
026/**
027 * This class defines a data structure for a change record entry for
028 * an modifyDN 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 ModifyDNChangeRecordEntry extends ChangeRecordEntry
037{
038  /** The new RDN. */
039  private final RDN newRDN;
040
041  /** The new superior DN. */
042  private final DN newSuperiorDN;
043
044  /** Delete the old RDN? */
045  private final boolean deleteOldRDN;
046
047
048  /**
049   * Creates a new entry with the provided information.
050   *
051   * @param dn
052   *          The distinguished name for this entry.  It must not be
053   *          <CODE>null</CODE>.
054   * @param newRDN
055   *          The new RDN.  It must not be <CODE>null</CODE>.
056   * @param deleteOldRDN
057   *          Delete the old RDN?
058   * @param newSuperiorDN
059   *          The new superior DN.  It may be <CODE>null</CODE> if the entry is
060   *          not to be moved below a new parent.
061   */
062  public ModifyDNChangeRecordEntry(DN dn, RDN newRDN, boolean deleteOldRDN,
063                                   DN newSuperiorDN)
064  {
065    super(dn);
066
067    ifNull(newRDN);
068
069    this.newSuperiorDN = newSuperiorDN;
070    this.newRDN = newRDN;
071    this.deleteOldRDN = deleteOldRDN;
072  }
073
074
075  /**
076   * Get the new RDN for the requested modify DN operation.
077   *
078   * @return the new RDN.
079   */
080  public RDN getNewRDN()
081  {
082    return newRDN;
083  }
084
085
086  /**
087   * Get the new superior DN for the requested modify DN operation.
088   *
089   * @return the new superior DN, or <CODE>null</CODE> if there is none.
090   */
091  public DN getNewSuperiorDN()
092  {
093    return newSuperiorDN;
094  }
095
096
097  /**
098   * Get the new RDN for the requested modify DN operation.
099   *
100   * @return the new RDN.
101   */
102  public boolean deleteOldRDN()
103  {
104    return deleteOldRDN;
105  }
106
107
108  /**
109   * Retrieves the name of the change operation type.
110   *
111   * @return  The name of the change operation type.
112   */
113  @Override
114  public ChangeOperationType getChangeOperationType()
115  {
116    return ChangeOperationType.MODIFY_DN;
117  }
118
119
120
121  @Override
122  public String toString()
123  {
124    StringBuilder buffer = new StringBuilder();
125    buffer.append("ModifyDNChangeRecordEntry(dn=\"");
126    buffer.append(getDN());
127    buffer.append("\", newRDN=\"");
128    buffer.append(newRDN);
129    buffer.append("\", deleteOldRDN=");
130    buffer.append(deleteOldRDN);
131
132    if (newSuperiorDN != null)
133    {
134      buffer.append(", newSuperior=\"");
135      buffer.append(newSuperiorDN);
136      buffer.append("\"");
137    }
138
139    buffer.append(")");
140
141    return buffer.toString();
142  }
143}
144