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.shared.dsmlv2.reponse;
021
022
023import java.util.ArrayList;
024import java.util.List;
025
026import org.apache.directory.shared.ldap.model.message.AbstractResponse;
027import org.apache.directory.shared.ldap.model.message.MessageTypeEnum;
028
029
030/**
031 * This class represents the DSML Search Response
032 *
033 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
034 */
035public class SearchResponse extends AbstractResponse
036{
037    /** The List of contained Search Result Entries */
038    private List<SearchResultEntryDsml> searchResultEntryList = new ArrayList<SearchResultEntryDsml>();
039
040    /** The List of contained Search Result References */
041    private List<SearchResultReferenceDsml> searchResultReferenceList = new ArrayList<SearchResultReferenceDsml>();
042
043    /** The Search Result Done object */
044    private SearchResultDoneDsml searchResultDone;
045
046
047    /**
048     * Creates a new instance of SearchResponse.
049     *
050     * @param messageId the response eliciting this Request
051     * @param type the message type of the response
052     */
053    public SearchResponse( int messageId, MessageTypeEnum type )
054    {
055        super( messageId, type );
056    }
057
058
059    /**
060     * Adds a Search Result Entry
061     *
062     * @param searchResultEntry
063     *      the Search Result Entry to add
064     * @return
065     *      true (as per the general contract of the Collection.add method)
066     */
067    public boolean addSearchResultEntry( SearchResultEntryDsml searchResultEntry )
068    {
069        return searchResultEntryList.add( searchResultEntry );
070    }
071
072
073    /**
074     * Gets the Current Search Result Entry
075     * 
076     * @return
077     *      the current Searche Result Entry
078     */
079    public SearchResultEntryDsml getCurrentSearchResultEntry()
080    {
081        if ( searchResultEntryList.size() > 0 )
082        {
083            return searchResultEntryList.get( searchResultEntryList.size() - 1 );
084        }
085        else
086        {
087            return null;
088        }
089    }
090
091
092    /**
093     * Gets the Search Result Entry List
094     *
095     * @return
096     *      the Search Result Entry List
097     */
098    public List<SearchResultEntryDsml> getSearchResultEntryList()
099    {
100        return searchResultEntryList;
101    }
102
103
104    /**
105     * Adds a Search Result Reference
106     *
107     * @param searchResultReference
108     *      the Search Result Reference to add
109     * @return
110     *      true (as per the general contract of the Collection.add method)
111     */
112    public boolean addSearchResultReference( SearchResultReferenceDsml searchResultReference )
113    {
114        return searchResultReferenceList.add( searchResultReference );
115    }
116
117
118    /**
119     * Gets the current Search Result Reference
120     *
121     * @return
122     *      the current Search Result Reference
123     */
124    public SearchResultReferenceDsml getCurrentSearchResultReference()
125    {
126        if ( searchResultReferenceList.size() > 0 )
127        {
128            return searchResultReferenceList.get( searchResultReferenceList.size() - 1 );
129        }
130        else
131        {
132            return null;
133        }
134    }
135
136
137    /**
138     * Gets the Search Result Reference List
139     *
140     * @return
141     *      the Search Result Reference List
142     */
143    public List<SearchResultReferenceDsml> getSearchResultReferenceList()
144    {
145        return searchResultReferenceList;
146    }
147
148
149    /**
150     * Gets the Search Result Entry
151     * 
152     * @return
153     *      the Search Result Entry
154     */
155    public SearchResultDoneDsml getSearchResultDone()
156    {
157        return searchResultDone;
158    }
159
160
161    /**
162     * Sets the Search Result Entry
163     *
164     * @param searchResultDone
165     *      the Search Result Entry to set
166     */
167    public void setSearchResultDone( SearchResultDoneDsml searchResultDone )
168    {
169        this.searchResultDone = searchResultDone;
170    }
171
172
173    @Override
174    public MessageTypeEnum getType()
175    {
176        return null;
177    }
178}