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.protocols.ldap; 018 019 020 021import org.forgerock.opendj.io.ASN1Writer; 022import org.forgerock.opendj.ldap.ByteString; 023 024import org.forgerock.i18n.slf4j.LocalizedLogger; 025import static org.opends.server.protocols.ldap.LDAPConstants.*; 026import static org.opends.server.util.ServerConstants.*; 027 028import java.io.IOException; 029 030 031/** 032 * This class defines the structures and methods for an LDAP delete request 033 * protocol op, which is used to remove an entry from the Directory Server. 034 */ 035public class DeleteRequestProtocolOp 036 extends ProtocolOp 037{ 038 private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); 039 040 /** The DN for this delete request. */ 041 private ByteString dn; 042 043 044 045 /** 046 * Creates a new delete request protocol op with the specified DN. 047 * 048 * @param dn The DN for this delete request protocol op. 049 */ 050 public DeleteRequestProtocolOp(ByteString dn) 051 { 052 this.dn = dn; 053 } 054 055 056 057 /** 058 * Retrieves the DN for this delete request. 059 * 060 * @return The DN for this delete request. 061 */ 062 public ByteString getDN() 063 { 064 return dn; 065 } 066 067 /** 068 * Writes this protocol op to an ASN.1 output stream. 069 * 070 * @param stream The ASN.1 output stream to write to. 071 * @throws IOException If a problem occurs while writing to the stream. 072 */ 073 @Override 074 public void write(ASN1Writer stream) throws IOException 075 { 076 stream.writeOctetString(OP_TYPE_DELETE_REQUEST, dn); 077 } 078 079 080 081 /** 082 * Retrieves the BER type for this protocol op. 083 * 084 * @return The BER type for this protocol op. 085 */ 086 @Override 087 public byte getType() 088 { 089 return OP_TYPE_DELETE_REQUEST; 090 } 091 092 093 094 /** 095 * Retrieves the name for this protocol op type. 096 * 097 * @return The name for this protocol op type. 098 */ 099 @Override 100 public String getProtocolOpName() 101 { 102 return "Delete Request"; 103 } 104 105 106 /** 107 * Appends a string representation of this LDAP protocol op to the provided 108 * buffer. 109 * 110 * @param buffer The buffer to which the string should be appended. 111 */ 112 @Override 113 public void toString(StringBuilder buffer) 114 { 115 buffer.append("DeleteRequest(dn="); 116 buffer.append(dn); 117 buffer.append(")"); 118 } 119 120 121 122 /** 123 * Appends a multi-line string representation of this LDAP protocol op to the 124 * provided buffer. 125 * 126 * @param buffer The buffer to which the information should be appended. 127 * @param indent The number of spaces from the margin that the lines should 128 * be indented. 129 */ 130 @Override 131 public void toString(StringBuilder buffer, int indent) 132 { 133 StringBuilder indentBuf = new StringBuilder(indent); 134 for (int i=0 ; i < indent; i++) 135 { 136 indentBuf.append(' '); 137 } 138 139 buffer.append(indentBuf); 140 buffer.append("Delete Request"); 141 buffer.append(EOL); 142 143 buffer.append(indentBuf); 144 buffer.append(" Entry DN: "); 145 buffer.append(dn); 146 buffer.append(EOL); 147 } 148} 149