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 */
020 package org.apache.directory.shared.ldap.message;
021
022 import org.apache.directory.shared.ldap.codec.MessageTypeEnum;
023 import org.apache.directory.shared.ldap.message.internal.InternalDeleteRequest;
024 import org.apache.directory.shared.ldap.message.internal.InternalDeleteResponse;
025 import org.apache.directory.shared.ldap.message.internal.InternalResultResponse;
026 import org.apache.directory.shared.ldap.name.DN;
027
028
029 /**
030 * Delete request implementation.
031 *
032 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
033 * @version $Rev: 918756 $
034 */
035 public class DeleteRequestImpl extends AbstractAbandonableRequest implements InternalDeleteRequest
036 {
037 static final long serialVersionUID = 3187847454305567542L;
038
039 /** The distinguished name of the entry to delete */
040 private DN name;
041
042 private InternalDeleteResponse response;
043
044
045 // ------------------------------------------------------------------------
046 // Constructors
047 // ------------------------------------------------------------------------
048
049 /**
050 * Creates a Lockable DeleteRequest implementing object used to delete a
051 * leaf entry from the DIT.
052 *
053 * @param id
054 * the sequential message identifier
055 */
056 public DeleteRequestImpl(final int id)
057 {
058 super( id, TYPE );
059 }
060
061
062 // ------------------------------------------------------------------------
063 // DeleteRequest Interface Method Implementations
064 // ------------------------------------------------------------------------
065
066 /**
067 * Gets the distinguished name of the leaf entry to be deleted by this
068 * request.
069 *
070 * @return the DN of the leaf entry to delete.
071 */
072 public DN getName()
073 {
074 return name;
075 }
076
077
078 /**
079 * Sets the distinguished name of the leaf entry to be deleted by this
080 * request.
081 *
082 * @param name
083 * the DN of the leaf entry to delete.
084 */
085 public void setName( DN name )
086 {
087 this.name = name;
088 }
089
090
091 // ------------------------------------------------------------------------
092 // SingleReplyRequest Interface Method Implementations
093 // ------------------------------------------------------------------------
094
095 /**
096 * Gets the protocol response message type for this request which produces
097 * at least one response.
098 *
099 * @return the message type of the response.
100 */
101 public MessageTypeEnum getResponseType()
102 {
103 return RESP_TYPE;
104 }
105
106
107 /**
108 * The result containing response for this request.
109 *
110 * @return the result containing response for this request
111 */
112 public InternalResultResponse getResultResponse()
113 {
114 if ( response == null )
115 {
116 response = new DeleteResponseImpl( getMessageId() );
117 }
118
119 return response;
120 }
121
122
123 /**
124 * Checks to see if an object is equivalent to this DeleteRequest. First
125 * there's a quick test to see if the obj is the same object as this one -
126 * if so true is returned. Next if the super method fails false is returned.
127 * Then the name of the entry is compared - if not the same false is
128 * returned. Finally the method exists returning true.
129 *
130 * @param obj
131 * the object to test for equality to this
132 * @return true if the obj is equal to this DeleteRequest, false otherwise
133 */
134 public boolean equals( Object obj )
135 {
136 if ( this == obj )
137 {
138 return true;
139 }
140
141 if ( !super.equals( obj ) )
142 {
143 return false;
144 }
145
146 InternalDeleteRequest req = ( InternalDeleteRequest ) obj;
147
148 if ( name != null && req.getName() == null )
149 {
150 return false;
151 }
152
153 if ( name == null && req.getName() != null )
154 {
155 return false;
156 }
157
158 if ( name != null && req.getName() != null )
159 {
160 if ( !name.equals( req.getName() ) )
161 {
162 return false;
163 }
164 }
165
166 return true;
167 }
168
169
170 /**
171 * Return a String representing a DelRequest
172 *
173 * @return A DelRequest String
174 */
175 public String toString()
176 {
177
178 StringBuffer sb = new StringBuffer();
179
180 sb.append( " Del request\n" );
181 sb.append( " Entry : '" ).append( name.toString() ).append( "'\n" );
182
183 return sb.toString();
184 }
185 }