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-2015 ForgeRock AS. 016 */ 017package org.opends.server.protocols.ldap; 018 019 020import java.io.IOException; 021 022import org.forgerock.opendj.io.*; 023import org.forgerock.opendj.ldap.ByteString; 024 025import org.forgerock.i18n.slf4j.LocalizedLogger; 026import static org.opends.server.protocols.ldap.LDAPConstants.*; 027import static org.opends.server.util.ServerConstants.*; 028 029 030/** 031 * This class defines the structures and methods for an LDAP modify DN request 032 * protocol op, which is used to move or rename an entry or subtree within the 033 * Directory Server. 034 */ 035public class ModifyDNRequestProtocolOp 036 extends ProtocolOp 037{ 038 private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); 039 040 /** The current entry DN for this modify DN request. */ 041 private ByteString entryDN; 042 043 /** The new RDN for this modify DN request. */ 044 private ByteString newRDN; 045 046 /** The new superior DN for this modify DN request. */ 047 private ByteString newSuperior; 048 049 /** Indicates whether to delete the current RDN value(s). */ 050 private boolean deleteOldRDN; 051 052 053 054 /** 055 * Creates a new modify DN request protocol op with the provided information. 056 * 057 * @param entryDN The current entry DN for this modify DN request. 058 * @param newRDN The new RDN for this modify DN request. 059 * @param deleteOldRDN Indicates whether to delete the current RDN value(s). 060 */ 061 public ModifyDNRequestProtocolOp(ByteString entryDN, 062 ByteString newRDN, boolean deleteOldRDN) 063 { 064 this.entryDN = entryDN; 065 this.newRDN = newRDN; 066 this.deleteOldRDN = deleteOldRDN; 067 this.newSuperior = null; 068 } 069 070 071 072 /** 073 * Creates a new modify DN request protocol op with the provided information. 074 * 075 * @param entryDN The current entry DN for this modify DN request. 076 * @param newRDN The new RDN for this modify DN request. 077 * @param deleteOldRDN Indicates whether to delete the current RDN value(s). 078 * @param newSuperior The new superior DN for this modify DN request. 079 */ 080 public ModifyDNRequestProtocolOp(ByteString entryDN, 081 ByteString newRDN, boolean deleteOldRDN, 082 ByteString newSuperior) 083 { 084 this.entryDN = entryDN; 085 this.newRDN = newRDN; 086 this.deleteOldRDN = deleteOldRDN; 087 this.newSuperior = newSuperior; 088 } 089 090 091 092 /** 093 * Retrieves the current entry DN for this modify DN request. 094 * 095 * @return The current entry DN for this modify DN request. 096 */ 097 public ByteString getEntryDN() 098 { 099 return entryDN; 100 } 101 102 103 104 /** 105 * Retrieves the new RDN for this modify DN request. 106 * 107 * @return The new RDN for this modify DN request. 108 */ 109 public ByteString getNewRDN() 110 { 111 return newRDN; 112 } 113 114 115 116 /** 117 * Indicates whether the current RDN value(s) should be deleted. 118 * 119 * @return <CODE>true</CODE> if the current RDN value(s) should be deleted, 120 * or <CODE>false</CODE> if not. 121 */ 122 public boolean deleteOldRDN() 123 { 124 return deleteOldRDN; 125 } 126 127 128 129 /** 130 * Retrieves the new superior DN for this modify DN request. 131 * 132 * @return The new superior DN for this modify DN request, or 133 * <CODE>null</CODE> if none was provided. 134 */ 135 public ByteString getNewSuperior() 136 { 137 return newSuperior; 138 } 139 140 141 142 /** 143 * Retrieves the BER type for this protocol op. 144 * 145 * @return The BER type for this protocol op. 146 */ 147 public byte getType() 148 { 149 return OP_TYPE_MODIFY_DN_REQUEST; 150 } 151 152 153 154 /** 155 * Retrieves the name for this protocol op type. 156 * 157 * @return The name for this protocol op type. 158 */ 159 public String getProtocolOpName() 160 { 161 return "Modify DN Request"; 162 } 163 164 /** 165 * Writes this protocol op to an ASN.1 output stream. 166 * 167 * @param stream The ASN.1 output stream to write to. 168 * @throws IOException If a problem occurs while writing to the stream. 169 */ 170 public void write(ASN1Writer stream) throws IOException 171 { 172 stream.writeStartSequence(OP_TYPE_MODIFY_DN_REQUEST); 173 stream.writeOctetString(entryDN); 174 stream.writeOctetString(newRDN); 175 stream.writeBoolean(deleteOldRDN); 176 177 if(newSuperior != null) 178 { 179 stream.writeOctetString(TYPE_MODIFY_DN_NEW_SUPERIOR, newSuperior); 180 } 181 182 stream.writeEndSequence(); 183 } 184 185 186 187 /** 188 * Appends a string representation of this LDAP protocol op to the provided 189 * buffer. 190 * 191 * @param buffer The buffer to which the string should be appended. 192 */ 193 public void toString(StringBuilder buffer) 194 { 195 buffer.append("ModifyDNRequest(dn=").append(entryDN); 196 buffer.append(", newRDN=").append(newRDN); 197 buffer.append(", deleteOldRDN=").append(deleteOldRDN); 198 199 if (newSuperior != null) 200 { 201 buffer.append(", newSuperior=").append(newSuperior); 202 } 203 204 buffer.append(")"); 205 } 206 207 208 209 /** 210 * Appends a multi-line string representation of this LDAP protocol op to the 211 * provided buffer. 212 * 213 * @param buffer The buffer to which the information should be appended. 214 * @param indent The number of spaces from the margin that the lines should 215 * be indented. 216 */ 217 public void toString(StringBuilder buffer, int indent) 218 { 219 StringBuilder indentBuf = new StringBuilder(indent); 220 for (int i=0 ; i < indent; i++) 221 { 222 indentBuf.append(' '); 223 } 224 225 buffer.append(indentBuf); 226 buffer.append("Modify DN Request"); 227 buffer.append(EOL); 228 229 buffer.append(indentBuf); 230 buffer.append(" Entry DN: "); 231 buffer.append(entryDN); 232 buffer.append(EOL); 233 234 buffer.append(indentBuf); 235 buffer.append(" New RDN: "); 236 buffer.append(newRDN); 237 buffer.append(EOL); 238 239 buffer.append(indentBuf); 240 buffer.append(" Delete Old RDN: "); 241 buffer.append(deleteOldRDN); 242 buffer.append(EOL); 243 244 if (newSuperior != null) 245 { 246 buffer.append(indentBuf); 247 buffer.append(" New Superior: "); 248 buffer.append(newSuperior); 249 buffer.append(EOL); 250 } 251 } 252} 253