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