1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 * 19 */ 20 package org.apache.directory.api.ldap.model.message; 21 22 23 import org.apache.directory.api.ldap.model.name.Dn; 24 25 26 /** 27 * Delete request implementation. 28 * 29 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 30 */ 31 public class DeleteRequestImpl extends AbstractAbandonableRequest implements DeleteRequest 32 { 33 static final long serialVersionUID = 3187847454305567542L; 34 35 /** The distinguished name of the entry to delete */ 36 private Dn name; 37 38 /** The deleteResponse associated with this request */ 39 private DeleteResponse response; 40 41 42 // ------------------------------------------------------------------------ 43 // Constructors 44 // ------------------------------------------------------------------------ 45 /** 46 * Creates a DeleteRequest implementing object used to delete a 47 * leaf entry from the DIT. 48 */ 49 public DeleteRequestImpl() 50 { 51 super( -1, MessageTypeEnum.DEL_REQUEST ); 52 } 53 54 55 // ------------------------------------------------------------------------ 56 // DeleteRequest Interface Method Implementations 57 // ------------------------------------------------------------------------ 58 59 /** 60 * Gets the distinguished name of the leaf entry to be deleted by this 61 * request. 62 * 63 * @return the Dn of the leaf entry to delete. 64 */ 65 public Dn getName() 66 { 67 return name; 68 } 69 70 71 /** 72 * {@inheritDoc} 73 */ 74 public DeleteRequest setName( Dn name ) 75 { 76 this.name = name; 77 78 return this; 79 } 80 81 82 /** 83 * {@inheritDoc} 84 */ 85 public DeleteRequest setMessageId( int messageId ) 86 { 87 super.setMessageId( messageId ); 88 89 return this; 90 } 91 92 93 /** 94 * {@inheritDoc} 95 */ 96 public DeleteRequest addControl( Control control ) 97 { 98 return ( DeleteRequest ) super.addControl( control ); 99 } 100 101 102 /** 103 * {@inheritDoc} 104 */ 105 public DeleteRequest addAllControls( Control[] controls ) 106 { 107 return ( DeleteRequest ) super.addAllControls( controls ); 108 } 109 110 111 /** 112 * {@inheritDoc} 113 */ 114 public DeleteRequest removeControl( Control control ) 115 { 116 return ( DeleteRequest ) super.removeControl( control ); 117 } 118 119 120 // ------------------------------------------------------------------------ 121 // SingleReplyRequest Interface Method Implementations 122 // ------------------------------------------------------------------------ 123 124 /** 125 * Gets the protocol response message type for this request which produces 126 * at least one response. 127 * 128 * @return the message type of the response. 129 */ 130 public MessageTypeEnum getResponseType() 131 { 132 return MessageTypeEnum.DEL_RESPONSE; 133 } 134 135 136 /** 137 * The result containing response for this request. 138 * 139 * @return the result containing response for this request 140 */ 141 public DeleteResponse getResultResponse() 142 { 143 if ( response == null ) 144 { 145 response = new DeleteResponseImpl( getMessageId() ); 146 } 147 148 return response; 149 } 150 151 152 /** 153 * {@inheritDoc} 154 */ 155 @Override 156 public int hashCode() 157 { 158 int hash = 37; 159 160 if ( name != null ) 161 { 162 hash = hash * 17 + name.hashCode(); 163 } 164 165 hash = hash * 17 + super.hashCode(); 166 167 return hash; 168 } 169 170 171 /** 172 * Checks to see if an object is equivalent to this DeleteRequest. First 173 * there's a quick test to see if the obj is the same object as this one - 174 * if so true is returned. Next if the super method fails false is returned. 175 * Then the name of the entry is compared - if not the same false is 176 * returned. Finally the method exists returning true. 177 * 178 * @param obj the object to test for equality to this 179 * @return true if the obj is equal to this DeleteRequest, false otherwise 180 */ 181 public boolean equals( Object obj ) 182 { 183 if ( this == obj ) 184 { 185 return true; 186 } 187 188 if ( !super.equals( obj ) ) 189 { 190 return false; 191 } 192 193 DeleteRequest req = ( DeleteRequest ) obj; 194 195 if ( name != null && req.getName() == null ) 196 { 197 return false; 198 } 199 200 if ( name == null && req.getName() != null ) 201 { 202 return false; 203 } 204 205 if ( ( name != null ) && ( req.getName() != null ) && !name.equals( req.getName() ) ) 206 { 207 return false; 208 } 209 210 return true; 211 } 212 213 214 /** 215 * Return a String representing a DelRequest 216 * 217 * @return A DelRequest String 218 */ 219 public String toString() 220 { 221 222 StringBuilder sb = new StringBuilder(); 223 224 sb.append( " Del request\n" ); 225 sb.append( " Entry : '" ).append( name.toString() ).append( "'\n" ); 226 sb.append( super.toString() ); 227 228 return super.toString( sb.toString() ); 229 } 230 }