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
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  public void write(ASN1Writer stream) throws IOException
074  {
075    stream.writeOctetString(OP_TYPE_DELETE_REQUEST, dn);
076  }
077
078
079
080  /**
081   * Retrieves the BER type for this protocol op.
082   *
083   * @return  The BER type for this protocol op.
084   */
085  public byte getType()
086  {
087    return OP_TYPE_DELETE_REQUEST;
088  }
089
090
091
092  /**
093   * Retrieves the name for this protocol op type.
094   *
095   * @return  The name for this protocol op type.
096   */
097  public String getProtocolOpName()
098  {
099    return "Delete Request";
100  }
101
102
103  /**
104   * Appends a string representation of this LDAP protocol op to the provided
105   * buffer.
106   *
107   * @param  buffer  The buffer to which the string should be appended.
108   */
109  public void toString(StringBuilder buffer)
110  {
111    buffer.append("DeleteRequest(dn=");
112    buffer.append(dn);
113    buffer.append(")");
114  }
115
116
117
118  /**
119   * Appends a multi-line string representation of this LDAP protocol op to the
120   * provided buffer.
121   *
122   * @param  buffer  The buffer to which the information should be appended.
123   * @param  indent  The number of spaces from the margin that the lines should
124   *                 be indented.
125   */
126  public void toString(StringBuilder buffer, int indent)
127  {
128    StringBuilder indentBuf = new StringBuilder(indent);
129    for (int i=0 ; i < indent; i++)
130    {
131      indentBuf.append(' ');
132    }
133
134    buffer.append(indentBuf);
135    buffer.append("Delete Request");
136    buffer.append(EOL);
137
138    buffer.append(indentBuf);
139    buffer.append("  Entry DN:  ");
140    buffer.append(dn);
141    buffer.append(EOL);
142  }
143}
144