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 2010 Sun Microsystems, Inc.
025 *      Portions Copyright 2012-2015 ForgeRock AS
026 */
027package org.opends.server.replication.plugin;
028
029import org.opends.server.replication.common.CSN;
030import org.opends.server.replication.protocol.ModifyDNMsg;
031import org.opends.server.replication.protocol.ReplicationMsg;
032import org.opends.server.types.DN;
033import org.opends.server.types.Entry;
034
035/**
036 * This class if used to build fake MODDN Operation from the historical
037 * information that stay in the entry in the database.
038 *
039 * This is useful when a LDAP server can't find a LDAP server that
040 * has already seen all its changes and therefore need to retransmit them.
041 */
042public class FakeModdnOperation extends FakeOperation
043{
044  private Entry entry;
045
046  /**
047   * Creates a new FakeModdnOperation.
048   *
049   * @param csn     The CSN when the entry was last renamed.
050   * @param entry   The entry that the MODDN operation will rename.
051   */
052  public FakeModdnOperation(CSN csn, Entry entry)
053  {
054    super(csn);
055    this.entry = entry;
056  }
057
058  /** {@inheritDoc} */
059  @Override
060  public ReplicationMsg generateMessage()
061  {
062    DN dn = entry.getName();
063    return new ModifyDNMsg(dn, getCSN(),
064        EntryHistorical.getEntryUUID(entry),
065        LDAPReplicationDomain.findEntryUUID(dn.parent()),
066        false, dn.parent().toString(), dn.rdn().toString());
067  }
068}