001 /*
002 * Copyright 2009-2012 UnboundID Corp.
003 * All Rights Reserved.
004 */
005 /*
006 * Copyright (C) 2009-2012 UnboundID Corp.
007 *
008 * This program is free software; you can redistribute it and/or modify
009 * it under the terms of the GNU General Public License (GPLv2 only)
010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
011 * as published by the Free Software Foundation.
012 *
013 * This program is distributed in the hope that it will be useful,
014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016 * GNU General Public License for more details.
017 *
018 * You should have received a copy of the GNU General Public License
019 * along with this program; if not, see <http://www.gnu.org/licenses>.
020 */
021 package com.unboundid.ldap.protocol;
022
023
024
025 import com.unboundid.asn1.ASN1Buffer;
026 import com.unboundid.asn1.ASN1StreamReader;
027 import com.unboundid.ldap.sdk.LDAPException;
028 import com.unboundid.ldap.sdk.ResultCode;
029 import com.unboundid.util.NotMutable;
030 import com.unboundid.util.InternalUseOnly;
031 import com.unboundid.util.ThreadSafety;
032 import com.unboundid.util.ThreadSafetyLevel;
033
034 import static com.unboundid.ldap.protocol.ProtocolMessages.*;
035 import static com.unboundid.util.Debug.*;
036 import static com.unboundid.util.StaticUtils.*;
037 import static com.unboundid.util.Validator.*;
038
039
040
041 /**
042 * This class provides an implementation of an LDAP delete request protocol op.
043 */
044 @InternalUseOnly()
045 @NotMutable()
046 @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
047 public final class DeleteRequestProtocolOp
048 implements ProtocolOp
049 {
050 /**
051 * The serial version UID for this serializable class.
052 */
053 private static final long serialVersionUID = 1577020640104649789L;
054
055
056
057 // The entry DN for this delete request.
058 private final String dn;
059
060
061
062 /**
063 * Creates a new delete request protocol op with the provided information.
064 *
065 * @param dn The entry DN for this delete request.
066 */
067 public DeleteRequestProtocolOp(final String dn)
068 {
069 this.dn = dn;
070 }
071
072
073
074 /**
075 * Creates a new delete request protocol op read from the provided ASN.1
076 * stream reader.
077 *
078 * @param reader The ASN.1 stream reader from which to read the delete
079 * request protocol op.
080 *
081 * @throws LDAPException If a problem occurs while reading or parsing the
082 * delete request.
083 */
084 DeleteRequestProtocolOp(final ASN1StreamReader reader)
085 throws LDAPException
086 {
087 try
088 {
089 dn = reader.readString();
090 ensureNotNull(dn);
091 }
092 catch (Exception e)
093 {
094 debugException(e);
095
096 throw new LDAPException(ResultCode.DECODING_ERROR,
097 ERR_DELETE_REQUEST_CANNOT_DECODE.get(getExceptionMessage(e)), e);
098 }
099 }
100
101
102
103 /**
104 * Retrieves the target entry DN for this delete request.
105 *
106 * @return The target entry DN for this delete request.
107 */
108 public String getDN()
109 {
110 return dn;
111 }
112
113
114
115 /**
116 * {@inheritDoc}
117 */
118 public byte getProtocolOpType()
119 {
120 return LDAPMessage.PROTOCOL_OP_TYPE_DELETE_REQUEST;
121 }
122
123
124
125 /**
126 * {@inheritDoc}
127 */
128 public void writeTo(final ASN1Buffer buffer)
129 {
130 buffer.addOctetString(LDAPMessage.PROTOCOL_OP_TYPE_DELETE_REQUEST, dn);
131 }
132
133
134
135 /**
136 * Retrieves a string representation of this protocol op.
137 *
138 * @return A string representation of this protocol op.
139 */
140 @Override()
141 public String toString()
142 {
143 final StringBuilder buffer = new StringBuilder();
144 toString(buffer);
145 return buffer.toString();
146 }
147
148
149
150 /**
151 * {@inheritDoc}
152 */
153 public void toString(final StringBuilder buffer)
154 {
155 buffer.append("DeleteRequestProtocolOp(dn='");
156 buffer.append(dn);
157 buffer.append("')");
158 }
159 }