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.dsmlv2.reponse;
21  
22  
23  import java.util.ArrayList;
24  import java.util.List;
25  
26  import org.apache.directory.api.ldap.model.message.AbstractResponse;
27  import org.apache.directory.api.ldap.model.message.MessageTypeEnum;
28  
29  
30  /**
31   * This class represents the DSML Search Response
32   *
33   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
34   */
35  public class SearchResponse extends AbstractResponse
36  {
37      /** The List of contained Search Result Entries */
38      private List<SearchResultEntryDsml> searchResultEntryList = new ArrayList<SearchResultEntryDsml>();
39  
40      /** The List of contained Search Result References */
41      private List<SearchResultReferenceDsml> searchResultReferenceList = new ArrayList<SearchResultReferenceDsml>();
42  
43      /** The Search Result Done object */
44      private SearchResultDoneDsml searchResultDone;
45  
46  
47      /**
48       * Creates a new instance of SearchResponse.
49       */
50      public SearchResponse()
51      {
52          super( -1, null );
53      }
54  
55  
56      /**
57       * Creates a new instance of SearchResponse.
58       *
59       * @param messageId the response eliciting this Request
60       */
61      public SearchResponse( int messageId )
62      {
63          super( messageId, null );
64      }
65  
66  
67      /**
68       * Adds a Search Result Entry
69       *
70       * @param searchResultEntry
71       *      the Search Result Entry to add
72       * @return
73       *      true (as per the general contract of the Collection.add method)
74       */
75      public boolean addSearchResultEntry( SearchResultEntryDsml searchResultEntry )
76      {
77          return searchResultEntryList.add( searchResultEntry );
78      }
79  
80  
81      /**
82       * Removes a Search Result Entry
83       *
84       * @param searchResultEntry
85       *      the Search Result Entry to remove
86       * @return
87       *      true (as per the general contract of the Collection.remove method)
88       */
89      public boolean removeSearchResultEntry( SearchResultEntryDsml searchResultEntry )
90      {
91          return searchResultEntryList.remove( searchResultEntry );
92      }
93  
94  
95      /**
96       * Gets the Current Search Result Entry
97       * 
98       * @return
99       *      the current Searche Result Entry
100      */
101     public SearchResultEntryDsml getCurrentSearchResultEntry()
102     {
103         if ( searchResultEntryList.size() > 0 )
104         {
105             return searchResultEntryList.get( searchResultEntryList.size() - 1 );
106         }
107         else
108         {
109             return null;
110         }
111     }
112 
113 
114     /**
115      * Gets the Search Result Entry List
116      *
117      * @return
118      *      the Search Result Entry List
119      */
120     public List<SearchResultEntryDsml> getSearchResultEntryList()
121     {
122         return searchResultEntryList;
123     }
124 
125 
126     /**
127      * Adds a Search Result Reference
128      *
129      * @param searchResultReference
130      *      the Search Result Reference to add
131      * @return
132      *      true (as per the general contract of the Collection.add method)
133      */
134     public boolean addSearchResultReference( SearchResultReferenceDsml searchResultReference )
135     {
136         return searchResultReferenceList.add( searchResultReference );
137     }
138 
139 
140     /**
141      * Removes a Search Result Reference
142      *
143      * @param searchResultReference
144      *      the Search Result Reference to remove
145      * @return
146      *      true (as per the general contract of the Collection.remove method)
147      */
148     public boolean removeSearchResultReference( SearchResultReferenceDsml searchResultReference )
149     {
150         return searchResultReferenceList.remove( searchResultReference );
151     }
152 
153 
154     /**
155      * Gets the current Search Result Reference
156      *
157      * @return
158      *      the current Search Result Reference
159      */
160     public SearchResultReferenceDsml getCurrentSearchResultReference()
161     {
162         if ( searchResultReferenceList.size() > 0 )
163         {
164             return searchResultReferenceList.get( searchResultReferenceList.size() - 1 );
165         }
166         else
167         {
168             return null;
169         }
170     }
171 
172 
173     /**
174      * Gets the Search Result Reference List
175      *
176      * @return
177      *      the Search Result Reference List
178      */
179     public List<SearchResultReferenceDsml> getSearchResultReferenceList()
180     {
181         return searchResultReferenceList;
182     }
183 
184 
185     /**
186      * Gets the Search Result Entry
187      * 
188      * @return
189      *      the Search Result Entry
190      */
191     public SearchResultDoneDsml getSearchResultDone()
192     {
193         return searchResultDone;
194     }
195 
196 
197     /**
198      * Sets the Search Result Entry
199      *
200      * @param searchResultDone
201      *      the Search Result Entry to set
202      */
203     public void setSearchResultDone( SearchResultDoneDsml searchResultDone )
204     {
205         this.searchResultDone = searchResultDone;
206     }
207 
208 
209     @Override
210     public MessageTypeEnum getType()
211     {
212         return null;
213     }
214 }