001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020package org.apache.directory.api.ldap.model.message; 021 022 023import org.apache.directory.api.ldap.model.name.Dn; 024 025 026/** 027 * Delete request implementation. 028 * 029 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 030 */ 031public class DeleteRequestImpl extends AbstractAbandonableRequest implements DeleteRequest 032{ 033 static final long serialVersionUID = 3187847454305567542L; 034 035 /** The distinguished name of the entry to delete */ 036 private Dn name; 037 038 /** The deleteResponse associated with this request */ 039 private DeleteResponse response; 040 041 042 // ------------------------------------------------------------------------ 043 // Constructors 044 // ------------------------------------------------------------------------ 045 /** 046 * Creates a DeleteRequest implementing object used to delete a 047 * leaf entry from the DIT. 048 */ 049 public DeleteRequestImpl() 050 { 051 super( -1, MessageTypeEnum.DEL_REQUEST ); 052 } 053 054 055 // ------------------------------------------------------------------------ 056 // DeleteRequest Interface Method Implementations 057 // ------------------------------------------------------------------------ 058 059 /** 060 * Gets the distinguished name of the leaf entry to be deleted by this 061 * request. 062 * 063 * @return the Dn of the leaf entry to delete. 064 */ 065 public Dn getName() 066 { 067 return name; 068 } 069 070 071 /** 072 * {@inheritDoc} 073 */ 074 public DeleteRequest setName( Dn name ) 075 { 076 this.name = name; 077 078 return this; 079 } 080 081 082 /** 083 * {@inheritDoc} 084 */ 085 public DeleteRequest setMessageId( int messageId ) 086 { 087 super.setMessageId( messageId ); 088 089 return this; 090 } 091 092 093 /** 094 * {@inheritDoc} 095 */ 096 public DeleteRequest addControl( Control control ) 097 { 098 return ( DeleteRequest ) super.addControl( control ); 099 } 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}