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