View Javadoc
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      @Override
66      public Dn getName()
67      {
68          return name;
69      }
70  
71  
72      /**
73       * {@inheritDoc}
74       */
75      @Override
76      public DeleteRequest setName( Dn name )
77      {
78          this.name = name;
79  
80          return this;
81      }
82  
83  
84      /**
85       * {@inheritDoc}
86       */
87      @Override
88      public DeleteRequest setMessageId( int messageId )
89      {
90          super.setMessageId( messageId );
91  
92          return this;
93      }
94  
95  
96      /**
97       * {@inheritDoc}
98       */
99      @Override
100     public DeleteRequest addControl( Control control )
101     {
102         return ( DeleteRequest ) super.addControl( control );
103     }
104 
105 
106     /**
107      * {@inheritDoc}
108      */
109     @Override
110     public DeleteRequest addAllControls( Control[] controls )
111     {
112         return ( DeleteRequest ) super.addAllControls( controls );
113     }
114 
115 
116     /**
117      * {@inheritDoc}
118      */
119     @Override
120     public DeleteRequest removeControl( Control control )
121     {
122         return ( DeleteRequest ) super.removeControl( control );
123     }
124 
125 
126     // ------------------------------------------------------------------------
127     // SingleReplyRequest Interface Method Implementations
128     // ------------------------------------------------------------------------
129 
130     /**
131      * Gets the protocol response message type for this request which produces
132      * at least one response.
133      * 
134      * @return the message type of the response.
135      */
136     @Override
137     public MessageTypeEnum getResponseType()
138     {
139         return MessageTypeEnum.DEL_RESPONSE;
140     }
141 
142 
143     /**
144      * The result containing response for this request.
145      * 
146      * @return the result containing response for this request
147      */
148     @Override
149     public DeleteResponse getResultResponse()
150     {
151         if ( response == null )
152         {
153             response = new DeleteResponseImpl( getMessageId() );
154         }
155 
156         return response;
157     }
158 
159 
160     /**
161      * {@inheritDoc}
162      */
163     @Override
164     public int hashCode()
165     {
166         int hash = 37;
167 
168         if ( name != null )
169         {
170             hash = hash * 17 + name.hashCode();
171         }
172 
173         hash = hash * 17 + super.hashCode();
174 
175         return hash;
176     }
177 
178 
179     /**
180      * Checks to see if an object is equivalent to this DeleteRequest. First
181      * there's a quick test to see if the obj is the same object as this one -
182      * if so true is returned. Next if the super method fails false is returned.
183      * Then the name of the entry is compared - if not the same false is
184      * returned. Finally the method exists returning true.
185      * 
186      * @param obj the object to test for equality to this
187      * @return true if the obj is equal to this DeleteRequest, false otherwise
188      */
189     @Override
190     public boolean equals( Object obj )
191     {
192         if ( this == obj )
193         {
194             return true;
195         }
196 
197         if ( !super.equals( obj ) )
198         {
199             return false;
200         }
201 
202         DeleteRequest req = ( DeleteRequest ) obj;
203 
204         if ( name != null && req.getName() == null )
205         {
206             return false;
207         }
208 
209         if ( name == null && req.getName() != null )
210         {
211             return false;
212         }
213 
214         if ( ( name != null ) && ( req.getName() != null ) && !name.equals( req.getName() ) )
215         {
216             return false;
217         }
218 
219         return true;
220     }
221 
222 
223     /**
224      * Return a String representing a DelRequest
225      * 
226      * @return A DelRequest String
227      */
228     @Override
229     public String toString()
230     {
231 
232         StringBuilder sb = new StringBuilder();
233 
234         sb.append( "    Del request\n" );
235         sb.append( "        Entry : '" ).append( name.toString() ).append( "'\n" );
236         sb.append( super.toString() );
237 
238         return super.toString( sb.toString() );
239     }
240 }